diff options
author | Aaron Ball <nullspoon@iohq.net> | 2016-02-21 15:46:41 -0700 |
---|---|---|
committer | Aaron Ball <nullspoon@iohq.net> | 2016-02-21 15:46:41 -0700 |
commit | ff3b57174c71c0d284d624a044810144c059ec2e (patch) | |
tree | d0b5991b3b03c5629cc3388c67aaf20c2b176dde | |
parent | 06a3a4fb343ed6c2304ba90d0218057edfa53d37 (diff) | |
download | vmgr-ff3b57174c71c0d284d624a044810144c059ec2e.tar.gz vmgr-ff3b57174c71c0d284d624a044810144c059ec2e.tar.xz |
Added many function comments
Also cleaned up old commented out code that is no longer in use.
-rwxr-xr-x | vmgr | 64 |
1 files changed, 45 insertions, 19 deletions
@@ -72,6 +72,12 @@ function log { # # Executes virt-install with the specified arguments. # +# @param name Name of the virtual machine (what displays in libvirt utils) +# @param disk Path to the disk file +# @param mac Mac address of the primary nic (eth0) +# Note that this is important as it will determine the ip address +# of the system. +# function install { local name=${1} local disk=${2} @@ -97,16 +103,18 @@ function install { } - # # Clones a disk. Supports two speed options, fast or small. # Fast just does a simple copy of the disk from source to destination. # Small uses qemu-img to recompress the disk from source to destination to save # space. # -# @param src -# @param dest -# @param speed +# @param src Path to source disk to clone +# @param dest Path to location that the source disk will clone to +# @param speed Speed of conversion (options: small, fast). +# "fast" uses cp, but is less storage-conscious. +# "small" uses qemu-img convert, which is slower, but smaller as +# it recompresses the disk. # function clone_disk { local src=${1} @@ -132,6 +140,11 @@ function clone_disk { # Reserves an ip on the specified network for mac address ${mac}. Also inserts # dns entry for the specified name. # +# @param network Virsh network name of reservation (for virsh net-*) +# @param name Name of the host (this will resolve in dns) +# @param mac Mac address to reserve the ip with +# @param ip IP address to reserve +# function net_reserve_ip { local network=${1} local name=${2} @@ -152,8 +165,14 @@ function net_reserve_ip { fi } + +# +# Deletes an ip address reservation for the specified network. # -# TODO +# @param network Virsh network name of reservation (for virsh net-*) +# @param name Name of the host (this is what resolves in dns) +# @param mac Mac address the IP is reserved to +# @param ip IP address that will be deleted # function net_rm_reservation { local network=${1} @@ -172,10 +191,12 @@ function net_rm_reservation { } - # # Determines the next available vm index based on network mac address usage. # +# @param network +# @param prefixmac +# function get_next_index { local network=${1} local prefixmac=${2} @@ -188,7 +209,6 @@ function get_next_index { # For each index, check if the mac address exists while [ $(echo ${hostxml} | grep "mac='${prefixmac}${index}'" -c ) -ne 0 ]; do - #echo "Host exists at ${macprefix}${index}" # Use this fancy printf statement to ensure we're always zero padded. index=$(printf "%0*d" 2 $((${index} + 1))) done @@ -199,7 +219,9 @@ function get_next_index { # -# TODO +# Parses a hostname or fqdn to determine a host's 2-digit index (00-99). +# +# @param name Host name or fqdn to parse for host index # function get_index_from_name { local name=${1} @@ -220,7 +242,15 @@ function get_index_from_name { } - +# +# Creates a new vm from the specified template. Seamlessly handles host index +# increment (appended to prefix). Also handles mac address generation, ip +# reservation and assignment, and disk cloning from template. +# +# @param prefix Host prefix (index will be appended to this to make hostname) +# @param template Path to disk template the vm will be created from +# @param domain Domain to be appended to the hostname. Defaults to empty. +# function vm_new { [[ -z ${1} ]] && log fatal "A prefix name for the new vm is required." [[ -z ${2} ]] && log fatal "A template disk path is required." @@ -236,14 +266,6 @@ function vm_new { local name="${prefix}${next}${domain}" local disk="${name}.sda.qcow2" - # echo -e "VM Variables:\n-------------" - # echo -e " \e[1mmac\e[0m: ${mac}" - # echo -e " \e[1mip\e[0m: ${ip}" - # echo -e " \e[1mname\e[0m: ${name}" - # echo -e " \e[1mdisk\e[0m: ${disk}" - # echo -e " \e[1mtemplate\e[0m: ${template}" - # echo - # Clone the disk log info "Cloning disk from ${template} to ${disk}" clone_disk ${template} ${disk} 'fast' @@ -255,7 +277,12 @@ function vm_new { install ${name} ${disk} ${mac} } - +# +# Shuts down and deletes specified vm Also removes network ip address +# reservation as well as all related storage. +# +# @param name Name of vm to be destroyed +# function vm_rm { [[ -z ${1} ]] && echo "Please a vm name to be deleted." && exit 1 @@ -303,7 +330,6 @@ function vm_rm { } - # # Lists all VMs currently running, their expected ips, and mac addresses. # |