def create_router(self, context, router): router = super(OVNL3RouterPlugin, self).create_router(context, router) try: self.create_lrouter_in_ovn(router) except Exception: LOG.exception(_LE('Unable to create lrouter for %s'), router['id']) super(OVNL3RouterPlugin, self).delete_router(context, router['id']) raise n_exc.ServiceUnavailable() return router
def update_router(self, context, id, router): original_router = self.get_router(context, id) result = super(OVNL3RouterPlugin, self).update_router(context, id, router) update = {} added = [] removed = [] router_name = utils.ovn_name(id) if 'admin_state_up' in router['router']: enabled = router['router']['admin_state_up'] if enabled != original_router['admin_state_up']: update['enabled'] = enabled if 'name' in router['router']: if router['router']['name'] != original_router['name']: external_ids = { ovn_const.OVN_ROUTER_NAME_EXT_ID_KEY: router['router']['name'] } update['external_ids'] = external_ids """ Update static routes """ if 'routes' in router['router']: routes = router['router']['routes'] added, removed = n_utils.diff_list_of_dict( original_router['routes'], routes) if update or added or removed: try: with self._ovn.transaction(check_error=True) as txn: if update: txn.add(self._ovn.update_lrouter( router_name, **update)) for route in added: txn.add( self._ovn.add_static_route( router_name, ip_prefix=route['destination'], nexthop=route['nexthop'])) for route in removed: txn.add( self._ovn.delete_static_route( router_name, ip_prefix=route['destination'], nexthop=route['nexthop'])) except Exception: LOG.exception(_LE('Unable to update lrouter for %s'), id) super(OVNL3RouterPlugin, self).update_router(context, id, original_router) raise n_exc.ServiceUnavailable() return result
def get_connected_socket(cls): OVSDB_IP = "localhost" OVSDB_PORT = 6640 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: sock.connect((OVSDB_IP, OVSDB_PORT)) print("echo Connected to the ovsdb \n") except socket.error: _, _, tb = sys.exc_info() six.reraise(exceptions.ServiceUnavailable, exceptions.ServiceUnavailable(), tb) return sock
def create_router(self, context, router): gw_info, router = self._create_router(context, router) try: self.create_lrouter_in_ovn(router) except Exception: LOG.exception(_LE('Unable to create lrouter for %s'), router['id']) super(OVNL3RouterPlugin, self).delete_router(context, router['id']) raise n_exc.ServiceUnavailable() try: if gw_info: self._update_router_gw_info(context, router['id'], gw_info) except Exception: LOG.exception(_LE('Fail to set gateway for router %s'), router['id']) return router
def _create_router_gw_port(self, context, router, network_id, ext_ips): # Port has no 'tenant-id', as it is hidden from user LOG.debug("Class OVNL3RouterPlugin:::") gw_port = self._core_plugin.create_port( context.elevated(), { 'port': { 'tenant_id': router['tenant_id'], 'network_id': network_id, 'mac_address': attributes.ATTR_NOT_SPECIFIED, 'fixed_ips': attributes.ATTR_NOT_SPECIFIED, 'device_id': router['id'], 'device_owner': l3_db.DEVICE_OWNER_ROUTER_GW, 'admin_state_up': True, 'name': 'Extnet_' + router['name'][0:18] } }) if not gw_port['fixed_ips']: self._core_plugin.delete_port(context.elevated(), gw_port['id'], l3_port_check=False) msg = (_('No IPs available for external network %s') % network_id) raise n_exc.BadRequest(resource='router', msg=msg) try: self.create_gw_router_port_in_ovn(context, router['id'], gw_port) except Exception: self._core_plugin.delete_port(context.elevated(), gw_port['id'], l3_port_check=False) self.delete_gw_router_port_in_ovn(router['id'], gw_port['id']) LOG.exception(_LE('Fail to update gateway info for router %s'), router['id']) raise n_exc.ServiceUnavailable() with context.session.begin(subtransactions=True): router.gw_port = self._core_plugin._get_port( context.elevated(), gw_port['id']) router_port = l3_db.RouterPort( router_id=router.id, port_id=gw_port['id'], port_type=l3_db.DEVICE_OWNER_ROUTER_GW) context.session.add(router) context.session.add(router_port)
def login_server(self): if self.session: yield else: ret = self.login() LOG.debug("SMC server LOGIN successfully.") if ret: try: yield except Exception: LOG.exception(_LE("exception while connect to server!")) raise n_exc.ServiceUnavailable(resource='SMC server', msg=_("OPERATION failed")) finally: self.logout() else: raise n_exc.BadRequest(resource='SMC server', msg=_("LOGIN failed!"))
def diag_not_implemented(self, res, id, input): LOG.warning("Diagnostics not implemented on resource %ss." % res) raise n_exc.ServiceUnavailable()