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, 'id': u'01c2468ab38b4d4490a39765bb87cb00' } router = {'router': router_obj} records = tn_db.query_records(context, l3_models.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) route = tn_db.query_records(context, l3_models.RouterRoute, router_id=router['router']['id']) if route is not None or route != []: l3_driver._update_tn_router_route(context, router['router']['id'], route) p.update()
def test(context): ports = tn_db.query_records(context, models_v2.Port) for port in ports: LOG.debug(port) vlan_id = tnos_router.get_vlan_id(context, port['network_id']) LOG.debug(str(vlan_id))
def get_intf_info(context, router_id): api_client = get_tn_client(context, router_id) msg = api_client.request(templates.GET_INTF_INFO) intf_info = msg['reply'] intfs = tn_db.query_records(context, tn_db.Tn_Interface, router_id=router_id) for info in intf_info: for intf in intfs: if info['mkey'] == intf.inner_name: tn_db.update_record(context, intf, inner_id=info['mkey_id'], type=info['type'])
def firewall_migration(context, fw_plugin): fw_list = fw_plugin.get_firewalls(context) for fw in fw_list: fw_with_rules = fw_plugin._make_firewall_dict_with_rules(context, fw['id']) fw_routers = tn_db.query_records(context, fw_rt_db.FirewallRouterAssociation, fw_id=fw['id']) fw_with_rules['add-router-ids'] = [fw_router.router_id for fw_router in fw_routers] LOG.debug(fw_with_rules['add-router-ids']) fw_plugin.create_firewall(context, fw_with_rules)
def shutdown_old_intf(context, router_id): intfs = tn_db.query_records(context, tn_db.Tn_Interface, router_id=router_id) time.sleep(3) for intf in intfs: if intf.is_gw == 'True': port_name = 'qg-'+intf.id[:11] else: port_name = 'qr-'+intf.id[:11] cmd = 'sudo ip netns exec qrouter-' + router_id + ' ifconfig ' + port_name + ' down' LOG.debug("excute cmd : %s", cmd) subprocess.Popen(cmd, shell=True)
def update_firewall_for_delete_router(self, context, router_id): LOG.debug("fwaas delete_router() called, router_id: %(rtid)s", {'rtid': router_id}) cls = firewall_router_insertion_db.FirewallRouterAssociation db_fw_rt = tn_db.query_record(context, cls, router_id=router_id) if not db_fw_rt: return None fw_rts = tn_db.query_records(context, cls, fw_id=db_fw_rt.fw_id) routers = [fw_rt.router_id for fw_rt in fw_rts] routers.remove(router_id) firewall = {u'firewall': {'router_ids': routers}} return self.update_firewall(context, db_fw_rt.fw_id, firewall)
def get_manage_ip(context, manage_ip): max_num = 0 ip = None routers = tn_db.query_records(context, tn_db.Tn_Router) for router in routers: ip = router.manage_ip ip = ip.split('.') if int(ip[2]) > max_num: max_num = int(ip[2]) if ip is None: return manage_ip elif max_num < 254: ip[2] = str(max_num + 1) ip = '.'.join(ip) return ip else: return None
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 = tn_db.query_records(context, l3_models.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()
def get_list(context, **kwargs): return tn_db.query_records(context, tn_db.Tn_Firewall, **kwargs)
def gets(context, **kwargs): return tn_db.query_records(context, tn_db.Tn_Rule, **kwargs)
def get_static_routes(context, **kwargs): return tn_db.query_records(context, tn_db.Tn_Static_Route, **kwargs)
def get_intfs(context, **kwargs): return tn_db.query_records(context, tn_db.Tn_Interface, **kwargs)
def get_tn_routers(context, **kwargs): return tn_db.query_records(context, tn_db.Tn_Router, **kwargs)
def port_migration(context, 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' } records = tn_db.query_records(context, models_v2.Port) with Progress(len(records), 'port_migration') as p: for record in records: reset(port) cls2dict(record, port) db_routerport = tn_db.query_record(context, l3_models.RouterPort, port_id=record.id) if getattr(db_routerport, 'port_type', None) in [ROUTER_INTF, ROUTER_GW]: l3_driver.add_router_interface(context, port) p.update()
def get_firewall_rules(self, context, policy_id): return tn_db.query_records(context, firewall_db.FirewallRule, firewall_policy_id=policy_id)
def get_firewalls(self, context): return tn_db.query_records(context, firewall_db.Firewall)