예제 #1
0
def create_l2_vlan(name, nic, zone_uuid, vlan, session_uuid=None):
    '''
    Delete L2 will stop all VMs which is using this L2. When VM started again, 
    the related L2 NIC will be removed. 
    '''
    action = api_actions.CreateL2VlanNetworkAction()
    action.name = name
    action.physicalInterface = nic
    action.vlan = vlan
    action.zoneUuid = zone_uuid
    action.timeout = 300000
    evt = acc_ops.execute_action_with_session(action, session_uuid)
    test_util.action_logger("[Vlan L2:] %s is created" % evt.uuid)
    return evt
예제 #2
0
    def _deploy_l2_network(zone, is_vlan):
        if is_vlan:
            if not xmlobject.has_element(zone, "l2Networks.l2VlanNetwork"):
                return
            l2Network = zone.l2Networks.l2VlanNetwork
        else:
            if not xmlobject.has_element(zone,
                                         "l2Networks.l2NoVlanNetwork"):
                return
            l2Network = zone.l2Networks.l2NoVlanNetwork

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

        for zone_ref in range(zone_dup):
            zoneName = generate_dup_name(zone.name_, zone_ref, 'z')

            zinvs = res_ops.get_resource(res_ops.ZONE, session_uuid, name=zoneName)
            zinv = get_first_item_from_list(zinvs, 'Zone', zoneName, 'L2 network')

            # can only deal with single cluster duplication case.
            cluster = xmlobject.safe_list(zone.clusters.cluster)[0]

            if cluster.duplication__ == None:
                cluster_duplication = 1
            else:
                cluster_duplication = int(cluster.duplication__)

            for cluster_ref in range(cluster_duplication):
                for l2 in xmlobject.safe_list(l2Network):
                    if l2_name and l2_name != l2.name_:
                        continue

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

                    for j in range(l2_dup):
                        l2Name = generate_dup_name(
                            generate_dup_name(
                                generate_dup_name(
                                    l2.name_, zone_ref, 'z')
                                , cluster_ref, 'c')
                            , j, 'n')

                        if not l2.description__:
                            l2.description_ = 'l2'

                        l2Des = generate_dup_name(
                            generate_dup_name(
                                generate_dup_name(
                                    l2.description_, zone_ref, 'z')
                                , cluster_ref, 'c')
                            , j, 'n')

                        if is_vlan:
                            l2_vlan = int(l2.vlan_) + j

                        if is_vlan:
                            action = api_actions.CreateL2VlanNetworkAction()
                        else:
                            action = api_actions.CreateL2NoVlanNetworkAction()

                        action.sessionUuid = session_uuid
                        action.name = l2Name
                        action.description = l2Des

                        action.physicalInterface = l2.physicalInterface_
                        action.zoneUuid = zinv.uuid
                        if is_vlan:
                            action.vlan = l2_vlan

                        if l2.uuid__:
                            action.resourceUuid = l2.uuid__

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