Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nutanix AHV の VM Snapshot 一覧を取得する。(VM 単位)
import sys
import json
import requests
import datetime
args = sys.argv
conf_file = args[1]
vm_uuid = args[2]
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'})
# Get VM Snapshot.
url = base_url + 'snapshots/?vm_uuid=' + vm_uuid
snapshots = s.get(url, verify=False).json()
for snapshot in snapshots['entities']:
snap_uuid = snapshot['uuid']
snap_name = snapshot['snapshot_name']
vm_name = snapshot['vm_create_spec']['name']
created_time = datetime.datetime.fromtimestamp(int(snapshot['created_time']) / 1000000)
print('--')
print('vm_name: ' + vm_name)
print('snapshot_name: ' + snap_name)
print('created_time: ' + str(created_time))
print('snapshot_uuid: ' + snap_uuid)
print('vm_uuid: ' + vm_uuid)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.