-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.sh
executable file
·78 lines (63 loc) · 2.97 KB
/
main.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
source config.sh
source functions.sh
#main
ARRAY=()
#1 retrieve+display name-instance value(s) from /storage-container/ resource
echo "display the name(s) of /storage-container/ resource instances"
ARRAY=$(getResourceValues $RESOURCE_SC $KEY_NAME)
echo "resource:${RESOURCE_SC} key:${KEY_NAME} value(s):${ARRAY[@]}"
echo
#2 retrieve+display name-instance value(s) from /images/ resource
echo "display the name(s) of /image/ resource instances"
ARRAY=$(getResourceValues $RESOURCE_IM $KEY_NAME)
echo "resource:${RESOURCE_IM} key:${KEY_NAME} value(s):${ARRAY[@]}"
echo
#3 retrieve "default-container" storage-container uuid from /storage-container/ resource
echo "retrieve the default container uuid from /storage-container/ resource"
DEFAULT_SC_UUID=$(getResourceEntityValue $RESOURCE_SC $KEY_NAME $DISK_CONTAINER_NAME $KEY_STORAGE_CONTAINER_UUID)
echo "resource:${RESOURCE_SC} key:${KEY_STORAGE_CONTAINER_UUID} value:${DEFAULT_SC_UUID}"
echo
#4 retrieve "ISO" storage-container uuid from /storage-container/ resource
echo "retrieve the ISO container uuid from /storage-container/ resource"
ISO_SC_UUID=$(getResourceEntityValue $RESOURCE_SC $KEY_NAME $ISO_CONTAINER_NAME $KEY_STORAGE_CONTAINER_UUID)
echo "resource:${RESOURCE_SC} key:${KEY_STORAGE_CONTAINER_UUID} value:${ISO_SC_UUID}"
echo
#5 retrieve "windows" vmdisk-uuid from /images/ resource
echo "retrieve the vmdisk uuid from /images/ resource for windows iso image"
WIN_VMDISK_UUID=$(getResourceEntityValue $RESOURCE_IM $KEY_NAME $OS_IMAGE_NAME $KEY_VMDISK_UUID)
echo "resource:${RESOURCE_IM} key:${KEY_VMDISK_UUID} value:${WIN_VMDISK_UUID}"
echo
#6 retrieve "ngt" vmdisk-uuid from /images/ resource
echo "retrieve the vmdisk uuid from /images/ resource for virt-io iso image"
NGT_VMDISK_UUID=$(getResourceEntityValue $RESOURCE_IM $KEY_NAME $NGT_IMAGE_NAME $KEY_VMDISK_UUID)
echo "resource:${RESOURCE_IM} key:${KEY_VMDISK_UUID} value:${NGT_VMDISK_UUID}"
echo
#7 create vm
echo "create the vm"
RESPONSE=$(createResource $RESOURCE_VM GEN_VM_CREATE_MSG $WIN_VMDISK_UUID $DEFAULT_SC_UUID $NGT_VMDISK_UUID 10737418240)
echo "create(vm): $(taskStatus ${RESPONSE} ${RUNNING})"
echo
#8 retrieve vm uuid single resource-instance value
echo "retrieve the vm uuid"
VM_UUID=$(getResourceValue $RESOURCE_VM ".${KEY_ENTITY_ARRAY}[0].${KEY_VM_UUID}")
echo "resource:${RESOURCE_VM} key:${KEY_VM_UUID}: value:${VM_UUID}"
echo
#9 set power-state "on"
echo "power the vm on"
RESPONSE=$(setPowerState $RESOURCE_VM GEN_VM_POWER_MSG $VM_UUID "ON")
echo "powerOn(vm): $(taskStatus ${RESPONSE} ${RUNNING})"
echo
#10 set power-state "off"
echo "power the vm off"
RESPONSE=$(setPowerState $RESOURCE_VM GEN_VM_POWER_MSG $VM_UUID "OFF")
echo "powerOff(vm): $(taskStatus ${RESPONSE} ${RUNNING})"
echo
#11 delete VM resource
echo "delete the vm"
RESPONSE=$(deleteResource $RESOURCE_VM $VM_UUID)
echo "delete(vm): $(taskStatus ${RESPONSE} ${RUNNING})"
#uncomment the following to display formatted json using jq
#RESULT=$(getResource $RESOURCE_IM)
#echo $RESULT | jq '.'
#endmain