Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nutanix AHV で VM スナップショットを作成する。
import sys
import json
import requests
args = sys.argv
conf_file = args[1]
vm_uuid = args[2]
snapshot_name = args[3]
def main():
with open(conf_file, "r") as file:
conf = file.read()
conf = json.loads(conf)
prism_addr = conf["prism_address"]
prism_user = conf["user_name"]
prism_pass = conf["password"]
base_url = 'https://' + prism_addr + ':9440/PrismGateway/services/rest/v2.0/'
insecure_warn = requests.packages.urllib3.exceptions.InsecureRequestWarning
requests.packages.urllib3.disable_warnings(insecure_warn)
s = requests.Session()
s.auth = (prism_user, prism_pass)
s.headers.update({'Content-Type': 'application/json; charset=utf-8'})
# VM Snapshot Spec
snapshot_spec = {
'snapshot_specs': [
{
'snapshot_name': snapshot_name,
'vm_uuid': vm_uuid
}
]
}
print('Snapshot spec --')
print(snapshot_spec)
# Create VM Snapshot.
url = base_url + 'snapshots/'
task_info = s.post(url, json=snapshot_spec, verify=False).json()
print('Snapshot task --')
print(json.dumps(task_info))
if __name__ == '__main__':
main()
@gowatana

This comment has been minimized.

Owner

gowatana commented Dec 4, 2018

下記の投稿むけ。

Nutanix REST API v2 で VM の Snapshot を作成してみる。(Python)
http://blog.ntnx.jp/entry/2018/12/04/080722

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment