From 4cff3cbaadd5a5b30f001f71a251ee38f90279ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Logerais=20=28Numericable=20-=20Ing=C3=A9nierie?= =?UTF-8?q?=20Syst=C3=A8me=29?= Date: Fri, 14 Jun 2013 16:59:16 +0200 Subject: [PATCH] Updated some libs --- libs/password.bash | 4 ++++ libs/virtualization.bash | 38 ++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/libs/password.bash b/libs/password.bash index c3fe782..d0ec4f6 100755 --- a/libs/password.bash +++ b/libs/password.bash @@ -3,8 +3,10 @@ encpasswd() { local password_clear=$1 local password_md5hash=$(openssl passwd -1 $password_clear) + local password_sha1=$(echo -n $password_clear | openssl dgst -sha1) echo "Password : $password_clear" echo "MD5HASH : $password_md5hash" + echo "SHA1 : $password_sha1" } genpasswd() { @@ -12,6 +14,8 @@ genpasswd() { [ "$l" == "" ] && l=12 local password_clear=$(tr -dc A-Za-z0-9_ < /dev/urandom | head -c ${l} | xargs) local password_md5hash=$(openssl passwd -1 $password_clear) + local password_sha1=$(echo -n $password_clear | openssl dgst -sha1) echo "Password : $password_clear" echo "MD5HASH : $password_md5hash" + echo "SHA1 : $password_sha1" } diff --git a/libs/virtualization.bash b/libs/virtualization.bash index ee1e963..c31b798 100755 --- a/libs/virtualization.bash +++ b/libs/virtualization.bash @@ -1,6 +1,6 @@ #!/bin/bash -hypervisor_connect() { +hypervisor_connect() { if [ -e "${1}" ]; then echo "Usage : $0 hypervisor_name_or_ip"; return 1; fi hypervisor=${1} @@ -11,7 +11,7 @@ hypervisor_connect() { } -hypervisor_command() { +hypervisor_command() { if [ -e "${1}" ]; then echo "Usage : $0 hypervisor_name_or_ip"; return 1; fi hypervisor=${1} @@ -23,7 +23,7 @@ hypervisor_command() { } -vm_create() { +vm_create() { if [ $# -ne 5 ]; then echo "Usage : $0 hypervisor_name_or_ip vm_name vm_ram_size vm_disk_size vm_mac"; return 1; fi hypervisor=${1} @@ -52,7 +52,7 @@ vm_create() { } -vm_start() { +vm_start() { if [ $# -ne 2 ]; then echo "Usage : $0 hypervisor_name_or_ip vm_name"; return 1; fi hypervisor=${1} @@ -60,11 +60,11 @@ vm_start() { echo echo "Trying to start ${name} on ${hypervisor} with virsh" - virsh --connect=qemu+ssh://${USER}@${hypervisor}/system start ${name} + virsh --connect=qemu+ssh://${USER}@${hypervisor}/system start ${name} } -vm_stop() { +vm_stop() { if [ $# -ne 2 ]; then echo "Usage : $0 hypervisor_name_or_ip vm_name"; return 1; fi hypervisor=${1} @@ -72,11 +72,11 @@ vm_stop() { echo echo "Trying to stop ${name} on ${hypervisor} with virsh" - virsh --connect=qemu+ssh://${USER}@${hypervisor}/system shutdown ${name} + virsh --connect=qemu+ssh://${USER}@${hypervisor}/system shutdown ${name} } -vm_destroy() { +vm_destroy() { if [ $# -ne 2 ]; then echo "Usage : $0 hypervisor_name_or_ip vm_name"; return 1; fi hypervisor=${1} @@ -84,11 +84,11 @@ vm_destroy() { echo echo "Trying to destroy ${name} on ${hypervisor} with virsh" - virsh --connect=qemu+ssh://${USER}@${hypervisor}/system destroy ${name} + virsh --connect=qemu+ssh://${USER}@${hypervisor}/system destroy ${name} } -vm_connect() { +vm_connect() { if [ $# -ne 2 ]; then echo "Usage : $0 hypervisor_name_or_ip vm_name"; return 1; fi hypervisor=${1} @@ -96,28 +96,29 @@ vm_connect() { echo echo "Trying to connect to ${name} on ${hypervisor} with virsh" - virsh --connect=qemu+ssh://${USER}@${hypervisor}/system ttyconsole ${name} - virsh --connect=qemu+ssh://${USER}@${hypervisor}/system console ${name} + virsh --connect=qemu+ssh://${USER}@${hypervisor}/system ttyconsole ${name} + virsh --connect=qemu+ssh://${USER}@${hypervisor}/system console ${name} } #### A tester -vm_change_bridge() { +vm_change_bridge() { - if [ $# -ne 2 ]; then echo "Usage : $0 hypervisor_name_or_ip vm_name vm_mac vm_new_bridge"; return 1; fi + if [ $# -ne 4 ]; then echo "Usage : $0 hypervisor_name_or_ip vm_name vm_mac vm_new_bridge"; return 1; fi hypervisor=${1} name=${2} mac=${3} bridge=${4} - #domiflist ${name} - #detach-interface --config --domain ${name} --type bridge --mac ${mac} - #attach-interface --config --domain ${name} --type bridge --mac ${mac} --source ${bridge} + virsh --connect=qemu+ssh://${USER}@${hypervisor}/system domiflist ${name} + virsh --connect=qemu+ssh://${USER}@${hypervisor}/system detach-interface --config --domain ${name} --type bridge --mac ${mac} + virsh --connect=qemu+ssh://${USER}@${hypervisor}/system attach-interface --config --domain ${name} --type bridge --mac ${mac} --source ${bridge} + virsh --connect=qemu+ssh://${USER}@${hypervisor}/system domiflist ${name} } #### A tester -vm_add_data_disk() { +vm_add_data_disk() { if [ $# -ne 2 ]; then echo "Usage : $0 hypervisor_name_or_ip vm_name size"; return 1; fi hypervisor=${1} @@ -150,3 +151,4 @@ complete -W "$(_hypervisors)" vm_create complete -W "$(_hypervisors)" vm_start complete -W "$(_hypervisors)" vm_stop complete -W "$(_hypervisors)" vm_connect +complete -W "$(_hypervisors)" vm_change_bridge