本文整理汇总了Python中pyVmomi.vim.ClusterComputeResource方法的典型用法代码示例。如果您正苦于以下问题:Python vim.ClusterComputeResource方法的具体用法?Python vim.ClusterComputeResource怎么用?Python vim.ClusterComputeResource使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyVmomi.vim
的用法示例。
在下文中一共展示了vim.ClusterComputeResource方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: cleanup_cluster
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def cleanup_cluster(context):
"""Delete cluster after vcenter sample run"""
cluster1_name = context.testbed.config['CLUSTER1_NAME']
names = set([cluster1_name])
cluster_summaries = context.client.vcenter.Cluster.list(
Cluster.FilterSpec(names=names))
print("Found '{}' Clusters matching names {}".
format(len(cluster_summaries), ", ".join(["'{}'".
format(n) for n in names])))
if len(cluster_summaries) < 1:
return
# Delete the cluster using the managed object
cluster = cluster_summaries[0].cluster
cluster_mo = vim.ClusterComputeResource(cluster, context.soap_stub)
print("Deleting Cluster '{}' ({})".format(cluster, cluster1_name))
task = cluster_mo.Destroy()
pyVim.task.WaitForTask(task)
示例2: move_host_into_cluster_vim
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def move_host_into_cluster_vim(context, host_name, cluster_name):
"""Use vim api to move host to another cluster"""
TIMEOUT = 30 # sec
host = context.testbed.entities['HOST_IDS'][host_name]
host_mo = vim.HostSystem(host, context.soap_stub)
# Move the host into the cluster
if not host_mo.runtime.inMaintenanceMode:
task = host_mo.EnterMaintenanceMode(TIMEOUT)
pyVim.task.WaitForTask(task)
print("Host '{}' ({}) in maintenance mode".format(host, host_name))
cluster = context.testbed.entities['CLUSTER_IDS'][cluster_name]
cluster_mo = vim.ClusterComputeResource(cluster, context.soap_stub)
task = cluster_mo.MoveInto([host_mo])
pyVim.task.WaitForTask(task)
print("Host '{}' ({}) moved into Cluster {} ({})".
format(host, host_name, cluster, cluster_name))
task = host_mo.ExitMaintenanceMode(TIMEOUT)
pyVim.task.WaitForTask(task)
print("Host '{}' ({}) out of maintenance mode".format(host, host_name))
示例3: execute
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def execute(self):
# Find the cluster's resource pool moid
cluster_obj = get_obj(self.servicemanager.content,
[vim.ClusterComputeResource], self.cluster_name)
assert cluster_obj is not None
print("Cluster Moref: {0}".format(cluster_obj))
deployment_target = LibraryItem.DeploymentTarget(
resource_pool_id=cluster_obj.resourcePool._GetMoId())
lib_item_id = self.helper.get_item_id_by_name(self.lib_item_name)
assert lib_item_id
ovf_summary = self.client.ovf_lib_item_service.filter(ovf_library_item_id=lib_item_id,
target=deployment_target)
print('Found an OVF template :{0} to deploy.'.format(ovf_summary.name))
# Deploy the ovf template
self.deploy_ovf_template(lib_item_id, ovf_summary, deployment_target)
示例4: _get_cluster_compute_resource
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def _get_cluster_compute_resource(self, resource_name=None):
""" Returns a Compute Cluster Resource managed object. If a name is specified,
a vim.ClusterComputeResource object is returned for the specific resource. If no name is
specified, the method checks if there are is a default resource specified and returns the
object of the resource. Finally, if there is no name or defaults specified, it queries
the Vmware provider and picks the first object returned in the list.
Args:
resource_name (string): The name of the Cluster Compute Resource.
If None, first one will be picked.
Returns:
pyVmomi.vim.ClusterComputeResource: The managed object of the cluster compute resource.
"""
if resource_name is not None:
return self.system.get_obj(vim.ClusterComputeResource, resource_name)
elif self.system.default_cluster_compute_resource is not None:
return self.system.get_obj(vim.ClusterComputeResource,
self.system.default_cluster_compute_resource)
else:
return self.system.get_obj_list(vim.ClusterComputeResource)[0]
示例5: main
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def main():
try:
si = None
try:
print "Trying to connect to VCENTER SERVER . . ."
si = connect.Connect(inputs['vcenter_ip'], 443, inputs['vcenter_user'], inputs['vcenter_password'])
except IOError, e:
pass
atexit.register(Disconnect, si)
print "Connected to VCENTER SERVER !"
content = si.RetrieveContent()
datacenter = get_obj(content, [vim.Datacenter], inputs['datacenter'])
cluster = get_obj(content, [vim.ClusterComputeResource], inputs['cluster'])
network_folder = datacenter.networkFolder
#Create DV Switch
dv_switch = create_dvSwitch(si, content, network_folder, cluster)
#Add port group to this switch
add_dvPort_group(si, dv_switch)
示例6: create_view
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def create_view(self, vc_obj_type):
"""
Create a view scoped to the vCenter object type desired.
This should be called before collecting data about vCenter object types.
:param vc_obj_type: vCenter object type to extract, must be key in vc_obj_views
:type vc_obj_type: str
"""
# Mapping of object type keywords to view types
vc_obj_views = {
"datacenters": vim.Datacenter,
"clusters": vim.ClusterComputeResource,
"hosts": vim.HostSystem,
"virtual_machines": vim.VirtualMachine,
}
# Ensure an active vCenter session exists
if not self.vc_session:
log.info("No existing vCenter session found.")
self.authenticate()
return self.vc_session.viewManager.CreateContainerView(
self.vc_session.rootFolder, # View starting point
[vc_obj_views[vc_obj_type]], # Object types to look for
True # Should we recurively look into view
)
示例7: find_cluster_by_name
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def find_cluster_by_name(content, cluster_name, datacenter=None):
if datacenter:
folder = datacenter.hostFolder
else:
folder = content.rootFolder
return find_object_by_name(content, cluster_name, [vim.ClusterComputeResource], folder=folder)
示例8: get_cluster
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def get_cluster(self, cluster):
if cluster not in self.clusters:
self.clusters[cluster] = self.find_obj(self.content, [vim.ClusterComputeResource], cluster)
return self.clusters[cluster]
示例9: list_zone
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def list_zone(self, region):
params = replace_params(self.vars)
st = get_service_instance(params)
content = st.RetrieveContent()
container = content.rootFolder
viewType = [vim.Datacenter]
region = get_obj(content, viewType, container, region)
zones = []
for entity in region.hostFolder.childEntity:
zone = {
"storages": [],
"networks": [],
"cluster": [],
}
if isinstance(entity, vim.ClusterComputeResource):
zone["cluster"] = entity.name
zone["resourcePool"] = []
zone["resourcePool"].append(entity.resourcePool.name)
for rp in entity.resourcePool.resourcePool:
zone["resourcePool"].append(rp.name)
for network in entity.network:
zone.get("networks").append(network.name)
for datastore in entity.datastore:
zone.get("storages").append({
"name": datastore.name,
"type": datastore.summary.type,
"multipleHostAccess": datastore.summary.multipleHostAccess
})
zones.append(zone)
return zones
示例10: get_cluster_name_by_id
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def get_cluster_name_by_id(content, name):
cluster_obj = get_obj(content, [vim.ClusterComputeResource], name)
if cluster_obj is not None:
self.mo_id = cluster_obj._GetMoId()
print('Cluster MoId: {0}'.format(self.mo_id))
else:
print('Cluster: {0} not found'.format(self.cluster_name))
示例11: _execute
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def _execute(self):
content = self.servicemanager.content
cluster_obj = get_obj(content, [vim.ClusterComputeResource],
self.cluster_name)
if cluster_obj is not None:
self.mo_id = cluster_obj._GetMoId()
print('Cluster MoId: {0}'.format(self.mo_id))
else:
print('Cluster: {0} not found'.format(self.cluster_name))
示例12: _set_vm_relocate_spec
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def _set_vm_relocate_spec(self, resource_pool, host, sparse, progress_callback,
deploy_on_ds_cluster):
"""Set properties for Virtual Machine Relocate Operation specification """
vm_reloc_spec = vim.VirtualMachineRelocateSpec()
# Set resource pool
if isinstance(resource_pool, vim.ResourcePool):
vm_reloc_spec.pool = resource_pool
elif isinstance(resource_pool, vim.ClusterComputeResource):
vm_reloc_spec.pool = resource_pool.resourcePool
else:
if deploy_on_ds_cluster:
vm_reloc_spec.pool = self._get_cluster_compute_resource(resource_pool).resourcePool
else:
vm_reloc_spec.pool = self._get_resource_pool(resource_pool)
progress_callback("Picked resource pool `{}`".format(vm_reloc_spec.pool.name))
# Target Host for the VM, this could be none
vm_reloc_spec.host = (host if isinstance(host, vim.HostSystem)
else self.system.get_obj(vim.HostSystem, host))
if sparse:
vm_reloc_spec.transform = vim.VirtualMachineRelocateTransformation().sparse
progress_callback("Transformation has been set to sparse")
else:
vm_reloc_spec.transform = vim.VirtualMachineRelocateTransformation().flat
progress_callback("Transformation has been set to flat")
return vm_reloc_spec
示例13: list_cluster
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def list_cluster(self):
return [str(h.name) for h in self.get_obj_list(vim.ClusterComputeResource)]
示例14: get_cluster
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def get_cluster(self, cluster_name=None):
"""
Finds and returns the named Cluster.
:param str cluster_name: Name of the cluster
[default: first cluster found in datacenter]
:return: The cluster found
:rtype: vim.ClusterComputeResource or None
"""
return self.get_item(cluster_name, vim.ClusterComputeResource)
示例15: get_clusters
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import ClusterComputeResource [as 别名]
def get_clusters(self):
"""
Get all the clusters associated with the vCenter server.
:return: All clusters associated with the vCenter server
:rtype: list(vim.ClusterComputeResource)
"""
return self.get_objs(self.content.rootFolder,
[vim.ClusterComputeResource])