本文整理汇总了Python中pysphere.VIServer._get_datacenters方法的典型用法代码示例。如果您正苦于以下问题:Python VIServer._get_datacenters方法的具体用法?Python VIServer._get_datacenters怎么用?Python VIServer._get_datacenters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysphere.VIServer
的用法示例。
在下文中一共展示了VIServer._get_datacenters方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_vm
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import _get_datacenters [as 别名]
def create_vm():
opts = options()
# CONNECTION PARAMTERS
server = opts.esx_host
user = opts.user
password = opts.passwd
# REQUIRED PARAMETERS
vmname = opts.name
# datacentername = "ha-datacenter"
datacentername = opts.datacenter
hostname = opts.hostname
annotation = "My Product Product Virtual Machine"
memorysize = opts.ram
cpucount = opts.cpus
# cd_iso_location =
# "iso/My_Product_2013_02_26_05_15_00.iso"
# # located in the ESX datastore
cd_iso_location = opts.iso
guestosid = "centos64Guest"
# find your os in
# http://www.vmware.com/support/developer/vc-sdk/visdk41pubs/ApiReference/vim.vm.GuestOsDescriptor.GuestOsIdentifier.html
disksize = (1024 ** 2) * 100 # In Kb: 1024 ** 2 (power) = 1GB; 1GB * 100 = 100GB.
# OPTIONAL PARAMETERS
datastorename = opts.datastore # if None, will use the first datastore available
# CONNECT TO THE SERVER
s = VIServer()
s.connect(server, user, password)
# GET INITIAL PROPERTIES AND OBJECTS
# get datacenter
dcmor = s._get_datacenters()[datacentername]
dcprops = VIProperty(s, dcmor)
# get host folder
hfmor = dcprops.hostFolder._obj
# get computer resources
crmors = s._retrieve_properties_traversal(property_names=['name',
'host'], from_node=hfmor, obj_type='ComputeResource')
# get host
for hosts in s.get_hosts().items():
try:
if hosts.index(hostname) == 1:
hostmor = hosts[0]
except:
pass
# get computer resource of this host
crmor = None
for cr in crmors:
if crmor:
break
for p in cr.PropSet:
# print 'p.Name:', p.Name
if p.Name == "host":
for h in p.Val.get_element_ManagedObjectReference():
if h == hostmor:
crmor = cr.Obj
break
if crmor:
break
crprops = VIProperty(s, crmor)
# get resource pool
rpmor = crprops.resourcePool._obj
# get vmFolder
vmfmor = dcprops.vmFolder._obj
# CREATE VM CONFIGURATION
# get config target
request = VI.QueryConfigTargetRequestMsg()
_this = request.new__this(crprops.environmentBrowser._obj)
_this.set_attribute_type(crprops.environmentBrowser._obj.get_attribute_type())
request.set_element__this(_this)
h = request.new_host(hostmor)
h.set_attribute_type(hostmor.get_attribute_type())
request.set_element_host(h)
config_target = s._proxy.QueryConfigTarget(request)._returnval
# get default devices
request = VI.QueryConfigOptionRequestMsg()
_this = request.new__this(crprops.environmentBrowser._obj)
_this.set_attribute_type(crprops.environmentBrowser._obj.get_attribute_type())
request.set_element__this(_this)
h = request.new_host(hostmor)
h.set_attribute_type(hostmor.get_attribute_type())
request.set_element_host(h)
config_option = s._proxy.QueryConfigOption(request)._returnval
defaul_devs = config_option.DefaultDevice
# get network name
# would be assigned to the last known working network interface.
#.........这里部分代码省略.........