本文整理汇总了Python中pyVmomi.vim.HostSystem方法的典型用法代码示例。如果您正苦于以下问题:Python vim.HostSystem方法的具体用法?Python vim.HostSystem怎么用?Python vim.HostSystem使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyVmomi.vim
的用法示例。
在下文中一共展示了vim.HostSystem方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_host_system_failfast
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def get_host_system_failfast(
self,
name,
verbose=False,
host_system_term='HS'
):
"""
Get a HostSystem object
fail fast if the object isn't a valid reference
"""
if verbose:
print("Finding HostSystem named %s..." % name)
hs = self.get_host_system(name)
if hs is None:
print("Error: %s '%s' does not exist" % (host_system_term, name))
sys.exit(1)
if verbose:
print("Found HostSystem: {0} Name: {1}" % (hs, hs.name))
return hs
示例2: move_host_into_cluster_vim
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [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: report
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def report(self):
si = self.si
about = si.content.about
print("Host: %s" % self.vcip)
print("Datacenter: %s" % self.dc.name)
print("Version: %s" % about.version)
print("Api Version: %s" % about.apiVersion)
print("Datacenter: %s" % self.dc.name)
rootFolder = self.rootFolder
o = si.content.viewManager.CreateContainerView(rootFolder, [vim.HostSystem], True)
view = o.view
o.Destroy()
for h in view:
print("Host: %s" % h.name)
o = si.content.viewManager.CreateContainerView(rootFolder, [vim.ComputeResource], True)
view = o.view
o.Destroy()
for clu in view:
print("Cluster: %s" % clu.name)
for dts in clu.datastore:
print("Pool: %s" % dts.name)
示例4: GetVMHosts
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def GetVMHosts(content, regex_esxi=None):
host_view = content.viewManager.CreateContainerView(content.rootFolder,
[vim.HostSystem],
True)
obj = [host for host in host_view.view]
match_obj = []
if regex_esxi:
for esxi in obj:
if re.findall(r'%s.*' % regex_esxi, esxi.name):
match_obj.append(esxi)
match_obj_name = [match_esxi.name for match_esxi in match_obj]
print("Matched ESXi hosts: %s" % match_obj_name)
host_view.Destroy()
return match_obj
else:
host_view.Destroy()
return obj
示例5: get_storage_devices
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def get_storage_devices(self, host):
"""
Fetches all the storage devices in the Host. It excludes
the enclosures.
Args:
host (vim.HostSystem): Host instance
Returns:
list: List of storage devices in Host
"""
logger.debug(f"Fetching all the storage devices in host {host.name}")
storage_system = host.configManager.storageSystem
storage_device_info = storage_system.storageDeviceInfo
return [
ScsiDisk.deviceName for ScsiDisk in storage_device_info.scsiLun
if ScsiDisk.deviceType == 'disk'
]
示例6: get_mounted_devices_in_vsan
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def get_mounted_devices_in_vsan(self, host):
"""
Fetches the devices which was mounted in VSAN
Args:
host (vim.HostSystem): Host instance
Returns:
list: List of storage devices which was mounted
"""
device_list = []
logger.debug(
f"Fetching all the storage devices mounted in host {host.name}"
)
disk_mapping = host.config.vsanHostConfig.storageInfo.diskMapping
for each in disk_mapping:
device_list.append(each.ssd.devicePath)
for hd in each.nonSsd:
device_list.append(hd.devicePath)
logger.debug(f"Mounted devices in Host {host.name}: {device_list}")
return device_list
示例7: get_mounted_devices
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def get_mounted_devices(self, host, datastore_type="VMFS"):
"""
Fetches the available storage devices on Host.
Args:
host (vim.HostSystem): Host instance
datastore_type (str): Type of datastore. Either VMFS or vsan
By default, it will take VMFS as datastore type.
Returns:
list: List of storage devices available for use
"""
if datastore_type == VMFS:
return self.get_mounted_devices_in_vmfs(host)
else:
return self.get_mounted_devices_in_vsan(host)
示例8: get_active_partition
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def get_active_partition(self, host):
"""
Fetches the active partition disk on Host
Args:
host (vim.HostSystem): Host instance
Returns:
str: Active partition disk
"""
logger.debug(
f"Getting the active partition device in host {host.name}"
)
active_partition = host.config.activeDiagnosticPartition
if not active_partition:
active_partition = self.get_active_partition_from_mount_info(host)
return active_partition
return active_partition.id.diskName
示例9: get_host_obj
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def get_host_obj(self, host_name):
"""
Fetches the Host object
Args:
host_name (str): Host name
Returns:
vim.HostSystem: Host instance
"""
content = self.get_content
host_view = content.viewManager.CreateContainerView(
content.rootFolder,
[vim.HostSystem],
True
)
host_obj = [host for host in host_view.view]
host_view.Destroy()
for host in host_obj:
if host.name == host_name:
return host
示例10: get_used_devices
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def get_used_devices(self, host):
"""
Fetches the used storage devices in Host.
Note: Storage devices may be used in different Resource Pools
of OCS clusters.
Args:
host (vim.HostSystem): Host instance
Returns:
list: List of storage devices used
"""
logger.debug(
f"Fetching all the storage devices used in host {host.name}"
)
cluster = host.parent
dc = cluster.parent.parent.name
lunids = self.get_lunids(dc)
host_devices_mapping = self.map_lunids_to_devices(**lunids)
return host_devices_mapping.get(host)
示例11: erase_partition
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def erase_partition(self, host, device_path):
"""
Erase the partitions on the disk
Args:
host (vim.HostSystem): Host instance
device_path (str): Device path to erase the partition
e.g:"/vmfs/devices/disks/naa.910229801b540c0125ef160f3048faba"
"""
# set empty partition spec
spec = vim.HostDiskPartitionSpec()
host.configManager.storageSystem.UpdateDiskPartitions(
device_path,
spec
)
示例12: create_view
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [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
)
示例13: get_host_system
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def get_host_system(self, name):
return self.get_obj([vim.HostSystem], name)
示例14: find_hostsystem_by_name
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def find_hostsystem_by_name(content, hostname):
return find_object_by_name(content, hostname, [vim.HostSystem])
示例15: get_all_host_objs
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import HostSystem [as 别名]
def get_all_host_objs(self, cluster_name=None, esxi_host_name=None):
"""
Function to get all host system managed object
Args:
cluster_name: Name of Cluster
esxi_host_name: Name of ESXi server
Returns: A list of all host system managed objects, else empty list
"""
host_obj_list = []
if not self.is_vcenter():
hosts = get_all_objs(self.content, [vim.HostSystem]).keys()
if hosts:
host_obj_list.append(list(hosts)[0])
else:
if cluster_name:
cluster_obj = self.find_cluster_by_name(cluster_name=cluster_name)
if cluster_obj:
host_obj_list = [host for host in cluster_obj.host]
else:
self.module.fail_json(changed=False, msg="Cluster '%s' not found" % cluster_name)
elif esxi_host_name:
if isinstance(esxi_host_name, str):
esxi_host_name = [esxi_host_name]
for host in esxi_host_name:
esxi_host_obj = self.find_hostsystem_by_name(host_name=host)
if esxi_host_obj:
host_obj_list = [esxi_host_obj]
else:
self.module.fail_json(changed=False, msg="ESXi '%s' not found" % host)
return host_obj_list
# Network related functions