コード例 #1
0
def router_migration(context, l3_driver):
    """
    # table routers, router_extra_attributes
    router={
        u'router': {
            'external_gateway_info': None,
            u'name': u'adm_router',
            u'admin_state_up': True,
            u'tenant_id': u'01c2468ab38b4d4490a39765bb87cb00',
            'distributed': 'fakedistributed',
            'ha': 'fakeha'
        }
    }
    """
    router_obj = {
        'name': 'adm_router',
        'admin_state_up': True,
        'tenant_id': u'01c2468ab38b4d4490a39765bb87cb00'
    }
    router = {'router': router_obj}

    records = ngfw_db.query_records(context, l3_db.Router)
    with Progress(len(records), 'router_migration') as p:
        for record in records:
            reset(router_obj)
            cls2dict(record, router_obj)
            l3_driver.create_router(context, router)
            p.update()
コード例 #2
0
def network_migration(context, mech_driver):
    """
    # networks, ml2_network_segments
    network =  {
        #'status': 'ACTIVE',
        #'subnets': [],
        'name': u'test-net',
        #'provider: physical_network': u'physnet1',
        #'admin_state_up': True,
        'tenant_id': u'11513667f4ee4a14acb0985659459988',
        'provider: network_type': u'vlan',
        'router:external': False,
        #'shared': False,
        'id': 'ff0a1d64-ce30-4ed0-ba37-597eaf8976f0',
        #'provider: segmentation_id': 1200L
    }
    # ml2_network_segments
    segments = [{
        'segmentation_id': 1200L,
        'physical_network': u'physnet1',
        'id': u'e7dfa4fb-038a-4aad-b6fa-73afba788888',
        'network_type': u'vlan'
    }]
    """
    net = {
        'name': '',
        'tenant_id': '',
        'provider: network_type': '',
        'router:external': False,
        'id': '',
    }

    segment = {
        'segmentation_id': 0,
        'physical_network': '',
        'id': '',
        'network_type': ''
    }
    records = ngfw_db.query_records(context, models_v2.Network)
    with Progress(len(records), 'network_migration') as p:
        for record in records:
            reset(net)
            reset(segment)
            db_seg = ngfw_db.query_record(context,
                                          ml2_db.NetworkSegment,
                                          network_id=record.id)
            cls2dict(record, net)
            db_extnet = ngfw_db.query_record(context,
                                             ExternalNetwork,
                                             network_id=record.id)
            if db_extnet:
                net['router:external'] = True

            cls2dict(db_seg, segment)
            net['provider: network_type'] = db_seg.network_type
            mech_context = Fake_mech_context(_plugin_context=context,
                                             current=net,
                                             network_segments=[segment])
            mech_driver.create_network_postcommit(mech_context)
            p.update()
コード例 #3
0
def subnet_migration(context, mech_driver):
    # table subnets
    subnet = {
        'allocation_pools': [{
            'start': '172.20.21.2',
            'end': '172.20.21.254'
        }],
        'cidr': '172.20.21.0/24',
        'id': 'ee1506dc-d1a9-45b3-840e-137bdaebce52',
        'enable_dhcp': True,
        'network_id': u'ad47f7b8-4bb7-4591-b8ed-f720237dd24f',
        'tenant_id': u'11513667f4ee4a14acb0985659456f24',
        'dns_nameservers': [],
        'gateway_ip': u'172.20.21.1',
        'shared': False
    }
    ipallocation_pool = {'start': '172.20.21.2', 'end': '172.20.21.254'}
    records = ngfw_db.query_records(context, models_v2.Subnet)
    with Progress(len(records), 'subnet_migration') as p:
        for record in records:
            dns_nameservers = []
            reset(subnet)
            reset(ipallocation_pool)
            db_ipallocation = ngfw_db.query_record(context,
                                                   models_v2.IPAllocationPool,
                                                   subnet_id=record.id)
            cls2dict(db_ipallocation,
                     ipallocation_pool,
                     first_ip='start',
                     last_ip='end')
            db_dnssrvs = ngfw_db.query_records(context,
                                               models_v2.DNSNameServer,
                                               subnet_id=record.id)

            for dns in db_dnssrvs:
                dns_nameservers.append(dns.address)
            cls2dict(record, subnet)
            subnet['dns_nameservers'] = dns_nameservers
            subnet['allocation_pools'] = [ipallocation_pool]
            mech_context = Fake_mech_context(_plugin_context=context,
                                             current=subnet)
            mech_driver.create_subnet_postcommit(mech_context)
            p.update()
コード例 #4
0
def floatingip_migration(context, l3_driver):
    """
    # table floatingips, ipallocations
    floatingip = {
        u'floatingip': {
            u'floating_network_id': u'2bdcaa63-22c5-4e58-8e2e-8f35bef7f513',
            'tenant_id': u'11513667f4ee4a14acb0985659456f24',
            'fixed_ip_address': None,
            'port_id': None
        }
    }
    returned_obj
    {
        'floating_network_id': u'2bdcaa63-22c5-4e58-8e2e-8f35bef7f513',
        'router_id': None,
        'fixed_ip_address': None,
        'floating_ip_address': u'10.160.37.139',
        'tenant_id': u'11513667f4ee4a14acb0985659456f24',
        'status': 'DOWN',
        'port_id': None,
        'id': '78764016-da62-42fd-96a4-f2bd0510b5bc'
    }
    """

    returned_obj = {
        'fixed_ip_address': None,
        'floating_ip_address': u'10.160.37.139',
        'tenant_id': u'11513667f4ee4a14acb0985659456f24',
        'status': 'DOWN',
        'port_id': None,
        'id': '78764016-da62-42fd-96a4-f2bd0510b5bc'
    }
    floatingip = {'floatingip': returned_obj}
    records = ngfw_db.query_records(context, l3_db.FloatingIP)
    with Progress(len(records), 'floatingip_migration') as p:
        for record in records:
            reset(returned_obj)
            cls2dict(record, returned_obj, fixed_port_id='port_id')
            l3_driver.create_floatingip(context, floatingip, returned_obj)
            p.update()
コード例 #5
0
def port_migration(context, mech_driver, l3_driver):
    """
    :param mech_driver:
    :param context:
    :return:
    # table ports
    port
    {
        'status': 'DOWN',
        'binding: host_id': '',
        'allowed_address_pairs': [],
        'device_owner': 'network: router_interface',
        'binding: profile': {

        },
        # table ipallocations
        'fixed_ips': [{
            'subnet_id': u'f645b09c-a34a-42fb-9c14-b999e43a54c7',
            'ip_address': u'172.20.21.1'
        }],
        'id': 'fb66def6-bd5e-44a0-a3f7-7c0e8e08d9ff',
        'security_groups': [],
        'device_id': u'e4020c65-7003-468b-a34d-31af297397a0',
        'name': '',
        'admin_state_up': True,
        'network_id': u'f8e34426-ccf7-429c-b726-3809d54cabdc',
        'tenant_id': u'11513667f4ee4a14acb0985659456f24',
        'binding: vif_details': {
        },
        'binding: vnic_type': 'normal',
        'binding: vif_type': 'unbound',
        'mac_address': u'00: 0c: 29: d9: 18: 3f'
    }
    """
    port = {
        'device_owner':
        'network: router_interface',
        'fixed_ips': [{
            'subnet_id': u'f645b09c-a34a-42fb-9c14-b999e43a54c7',
            'ip_address': u'172.20.21.1'
        }],
        'id':
        'fb66def6-bd5e-44a0-a3f7-7c0e8e08d9ff',
        'device_id':
        u'e4020c65-7003-468b-a34d-31af297397a0',
        'admin_state_up':
        True,
        'network_id':
        u'f8e34426-ccf7-429c-b726-3809d54cabdc',
        'tenant_id':
        u'11513667f4ee4a14acb0985659456f24',
        'mac_address':
        u'00: 0c: 29: d9: 18: 3f'
    }
    ipallocation = {
        'subnet_id': u'f645b09c-a34a-42fb-9c14-b999e43a54c7',
        'ip_address': u'172.20.21.1'
    }
    MAC = utils.get_mac(mech_driver, context)
    records = ngfw_db.query_records(context, models_v2.Port)
    with Progress(len(records), 'port_migration') as p:
        for record in records:
            reset(port)
            cls2dict(record, port)
            if port['fixed_ips']:
                fixed_ips = []
                for fixed_ip in port['fixed_ips']:
                    cls2dict(fixed_ip, ipallocation)
                    fixed_ips.append(ipallocation)
                port['fixed_ips'] = fixed_ips
            if port['device_owner'] in [ROUTER_INTF, ROUTER_GW] and \
               MAC not in port['mac_address']:
                port['mac_address'] = MAC
                if not ngfw_db.query_count(context,
                                           models_v2.Port,
                                           mac_address=MAC,
                                           network_id=record.network_id):
                    ngfw_db.update_record(context, record, mac_address=MAC)
            mech_context = Fake_mech_context(_plugin_context=context,
                                             current=port)
            mech_driver.create_port_precommit(mech_context)
            mech_driver.create_port_postcommit(mech_context)
            db_routerport = ngfw_db.query_record(context,
                                                 l3_db.RouterPort,
                                                 port_id=record.id)
            if getattr(db_routerport, 'port_type', None) in [ROUTER_INTF]:
                l3_driver.add_router_interface(context, port)
            p.update()