亚洲精品久久久中文字幕-亚洲精品久久片久久-亚洲精品久久青草-亚洲精品久久婷婷爱久久婷婷-亚洲精品久久午夜香蕉

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

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

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

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’admin@vsphere.com’, ’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’, ’admin@vsphere.com’, ’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)獲取所有主機(jī)列表:

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’admin@vsphere.com’, ’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’, ’admin@vsphere.com’, ’123456’, 1,0.1)res = session.invoke_api(vim_util,'get_objects',session.vim,'HostSystem',1000)# 我們隨意選取一個(gè) 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)詳細(xì)信息:

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’admin@vsphere.com’, ’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’, ’admin@vsphere.com’, ’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]))讀取主機(jī)狀態(tài)

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’admin@vsphere.com’, ’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’, ’admin@vsphere.com’, ’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('主機(jī)地址: {} t 狀態(tài): {}'.format(addr.get('summary.config.name'),stats.get('summary.runtime.powerState')))讀取虛擬機(jī)狀態(tài)

from oslo_vmware import apifrom oslo_vmware import vim_utilimport urllib3urllib3.disable_warnings()session = api.VMwareAPISession( ’127.0.0.1’, ’admin@vsphere.com’, ’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管理虛擬機(jī)。

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=’admin@vsphere.com’, password=’123456’, session=session)# 列出所有虛擬機(jī)ref = vsphere_client.vcenter.VM.list()print(ref)# 通過(guò)虛擬機(jī)的名稱來(lái)進(jìn)行過(guò)濾ref = vsphere_client.vcenter.VM.list( vsphere_client.vcenter.VM.FilterSpec(names={’Baidu-NLP01’}) )print(ref)實(shí)現(xiàn)開(kāi)關(guān)機(jī)

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=’admin@vsphere.com’, password=’123456’, session=session)# 檢索系統(tǒng)是否開(kāi)機(jī)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('是否開(kāi)機(jī): {}'.format(power_status))# 檢索系統(tǒng)是否開(kāi)機(jī)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('已開(kāi)機(jī): {}'.format(power_status.state))else: print('已關(guān)機(jī)')# 關(guān)閉系統(tǒng) start / reset / suspend / stopvsphere_client.vm.Power.stop(vm.vm)# 刪除虛擬機(jī)vsphere_client.vcenter.VM.delete(vm)列出數(shù)據(jù)存儲(chǔ)

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=’admin@vsphere.com’, password=’123456’, session=session)# 列出集群#ref = vsphere_client.vcenter.Cluster.list()#print(ref)# 列出 vCenter 中所有文件夾#folder = vsphere_client.vcenter.Folder.list()# 列出數(shù)據(jù)存儲(chǔ)# 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('存儲(chǔ)結(jié)構(gòu): {} 數(shù)據(jù)存儲(chǔ)名稱: {}'.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=’admin@vsphere.com’, 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=’admin@vsphere.com’, password=’123456’, session=session)# 列出標(biāo)準(zhǔn)網(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ò)的名稱和標(biāo)識(shí)符,所以宿主機(jī)和虛擬機(jī)的網(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虛擬機(jī)的示例參考的詳細(xì)內(nèi)容,更多關(guān)于Python用oslo.vmware管理ESXI虛擬機(jī)的資料請(qǐng)關(guān)注好吧啦網(wǎng)其它相關(guān)文章!

標(biāo)簽: Python 編程
相關(guān)文章:
主站蜘蛛池模板: 色涩网站在线观看 | 亚洲高清一区二区三区 | 特级毛片免费视频播放 | 欧美成人免费高清网站 | 麻豆传媒网站网址入口 | 男女很黄很色床视频网站免 | 青青草原综合久久大伊人精品 | 一级女性全黄生活片免费 | 加勒比上原亚衣在线播放 | 国产剧情一区二区三区 | 亚洲精品午夜久久久伊人 | 成人性视频在线三级 | 免费晚上看片www | 亚洲精品一区二区深夜福利 | 手机看片自拍 | 成人一区二区丝袜美腿 | 欧美成人免费全部观看天天性色 | 成年黄色 | 久久99精品久久久久久野外 | 精品视频一区二区三区四区 | 亚洲国产精品va在线观看麻豆 | 全部毛片免费看 | 日韩一级黄色影片 | 91成人国产福利 | 日韩欧美成人免费中文字幕 | 国产精品美女福利视频一区 | 又亲又揉摸下面视频免费看 | 精品视频在线看 | 国产高清乱码无卡女大生 | 视频在线观看国产 | 亚色图| 国产51社区精品视频资源 | 婷婷色九月 | 在线中文字幕日韩 | 久久人人网 | 国产永久一区二区三区 | 黄色大片a级 | 国产精品探花千人斩久久 | 黄色a级免费 | 鲁大师在线观看在线播放 | 国产麻豆视频在线观看 |