Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ OPTIONS
-L Location of VMs (default: $HOME/virt/vms)
-m Memory Size (MB) (default: 1024)
-M Mac address (default: auto-assigned)
-n Network name (default: none, overrides -b parameter)
-p Console port (default: auto)
-s Custom shell script
-t Linux Distribution (default: centos8)
Expand Down
20 changes: 18 additions & 2 deletions kvm-install-vm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function usage_subcommand ()
printf " -L Location of VMs (default: $HOME/virt/vms)\n"
printf " -m Memory Size (MB) (default: 1024)\n"
printf " -M Mac address (default: auto-assigned)\n"
printf " -n Network name (default: none, overrides -b parameter)\n"
printf " -p Console port (default: auto)\n"
printf " -s Custom shell script\n"
printf " -t Linux Distribution (default: centos8)\n"
Expand Down Expand Up @@ -682,9 +683,19 @@ _EOF_
--target=${VMDIR}/${VMNAME} \
|| die "Could not create storage pool."

if [ -n "${NETWORK_NAME}" ]
then
NETWORK_PARAMS="$(param network ${NETWORK_NAME})"
elif [ -n "${BRIDGE}" ]
then
NETWORK_PARAMS="$(param bridge ${BRIDGE})"
else
NETWORK_PARAMS="none"
fi

# Add custom MAC Address if specified
NETWORK_PARAMS="$(join ',' \
$(param bridge ${BRIDGE}) \
${NETWORK_PARAMS} \
$(param model ${NETWORK_MODEL}) \
$(param mac ${MACADDRESS}) \
${NETWORK_EXTRA})"
Expand Down Expand Up @@ -757,6 +768,10 @@ _EOF_

MAC=$(virsh dumpxml ${VMNAME} | awk -F\' '/mac address/ {print $2}')
output "MAC address: ${MAC}"

if [ -n "${NETWORK_NAME}" ]; then
BRIDGE=$(virsh net-info "${NETWORK_NAME}" | awk -F':' '/Bridge/ {print $2}' | tr -d ' ')
fi

if [ -f "/var/lib/libvirt/dnsmasq/${BRIDGE}.status" ]
then
Expand Down Expand Up @@ -876,7 +891,7 @@ function set_custom_defaults ()
function create ()
{
# Parse command line arguments
while getopts ":b:c:d:D:f:g:i:k:l:L:m:M:p:s:t:T:u:ahynv" opt
while getopts ":b:c:d:D:f:g:i:k:l:L:m:M:n:p:s:t:T:u:ahynv" opt
do
case "$opt" in
a ) AUTOSTART=${OPTARG} ;;
Expand All @@ -892,6 +907,7 @@ function create ()
L ) VMDIR="${OPTARG}" ;;
m ) MEMORY="${OPTARG}" ;;
M ) MACADDRESS="${OPTARG}" ;;
n ) NETWORK_NAME="${OPTARG}" ;;
p ) PORT="${OPTARG}" ;;
s ) SCRIPTNAME="${OPTARG}" ;;
t ) DISTRO="${OPTARG}" ;;
Expand Down