当前位置: 首页>>代码示例>>Python>>正文


Python VirtualMachine.all方法代码示例

本文整理汇总了Python中psphere.managedobjects.VirtualMachine.all方法的典型用法代码示例。如果您正苦于以下问题:Python VirtualMachine.all方法的具体用法?Python VirtualMachine.all怎么用?Python VirtualMachine.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在psphere.managedobjects.VirtualMachine的用法示例。


在下文中一共展示了VirtualMachine.all方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: vsphere_check_with_api

# 需要导入模块: from psphere.managedobjects import VirtualMachine [as 别名]
# 或者: from psphere.managedobjects.VirtualMachine import all [as 别名]
def vsphere_check_with_api(api, run_time, text):
    """Uses api to perform checking of vms on vsphere-type provider.

    Args:
        api: api endpoint to vsphere
        run_time: when this run time is exceeded for the VM, it will be deleted
        text: when this string is found in the name of VM, it may be deleted
    """
    vms = VirtualMachine.all(api.api)
    vms_to_delete = []
    templates_to_delete = []

    nightly_templates = [VirtualMachine.get(api.api, name=x)
                         for x in api.list_template() if "miq-nightly" in x]
    nightly_templates.sort(key=lambda x: datetime.datetime.strptime(x.name[-12:], "%Y%m%d%H%M"))

    if len(nightly_templates) > MRU_NIGHTLIES:
        for template in nightly_templates[:-MRU_NIGHTLIES]:
            templates_to_delete.append(template.name)

    for vm in vms:
        vm_name = vm.name
        running_for = vm.summary.quickStats.uptimeSeconds / SEC_IN_DAY
        if running_for >= run_time and is_affected(vm_name, text):
            print("To delete: {} with runtime: {}".format(vm_name, running_for))
            vms_to_delete.append(vm_name)
    return (vms_to_delete, templates_to_delete)
开发者ID:dajohnso,项目名称:cfme_tests,代码行数:29,代码来源:delete_vm.py

示例2: exportVM

# 需要导入模块: from psphere.managedobjects import VirtualMachine [as 别名]
# 或者: from psphere.managedobjects.VirtualMachine import all [as 别名]
def exportVM(serverIp, user, passwd, vmName, workingDir):
    try:
        print "Connecting to the server...."
        client = Client(serverIp, user, passwd)
    except WebFault:
        print "Can't connect to the server"
        sys.exit(1)
    print "Connected"
    validVms = {}
    if vmName <> 'all':
        try:
            vm = VirtualMachine.get(client, name=vmName)
            if vm.runtime.powerState <> 'poweredOff':
                print 'Skipping VM:' + vm.name + ' VM is not powered off'
                sys.exit(5)
            if len(vm.network) <> 1:
                print 'Skipping VM:' + vm.name + ' The number of network devices is not equal to 1'
                sys.exit(5)
            vmdkPath = getVMDKUri(serverIp, vm)
            if vmdkPath != None:
                validVms[vm.name] = vmdkPath
        except ObjectNotFoundError:
            print 'Invalid VM name'
            client.logout()
            sys.exit(2)
    else:
        # inspect all vms
        vms = VirtualMachine.all(client)
        for vm in vms:
            if vm.runtime.powerState <> 'poweredOff':
                print 'Skipping VM:' + vm.name + ' VM is not powered off'
                continue
            if len(vm.network) <> 1:
                print 'Skipping VM:' + vm.name + ' The number of network devices is not equal to 1'
                continue
            vmdkPath = getVMDKUri(serverIp, vm)
            if vmdkPath != None:
                validVms[vm.name] = vmdkPath
            else:
                continue

    client.logout()
    if len(validVms.keys()) == 0:
        print 'Nothing to export'
        sys.exit(2)

    # get vmdks for all valid vms
    for vmName in validVms.keys():
        directory = workingDir + '/' + vmName + '/'
        if not os.path.exists(directory):
            os.makedirs(directory)
        VmdkUri = validVms[vmName]
        downloadFile(VmdkUri, user, passwd, directory + vmName + '.vmdk')
        extends = parseVMDK(directory + vmName + '.vmdk')
        if extends == None:
            print 'No accessable extends'
            sys.exit(3)
        else:
            available = getAvalableDiskSpaceBytes(workingDir)
            for s in extends.values():
                available = available - s
            if available < 0:
                print 'There is not enough free disk space to download all extends for VM:' + vmName
                exit(4)
            for e in extends.keys():
                m = re.match('^(.+?)/folder/(.+?)/(.+?)\?(.+)$', VmdkUri)
                uri = m.group(1) + '/folder/' + m.group(2) + '/' + urllib2.quote(e) + '?' + m.group(4)
                downloadFile(uri, user, passwd, directory + e)

    sys.exit(0)
开发者ID:eucalyptus,项目名称:eucalyptus-image-tools,代码行数:72,代码来源:export_vmdk.py


注:本文中的psphere.managedobjects.VirtualMachine.all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。