Created
July 31, 2018 22:35
-
-
Save gowatana/2c9294d765f7f3110fe6eec87ccdd54e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Usage: | |
# $ sh ./set-vm-power-state.sh ./prism-login.conf vm01 OFF | |
# $ sh ./set-vm-power-state.sh ./prism-login.conf vm01 ON | |
PRISM_LOGIN_FILE=$1 | |
VM_NAME=$2 | |
VM_POWER_STATE=$3 | |
. ${PRISM_LOGIN_FILE} | |
VM_JSON=vm-${VM_NAME}.json | |
VM_UUID=`curl -k -s -X POST \ | |
-H "Content-Type: application/json" \ | |
-u "${PRISM_USER}:${PRISM_PASS}" \ | |
-d "{}" \ | |
"https://${PRISM_ADDR}:9440/api/nutanix/v3/vms/list" | jq --monochrome-output -C '.entities[] | select(.spec.name == "'${VM_NAME}'") | .metadata.uuid'` | |
VM_UUID=`echo $VM_UUID | sed s/\"//g` | |
echo "VM_UUID: $VM_UUID" | |
curl -k -s -X GET \ | |
-H "Content-Type: application/json" \ | |
-u "${PRISM_USER}:${PRISM_PASS}" \ | |
"https://${PRISM_ADDR}:9440/api/nutanix/v3/vms/${VM_UUID}" | jq --monochrome-output -C '{spec: .spec, metadata: .metadata}' > ${VM_JSON} | |
cat ${VM_JSON} | jq --monochrome-output '.spec.resources.power_state |= "'${VM_POWER_STATE}'"' > ${VM_JSON}.power-state | |
curl -k -s -X PUT \ | |
-H "Content-Type: application/json" \ | |
-u "${PRISM_USER}:${PRISM_PASS}" \ | |
-d @${VM_JSON}.power-state \ | |
"https://${PRISM_ADDR}:9440/api/nutanix/v3/vms/${VM_UUID}" | jq --monochrome-output -C '.spec.resources.power_state' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下記の投稿むけ。
Nutanix REST API v3 で VM を停止 / 起動してみる。
http://blog.ntnx.jp/entry/2018/08/01/074640