Commit 356e975d authored by Paul John King's avatar Paul John King

Reworked _main function --

parent 72505706
......@@ -111,7 +111,7 @@ create_pool(){
if test $# != 2 ;
then
print_pool_usage_message >&2 ;
help_pool >&2 ;
return 1 ;
fi ;
......@@ -123,7 +123,8 @@ create_pool(){
_echo_stdin |
virsh -q pool-define "/dev/stdin" &&
virsh -q pool-autostart "${_NAME}" &&
virsh -q pool-start "${_NAME}" ;
virsh -q pool-start "${_NAME}" &&
return 0 || return 1 ;
} <<- __END_OF_STDIN__
<pool type="dir">
<name>${_NAME}</name>
......@@ -133,25 +134,25 @@ create_pool(){
</pool>
__END_OF_STDIN__
return $? ;
} ;
destroy_pool(){
if test $# != 1 ;
then
print_pool_usage_message >&2 ;
help_pool >&2 ;
return 1 ;
fi ;
local _NAME="${1}" ;
shift 1 ;
virsh -q pool-destroy "${_NAME}" &&
virsh -q pool-undefine "${_NAME}" ;
local _status=0 ;
return $? ;
virsh -q pool-destroy "${_NAME}" || _status=1 ;
virsh -q pool-undefine "${_NAME}" || _status=1 ;
return ${_status} ;
} ;
......@@ -185,7 +186,7 @@ create_volume(){
if test $# != 3 ;
then
print_volume_usage_message >&2 ;
help_volume >&2 ;
return 1 ;
fi ;
......@@ -219,7 +220,7 @@ destroy_volume(){
if test $# != 2 ;
then
print_volume_usage_message >&2 ;
help_volume >&2 ;
return 1 ;
fi ;
......@@ -299,6 +300,7 @@ create_domain(){
"m")
local _MAC_ADDRESS="${OPTARG}" ;
;;
"?")
echo "The command-line option '-${OPTARG}' is invalid." >&2 ;
return 1 ;
......@@ -309,7 +311,7 @@ create_domain(){
if test $# != 5 ;
then
print_domain_usage_message >&2 ;
help_domain >&2 ;
return 1 ;
fi ;
......@@ -425,6 +427,7 @@ verify_domain(){
"m")
local _MAC_ADDRESS="${OPTARG}" ;
;;
"?")
echo "The command-line option '-${OPTARG}' is invalid." >&2 ;
return 1 ;
......@@ -435,7 +438,7 @@ verify_domain(){
if test $# != 5 ;
then
print_domain_usage_message >&2 ;
help_domain >&2 ;
return 1 ;
fi ;
......@@ -473,7 +476,7 @@ destroy_domain(){
if test $# != 1 ;
then
print_domain_usage_message >&2 ;
help_domain >&2 ;
return 1 ;
fi ;
......@@ -569,6 +572,7 @@ create_machine(){
"i")
local _IPV4_ADDRESS="${OPTARG}" ;
;;
"?")
echo "The command-line option '-${OPTARG}' is invalid." >&2 ;
return 1 ;
......@@ -579,7 +583,7 @@ create_machine(){
if test $# != 5 ;
then
print_machine_usage_message >&2 ;
help_machine >&2 ;
return 1 ;
fi ;
......@@ -642,6 +646,7 @@ verify_machine(){
"i")
local _IPV4_ADDRESS="${OPTARG}" ;
;;
"?")
echo "The command-line option '-${OPTARG}' is invalid." >&2 ;
return 1 ;
......@@ -652,7 +657,7 @@ verify_machine(){
if test $# != 5 ;
then
print_machine_usage_message >&2 ;
help_machine >&2 ;
return 1 ;
fi ;
......@@ -696,7 +701,7 @@ destroy_machine(){
if test $# != 1 ;
then
print_machine_usage_message >&2 ;
help_machine >&2 ;
return 1 ;
fi ;
......@@ -767,7 +772,7 @@ get_image_path(){
if test $# != 2 ;
then
print_get_image_path_usage_message >&2 ;
help_utility >&2 ;
return 1 ;
fi ;
......@@ -785,7 +790,7 @@ get_mac_address(){
if test $# != 1 ;
then
print_get_mac_address_usage_message >&2 ;
help_utility >&2 ;
return 1 ;
fi ;
......@@ -1208,7 +1213,7 @@ _get_value_by_tag_and_attribute_from_xml(){
*"<${_TAG} ${_NAME}="[\"\']*">"*|\
*"<${_TAG} "*" ${_NAME}="[\"\']*">"*)
echo "${_line}" ;
exit 1 ;
return 1 ;
;;
esac ;
done ;
......@@ -1227,140 +1232,134 @@ _get_value_by_tag_and_attribute_from_xml(){
} ;
# Script
# ------
case "${1} ${2} ${3}" in
"get image path")
shift 3 ;
get_image_path "${@}" ;
exit $? ;
;;
"get mac address")
shift 3 ;
get_mac_address "${@}" ;
exit $? ;
;;
esac ;
case "${1} ${2}" in
"create pool")
shift 2 ;
create_pool "${@}" ;
exit $? ;
;;
"destroy pool")
shift 2 ;
destroy_pool "${@}" ;
exit $? ;
;;
"help pool")
shift 2 ;
help_pool "${@}" ;
exit $? ;
;;
"create volume")
shift 2 ;
create_volume "${@}" ;
exit $? ;
;;
"destroy volume")
shift 2 ;
destroy_volume "${@}" ;
exit $? ;
;;
"help volume")
shift 2 ;
help_volume "${@}" ;
exit $? ;
;;
"create domain")
shift 2 ;
create_domain "${@}" ;
exit $? ;
;;
"examine domain")
shift 2 ;
examine_domain "${@}" ;
exit $? ;
;;
"verify domain")
shift 2 ;
verify_domain "${@}" ;
exit $? ;
;;
"destroy domain")
shift 2 ;
destroy_domain "${@}" ;
exit $? ;
;;
"help domain")
shift 2 ;
help_domain "${@}" ;
exit $? ;
;;
"create machine")
shift 2 ;
create_machine "${@}" ;
exit $? ;
;;
"examine machine")
shift 2 ;
examine_machine "${@}" ;
exit $? ;
;;
"verify machine")
shift 2 ;
verify_machine "${@}" ;
exit $? ;
;;
"destroy machine")
shift 2 ;
destroy_machine "${@}" ;
exit $? ;
;;
"help machine")
shift 2 ;
help_machine "${@}" ;
exit $? ;
;;
"help utility")
shift 2 ;
help_utility "${@}" ;
exit $? ;
;;
esac ;
case "${1}" in
"usage")
shift 1 ;
usage ;
exit 0 ;
;;
"help")
shift 1 ;
help ;
exit 0 ;
;;
esac ;
usage ;
exit 1 ;
# Main Function
# -------------
_main(){
case "${@} " in
"usage ")
usage ;
return 0 ;
;;
"help ")
help ;
return 0 ;
;;
"help pool "*)
help_pool ;
return 0 ;
;;
"create pool "*)
shift 2 ;
create_pool "${@}" ;
return $? ;
;;
"destroy pool "*)
shift 2 ;
destroy_pool "${@}" ;
return $? ;
;;
"help volume "*)
help_volume ;
return 0 ;
;;
"create volume "*)
shift 2 ;
create_volume "${@}" ;
return $? ;
;;
"destroy volume "*)
shift 2 ;
destroy_volume "${@}" ;
return $? ;
;;
"help domain "*)
help_domain ;
return 0 ;
;;
"create domain "*)
shift 2 ;
create_domain "${@}" ;
return $? ;
;;
"examine domain "*)
shift 2 ;
examine_domain "${@}" ;
return $? ;
;;
"verify domain "*)
shift 2 ;
verify_domain "${@}" ;
return $? ;
;;
"destroy domain "*)
shift 2 ;
destroy_domain "${@}" ;
return $? ;
;;
"help machine "*)
help_machine ;
return 0 ;
;;
"create machine "*)
shift 2 ;
create_machine "${@}" ;
return $? ;
;;
"examine machine "*)
shift 2 ;
examine_machine "${@}" ;
return $? ;
;;
"verify machine "*)
shift 2 ;
verify_machine "${@}" ;
return $? ;
;;
"destroy machine "*)
shift 2 ;
destroy_machine "${@}" ;
return $? ;
;;
"help utility "*)
help_utility ;
return 0 ;
;;
"get image path "*)
shift 3 ;
get_image_path "${@}" ;
return $? ;
;;
"get mac address "*)
shift 3 ;
get_mac_address "${@}" ;
return $? ;
;;
esac ;
usage ;
return 1 ;
} ;
_main "${@}" ;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment