Added dhcpserver command

This commit is contained in:
2015-04-09 21:03:03 +02:00
parent 6d1f1d3e5e
commit 7df3e8c621
2 changed files with 81 additions and 2 deletions

1
README
View File

@@ -17,6 +17,7 @@ Current version of script was written and tested against VBoxManage in version
- createhd - createhd
- createvm - createvm
- debugvm - debugvm
- dhcpserver
- list - list
- showhdinfo - showhdinfo
- showvminfo - showvminfo

View File

@@ -7,8 +7,6 @@
# #
# [1] Sebastian T. Hafner <sonix@own-hero.net> # [1] Sebastian T. Hafner <sonix@own-hero.net>
# #
#
# [ ] dhcpserver
# [ ] discardstate # [ ] discardstate
# [ ] export # [ ] export
# [ ] extpack # [ ] extpack
@@ -163,6 +161,44 @@ _VBoxManage() {
done done
} }
_dhcp_comp() {
local cur=$1
local list
local item
list=$(VBoxManage list dhcpservers | \
grep NetworkName: | \
sed 's/NetworkName:\s\+//' | \
sed 's/\s/\\ /g'| \
tr '\n' '|' | \
sed 's/|$//')
IFS='|' read -ra list <<< "$list"
for item in "${list[@]}"
do
[[ ${item^^} == ${cur^^}* ]] && COMPREPLY+=("$item")
done
}
_hostonlyif_comp() {
local cur=$1
local list
local item
list=$(VBoxManage list hostonlyifs | \
egrep ^Name: | \
sed 's/Name:\s\+//' | \
sed 's/\s/\\ /g'| \
tr '\n' '|' | \
sed 's/|$//')
IFS='|' read -ra list <<< "$list"
for item in "${list[@]}"
do
[[ ${item^^} == ${cur^^}* ]] && COMPREPLY+=("$item")
done
}
# Check the COMP_WORDS looking for name of the vm. If name contain space or # Check the COMP_WORDS looking for name of the vm. If name contain space or
# is enclosed in quotes, glue name together in variable name. Variable index # is enclosed in quotes, glue name together in variable name. Variable index
# will hold the last index of COMP_WORDS array which contain the end of the # will hold the last index of COMP_WORDS array which contain the end of the
@@ -654,6 +690,48 @@ _VBoxManage() {
fi fi
;; ;;
dhcpserver) dhcpserver)
items=(add modify remove)
subcommand=${COMP_WORDS[2]}
if [[ " ${items[@]} " == *" $subcommand "* ]]; then
case "${subcommand}" in
add|modify)
items=(--ip --netmask --lowerip --upperip)
[[ " ${COMP_WORDS[@]} " != *" --ifname"* &&
" ${COMP_WORDS[@]} " != *" --netname"* ]] &&
items+=(--netname --ifname)
[[ " ${COMP_WORDS[@]} " != *" --enable"* &&
" ${COMP_WORDS[@]} " != *" --disable"* ]] &&
items+=(--enable --disable)
_get_excluded_items "${items[@]}"
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
;;
remove)
case "${prev}" in
--netname)
COMPREPLY=()
_dhcp_comp ${cur}
;;
--ifname)
COMPREPLY=()
_hostonlyif_comp ${cur}
;;
esac
if [[ " ${COMP_WORDS[@]} " != *" --ifname"* &&
" ${COMP_WORDS[@]} " != *" --netname"* ]]; then
items=(--netname --ifname)
_get_excluded_items "${items[@]}"
COMPREPLY=( $(compgen -W "$result" -- ${cur}) )
fi
;;
esac
else
[[ ${#COMPREPLY[@]} -eq 0 ]] && \
COMPREPLY=( $(compgen -W "${items[*]}" -- ${cur}) )
fi
;; ;;
discardstate) discardstate)
;; ;;