diff options
-rwxr-xr-x | virtualenv/virt | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/virtualenv/virt b/virtualenv/virt index 46c56dc..b88d04e 100755 --- a/virtualenv/virt +++ b/virtualenv/virt @@ -28,6 +28,10 @@ get_XML_attribute() { /usr/bin/virsh dumpxml "$domain" \ | /usr/bin/xmlstarlet sel -t -m /domain/"$object" -v @"$attribute" } +add_net_section() { + local net="${3:-$network}" section="$1" xml="$2" + /usr/bin/virsh net-update "$net" add "$section" --xml "$xml" --live --config +} doesExist() { /usr/bin/virsh -r list --all --name | grep -qxF "$1" @@ -78,17 +82,37 @@ install() { # TODO: the bus should be chosen at random among sata,ide,scsi,usb # TODO: test EFI: http://www.linux-kvm.org/page/OVMF + local network=default /usr/bin/virt-install -q \ --name "$name" \ --arch "$ARCH" \ --ram 128 \ --cdrom "$cdrom" \ --disk "$disk",cache=writeback,bus=sata \ - --network network=default \ + --network network=$network \ --graphics spice + # Attribute the next available IP. You may also want to add a domain + # section, e.g., <domain name='libvirt.example.org'/>, and prepend + # the DNS IP to /etc/resolv.conf. + # Cf. http://libvirt.org/formatnetwork.html + local mac ip + mac=$(get_XML_attribute "$name" devices/interface/mac address) + ip=$( /usr/bin/virsh net-dumpxml $network \ + | /usr/bin/xmlstarlet sel -t -m /network/ip/dhcp/host -n -v @ip \ + | sed '/^\s*$/d' \ + | sort -n \ + | tail -1 ) + [ -n "$ip" ] || \ + ip=$( /usr/bin/virsh net-dumpxml $network \ + | /usr/bin/xmlstarlet sel -t -m /network/ip -v @address ) + ip=${ip%.*}.$(( 1 + ${ip##*.} )) + add_net_section ip-dhcp-host "<host mac='$mac' name='$name' ip='$ip'/>" + add_net_section dns-host "<host ip='$ip'><hostname>$name</hostname></host>" + cat >&2 <<- EOF - Domain '$name' has been created. As you can see in + Domain '$name' has been created, and has been attributed the IP $ip. + As you can see in virsh list |