Skip to content

Instantly share code, notes, and snippets.

@gowatana
Last active August 30, 2020 09:21
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/ddbaac0314155c8a133d04f65b5c4249 to your computer and use it in GitHub Desktop.
Save gowatana/ddbaac0314155c8a133d04f65b5c4249 to your computer and use it in GitHub Desktop.
import sys
import json
import requests
args = sys.argv
vm_name = args[1]
cvm_ip = 'NutanixクラスタVIP'
cvm_user = 'ユーザ'
cvm_pass = 'パスワード'
if __name__ == '__main__':
base_url = 'https://' + cvm_ip + ':9440/PrismGateway/services/rest/v2.0/'
requests.packages.urllib3.disable_warnings()
s = requests.Session()
s.auth = (cvm_user, cvm_pass)
s.headers.update({'Content-Type': 'application/json; charset=utf-8'})
api_url = base_url + 'vms'
vms = s.get(api_url, verify=False).json()
for vm in vms['entities']:
if vm['name'] == vm_name:
vm_uuid = vm['uuid']
api_url = base_url + '/vms/' + vm['uuid'] + '/nics/?include_address_assignments=true'
vnics = s.get(api_url, verify=False).json()
for vnic in vnics['entities']:
vnic_mac = vnic['mac_address']
if vnic.get('requested_ip_address'):
vnic_ip = vnic['requested_ip_address']
else:
vnic_ip = ''
print(vm_uuid + ',' + vnic_mac + ',' + vnic_ip + ',' + vm_name)
@gowatana
Copy link
Author

下記の投稿むけ。

Nutanix API v2 で VM の IP アドレスを取得してみる。
http://blog.ntnx.jp/entry/2017/10/03/020533

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