色综合图-色综合图片-色综合图片二区150p-色综合图区-玖玖国产精品视频-玖玖香蕉视频

您的位置:首頁技術(shù)文章
文章詳情頁

Python使用oslo.vmware管理ESXI虛擬機的示例參考

瀏覽:259日期:2022-06-15 18:30:36
目錄讀取所有節(jié)點主機獲取所有區(qū)域:獲取所有主機列表:獲取 HostSystem MO詳細信息:資源清單讀取主機狀態(tài)循環(huán)輸出讀取虛擬機狀態(tài)Vsphere API基礎(chǔ):實現(xiàn)開關(guān)機列出數(shù)據(jù)存儲獲取資源池列出網(wǎng)絡(luò)讀取所有節(jié)點主機

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’[email protected]’, ’123456’, 1,0.1)#result1 = session.invoke_api(vim_util,’get_objects’,session.vim, ’HostSystem’, 100)#print(result1.objects[0])# rep2 = session.invoke_api(vim_util,’get_object_properties_dict’,session.vim, result1.objects[0].obj,’vm’)res = session.invoke_api(vim_util,'get_objects',session.vim,'ResourcePool',100)print(res)獲取所有區(qū)域:

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’[email protected]’, ’123456’, 1,0.1)res = session.invoke_api(vim_util,'get_objects',session.vim,'ComputeResource',100)addr = []for i in res.objects: addr.append(i.propSet[0][1])print(addr)獲取所有主機列表:

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’[email protected]’, ’123456’, 1,0.1)res = session.invoke_api(vim_util,'get_objects',session.vim,'HostSystem',1000)addr = []for i in res.objects: addr.append(i.propSet[0][1])print(addr)獲取 HostSystem MO

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’[email protected]’, ’123456’, 1,0.1)res = session.invoke_api(vim_util,'get_objects',session.vim,'HostSystem',1000)# 我們隨意選取一個 ESXi Host, 并且打印其 Objecthost_obj = res.objects[0].obj# 獲取 HostNetworkSystem MO, 并打印其 Valuehost_network_system_val = session.invoke_api(vim_util, ’get_object_properties_dict’,session.vim,host_obj,’configManager.networkSystem’)print(host_network_system_val)詳細信息:

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’[email protected]’, ’123456’, 1,0.1)res = session.invoke_api(vim_util,'get_objects',session.vim,'VirtualMachine',1000)summary = session.invoke_api(vim_util, ’get_object_properties_dict’, session.vim, res.objects[0].obj,’summary’)print(summary)資源清單

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’[email protected]’, ’123456’, 1,0.1)res = session.invoke_api(vim_util,'get_objects',session.vim,'Datacenter',1000)# 獲取 Cluster 資源清單computeResource = session.invoke_api( vim_util, ’get_objects’, session.vim, ’ComputeResource’, 100)for each in computeResource.objects: print('資源清單: {}'.format(each[1][0][1]))讀取主機狀態(tài)

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’[email protected]’, ’123456’, 1,0.1)res = session.invoke_api(vim_util,'get_objects',session.vim,'HostSystem',1000)summary = session.invoke_api(vim_util, ’get_object_properties_dict’, session.vim, res.objects[0].obj,’summary.runtime.powerState’)summary1 = session.invoke_api(vim_util, ’get_object_properties_dict’, session.vim, res.objects[0].obj,’summary.config.name’)print(summary.get('summary.runtime.powerState'))print(summary1.get('summary.config.name'))循環(huán)輸出

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’[email protected]’, ’123456’, 1,0.1)res = session.invoke_api(vim_util,'get_objects',session.vim,'HostSystem',100)tim = 0for each in res.objects: tim = tim +1 print(tim) stats = session.invoke_api(vim_util, ’get_object_properties_dict’, session.vim, each.obj,’summary.runtime.powerState’) addr = session.invoke_api(vim_util, ’get_object_properties_dict’, session.vim, each.obj,’summary.config.name’) print('主機地址: {} t 狀態(tài): {}'.format(addr.get('summary.config.name'),stats.get('summary.runtime.powerState')))讀取虛擬機狀態(tài)

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’[email protected]’, ’123456’, 1,0.1)res = session.invoke_api(vim_util,'get_objects',session.vim,'VirtualMachine',100)instance = res.objects[0].objprint(instance)stats = session.invoke_api(vim_util, ’get_object_properties_dict’, session.vim, instance, ’summary’)print(stats)

使用com.vmware.vcenter_client管理虛擬機。

Vsphere API基礎(chǔ):

import requestsimport urllib3from vmware.vapi.vsphere.client import create_vsphere_clientsession = requests.session()session.verify = Falseurllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)vsphere_client = create_vsphere_client(server=’127.0.0.1’, username=’[email protected]’, password=’123456’, session=session)# 列出所有虛擬機ref = vsphere_client.vcenter.VM.list()print(ref)# 通過虛擬機的名稱來進行過濾ref = vsphere_client.vcenter.VM.list( vsphere_client.vcenter.VM.FilterSpec(names={’Baidu-NLP01’}) )print(ref)實現(xiàn)開關(guān)機

import requestsimport urllib3from vmware.vapi.vsphere.client import create_vsphere_clientsession = requests.session()session.verify = Falseurllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)vsphere_client = create_vsphere_client(server=’127.0.0.1’, username=’[email protected]’, password=’123456’, session=session)# 檢索系統(tǒng)是否開機vm = vsphere_client.vcenter.VM.list(vsphere_client.vcenter.VM.FilterSpec(names={’GZH-SERVER3’}))[0]power_status = vsphere_client.vcenter.vm.Power.get(vm.vm)print('是否開機: {}'.format(power_status))# 檢索系統(tǒng)是否開機vm = vsphere_client.vcenter.VM.list(vsphere_client.vcenter.VM.FilterSpec(names={’192.168.81.51’}))if len(vm) != 0: vm = vm[0] power_status = vsphere_client.vcenter.vm.Power.get(vm.vm) print('已開機: {}'.format(power_status.state))else: print('已關(guān)機')# 關(guān)閉系統(tǒng) start / reset / suspend / stopvsphere_client.vm.Power.stop(vm.vm)# 刪除虛擬機vsphere_client.vcenter.VM.delete(vm)列出數(shù)據(jù)存儲

import requestsimport urllib3from vmware.vapi.vsphere.client import create_vsphere_clientfrom com.vmware.vcenter_client import Folderfrom com.vmware.vcenter_client import Datastorefrom com.vmware.vcenter_client import Networksession = requests.session()session.verify = Falseurllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)vsphere_client = create_vsphere_client(server=’127.0.0.1’, username=’[email protected]’, password=’123456’, session=session)# 列出集群#ref = vsphere_client.vcenter.Cluster.list()#print(ref)# 列出 vCenter 中所有文件夾#folder = vsphere_client.vcenter.Folder.list()# 列出數(shù)據(jù)存儲# store = vsphere_client.vcenter.Datastore.list()datastore_name = ’192.168.64.20’filter_spec = Datastore.FilterSpec(names={datastore_name})datastore_summaries = vsphere_client.vcenter.Datastore.list(filter_spec)datastore_id = datastore_summaries[0].datastoreprint('存儲結(jié)構(gòu): {} 數(shù)據(jù)存儲名稱: {}'.format(datastore_summaries,datastore_id))獲取資源池

import requestsimport urllib3from vmware.vapi.vsphere.client import create_vsphere_clientfrom com.vmware.vcenter_client import Clusterfrom com.vmware.vcenter_client import ResourcePoolsession = requests.session()session.verify = Falseurllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)vsphere_client = create_vsphere_client(server=’127.0.0.1’, username=’[email protected]’, password=’123456’, session=session)# 獲取所有資源池filter = vsphere_client.vcenter.ResourcePool.list()print(filter)# 根據(jù)集群名獲取資源池cluster_name = ’vSAN-Cluster1’cluster_id = vsphere_client.vcenter.Cluster.list(Cluster.FilterSpec(names={cluster_name}))[0].clusterresource_pool_id = vsphere_client.vcenter.ResourcePool.list(ResourcePool.FilterSpec(clusters={cluster_id}))[0].resource_poolprint(resource_pool_id)列出網(wǎng)絡(luò)

import requestsimport urllib3from vmware.vapi.vsphere.client import create_vsphere_clientfrom com.vmware.vcenter_client import Networksession = requests.session()session.verify = Falseurllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)vsphere_client = create_vsphere_client(server=’127.0.0.1’, username=’[email protected]’, password=’123456’, session=session)# 列出標準網(wǎng)絡(luò)filter = vsphere_client.vcenter.Network.list()print(filter)’’’它的 type 有三種類型:DISTRIBUTED_PORTGROUP:vcenter 創(chuàng)建和管理的網(wǎng)絡(luò);OPAQUE_NETWORK:VSphere 之外的設(shè)備所創(chuàng)建,但是 vSphere 卻可以知道網(wǎng)絡(luò)的名稱和標識符,所以宿主機和虛擬機的網(wǎng)卡才能夠連接到;STANDARD_PORTGROUP:ESX 創(chuàng)建和管理的網(wǎng)絡(luò)。’’’filter = Network.FilterSpec(names={’vlan 164’},types={Network.Type.STANDARD_PORTGROUP})network_summaries = vsphere_client.vcenter.Network.list(filter=filter)print(network_summaries)# 列出分布式網(wǎng)絡(luò)filter = Network.FilterSpec( names=set([’vlan 164’]), types=set([Network.Type.DISTRIBUTED_PORTGROUP]))network_summaries = vsphere_client.vcenter.Network.list(filter=filter)if len(network_summaries) > 0: network_id = network_summaries[0].network print(network_id)else: print('Distributed Portgroup Network not found in Datacenter')

文章出處:https://www.cnblogs.com/lyshark

以上就是Python使用oslo.vmware管理ESXI虛擬機的示例參考的詳細內(nèi)容,更多關(guān)于Python用oslo.vmware管理ESXI虛擬機的資料請關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 国产成人免费高清视频 | 日本护士一级毛片在线播放 | 欧美 另类 精品一区视频 | 呦视频在线一区二区三区 | 亚洲国产韩国一区二区 | 手机看成人免费大片 | 免费一区二区 | 欧美日韩一区二区三区视视频 | 国产成人精品一区 | 韩国一级a毛片 | 国产精品爱久久久久久久小 | 国产欧美va欧美va香蕉在线观 | 女人张开双腿让男人桶完整 | 国产女人在线观看 | 国产亚洲精品久久久久久无 | 亚洲b| 国产一成人精品福利网站 | 欧美精品三级在线 | 国产或人精品日本亚洲77美色 | 国产日本在线视频 | 日韩国产免费 | 一级做性色a爱片久久片 | 亚洲精品高清国产一线久久97 | 一级特级欧美a毛片免费 | 欧美色欧美色 | 欧美三级不卡在线观看视频 | 欧美一线高本道高清在线 | 日本性色 | 波多野结衣一级 | 免费黄色欧美 | 免费一级毛片视频 | 欧美精品v日韩精品v国产精品 | 国产精品久久一区二区三区 | 中文无线乱码二三四区 | 亚洲日本va午夜中文字幕一区 | 一区二区三区久久 | 日本国产一区二区三区 | 成人国产在线不卡视频 | 亚洲天堂影院在线观看 | 中文一区二区在线观看 | 在线看欧美日韩中文字幕 |