def _run_as_root_detect_device_not_found(self, *args, **kwargs): try: return self._as_root(*args, **kwargs) except RuntimeError as rte: with excutils.save_and_reraise_exception() as ctx: if "Cannot find device" in str(rte): ctx.reraise = False raise n_exc.DeviceNotFoundError(device_name=self.name)
def delete_gateway(self, gateway, table=None): ip_version = get_ip_version(gateway) args = ['del', 'default', 'via', gateway, 'dev', self.name] if table: args += ['table', table] try: self._as_root([ip_version], tuple(args)) except RuntimeError as rte: with (excutils.save_and_reraise_exception()) as ctx: if "Cannot find device" in rte.message: ctx.reraise = False raise exceptions.DeviceNotFoundError(device_name=self.name)
def create_floatingip(self, context, floatingip): floatingip_port = None try: floatingip_dict = super(DFL3RouterPlugin, self).create_floatingip( context, floatingip, initial_status=const.FLOATINGIP_STATUS_DOWN) fip_version = floatingip_dict['revision_number'] # Note: Here the context is elevated, because the floatingip port # will not have tenant and floatingip subnet might be in other # tenant. admin_context = context.elevated() floatingip_port = self._get_floatingip_port( admin_context, floatingip_dict['id']) if not floatingip_port: raise n_common_exc.DeviceNotFoundError( device_name=floatingip_dict['id']) subnet_id = floatingip_port['fixed_ips'][0]['subnet_id'] floatingip_subnet = self._get_floatingip_subnet( admin_context, subnet_id) if floatingip_subnet is None: raise n_exc.SubnetNotFound(subnet_id=subnet_id) except Exception: with excutils.save_and_reraise_exception() as ctxt: ctxt.reraise = True # delete the stale floatingip port try: if floatingip_port: self.nb_api.delete_lport(floatingip_port['id'], floatingip_port['tenant_id']) except df_exceptions.DBKeyNotFound: pass self.nb_api.create_floatingip( id=floatingip_dict['id'], topic=floatingip_dict['tenant_id'], name=floatingip_dict.get('name', df_const.DF_FIP_DEFAULT_NAME), floating_ip_address=floatingip_dict['floating_ip_address'], floating_network_id=floatingip_dict['floating_network_id'], router_id=floatingip_dict['router_id'], port_id=floatingip_dict['port_id'], fixed_ip_address=floatingip_dict['fixed_ip_address'], status=floatingip_dict['status'], floating_port_id=floatingip_port['id'], floating_mac_address=floatingip_port['mac_address'], external_gateway_ip=floatingip_subnet['gateway_ip'], version=fip_version, external_cidr=floatingip_subnet['cidr']) return floatingip_dict
def delete_gateway(self, gateway, table=None): ip_version = get_ip_version(gateway) args = ['del', 'default', 'via', gateway] args += self._dev_args() args += self._table_args(table) try: self._as_root([ip_version], tuple(args)) except RuntimeError as rte: with (excutils.save_and_reraise_exception()) as ctx: if "Cannot find device" in str(rte): ctx.reraise = False raise exceptions.DeviceNotFoundError( device_name=self.name)
def create_floatingip(self, context, floatingip): try: floatingip_port = None with context.session.begin(subtransactions=True): floatingip_dict = super(DFPlugin, self).create_floatingip( context, floatingip, initial_status=const.FLOATINGIP_STATUS_DOWN) floatingip_port = self._get_floatingip_port( context, floatingip_dict['id']) if not floatingip_port: raise n_exc.DeviceNotFoundError( device_name=floatingip_dict['id']) subnet_id = floatingip_port['fixed_ips'][0]['subnet_id'] floatingip_subnet = self._get_floatingip_subnet( context, subnet_id) if floatingip_subnet is None: raise n_exc.SubnetNotFound(subnet_id=subnet_id) fip_version = version_db._create_db_version_row( context.session, floatingip_dict['id']) except Exception: with excutils.save_and_reraise_exception() as ctxt: ctxt.reraise = True # delete the stale floatingip port try: if floatingip_port: self.nb_api.delete_lport(floatingip_port['id'], floatingip_port['tenant_id']) except df_exceptions.DBKeyNotFound: pass self.nb_api.create_floatingip( id=floatingip_dict['id'], topic=floatingip_dict['tenant_id'], name=floatingip_dict.get('name', df_const.DF_FIP_DEFAULT_NAME), floating_ip_address=floatingip_dict['floating_ip_address'], floating_network_id=floatingip_dict['floating_network_id'], router_id=floatingip_dict['router_id'], port_id=floatingip_dict['port_id'], fixed_ip_address=floatingip_dict['fixed_ip_address'], status=floatingip_dict['status'], floating_port_id=floatingip_port['id'], floating_mac_address=floatingip_port['mac_address'], external_gateway_ip=floatingip_subnet['gateway_ip'], version=fip_version, external_cidr=floatingip_subnet['cidr']) return floatingip_dict
def create_floatingip(self, context, floatingip): floatingip_port = None try: floatingip_dict = super(DFL3RouterPlugin, self).create_floatingip( context, floatingip, initial_status=const.FLOATINGIP_STATUS_DOWN) # Note: Here the context is elevated, because the floatingip port # will not have tenant and floatingip subnet might be in other # tenant. admin_context = context.elevated() floatingip_port = self._get_floatingip_port( admin_context, floatingip_dict['id']) if not floatingip_port: raise n_common_exc.DeviceNotFoundError( device_name=floatingip_dict['id']) except Exception: with excutils.save_and_reraise_exception() as ctxt: ctxt.reraise = True # delete the stale floatingip port try: if floatingip_port: self.nb_api.delete( l2.LogicalPort(id=floatingip_port['id'], topic=floatingip_port['tenant_id'])) except df_exceptions.DBKeyNotFound: pass self.nb_api.create( l3.FloatingIp( id=floatingip_dict['id'], topic=floatingip_dict['tenant_id'], name=floatingip_dict.get('name', df_const.DF_FIP_DEFAULT_NAME), version=floatingip_dict['revision_number'], status=floatingip_dict['status'], floating_ip_address=floatingip_dict['floating_ip_address'], fixed_ip_address=floatingip_dict['fixed_ip_address'], lrouter=floatingip_dict['router_id'], lport=floatingip_dict['port_id'], floating_lport=floatingip_port['id'], ), skip_send_event=('port_id' not in floatingip_dict), ) return floatingip_dict