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 = fortinet_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 fortinet_db.query_count(context, models_v2.Port, mac_address=MAC, network_id=record.network_id): fortinet_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 = fortinet_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()
def update_floatingip_status(self, context, res, status, **kwargs): if res.get('status', None): res['status'] = status record = fortinet_db.query_record(context, l3_db.FloatingIP, **kwargs) fortinet_db.update_record(context, record, status=status)