婷婷综合国产,91蜜桃婷婷狠狠久久综合9色 ,九九九九九精品,国产综合av

主頁(yè) > 知識(shí)庫(kù) > Python使用oslo.vmware管理ESXI虛擬機(jī)的示例參考

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

熱門標(biāo)簽:地圖標(biāo)注視頻廣告 梅州外呼業(yè)務(wù)系統(tǒng) 老人電話機(jī)器人 北京電信外呼系統(tǒng)靠譜嗎 洪澤縣地圖標(biāo)注 百度地圖標(biāo)注位置怎么修改 大連crm外呼系統(tǒng) 無(wú)錫客服外呼系統(tǒng)一般多少錢 高德地圖標(biāo)注是免費(fèi)的嗎

讀取所有節(jié)點(diǎn)主機(jī)

from oslo_vmware import api
from oslo_vmware import vim_util
import urllib3

urllib3.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 api
from oslo_vmware import vim_util
import urllib3

urllib3.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 api
from oslo_vmware import vim_util
import urllib3

urllib3.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 api
from oslo_vmware import vim_util
import urllib3

urllib3.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, 并且打印其 Object
host_obj = res.objects[0].obj


# 獲取 HostNetworkSystem MO, 并打印其 Value
host_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 api
from oslo_vmware import vim_util
import urllib3

urllib3.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 api
from oslo_vmware import vim_util
import urllib3

urllib3.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 api
from oslo_vmware import vim_util
import urllib3

urllib3.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 api
from oslo_vmware import vim_util
import urllib3

urllib3.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 = 0
for 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 api
from oslo_vmware import vim_util
import urllib3

urllib3.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].obj
print(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 requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client

session = requests.session()
session.verify = False
urllib3.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 requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client

session = requests.session()
session.verify = False
urllib3.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 / stop
vsphere_client.vm.Power.stop(vm.vm)

# 刪除虛擬機(jī)
vsphere_client.vcenter.VM.delete(vm)

列出數(shù)據(jù)存儲(chǔ)

import requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client
from com.vmware.vcenter_client import Folder
from com.vmware.vcenter_client import Datastore
from com.vmware.vcenter_client import Network

session = requests.session()
session.verify = False
urllib3.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].datastore
print("存儲(chǔ)結(jié)構(gòu): {} 數(shù)據(jù)存儲(chǔ)名稱: {}".format(datastore_summaries,datastore_id))

獲取資源池

import requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client
from com.vmware.vcenter_client import Cluster
from com.vmware.vcenter_client import ResourcePool

session = requests.session()
session.verify = False
urllib3.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].cluster
resource_pool_id = vsphere_client.vcenter.ResourcePool.list(ResourcePool.FilterSpec(clusters={cluster_id}))[0].resource_pool

print(resource_pool_id)

列出網(wǎng)絡(luò)

import requests
import urllib3
from vmware.vapi.vsphere.client import create_vsphere_client
from com.vmware.vcenter_client import Network

session = requests.session()
session.verify = False
urllib3.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)注腳本之家其它相關(guān)文章!

您可能感興趣的文章:
  • java虛擬機(jī)JVM類加載機(jī)制原理(面試必問(wèn))
  • vmware虛擬機(jī)安裝deepin20最全詳細(xì)過(guò)程
  • Java虛擬機(jī)類加載器之雙親委派機(jī)制模型案例
  • Python動(dòng)態(tài)規(guī)劃實(shí)現(xiàn)虛擬機(jī)部署的算法思想
  • 最新虛擬機(jī)VMware 14安裝教程
  • java虛擬機(jī)中棧的運(yùn)行知識(shí)點(diǎn)總結(jié)
  • Java虛擬機(jī)精選面試題20道
  • Java reservedcodecachesize虛擬機(jī)參數(shù)案例詳解

標(biāo)簽:岳陽(yáng) 安慶 清遠(yuǎn) 洛陽(yáng) 泉州 怒江 長(zhǎng)春 吉林

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Python使用oslo.vmware管理ESXI虛擬機(jī)的示例參考》,本文關(guān)鍵詞  Python,使用,oslo.vmware,管理,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Python使用oslo.vmware管理ESXI虛擬機(jī)的示例參考》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Python使用oslo.vmware管理ESXI虛擬機(jī)的示例參考的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    主站蜘蛛池模板: 望谟县| 綦江县| 黔南| 余江县| 杭锦后旗| 辽宁省| 石屏县| 婺源县| 广西| 运城市| 鲜城| 丰宁| 双峰县| 肃南| 海原县| 息烽县| 巴里| 南和县| 嘉峪关市| 自治县| 乌什县| 福州市| 甘德县| 罗平县| 罗江县| 开江县| 肃北| 巴彦县| 淮滨县| 普格县| 永州市| 长海县| 格尔木市| 靖宇县| 思茅市| 泰来县| 阜南县| 福泉市| 长治县| 庐江县| 榆社县|