Skip to content

Instantly share code, notes, and snippets.

@gowatana
Created December 10, 2018 17:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gowatana/1ff53e2bec5564d8aff3a3f3547dbddc to your computer and use it in GitHub Desktop.
Save gowatana/1ff53e2bec5564d8aff3a3f3547dbddc to your computer and use it in GitHub Desktop.
Nutanix CE で、VM 名から VM UUID を取得する。
import sys
import json
import requests
args = sys.argv
conf_file = args[1]
vm_name = 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.
url = base_url + 'vms/'
vms = s.get(url, verify=False).json()
vm_entities = []
for vm in vms['entities']:
if (vm['name'] == vm_name):
print('vm_uuid: ' + vm['uuid'])
vm_entities.append(vm)
vm_count = len(vm_entities)
if (vm_count > 1):
print('VM: ' + vm_name + ' => ' + str(vm_count) +' VMs')
print(json.dumps(vm_entities, indent=2))
if __name__ == '__main__':
main()
@gowatana
Copy link
Author

下記の投稿むけ。

Nutanix REST API v2 で VM 名から VM UUID を取得してみる。(Python)
http://blog.ntnx.jp/entry/2018/12/11/021259

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