def test_db(context): # tn_db.add_record(context, tn_db.Tn_Router, id='1234567890', priv_id='123', tenant_id='123', # name='test', manage_ip='1.1.1.1') router = tn_db.query_record(context, tn_db.Tn_Router, id='1234567890') # LOG.debug('router name %s', router.name) # tn_db.add_record(context, tn_db.Tn_Interface, name='12345', tenant_id='00001') interface = tn_db.query_record(context, tn_db.Tn_Interface, id='12345') LOG.debug('interface %s', interface) route = tn_db.query_record(context, tn_db.Tn_Static_Route, router_id='12345') LOG.debug('route %s', route) address = tn_db.query_record(context, tn_db.Tn_Address, rule_id='12345') LOG.debug('address %s', address) service = tn_db.query_record(context, tn_db.Tn_Service, rule_id='12345') LOG.debug('service %s', service) rule = tn_db.query_record(context, tn_db.Tn_Rule, id='12345') LOG.debug('rule %s', rule) policy = tn_db.query_record(context, tn_db.Tn_Policy, id='12345') LOG.debug('policy %s', policy) firewall = tn_db.query_record(context, tn_db.Tn_Firewall, id='12345') LOG.debug('firewall %s', firewall)
def del_router(context, router_id): # kill vm and delete router router = tn_db.query_record(context, tn_db.Tn_Router, id=router_id) if router is not None: tn_drv.destroy_vm(router_id, router.image_name) tn_db.delete_record(context, tn_db.Tn_Router, id=router_id) del TNOS_CLIENT[router_id]
def create_router(self, context, router): LOG.debug("create_router: router=%s" % (router)) # Limit one router per tenant if not router.get('router', None): return rlt = super(TNL3ServicePlugin, self).create_router(context, router) LOG.debug(rlt) #with context.session.begin(subtransactions=True): tenant_id = router['router']['tenant_id'] router_name = router['router']['name'] router_db = tn_db.query_record(context, l3_db.Router, name=router_name, tenant_id=tenant_id) LOG.debug(router_db) router_id = router_db['id'] try: tnos_router.create_router(context, router_id, tenant_id, router_name, self._tn_info["image_path"], self._tn_info['address']) gateway = router['router'].get('external_gateway_info') if gateway is not None: self._update_tn_router_gw(context, router_id, gateway, rlt) except Exception as e: LOG.error("Failed to create_router router=%(router)s", {"router": router}) resources.Exinfo(e) return rlt
def del_apply(context, client, rule_id): svc = tn_db.query_record(context, tn_db.Tn_Service, rule_id=rule_id) if svc is not None: client.request(templates.DEL_SERVICE_ENTRY, name=svc.name, protocol=svc.protocol, dst_port_max=svc.dst_port_max, dst_port_min=svc.dst_port_min, src_port_max=svc.src_port_max, src_port_min=svc.src_port_min)
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_tn_client(context, router_id): if router_id in TNOS_CLIENT: return TNOS_CLIENT[router_id] # for test if router_id == '999999': TNOS_CLIENT[router_id] = config.get_apiclient('88.1.1.1') return TNOS_CLIENT[router_id] tn_router = tn_db.query_record(context, tn_db.Tn_Router, id=router_id) if tn_router is not None: TNOS_CLIENT[router_id] = config.get_apiclient(tn_router.manage_ip) return TNOS_CLIENT[router_id]
def create_router(context, id, tenant_id, name, image_path='tnos.qcow2', manage_ip='90.1.1.1'): priv_id = tn_router_id_convert(id) ip = get_manage_ip(context, manage_ip) if ip is None: LOG.error('Too more routers, there is no manage ip!') return image = create_tnos(id, priv_id, image_path, ip) init_intf(priv_id, ip) TNOS_CLIENT[id] = config.get_apiclient(ip) router = tn_db.query_record(context, tn_db.Tn_Router, id=id) if router is None: tn_db.add_record(context, tn_db.Tn_Router, id=id, priv_id=priv_id, tenant_id=tenant_id, name=name, manage_ip=ip, image_name=image) else: tn_db.update_record(context, router, id=id, priv_id=priv_id, tenant_id=tenant_id, name=name, manage_ip=ip, image_name=image)
def del_intf(context, router_id, intf_id): intf = tn_db.query_record(context, tn_db.Tn_Interface, id=intf_id) if intf is not None: api_client = get_tn_client(context, router_id) if intf.is_gw == 'True': ovsctl.del_port(context, INT_BRIDGE_NAME, intf.extern_name) else: api_client.request(templates.DEL_SUB_INTF, intf_name=intf.inner_name, id=intf.inner_id) ovsctl.del_trunk_port_tag(context, intf.extern_name, intf.vlan_id) count = tn_db.query_count(context, tn_db.Tn_Interface, router_id=router_id, is_gw='False') if count == 1: # the last one ovsctl.del_port(context, INT_BRIDGE_NAME, intf.extern_name) tn_db.delete_record(context, tn_db.Tn_Interface, id=intf.id) # todo xiongjun: patch, fix bug: namespace interface will be up when add interface shutdown_old_intf(context, router_id)
def delete_router(self, context, id): LOG.debug("delete_router: router id=%s", id) try: if self.enable_fwaas: fw_plugin = directory.get_plugin(p_consts.FIREWALL) fw_plugin.update_firewall_for_delete_router(context, id) self._update_tn_router_route(context, id, del_all=True) self._remove_tn_router_interface(context, id, is_gw=True) router = tn_db.query_record(context, l3_db.Router, id=id) setattr(context, 'GUARD_TRANSACTION', False) if getattr(router, 'tenant_id', None): LOG.debug(router) tnos_router.del_router(context, router['id']) except Exception as e: with excutils.save_and_reraise_exception(): LOG.error(_LE("Failed to delete_router routerid=%(id)s"), {"id": id}) resources.Exinfo(e) else: super(TNL3ServicePlugin, self).delete_router(context, id)
def _get_floatingip(self, context, id): return tn_db.query_record(context, l3_models.FloatingIP, id=id)
def del_apply(context, client, rule_id, name): addr = tn_db.query_record(context, tn_db.Tn_Address, rule_id=rule_id, name=name) if addr is not None: client.request(templates.DEL_ADDRESS_ENTRY, name=addr.name)
def get(context, **kwargs): return tn_db.query_record(context, tn_db.Tn_Firewall, **kwargs)
def get(context, **kwargs): return tn_db.query_record(context, tn_db.Tn_Policy, **kwargs)
def get(context, **kwargs): return tn_db.query_record(context, tn_db.Tn_Rule, **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_intf(context, **kwargs): return tn_db.query_record(context, tn_db.Tn_Interface, **kwargs)
def get_firewall(self, context, id): return tn_db.query_record(context, firewall_db.Firewall, id=id)
def get_tn_router(context, router_id): return tn_db.query_record(context, tn_db.Tn_Router, id=router_id)