Merge "Allow to specify which image to create VM from"

This commit is contained in:
Jenkins 2016-11-21 07:23:29 +00:00 committed by Gerrit Code Review
commit 79e1769f0e
1 changed files with 13 additions and 6 deletions

View File

@ -6,12 +6,13 @@ set -e
usage() {
cat << EOF
Usage: $0 -a (create|destroy) [-c] [-n NUBER_OF_VMs] [-i PUBLIC_ETH_IFACE]
Usage: $0 -a (create|destroy) [-n NUBER_OF_VMs] [-i IMAGE]
-h Prints this help
-a Required action. Choise from "create" and "destroy"
-n Number of VMs to spawn (optional)
-k Kubernetes namespace (optional)
-i Image to boot VMs from (optional, will upload Cirros if ommited)
EOF
}
@ -32,11 +33,14 @@ create() {
NUMBER=2
fi
curl -o /tmp/cirros.img http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
openstack image create --disk-format qcow2 --public --file /tmp/cirros.img cirros
rm -f /tmp/cirros.img
if [ -z "${IMAGE}" ]; then
IMAGE=cirros
curl -o /tmp/cirros.img http://download.cirros-cloud.net/0.3.4/cirros-0.3.4-x86_64-disk.img
openstack image create --disk-format qcow2 --public --file /tmp/cirros.img cirros
rm -f /tmp/cirros.img
fi
NETID="$(openstack network show int-net -f value -c id)"
openstack server create --flavor m1.tiny --image cirros --nic net-id="$NETID" --min $NUMBER --max $NUMBER --wait test_vm
openstack server create --flavor m1.tiny --image "${IMAGE}" --nic net-id="$NETID" --min $NUMBER --max $NUMBER --wait test_vm
openstack server list
for vm in $(openstack server list -f value -c Name | grep test_vm); do
echo "Console for $vm:"
@ -53,7 +57,7 @@ destroy() {
openstack image delete cirros
}
while getopts ":a:n:k:h" opt; do
while getopts ":a:n:k:i:h" opt; do
case $opt in
a)
ACTION="$OPTARG"
@ -64,6 +68,9 @@ while getopts ":a:n:k:h" opt; do
k)
K8S_NAMESPACE="$OPTARG"
;;
i)
IMAGE="$OPTARG"
;;
h)
usage
exit 1