Exemplo n.º 1
0
        def handler_trap_exception(*args, **kwargs):
            try:
                response = handler(*args, **kwargs)
                return response
            except vnc_exc.AuthFailed as e:
                bottle.abort(401, str(e))
            except vnc_exc.PermissionDenied as e:
                npd._raise_contrail_exception('NotAuthorized', msg=str(e))
            except vnc_exc.BadRequest as e:
                npd._raise_contrail_exception('BadRequest', msg=str(e))
            except vnc_exc.RefsExistError as e:
                npd._raise_contrail_exception('Conflict', msg=str(e))
            except vnc_exc.OverQuota as e:
                npd._raise_contrail_exception('OverQuota', msg=str(e))
            except vnc_exc.NoIdError as e:
                npd._raise_contrail_exception('NotFound', msg=str(e))
            except Exception as e:
                # don't log details of bottle.abort i.e handled error cases
                if not isinstance(e, bottle.HTTPError):
                    string_buf = StringIO()
                    cgitb_hook(
                        file=string_buf,
                        format="text",
                    )
                    err_msg = string_buf.getvalue()
                    self._logger.error(err_msg)

                raise
    def _get_user_cfgdb(self, context):

        self._connect_to_db()

        if not self._multi_tenancy:
            return self._cfgdb
        user_id = context['user_id']
        role = string.join(context['roles'], ",")
        if not user_id in self._cfgdb_map:
            self._cfgdb_map[user_id] = DBInterface(
                self,
                self._auth_user,
                self._auth_passwd,
                self._auth_tenant,
                self._vnc_api_ip,
                self._vnc_api_port,
                user_info={
                    'user_id': user_id,
                    'role': role
                },
                list_optimization_enabled=self._list_optimization_enabled,
                contrail_extensions_enabled=self._contrail_extensions_enabled,
                apply_subnet_host_routes=self._sn_host_route)
            self._cfgdb_map[user_id].manager = self

        return self._cfgdb_map[user_id]
Exemplo n.º 3
0
 def _connect_to_db(self):
     """
     Many instantiations of plugin (base + extensions) but need to have
     only one config db conn (else error from ifmap-server)
     """
     if self._cfgdb is None:
         # Initialize connection to DB and add default entries
         exts_enabled = self._contrail_extensions_enabled
         apply_sn_route = self._sn_host_route
         self._cfgdb = DBInterface(self._auth_user,
                                   self._auth_passwd,
                                   self._auth_tenant,
                                   self._vnc_api_ip,
                                   self._vnc_api_port,
                                   contrail_extensions_enabled=exts_enabled,
                                   list_optimization_enabled=\
                                   self._list_optimization_enabled,
                                   apply_subnet_host_routes=apply_sn_route)
         self._cfgdb.manager = self