def _register_info(self, name, info): '''place the new info in the correct location in the registry. :param path: a string of plugin name. :param info: reference to a PluginInfo data structure, deregister a PluginInfo if specified as None. ''' registry = self._registry if info is None: # delete this entry. LOG.warn(_LW('Removing %(item)s from registry'), {'item': name}) registry.pop(name, None) return if name in registry and isinstance(registry[name], PluginInfo): if registry[name] == info: return details = { 'name': name, 'old': str(registry[name].plugin), 'new': str(info.plugin) } LOG.warn(_LW('Changing %(name)s from %(old)s to %(new)s'), details) else: LOG.info(_LI('Registering %(name)s -> %(value)s'), { 'name': name, 'value': str(info.plugin)}) info.user_provided = not self.is_global registry[name] = info
def refresh_server(self, server): '''Refresh server's attributes. Log warnings for non-critical API errors. ''' try: server.get() except exceptions.OverLimit as exc: LOG.warn( _LW("Server %(name)s (%(id)s) received an OverLimit " "response during server.get(): %(exception)s"), { 'name': server.name, 'id': server.id, 'exception': exc }) except exceptions.ClientException as exc: if ((getattr(exc, 'http_status', getattr(exc, 'code', None)) in (500, 503))): LOG.warn( _LW('Server "%(name)s" (%(id)s) received the ' 'following exception during server.get(): ' '%(exception)s'), { 'name': server.name, 'id': server.id, 'exception': exc }) else: raise
def trusts_auth_plugin(self): if self._trusts_auth_plugin: return self._trusts_auth_plugin self._trusts_auth_plugin = auth.load_from_conf_options( cfg.CONF, TRUSTEE_CONF_GROUP, trust_id=self.trust_id) if self._trusts_auth_plugin: return self._trusts_auth_plugin LOG.warn(_LW('Using the keystone_authtoken user as the bilean ' 'trustee user directly is deprecated. Please add the ' 'trustee credentials you need to the %s section of ' 'your bilean.conf file.') % TRUSTEE_CONF_GROUP) cfg.CONF.import_group('keystone_authtoken', 'keystonemiddleware.auth_token') self._trusts_auth_plugin = v3.Password( username=cfg.CONF.keystone_authtoken.admin_user, password=cfg.CONF.keystone_authtoken.admin_password, user_domain_id='default', auth_url=self.keystone_v3_endpoint, trust_id=self.trust_id) return self._trusts_auth_plugin
def get_server(self, server): try: return self.client().servers.get(server) except exceptions.NotFound as ex: LOG.warn(_LW('Server (%(server)s) not found: %(ex)s'), {'server': server, 'ex': ex}) raise exception.ServerNotFound(server=server)
def trusts_auth_plugin(self): if self._trusts_auth_plugin: return self._trusts_auth_plugin self._trusts_auth_plugin = auth.load_from_conf_options( cfg.CONF, TRUSTEE_CONF_GROUP, trust_id=self.trust_id) if self._trusts_auth_plugin: return self._trusts_auth_plugin LOG.warn( _LW('Using the keystone_authtoken user as the bilean ' 'trustee user directly is deprecated. Please add the ' 'trustee credentials you need to the %s section of ' 'your bilean.conf file.') % TRUSTEE_CONF_GROUP) cfg.CONF.import_group('keystone_authtoken', 'keystonemiddleware.auth_token') self._trusts_auth_plugin = v3.Password( username=cfg.CONF.keystone_authtoken.admin_user, password=cfg.CONF.keystone_authtoken.admin_password, user_domain_id='default', auth_url=self.keystone_v3_endpoint, trust_id=self.trust_id) return self._trusts_auth_plugin
def get_server(self, server): try: return self.client().servers.get(server) except exceptions.NotFound as ex: LOG.warn(_LW('Server (%(server)s) not found: %(ex)s'), { 'server': server, 'ex': ex }) raise exception.ServerNotFound(server=server)
def _remove_children(self, pid): if pid in self.children: self.children.remove(pid) LOG.info(_LI('Removed dead child %s'), pid) elif pid in self.stale_children: self.stale_children.remove(pid) LOG.info(_LI('Removed stale child %s'), pid) else: LOG.warn(_LW('Unrecognised child %s'), pid)
def _task(self, user_id, task_type): admin_context = bilean_context.get_admin_context() self.rpc_client.settle_account( admin_context, user_id, task=task_type) if task_type != self.DAILY: try: db_api.job_delete( admin_context, self._generate_job_id(user_id, task_type)) except exception.NotFound as e: LOG.warn(_LW("Failed in deleting job: %s") % six.text_type(e))
def server_to_ipaddress(self, server): '''Return the server's IP address, fetching it from Nova.''' try: server = self.client().servers.get(server) except exceptions.NotFound as ex: LOG.warn(_LW('Instance (%(server)s) not found: %(ex)s'), {'server': server, 'ex': ex}) else: for n in server.networks: if len(server.networks[n]) > 0: return server.networks[n][0]
def delete_jobs(self, user): """Delete all jobs related the specific user.""" admin_context = bilean_context.get_admin_context() for job_type in self.job_types: job_id = self._generate_job_id(user.id, job_type) try: if self._is_exist(job_id): self._remove_job(job_id) db_api.job_delete(admin_context, job_id) except Exception as e: LOG.warn(_LW("Failed in deleting job: %s") % six.text_type(e))
def server_to_ipaddress(self, server): '''Return the server's IP address, fetching it from Nova.''' try: server = self.client().servers.get(server) except exceptions.NotFound as ex: LOG.warn(_LW('Instance (%(server)s) not found: %(ex)s'), { 'server': server, 'ex': ex }) else: for n in server.networks: if len(server.networks[n]) > 0: return server.networks[n][0]
def warning(context, entity, action, status=None, status_reason=None, timestamp=None): timestamp = timestamp or timeutils.utcnow() event = Event(timestamp, logging.WARNING, entity, action=action, status=status, status_reason=status_reason, user_id=context.project) event.store(context) LOG.warn(_LW('%(name)s [%(id)s] %(action)s - %(status)s: %(reason)s'), {'name': event.obj_name, 'id': event.obj_id and event.obj_id[:8], 'action': action, 'status': status, 'reason': status_reason})
def client(self, name): client_plugin = self.client_plugin(name) if client_plugin: return client_plugin.client() if name in self._clients: return self._clients[name] # call the local method _<name>() if a real client plugin # doesn't exist method_name = '_%s' % name if callable(getattr(self, method_name, None)): client = getattr(self, method_name)() self._clients[name] = client return client LOG.warn(_LW('Requested client "%s" not found'), name)
def refresh_server(self, server): '''Refresh server's attributes. Log warnings for non-critical API errors. ''' try: server.get() except exceptions.OverLimit as exc: LOG.warn(_LW("Server %(name)s (%(id)s) received an OverLimit " "response during server.get(): %(exception)s"), {'name': server.name, 'id': server.id, 'exception': exc}) except exceptions.ClientException as exc: if ((getattr(exc, 'http_status', getattr(exc, 'code', None)) in (500, 503))): LOG.warn(_LW('Server "%(name)s" (%(id)s) received the ' 'following exception during server.get(): ' '%(exception)s'), {'name': server.name, 'id': server.id, 'exception': exc}) else: raise
def client(self, name): client_plugin = self.client_plugin(name) if client_plugin: return client_plugin.client() if name in self._clients: return self._clients[name] # call the local method _<name>() if a real client plugin # doesn't exist method_name = "_%s" % name if callable(getattr(self, method_name, None)): client = getattr(self, method_name)() self._clients[name] = client return client LOG.warn(_LW('Requested client "%s" not found'), name)
def update_jobs(self, user): """Update user's billing job""" # Delete all jobs except daily job admin_context = bilean_context.get_admin_context() for job_type in self.NOTIFY, self.FREEZE: job_id = self._generate_job_id(user.id, job_type) try: if self._is_exist(job_id): self._remove_job(job_id) db_api.job_delete(admin_context, job_id) except Exception as e: LOG.warn(_LW("Failed in deleting job: %s") % six.text_type(e)) if user.status == user.ACTIVE: self._add_notify_job(user) elif user.status == user.WARNING: self._add_freeze_job(user)
def resource_delete(self, cnxt, user_id, resource_id): """Delete a specific resource""" try: plugin_base.Resource.load(cnxt, resource_id=resource_id) except exception.ResourceNotFound: LOG.warn(_LW('The resource(%s) trying to delete not found.'), resource_id) return params = { 'name': 'delete_resource_%s' % resource_id, 'cause': action_mod.CAUSE_RPC, 'status': action_mod.Action.READY, 'inputs': {'resource_id': resource_id}, } action_id = action_mod.Action.create(cnxt, user_id, consts.USER_DELETE_RESOURCE, **params) dispatcher.start_action(action_id=action_id) LOG.info(_LI('Resource delete action queued: %s'), action_id)