• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python xmlobject.safe_list函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中zstacklib.utils.xmlobject.safe_list函数的典型用法代码示例。如果您正苦于以下问题:Python safe_list函数的具体用法?Python safe_list怎么用?Python safe_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: add_backup_storage

def add_backup_storage(deployConfig, session_uuid):
    if xmlobject.has_element(deployConfig, 'backupStorages.sftpBackupStorage'):
        for bs in xmlobject.safe_list(deployConfig.backupStorages.sftpBackupStorage):
            action = api_actions.AddSftpBackupStorageAction()
            action.sessionUuid = session_uuid
            action.name = bs.name_
            action.description = bs.description__
            action.url = bs.url_
            action.username = bs.username_
            action.password = bs.password_
            action.hostname = bs.hostname_
            action.timeout = AddKVMHostTimeOut #for some platform slowly salt execution
            action.type = inventory.SFTP_BACKUP_STORAGE_TYPE
            if bs.uuid__:
                action.resourceUuid = bs.uuid__
            thread = threading.Thread(target = _thread_for_action, args = (action, ))
            wait_for_thread_queue()
            thread.start()

    if xmlobject.has_element(deployConfig, 'backupStorages.simulatorBackupStorage'):
        for bs in xmlobject.safe_list(deployConfig.backupStorages.simulatorBackupStorage):
            action = api_actions.AddSimulatorBackupStorageAction()
            action.sessionUuid = session_uuid
            action.name = bs.name_
            action.description = bs.description__
            action.url = bs.url_
            action.type = inventory.SIMULATOR_BACKUP_STORAGE_TYPE
            action.totalCapacity = sizeunit.get_size(bs.totalCapacity_)
            action.availableCapacity = sizeunit.get_size(bs.availableCapacity_)
            thread = threading.Thread(target = _thread_for_action, args = (action, ))
            wait_for_thread_queue()
            thread.start()

    wait_for_thread_done()
开发者ID:zeus911,项目名称:zstack-utility,代码行数:34,代码来源:deploy_config.py


示例2: add_storage_for_backup

def add_storage_for_backup(deployConfig):
    print "try to add backup storage"
    if xmlobject.has_element(deployConfig, 'backupStorages.imageStoreBackupStorage'):
        print "find image store backup storage"
        for bs in xmlobject.safe_list(deployConfig.backupStorages.imageStoreBackupStorage):
            if hasattr(bs, 'local_backup_storage_'):
                print "find local_backup_storage"
                cond = res_ops.gen_query_conditions('tag', '=', "allowbackup")
                tags = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)
                if len(tags) > 0:
                    print "local backup storage already exists"
                    break
                cond = res_ops.gen_query_conditions('name', '=', bs.name_)
                bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)
                print bss
                add_local_bs_tag = tag_ops.create_system_tag('ImageStoreBackupStorageVO', bss[0].uuid,'allowbackup')
    if xmlobject.has_element(deployConfig, 'backupStorages.imageStoreBackupStorage'):
        for bs in xmlobject.safe_list(deployConfig.backupStorages.imageStoreBackupStorage):
            if hasattr(bs, 'remote_backup_storage_'):
                print "find remote_backup_storage"
                cond = res_ops.gen_query_conditions('tag', '=', "remotebackup")
                tags = res_ops.query_resource(res_ops.SYSTEM_TAG, cond)
                if len(tags) > 0:
                    print "remote backup storage already exists"
                    break
                cond = res_ops.gen_query_conditions('name', '=', bs.name_)
                bss = res_ops.query_resource(res_ops.BACKUP_STORAGE, cond)
                print bss
                add_local_bs_tag = tag_ops.create_system_tag('ImageStoreBackupStorageVO', bss[0].uuid,'remotebackup')
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:29,代码来源:run_path.py


示例3: _add_cluster

    def _add_cluster(action, zone_ref, cluster, cluster_ref):
        evt = action.run()
        deploy_logger(jsonobject.dumps(evt))
        cinv = evt.inventory

        try:
            if xmlobject.has_element(cluster, 'primaryStorageRef'):
                for pref in xmlobject.safe_list(cluster.primaryStorageRef):
                    ps_name = generate_dup_name(generate_dup_name(pref.text_, zone_ref, 'z'), cluster_ref, 'c')

                    pinvs = res_ops.get_resource(res_ops.PRIMARY_STORAGE, session_uuid, name=ps_name)
                    pinv = get_first_item_from_list(pinvs, 'Primary Storage', ps_name, 'Cluster')

                    action_ps = api_actions.AttachPrimaryStorageToClusterAction()
                    action_ps.sessionUuid = session_uuid
                    action_ps.clusterUuid = cinv.uuid
                    action_ps.primaryStorageUuid = pinv.uuid
                    evt = action_ps.run()
                    deploy_logger(jsonobject.dumps(evt))
        except:
            exc_info.append(sys.exc_info())

        if cluster.allL2NetworkRef__ == 'true':
            # find all L2 network in zone and attach to cluster
            cond = res_ops.gen_query_conditions('zoneUuid', '=',
                                                action.zoneUuid)
            l2_count = res_ops.query_resource_count(res_ops.L2_NETWORK,
                                                    cond, session_uuid)
            l2invs = res_ops.query_resource_fields(res_ops.L2_NETWORK,
                                                   [{'name': 'zoneUuid', 'op': '=', 'value': action.zoneUuid}],
                                                   session_uuid, ['uuid'], 0, l2_count)
        else:
            l2invs = []
            if xmlobject.has_element(cluster, 'l2NetworkRef'):
                for l2ref in xmlobject.safe_list(cluster.l2NetworkRef):
                    l2_name = generate_dup_name(generate_dup_name(l2ref.text_, zone_ref, 'z'), cluster_ref, 'c')

                    cond = res_ops.gen_query_conditions('zoneUuid', '=',
                                                        action.zoneUuid)
                    cond = res_ops.gen_query_conditions('name', '=', l2_name,
                                                        cond)

                    l2inv = res_ops.query_resource_fields(res_ops.L2_NETWORK,
                                                          cond, session_uuid, ['uuid'])
                    if not l2inv:
                        raise DeployError("Can't find l2 network [%s] in database." % l2_name)
                    l2invs.extend(l2inv)

        for l2inv in l2invs:
            action = api_actions.AttachL2NetworkToClusterAction()
            action.sessionUuid = session_uuid
            action.clusterUuid = cinv.uuid
            action.l2NetworkUuid = l2inv.uuid
            thread = threading.Thread(target=_thread_for_action, args=(action,))
            wait_for_thread_queue()
            thread.start()
开发者ID:ShaofeiWang,项目名称:zstack-utility,代码行数:56,代码来源:deploy_config.py


示例4: skip_if_not_storage_network_separate

def skip_if_not_storage_network_separate(scenarioConfig):
    is_storage_network_separated = False
    for host in xmlobject.safe_list(scenarioConfig.deployerConfig.hosts.host):
        for vm in xmlobject.safe_list(host.vms.vm):
            for l3Network in xmlobject.safe_list(vm.l3Networks.l3Network):
                if xmlobject.has_element(l3Network, 'primaryStorageRef'):
                    is_storage_network_separated = True
                    break
    if not is_storage_network_separated:
        test_util.test_skip("not found separate network in scenario config.")
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:10,代码来源:test_stub.py


示例5: add_ip_range

def add_ip_range(deployConfig, session_uuid, ip_range_name=None,
                 zone_name=None, l3_name=None):
    """
    Call by only adding an IP range. If the IP range is in L3 config,
    add_l3_network will add ip range direclty.

    deployConfig is a xmlobject. If using standard net_operation, please
    check net_operations.add_ip_range(test_util.IpRangeOption())
    """
    if not xmlobject.has_element(deployConfig, "zones.zone"):
        return

    l3networks = []
    for zone in xmlobject.safe_list(deployConfig.zones.zone):
        if zone_name and zone_name != zone.name_:
            continue

        l2networks = []

        if xmlobject.has_element(zone, 'l2Networks.l2NoVlanNetwork'):
            l2networks.extend(xmlobject.safe_list(zone.l2Networks.l2NoVlanNetwork))

        if xmlobject.has_element(zone, 'l2Networks.l2VlanNetwork'):
            l2networks.extend(xmlobject.safe_list(zone.l2Networks.l2VlanNetwork))

        for l2 in l2networks:
            if xmlobject.has_element(l2, 'l3Networks.l3BasicNetwork'):
                l3networks.extend(xmlobject.safe_list(l2.l3Networks.l3BasicNetwork))

    if zone.duplication__ == None:
        duplication = 1
    else:
        duplication = int(zone.duplication__)

    for zone_duplication in range(duplication):
        for l3 in l3networks:
            if l3_name and l3_name != l3.name_:
                continue

            if not xmlobject.has_element(l3, 'ipRange'):
                continue

            if zone_duplication == 0:
                l3Name = l3.name_
            else:
                l3Name = generate_dup_name(l3.name_, zone_duplication, 'z')

            l3_invs = res_ops.get_resource(res_ops.L3_NETWORK, session_uuid, name=l3Name)
            l3_inv = get_first_item_from_list(l3_invs, 'L3 Network', l3Name, 'IP range')
            do_add_ip_range(l3.ipRange, l3_inv.uuid, session_uuid,
                            ip_range_name)
开发者ID:ShaofeiWang,项目名称:zstack-utility,代码行数:51,代码来源:deploy_config.py


示例6: recover_host_vlan

def recover_host_vlan(host_vm, scenarioConfig, deploy_config):
    host_ip = host_vm.ip_
    test_lib.lib_wait_target_up(host_ip, '22', 120)
    host_config = sce_ops.get_scenario_config_vm(host_vm.name_,scenarioConfig)
    for l3network in xmlobject.safe_list(host_config.l3Networks.l3Network):
        if hasattr(l3network, 'l2NetworkRef'):
            for l2networkref in xmlobject.safe_list(l3network.l2NetworkRef):
                nic_name = sce_ops.get_ref_l2_nic_name(l2networkref.text_, deploy_config)
                if nic_name.find('.') >= 0 :
                    vlan = nic_name.split('.')[1]
                    test_util.test_logger('[vm:] %s %s is created.' % (host_ip, nic_name.replace("eth", "zsn")))
                    cmd = 'vconfig add %s %s' % (nic_name.split('.')[0].replace("eth", "zsn"), vlan)
                    test_lib.lib_execute_ssh_cmd(host_ip, host_config.imageUsername_, host_config.imagePassword_, cmd)
    return True
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:14,代码来源:test_stub.py


示例7: add_image

def add_image(deployConfig, session_uuid):
    def _add_image(action):
        increase_image_thread()
        try:
            evt = action.run()
            test_util.test_logger(jsonobject.dumps(evt))
        except:
            exc_info.append(sys.exc_info())
        finally:
            decrease_image_thread()

    if not xmlobject.has_element(deployConfig, 'images.image'):
        return

    for i in xmlobject.safe_list(deployConfig.images.image):
        for bsref in xmlobject.safe_list(i.backupStorageRef):
            bss = res_ops.get_resource(res_ops.BACKUP_STORAGE, session_uuid, name=bsref.text_)
            bs = get_first_item_from_list(bss, 'backup storage', bsref.text_, 'image')
            action = api_actions.AddImageAction()
            action.sessionUuid = session_uuid
            #TODO: account uuid will be removed later.
            action.accountUuid = inventory.INITIAL_SYSTEM_ADMIN_UUID
            action.backupStorageUuids = [bs.uuid]
            action.bits = i.bits__
            if not action.bits:
                action.bits = 64
            action.description = i.description__
            action.format = i.format_
            action.mediaType = i.mediaType_
            action.guestOsType = i.guestOsType__
            if not action.guestOsType:
                action.guestOsType = 'unknown'
            action.platform = i.platform__
            if not action.platform:
                action.platform = 'Linux'
            action.hypervisorType = i.hypervisorType__
            action.name = i.name_
            action.url = i.url_
            action.timeout = 1800000
            thread = threading.Thread(target = _add_image, args = (action, ))
            print 'before add image1: %s' % i.url_
            wait_for_image_thread_queue()
            print 'before add image2: %s' % i.url_
            thread.start()
            print 'add image: %s' % i.url_

    print 'all images add command are executed'
    wait_for_thread_done(True)
    print 'all images have been added'
开发者ID:TinaL3,项目名称:zstack-woodpecker,代码行数:49,代码来源:deploy_operations.py


示例8: add_network_service

def add_network_service(deployConfig, session_uuid):
    if not xmlobject.has_element(deployConfig, "zones.zone"):
        return

    l3networks = []
    for zone in xmlobject.safe_list(deployConfig.zones.zone):
        l2networks = []

        if xmlobject.has_element(zone, 'l2Networks.l2NoVlanNetwork'):
            l2networks.extend(xmlobject.safe_list(zone.l2Networks.l2NoVlanNetwork))

        if xmlobject.has_element(zone, 'l2Networks.l2VlanNetwork'):
            l2networks.extend(xmlobject.safe_list(zone.l2Networks.l2VlanNetwork))

        for l2 in l2networks:
            if xmlobject.has_element(l2, 'l3Networks.l3BasicNetwork'):
                l3networks.extend(xmlobject.safe_list(l2.l3Networks.l3BasicNetwork))

    providers = {}
    action = api_actions.QueryNetworkServiceProviderAction()
    action.sessionUuid = session_uuid
    action.conditions = []
    try:
        reply = action.run()
    except Exception as e:
        exc_info.append(sys.exc_info())
        raise e
    for pinv in reply:
        providers[pinv.name] = pinv.uuid

    if zone.duplication__ == None:
        duplication = 1
    else:
        duplication = int(zone.duplication__)

    for zone_duplication in range(duplication):
        for l3 in l3networks:
            if not xmlobject.has_element(l3, 'networkService'):
                continue

            if zone_duplication == 0:
                l3_name = l3.name_
            else:
                l3_name = generate_dup_name(l3.name_, zone_duplication, 'z')

            l3_invs = res_ops.get_resource(res_ops.L3_NETWORK, session_uuid, name=l3_name)
            l3_inv = get_first_item_from_list(l3_invs, 'L3 Network', l3_name, 'Network Service')
            do_add_network_service(l3.networkService, l3_inv.uuid,
                                   providers, session_uuid)
开发者ID:ShaofeiWang,项目名称:zstack-utility,代码行数:49,代码来源:deploy_config.py


示例9: _deploy_cluster

    def _deploy_cluster(zone):
        if not xmlobject.has_element(zone, "clusters.cluster"):
            return

        if zone.duplication__ == None:
            zone_duplication = 1
        else:
            zone_duplication = int(zone.duplication__)

        for zone_ref in range(zone_duplication):
            for cluster in xmlobject.safe_list(zone.clusters.cluster):
                if cluster_name and cluster_name != cluster.name_:
                    continue

                if cluster.duplication__ == None:
                    cluster_duplication = 1
                else:
                    cluster_duplication = int(cluster.duplication__)
    
                for cluster_ref in range(cluster_duplication):
                    action = api_actions.CreateClusterAction()
                    action.sessionUuid = session_uuid
                    action.name = generate_dup_name(generate_dup_name(cluster.name_, zone_ref, 'z'), cluster_ref, 'c')
                    action.description = generate_dup_name(generate_dup_name(cluster.description__, zone_ref, 'z'), cluster_ref, 'c')
        
                    action.hypervisorType = cluster.hypervisorType_
                    zone_name = generate_dup_name(zone.name_, zone_ref, 'z')
        
                    zinvs = res_ops.get_resource(res_ops.ZONE, session_uuid, name=zone_name)
                    zinv = get_first_item_from_list(zinvs, 'Zone', zone_name, 'Cluster')
                    action.zoneUuid = zinv.uuid
                    thread = threading.Thread(target=_add_cluster, args=(action, zone_ref, cluster, cluster_ref, ))
                    wait_for_thread_queue()
                    thread.start()
开发者ID:TinaL3,项目名称:zstack-woodpecker,代码行数:34,代码来源:deploy_operations.py


示例10: _deploy_l3_network

    def _deploy_l3_network(l2, zone_ref, cluster_ref):
        if not xmlobject.has_element(l2, "l3Networks.l3BasicNetwork"):
            return

        if not l2.duplication__:
            l2_dup = 1
        else:
            l2_dup = int(l2.duplication__)

        for l2_num in range(l2_dup):
            for l3 in xmlobject.safe_list(l2.l3Networks.l3BasicNetwork):
                if l3_name and l3_name != l3.name_:
                    continue

                l2Name = generate_dup_name(
                    generate_dup_name(generate_dup_name(l2.name_, zone_ref, 'z'), cluster_ref, 'c'), l2_num, 'n')
                l3Name = generate_dup_name(
                    generate_dup_name(generate_dup_name(l3.name_, zone_ref, 'z'), cluster_ref, 'c'), l2_num, 'n')

                l2invs = res_ops.get_resource(res_ops.L2_NETWORK,
                                              session_uuid,
                                              name=l2Name)
                l2inv = get_first_item_from_list(l2invs,
                                                 'L2 Network', l2Name, 'L3 Network')

                thread = threading.Thread(target=_do_l3_deploy,
                                          args=(l3, l2inv.uuid, l3Name, session_uuid,))
                wait_for_thread_queue()
                thread.start()
开发者ID:ShaofeiWang,项目名称:zstack-utility,代码行数:29,代码来源:deploy_config.py


示例11: add_virtual_router

def add_virtual_router(deployConfig, session_uuid, l3_name = None, \
        zone_name = None):

    if not xmlobject.has_element(deployConfig, 'instanceOfferings.virtualRouterOffering'):
        return

    for i in xmlobject.safe_list(deployConfig.instanceOfferings.virtualRouterOffering):
        if l3_name and l3_name != i.managementL3NetworkRef.text_:
            continue 

        if zone_name and zone_name != i.zoneRef.text_:
            continue 

        print "continue l3_name: %s; zone_name: %s" % (l3_name, zone_name)
        action = api_actions.CreateVirtualRouterOfferingAction()
        action.sessionUuid = session_uuid
        action.name = i.name_
        action.description = i.description__
        action.cpuNum = i.cpuNum_
        action.cpuSpeed = i.cpuSpeed_
        if i.memorySize__:
            action.memorySize = sizeunit.get_size(i.memorySize_)
        elif i.memoryCapacity_:
            action.memorySize = sizeunit.get_size(i.memoryCapacity_)

        action.isDefault = i.isDefault__
        action.type = 'VirtualRouter'

        zinvs = res_ops.get_resource(res_ops.ZONE, session_uuid, name=i.zoneRef.text_)
        zinv = get_first_item_from_list(zinvs, 'zone', i.zoneRef.text_, 'virtual router offering')
        action.zoneUuid = zinv.uuid
        cond = res_ops.gen_query_conditions('zoneUuid', '=', zinv.uuid)
        cond1 = res_ops.gen_query_conditions('name', '=', \
                i.managementL3NetworkRef.text_, cond)
        minvs = res_ops.query_resource(res_ops.L3_NETWORK, cond1, \
                session_uuid)

        minv = get_first_item_from_list(minvs, 'Management L3 Network', i.managementL3NetworkRef.text_, 'virtualRouterOffering')

        action.managementNetworkUuid = minv.uuid
        if xmlobject.has_element(i, 'publicL3NetworkRef'):
            cond1 = res_ops.gen_query_conditions('name', '=', \
                    i.publicL3NetworkRef.text_, cond)
            pinvs = res_ops.query_resource(res_ops.L3_NETWORK, cond1, \
                    session_uuid)
            pinv = get_first_item_from_list(pinvs, 'Public L3 Network', i.publicL3NetworkRef.text_, 'virtualRouterOffering')

            action.publicNetworkUuid = pinv.uuid

        iinvs = res_ops.get_resource(res_ops.IMAGE, session_uuid, \
                name=i.imageRef.text_)
        iinv = get_first_item_from_list(iinvs, 'Image', i.imageRef.text_, 'virtualRouterOffering')

        action.imageUuid = iinv.uuid

        thread = threading.Thread(target = _thread_for_action, args = (action, ))
        wait_for_thread_queue()
        thread.start()

    wait_for_thread_done()
开发者ID:TinaL3,项目名称:zstack-woodpecker,代码行数:60,代码来源:deploy_operations.py


示例12: add_instance_offering

def add_instance_offering(deployConfig, session_uuid):
    def _add_io(instance_offering_xml_obj, session_uuid):
        action = api_actions.CreateInstanceOfferingAction()
        action.sessionUuid = session_uuid
        action.name = instance_offering_xml_obj.name_
        action.description = instance_offering_xml_obj.description__
        action.cpuNum = instance_offering_xml_obj.cpuNum_
        action.cpuSpeed = instance_offering_xml_obj.cpuSpeed_
        if instance_offering_xml_obj.memorySize__:
            action.memorySize = sizeunit.get_size(instance_offering_xml_obj.memorySize_)
        elif instance_offering_xml_obj.memoryCapacity_:
            action.memorySize = sizeunit.get_size(instance_offering_xml_obj.memoryCapacity_)

        try:
            evt = action.run()
            test_util.test_logger(jsonobject.dumps(evt))
        except:
            exc_info.append(sys.exc_info())

    if not xmlobject.has_element(deployConfig, \
            'instanceOfferings.instanceOffering'):
        return

    for instance_offering_xml_obj in \
            xmlobject.safe_list(deployConfig.instanceOfferings.instanceOffering):
        thread = threading.Thread(target = _add_io, \
                args = (instance_offering_xml_obj, session_uuid, ))
        wait_for_thread_queue()
        thread.start()

    wait_for_thread_done()
开发者ID:TinaL3,项目名称:zstack-woodpecker,代码行数:31,代码来源:deploy_operations.py


示例13: get_sce_hosts

def get_sce_hosts(scenarioConfig=test_lib.all_scenario_config, scenarioFile=test_lib.scenario_file):
    host_list = []

    if scenarioConfig == None or scenarioFile == None or not os.path.exists(scenarioFile):
        return host_list

    for host in xmlobject.safe_list(scenarioConfig.deployerConfig.hosts.host):
        for vm in xmlobject.safe_list(host.vms.vm):
            with open(scenarioFile, 'r') as fd:
                xmlstr = fd.read()
                fd.close()
                scenario_file = xmlobject.loads(xmlstr)
                for s_vm in xmlobject.safe_list(scenario_file.vms.vm):
                    if s_vm.name_ == vm.name_:
                        host_list.append(s_vm)
    return host_list
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:16,代码来源:test_stub.py


示例14: _add_zone

    def _add_zone(zone, zone_duplication):
        action = api_actions.CreateZoneAction()
        action.sessionUuid = session_uuid
        if zone_duplication == 0:
            action.name = zone.name_
            action.description = zone.description__
            if zone.uuid__:
                action.resourceUuid = zone.uuid__
        else:
            action.name = generate_dup_name(zone.name_, zone_duplication, 'z')
            action.description = generate_dup_name(zone.description__, zone_duplication, 'zone')

        try:
            evt = action.run()
            deploy_logger(jsonobject.dumps(evt))
            zinv = evt.inventory
        except:
            exc_info.append(sys.exc_info())

        if xmlobject.has_element(zone, 'backupStorageRef'):
            for ref in xmlobject.safe_list(zone.backupStorageRef):
                bss = res_ops.get_resource(res_ops.BACKUP_STORAGE, session_uuid, name=ref.text_)
                bs = get_first_item_from_list(bss, 'Backup Storage', ref.text_, 'attach backup storage to zone')

                action = api_actions.AttachBackupStorageToZoneAction()
                action.sessionUuid = session_uuid
                action.backupStorageUuid = bs.uuid
                action.zoneUuid = zinv.uuid
                try:
                    evt = action.run()
                    deploy_logger(jsonobject.dumps(evt))
                except:
                    exc_info.append(sys.exc_info())
开发者ID:ShaofeiWang,项目名称:zstack-utility,代码行数:33,代码来源:deploy_config.py


示例15: add_instance_offering

def add_instance_offering(deployConfig, session_uuid):
    def _add_io(instance_offering_xml_obj, session_uuid):
        action = api_actions.CreateInstanceOfferingAction()
        action.sessionUuid = session_uuid
        action.name = instance_offering_xml_obj.name_
        action.description = instance_offering_xml_obj.description__
        action.cpuNum = instance_offering_xml_obj.cpuNum_
        action.cpuSpeed = instance_offering_xml_obj.cpuSpeed_
        action.memorySize = sizeunit.get_size(instance_offering_xml_obj.memorySize_)
        if instance_offering_xml_obj.uuid__:
            action.resourceUuid = instance_offering_xml_obj.uuid__
        evt = action.run()
        deploy_logger(jsonobject.dumps(evt))

    if not xmlobject.has_element(deployConfig,
                                 'instanceOfferings.instanceOffering'):
        return

    for instance_offering_xml_obj in \
            xmlobject.safe_list(deployConfig.instanceOfferings.instanceOffering):
        thread = threading.Thread(target=_add_io,
                                  args=(instance_offering_xml_obj, session_uuid,))
        wait_for_thread_queue()
        thread.start()

    wait_for_thread_done()
开发者ID:ShaofeiWang,项目名称:zstack-utility,代码行数:26,代码来源:deploy_config.py


示例16: _deploy_host

    def _deploy_host(cluster, zone_ref, cluster_ref):
        if not xmlobject.has_element(cluster, "hosts.host"):
            return

        if zone_ref == 0 and cluster_ref == 0:
            cluster_name = cluster.name_
        else:
            cluster_name = generate_dup_name(generate_dup_name(cluster.name_, zone_ref, 'z'), cluster_ref, 'c')

        cinvs = res_ops.get_resource(res_ops.CLUSTER, session_uuid, name=cluster_name)
        cinv = get_first_item_from_list(cinvs, 'Cluster', cluster_name, 'L3 network')
        for host in xmlobject.safe_list(cluster.hosts.host):
            if host_ip and host_ip != host.managementIp_:
                continue

            if host.duplication__ == None:
                host_duplication = 1
            else:
                host_duplication = int(host.duplication__)

            for i in range(host_duplication):
                if cluster.hypervisorType_ == inventory.KVM_HYPERVISOR_TYPE:
                    action = api_actions.AddKVMHostAction()
                    action.username = host.username_
                    action.password = host.password_
                    action.timeout = AddKVMHostTimeOut
                    if hasattr(host, 'sshPort_'):
                        action.port = host.sshPort_
                elif cluster.hypervisorType_ == inventory.SIMULATOR_HYPERVISOR_TYPE:
                    action = api_actions.AddSimulatorHostAction()
                    if host.cpuCapacity__:
                        action.cpuCapacity = host.cpuCapacity_
                    else:
                        action.cpuCapacity = 416000
                    if host.memoryCapacity__:
                        action.memoryCapacity = sizeunit.get_size(host.memoryCapacity_)
                    else:
                        action.memoryCapacity = sizeunit.get_size('1024G')

                action.sessionUuid = session_uuid
                action.clusterUuid = cinv.uuid
                action.hostTags = host.hostTags__
                if zone_ref == 0 and cluster_ref == 0 and i == 0:
                    action.name = host.name_
                    action.description = host.description__
                    action.managementIp = host.managementIp_
                    if host.uuid__:
                        action.resourceUuid = host.uuid__
                else:
                    action.name = generate_dup_name(
                        generate_dup_name(generate_dup_name(host.name_, zone_ref, 'z'), cluster_ref, 'c'), i, 'h')
                    action.description = generate_dup_name(
                        generate_dup_name(generate_dup_name(host.description__, zone_ref, 'z'), cluster_ref, 'c'), i,
                        'h')
                    action.managementIp = generate_dup_host_ip(host.managementIp_, zone_ref, cluster_ref, i)

                thread = threading.Thread(target=_thread_for_action, args=(action,))
                wait_for_thread_queue()
                thread.start()
开发者ID:ShaofeiWang,项目名称:zstack-utility,代码行数:59,代码来源:deploy_config.py


示例17: _deploy_primary_storage

    def _deploy_primary_storage(zone):
        if xmlobject.has_element(zone, 'primaryStorages.nfsPrimaryStorage'):
            zinvs = res_ops.get_resource(res_ops.ZONE, session_uuid, \
                    name=zone.name_)
            zinv = get_first_item_from_list(zinvs, 'Zone', zone.name_, 'primary storage')

            for pr in xmlobject.safe_list(zone.primaryStorages.nfsPrimaryStorage):
                if ps_name and ps_name != pr.name_:
                    continue

                action = api_actions.AddNfsPrimaryStorageAction()
                action.sessionUuid = session_uuid
                action.name = pr.name_
                action.description = pr.description__
                action.type = inventory.NFS_PRIMARY_STORAGE_TYPE
                action.url = pr.url_
                action.zoneUuid = zinv.uuid
                if pr.uuid__:
                    action.resourceUuid = pr.uuid__
                thread = threading.Thread(target=_thread_for_action, args=(action,))
                wait_for_thread_queue()
                thread.start()

        if xmlobject.has_element(zone, 'primaryStorages.simulatorPrimaryStorage'):
            if zone.duplication__ == None:
                duplication = 1
            else:
                duplication = int(zone.duplication__)

            for pr in xmlobject.safe_list(zone.primaryStorages.simulatorPrimaryStorage):
                for zone_ref in range(duplication):
                    for cluster in xmlobject.safe_list(zone.clusters.cluster):
                        for pref in xmlobject.safe_list(cluster.primaryStorageRef):
                            if pref.text_ == pr.name_:
                                if cluster.duplication__ == None:
                                    cluster_duplication = 1
                                else:
                                    cluster_duplication = int(cluster.duplication__)

                                for cluster_ref in range(cluster_duplication):
                                    action = _generate_sim_ps_action(zone, pr, zone_ref, cluster_ref)
                                    thread = threading.Thread(target=_thread_for_action, args=(action,))
                                    wait_for_thread_queue()
                                    thread.start()
开发者ID:zeus911,项目名称:zstack-utility,代码行数:44,代码来源:deploy_config.py


示例18: setup_static_ip

def setup_static_ip(scenario_file):
    ssh_cmd = 'sshpass -p password ssh -oStrictHostKeyChecking=no -oCheckHostIP=no -oUserKnownHostsFile=/dev/null'
    with open(scenario_file, 'r') as fd:
        xmlstr = fd.read()
        fd.close()
        scenario_file = xmlobject.loads(xmlstr)
        for vm in xmlobject.safe_list(scenario_file.vms.vm):
            mnip = vm.managementIp_
            if xmlobject.has_element(vm, 'ips'): 
                for ip in xmlobject.safe_list(vm.ips.ip):
                    nic_ip = ip.ip_
                    if nic_ip.startswith("10"):
                        if shell.run("%s %s 'ip a|grep br_zsn1'"%(ssh_cmd, mnip))== 0:
                            nic = "br_zsn1"
                        else:
                            nic = "zsn1"
                        netmask = "255.255.255.0"
                        shell.call("%s %s zs-network-setting -i %s %s %s|exit 0" %(ssh_cmd, mnip, nic, nic_ip, netmask) )
    return
开发者ID:zstackorg,项目名称:zstack-woodpecker,代码行数:19,代码来源:test_stub.py


示例19: add_l2_resource

def add_l2_resource(deploy_config, l2_name, zone_name = None, \
        session_uuid = None):
    session_uuid_flag = True
    if not session_uuid:
        session_uuid = acc_ops.login_as_admin()
        session_uuid_flag = False
    try:
        dep_ops.add_l2_network(deploy_config, session_uuid, l2_name, \
                zone_name = zone_name)
        l2_uuid = res_ops.get_resource(res_ops.L2_NETWORK, session_uuid, \
                name = l2_name)[0].uuid
        
        for zone in xmlobject.safe_list(deploy_config.zones.zone):
            if zone_name and zone_name != zone.name_:
                continue
            for cluster in xmlobject.safe_list(zone.clusters.cluster):
                if xmlobject.has_element(cluster, 'l2NetworkRef'):
                    for l2ref in xmlobject.safe_list(cluster.l2NetworkRef):
                        if l2_name != l2ref.text_:
                            continue

                        cluster_uuid = res_ops.get_resource(res_ops.CLUSTER, \
                                session_uuid, name=cluster.name_)[0].uuid
                        attach_l2(l2_uuid, cluster_uuid, session_uuid)

        dep_ops.add_l3_network(None, None, deploy_config, session_uuid, l2_name = l2_name, \
                zone_name = zone_name)
        cond = res_ops.gen_query_conditions('l2NetworkUuid', '=', l2_uuid)
        l3_name = res_ops.query_resource(res_ops.L3_NETWORK, cond, \
                session_uuid)[0].name
        dep_ops.add_virtual_router(None, None, deploy_config, session_uuid, \
                l3_name = l3_name, zone_name = zone_name)
    except Exception as e:
        test_util.test_logger('[Error] zstack deployment meets exception when adding l2 resource .')
        traceback.print_exc(file=sys.stdout)
        raise e
    finally:
        if not session_uuid_flag:
            acc_ops.logout(session_uuid)

    test_util.action_logger('Complete add l2 resources for [uuid:] %s' \
            % l2_uuid)
开发者ID:mrwangxc,项目名称:zstack-woodpecker,代码行数:42,代码来源:net_operations.py


示例20: _do_l3_deploy

    def _do_l3_deploy(l3, l2inv_uuid, l3Name, session_uuid):
        action = api_actions.CreateL3NetworkAction()
        action.sessionUuid = session_uuid
        action.description = l3.description__
        if l3.system__ and l3.system__ != 'False':
            action.system = 'true'
        action.l2NetworkUuid = l2inv_uuid
        action.name = l3Name
        if l3.uuid__:
            action.resourceUuid = l3.uuid__
        action.type = inventory.L3_BASIC_NETWORK_TYPE
        if l3.domain_name__:
            action.dnsDomain = l3.domain_name__

        try:
            evt = action.run()
        except:
            exc_info.append(sys.exc_info())

        deploy_logger(jsonobject.dumps(evt))
        l3_inv = evt.inventory

        # add dns
        if xmlobject.has_element(l3, 'dns'):
            for dns in xmlobject.safe_list(l3.dns):
                action = api_actions.AddDnsToL3NetworkAction()
                action.sessionUuid = session_uuid
                action.dns = dns.text_
                action.l3NetworkUuid = l3_inv.uuid
                try:
                    evt = action.run()
                except:
                    exc_info.append(sys.exc_info())
                deploy_logger(jsonobject.dumps(evt))

        # add ip range.
        if xmlobject.has_element(l3, 'ipRange'):
            do_add_ip_range(l3.ipRange, l3_inv.uuid, session_uuid)

        # add network service.
        providers = {}
        action = api_actions.QueryNetworkServiceProviderAction()
        action.sessionUuid = session_uuid
        action.conditions = []
        try:
            reply = action.run()
        except:
            exc_info.append(sys.exc_info())
        for pinv in reply:
            providers[pinv.name] = pinv.uuid

        if xmlobject.has_element(l3, 'networkService'):
            do_add_network_service(l3.networkService, l3_inv.uuid,
                                   providers, session_uuid)
开发者ID:ShaofeiWang,项目名称:zstack-utility,代码行数:54,代码来源:deploy_config.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python testagent.build_http_path函数代码示例发布时间:2022-05-26
下一篇:
Python xmlobject.has_element函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap