Created
August 30, 2020 14:13
-
-
Save gowatana/ef0d1d071f208eb71fc1dd46c707c4be to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
下記の投稿むけ。
Nutanix API v2 で VM の IP アドレスを取得してみる。(Python)
https://blog.ntnx.jp/entry/2020/08/30/231644