Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Nutanix CE の Prism から起動中 VM の AHV ホストを取得する。
import sys
import json
import requests
import datetime
args = sys.argv
conf_file = args[1]
with open(conf_file, "r") as file:
conf =
conf = json.loads(conf)
prism_addr = conf["prism_address"]
prism_user = conf["user_name"]
prism_pass = conf["password"]
insecure_warn = requests.packages.urllib3.exceptions.InsecureRequestWarning
def main():
base_url = 'https://' + prism_addr + ':9440/PrismGateway/services/rest/v2.0/'
s = requests.Session()
s.auth = (prism_user, prism_pass)
s.headers.update({'Content-Type': 'application/json; charset=utf-8'})
hosts = {}
data = s.get(base_url + 'hosts', verify=False).json()
for entity in data['entities']:
hv_uuid = entity['uuid']
hosts[hv_uuid] = entity['name']
ts =
ts_str = ts.isoformat()
data = s.get(base_url + 'vms', verify=False).json()
for entity in data['entities']:
if(entity['power_state'] == 'on'):
vm_name = entity['name']
hv_uuid = entity['host_uuid']
hv_name = hosts[hv_uuid]
to_csv_list = (ts_str, hv_name, vm_name)
if __name__ == '__main__':

This comment has been minimized.

Copy link
Owner Author

commented Nov 6, 2018


Nutanix API v2 で VM - AHV の CSV を取得してみる。(Python)

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.