本文整理汇总了Python中pyVmomi.vim.Folder方法的典型用法代码示例。如果您正苦于以下问题:Python vim.Folder方法的具体用法?Python vim.Folder怎么用?Python vim.Folder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyVmomi.vim
的用法示例。
在下文中一共展示了vim.Folder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: compile_folder_path_for_object
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def compile_folder_path_for_object(vobj):
""" make a /vm/foo/bar/baz like folder path for an object """
paths = []
if isinstance(vobj, vim.Folder):
paths.append(vobj.name)
thisobj = vobj
while hasattr(thisobj, 'parent'):
thisobj = thisobj.parent
try:
moid = thisobj._moId
except AttributeError:
moid = None
if moid in ['group-d1', 'ha-folder-root']:
break
if isinstance(thisobj, vim.Folder):
paths.append(thisobj.name)
paths.reverse()
return '/' + '/'.join(paths)
示例2: get_vm_path
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def get_vm_path(content, vm_name):
"""
Function to find the path of virtual machine.
Args:
content: VMware content object
vm_name: virtual machine managed object
Returns: Folder of virtual machine if exists, else None
"""
folder_name = None
folder = vm_name.parent
if folder:
folder_name = folder.name
fp = folder.parent
# climb back up the tree to find our path, stop before the root folder
while fp is not None and fp.name is not None and fp != content.rootFolder:
folder_name = fp.name + '/' + folder_name
try:
fp = fp.parent
except BaseException:
break
folder_name = '/' + folder_name
return folder_name
示例3: vm_folder_traversal
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def vm_folder_traversal():
"""
Build the traversal spec for the property collector to traverse vmFolder
"""
TraversalSpec = vmodl.query.PropertyCollector.TraversalSpec
SelectionSpec = vmodl.query.PropertyCollector.SelectionSpec
# Traversal through vmFolder branch
dcToVmf = TraversalSpec(name='dcToVmf', type=vim.Datacenter, path='vmFolder', skip=False)
dcToVmf.selectSet.append(SelectionSpec(name='visitFolders'))
# Recurse through the folders
visitFolders = TraversalSpec(name='visitFolders', type=vim.Folder, path='childEntity', skip=False)
visitFolders.selectSet.extend((SelectionSpec(name='visitFolders'), SelectionSpec(name='dcToVmf'),))
return SelectionSpec.Array((visitFolders, dcToVmf,))
示例4: get_templates
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def get_templates(self, entity):
templates = []
if isinstance(entity, vim.Folder):
for obj in entity.childEntity:
if isinstance(obj, vim.VirtualMachine) and obj.config.template:
template = {
"image_name": obj.name,
"guest_id": obj.guest.guestId
}
templates.append(template)
if isinstance(obj, vim.Folder):
tem = self.get_templates(obj)
if len(tem) > 0:
templates.extend(tem)
return templates
else:
return []
示例5: setup_cluster_vapi2
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def setup_cluster_vapi2(context):
"""Create a cluster from the Folder managed object"""
cluster1_name = context.testbed.config['CLUSTER1_NAME']
# Get the host folder for the Datacenter2 using the folder query
datacenter_name = context.testbed.config['DATACENTER2_NAME']
datacenter = context.testbed.entities['DATACENTER_IDS'][datacenter_name]
folder_summaries = context.client.vcenter.Folder.list(
Folder.FilterSpec(type=Folder.Type.HOST, datacenters=set([datacenter])))
folder = folder_summaries[0].folder
# Create a managed object from the folder identifier
folder_mo = vim.Folder(folder, context.soap_stub)
cluster_mo = folder_mo.CreateClusterEx(cluster1_name,
vim.cluster.ConfigSpecEx())
print("Created Cluster '{}' ({})".format(cluster_mo._moId, cluster1_name))
context.testbed.entities['CLUSTER_IDS'] = {
cluster1_name: cluster_mo._moId
}
示例6: rename
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def rename(folder, name):
"""
Renames a folder.
:param folder: Folder to rename
:type folder: vim.Folder
:param str name: New name for the folder
"""
logging.debug("Renaming %s to %s", folder.name, name)
folder.Rename_Task(newName=str(name)).wait()
# Injection of methods into vim.Folder pyVmomi class
#
# These enable "<folder>.create('name')" instead of
# "folder_utils.create_folder(<folder>, 'name')"
#
# This works because the implicit first argument
# to a class method call in Python is the instance
#
示例7: get_folder
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def get_folder(self, folder_name=None):
"""
Finds and returns the named Folder.
:param str folder_name: Name of folder [default: Datacenter vmFolder]
:return: The folder found
:rtype: vim.Folder
"""
if folder_name: # Try to find the named folder in the datacenter
return self.get_obj(self.datacenter, [vim.Folder], folder_name)
else: # Default to the VM folder in the datacenter
# Reference: pyvmomi/docs/vim/Datacenter.rst
self._log.warning("Could not find folder '%s' in Datacenter '%s', "
"defaulting to vmFolder",
folder_name, self.datacenter.name)
return self.datacenter.vmFolder
示例8: create_dummy_vm
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def create_dummy_vm(vm_name, service_instance, vm_folder, resource_pool,
datastore):
"""Creates a dummy VirtualMachine with 1 vCpu, 128MB of RAM.
:param name: String Name for the VirtualMachine
:param service_instance: ServiceInstance connection
:param vm_folder: Folder to place the VirtualMachine in
:param resource_pool: ResourcePool to place the VirtualMachine in
:param datastore: DataStrore to place the VirtualMachine on
"""
datastore_path = '[' + datastore + '] ' + vm_name
# bare minimum VM shell, no disks. Feel free to edit
vmx_file = vim.vm.FileInfo(logDirectory=None,
snapshotDirectory=None,
suspendDirectory=None,
vmPathName=datastore_path)
config = vim.vm.ConfigSpec(name=vm_name, memoryMB=128, numCPUs=1,
files=vmx_file, guestId='dosGuest',
version='vmx-07')
print("Creating VM {}...".format(vm_name))
task = vm_folder.CreateVM_Task(config=config, pool=resource_pool)
tasks.wait_for_tasks(service_instance, [task])
示例9: apply_terraform
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def apply_terraform(self, cluster, hosts_dict):
vars = cluster.plan.mixed_vars
st = connect.SmartConnectNoSSL(host=vars['vc_host'], user=vars['vc_username'],
pwd=vars['vc_password'], port=vars['vc_port'])
content = st.RetrieveContent()
container = content.rootFolder
dc = get_obj(content, [vim.Datacenter], container, vars['region'])
folder = get_obj(content, [vim.Folder], container, 'kubeoperator')
if not folder:
dc.vmFolder.CreateFolder('kubeoperator')
return super().apply_terraform(cluster, hosts_dict)
示例10: _search_folders_for_vm
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def _search_folders_for_vm(self, name):
# First get all VM folders
container = self.content.viewManager.CreateContainerView(
self.content.rootFolder, [vim.Folder], True)
folders = container.view
container.Destroy()
# Now search each folder for VM
vm = None
for folder in folders:
vm = self.content.searchIndex.FindChild(folder, name)
if vm:
break
return vm
示例11: create_folder
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def create_folder(self, folder_name):
"""Create a Vm folder under Datacenter
Args:
folder_name: Name of Vm Folder
return: vim.Folder
"""
dc = self.get_obj(vim.Datacenter, "Datacenter")
folder = dc.vmFolder.CreateFolder(folder_name)
return folder
示例12: destroy_folder
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def destroy_folder(self, folder_name):
"""Delete a Vm folder under Datacenter
Args:
folder_name: Name of Vm Folder
return: vim.Task
"""
folder = self._search_folders_for_vm(folder_name)
return folder.Destroy()
示例13: createfolder
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def createfolder(si, parentfolder, folder):
if find(si, parentfolder, vim.Folder, folder) is None:
parentfolder.CreateFolder(folder)
return None
示例14: deletefolder
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def deletefolder(si, parentfolder, folder):
folder = find(si, parentfolder, vim.Folder, folder)
if folder is not None:
folder.Destroy()
示例15: delete
# 需要导入模块: from pyVmomi import vim [as 别名]
# 或者: from pyVmomi.vim import Folder [as 别名]
def delete(self, name, snapshots=False):
si = self.si
dc = self.dc
vmFolder = dc.vmFolder
vm = findvm(si, vmFolder, name)
if vm is None:
return {'result': 'failure', 'reason': "VM %s not found" % name}
plan, image = 'kvirt', None
vmpath = vm.summary.config.vmPathName.replace('/%s.vmx' % name, '')
for entry in vm.config.extraConfig:
if entry.key == 'image':
image = entry.value
if entry.key == 'plan':
plan = entry.value
if vm.runtime.powerState == "poweredOn":
t = vm.PowerOffVM_Task()
waitForMe(t)
t = vm.Destroy_Task()
waitForMe(t)
if image is not None and 'coreos' not in image and 'rhcos' not in image and\
'fcos' not in image and vmpath.endswith(name):
deletedirectory(si, dc, vmpath)
if plan != 'kvirt':
planfolder = find(si, vmFolder, vim.Folder, plan)
if planfolder is not None and len(planfolder.childEntity) == 0:
planfolder.Destroy()
return {'result': 'success'}