本文整理汇总了Python中pysphere.VIServer._get_managed_objects方法的典型用法代码示例。如果您正苦于以下问题:Python VIServer._get_managed_objects方法的具体用法?Python VIServer._get_managed_objects怎么用?Python VIServer._get_managed_objects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pysphere.VIServer
的用法示例。
在下文中一共展示了VIServer._get_managed_objects方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: check
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import _get_managed_objects [as 别名]
def check(self):
super(zstack_vcenter_image_file_checker, self).check()
server = VIServer()
server.connect(vcenter_ip, domain_name, password)
all_vms = server._get_managed_objects(MORTypes.VirtualMachine)
for mor, name in all_vms.iteritems():
if name == sync_image_name:
return self.judge(True)
else:
return self.judge(False)
示例2: __init__
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import _get_managed_objects [as 别名]
#.........这里部分代码省略.........
:rtype: list
:return: A list of :class:`vmware.vsphere.VM`
"""
# get the vm paths
if instanceUuid and len(instanceUuid):
if not isinstance(instanceUuid, str):
raise BadParameterError("instanceUuid parameter must be a string")
if not filter:
filter = {}
filter["config.instanceUuid"] = [instanceUuid]
self._vmspaths = self._server.get_registered_vms(datacenter, advanced_filters=filter)
logger.debug("list_instances: retrieved %d vm paths" % len(self._vmspaths))
# instantiate instances for vm paths
self.vms = []
for p in self._vmspaths:
self.vms.append(VM(p, self))
# first time this function runs, fetch information about vm to datacenter mapping
self._fetch_datacenter_vms()
return self.vms
def get_hosts(self, datacenter=None):
"""Returns a dictionary of the existing hosts keys are their names
and values their ManagedObjectReference object.
Example usage:
>>> server.get_hosts()
{'host-23': '108.61.71.220', 'host-19': '108.61.71.219', 'host-36': '173.71.195.168'}
>>> server.get_hosts('datacenter-12')
>>> from catosphere import Server
>>> server = Server()
>>> server.connect()
>>> server.get_datacenters()
{'datacenter-12': 'csk3', 'datacenter-2': 'csk1', 'datacenter-7': 'csk2'}
>>> server.get_hosts('datacenter-2')
{'host-23': '108.61.71.220', 'host-19': '108.61.71.219'}
>>> server.get_hosts('datacenter-7')
{'host-36': '173.71.195.168'}
>>> server.get_hosts('datacenter-12')
{}
>>> server.get_hosts()
{'host-23': '108.61.71.220', 'host-19': '108.61.71.219', 'host-36': '173.71.195.168'}
>>> server.disconnect()
:return: a dict
e.g.
{'host-23': '108.61.71.220', 'host-19': '108.61.71.219', 'host-36': '173.71.195.168'}
if not hosts are found, empty dict is returned.
"""
if datacenter:
hosts = self._server._get_managed_objects(MORTypes.HostSystem, from_mor=datacenter)
else:
hosts = self._server.get_hosts()
return hosts
def get_datacenters(self):
"""Returns a dictionary of the existing datacenters. keys are their
ManagedObjectReference objects and values their names.
:return: a dict
e.g.
{'datacenter-12': 'csk3', 'datacenter-2': 'csk1', 'datacenter-7': 'csk2'}
"""
return self._server.get_datacenters()
# ******************************************************
# ***************** Private Methods *******************
# ******************************************************
def _fetch_datacenter_vms(self):
""" Fetch/cache datacenter vm mapping information.
This can be later used to retrieve datacenter information for each
VM.
"""
if not self._vm_datacenters:
dcs = self.get_datacenters()
for name in dcs.keys():
self._vm_datacenters[name] = self._server._get_managed_objects(MORTypes.VirtualMachine, from_mor=name)
# logger.debug(': _vm_datacenters: %s' % self._vm_datacenters)
def _get_instance(self, instanceUuid):
""" Retrieves instance by its instanceUuid.
TODO: make this faster by caching instances.
"""
instances = self.list_instances(instanceUuid)
if not instances:
raise InstanceNotFoundError("Instance %s not found" % instanceUuid)
else:
return instances[0]
示例3: Exception
# 需要导入模块: from pysphere import VIServer [as 别名]
# 或者: from pysphere.VIServer import _get_managed_objects [as 别名]
vcip = '10.1.8.50'
logger.debug("Trying to connect %s" % vcip)
vc.connect(vcip,'sbgcf\\svc_report','VMwar3!!')
cur_region = region
try:
host_d = {}
vm_d = {}
for c_mor, c_name in vc.get_clusters().items():
if(not c_name in clstrname_d): continue
logger.debug("Fetching cluster '%s'",c_name)
for h_mor,h_name in vc.get_hosts(from_mor=c_mor).items():
logger.debug("Fetching host %s",h_name)
host_d[h_name] = c_name
for v_mor, v_name in vc._get_managed_objects(MORTypes.VirtualMachine, from_mor=h_mor).items():
vm_d[v_name] = h_name
except:
raise Exception("Failed to query VM list from vCenter %s" % vcip)
is_replica = re.match('.+REPLICA',appid)
if(not vm in vm_d):
if(is_replica):
ERROR(ErrorCode.E_MISSING_REPLICA,appid," (%s)" % vm)
else:
ERROR(ErrorCode.E_MISSING_VM,appid," (%s)" % vm)
continue
m = re.match('(\S+-\S+-\S+-\S+-(AMP|MGMT))',appid)
clstrid = m.group(1)