vcenter通過python的sdk創建自定義的虛擬機信息,並配置相關的屬性信息(四)配置esxi的dns,以及查看調用dns數據

目錄

 

ESXI配置DNS

 mob查找

python3  sdk 調用查詢實例


ESXI配置DNS

界面配置

 mob查找

python3  sdk 調用查詢實例

'''
@Author: shun zi 2016
@Date: 2020-04-28 18:35:14
@LastEditTime: 2020-04-29 15:11:23
@LastEditors: Please set LastEditors
@Description: In User Settings Edit
@FilePath: host.py
'''
# -*- coding: utf-8 -*-
from pyvim import connect
import ssl
import pyVmomi
ssl._create_default_https_context = ssl._create_unverified_context
import atexit
service_instance = connect.SmartConnect(host='172xx.x.xx.15',user='[email protected]',pwd='xx.xx.xx.xx',port=443)
# service_instance = connect.SmartConnect(host='172.xx.xx..1',
#                                         user='[email protected]',
#                                         pwd='xxxxxxx',
#                                         port=443)

content = service_instance.RetrieveContent()
# print str(content)
# print str(content.dvSwitchManager)
# print str(content.viewManager)

vcontent = service_instance.content

for dc in vcontent.rootFolder.childEntity:
        if dc.name == 'Datacenter':
            break

clusterNotFound = False
for cluster in dc.hostFolder.childEntity:
        if cluster.name == 'colony':
            clusterNotFound = True
            break
if clusterNotFound == False:
        print("clusterNotFound:%s " % 'colony')

for host in cluster.host:
    print('host-name')
    print(str(host))
    print(host.name)
    print(host.config.network.dnsConfig)
    print(host.config.network.dnsConfig.hostName)
    print(host.config.network.dnsConfig.domainName)

esxi_ip_domain_list = []
for host in cluster.host:
        domainName = host.config.network.dnsConfig.domainName
        esxi_ip_domain_list.append(domainName)
        hostName = host.config.network.dnsConfig.hostName
        esxi_ip_domain_list.append(hostName)
        domain_name =  hostName + '.' + domainName
        esxi_ip_domain_list.append(domain_name)
        esxi_ip_domain_list.append(host.name)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章