Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import sys
import json
import requests
args = sys.argv
conf_file = args[1]
vm_name = args[2]
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"]
def main():
base_url = 'https://' + prism_addr + ':9440/PrismGateway/services/rest/v2.0/'
requests.packages.urllib3.disable_warnings()
s = requests.Session()
s.auth = (prism_user, prism_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'):
requested_ip_address = 'requested_ip_address:' + vnic['requested_ip_address']
else:
requested_ip_address = 'requested_ip_address:None'
list = [vm_uuid , vm_name, vnic_mac, requested_ip_address]
print(','.join(list))
if vnic.get('ip_address'):
ip_address = 'ip_address:' + vnic['ip_address']
else:
ip_address = 'ip_address:None'
list = [vm_uuid , vm_name, vnic_mac, ip_address]
print(','.join(list))
if __name__ == '__main__':
main()
@gowatana

This comment has been minimized.

Copy link
Owner Author

@gowatana gowatana commented Aug 30, 2020

下記の投稿むけ。

Nutanix API v2 で VM の IP アドレスを取得してみる。(Python)
https://blog.ntnx.jp/entry/2020/08/30/231644

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.