def post(self, name, source='custom', target_resource=None, data=None): LOG.debug('POST plugin ' + name + ':' + source + ':') manager = get_plugin_handler() try: plugin = manager.check_plugin_name(name) conversor = data_convert.FormatterBase.get_formatter(source) except exceptions.InvalidSourceException as e: LOG.exception(e) abort(500, e.message) except Exception as e: #add conversor not found, pluginnotfound exception LOG.exception(e) abort(404, e.message) #if ceilometer, fetch header data and resource #if custom, just expose data #source converter(source, extra_data, headers) #TODO: normalize data in object? action_data = conversor.format(name, data, target_resource=target_resource, headers=pecan.request.headers) action_data.create() LOG.debug(action_data) #TODO: Retrieve context if token in header from middleware #Should be done on authorization? If not provided used admin #build context should not call authorize in that case ctx = utils.build_context(None, True) self.action_rpc.run_action(ctx, [action_data]) return {'action_id': action_data.id}
def periodic_tasks(self, raise_on_error=False): """Tasks to be run at a periodic interval.""" # ctxt has not adquired token yet... print "PERIODIC: " print "=================" ctxt = utils.build_context(admin=True, authorize=False) return self.manager.periodic_tasks(ctxt, raise_on_error=raise_on_error)
def run_action(self, context, actions, block=False): if not type(actions) == list: actions = [actions] #if not context: # context = utils.build_context() # remove, is for test context = utils.build_context() return handler_manager().start_plugins_group(context, actions, block=block)
def before(self, state): if not config.CONF.pecan.auth_enable: state.request.admin_ctx = utils.build_context() return if self._should_authorize_url(state.request.url) and \ not is_valid_admin_user(state.request.headers): # (TODO) add log raise exceptions.AuthorizationException('Required admin') state.request.admin_ctx = utils.context_from_headers( state.request.headers)
def alarm(self, ctxt, alarm_id, source=None, contract_id=None, resource_id=None, project_id=None): # TODO: check why token is not there, from notification my be ok , but # from API is still the same? if ctxt.token is None: ctxt = utils.build_context() self.engine.alert(ctxt, alarm_id, source, contract_id=contract_id, resource_id=resource_id, project_id=project_id)
def post(self, contract): ctx = utils.build_context(None, True) contract_dict = self.engine.create(ctx, contract.to_dict()) return SLAContract.from_dict(contract_dict)
def delete(self, id): ctx = utils.build_context(None, True) self.engine.delete(ctx, id)
def put(self, contract_id, contract): ctx = utils.build_context(None, True) contract.id = contract_id contract_dict = self.engine.update(ctx, contract.to_dict()) return SLAContract.from_dict(contract_dict)
from healing import config from healing import utils from healing import handler_manager from healing.handler_plugins import action_data from healing.engine.alarms import manager from healing.engine.alarms import filters from healing.openstack.common import log as logging logging.setup('heal') config.parse_args() ctx = utils.build_context() mg = handler_manager.get_plugin_handler() to_run = [] for x in range(1, 20): to_run.append( action_data.ActionData(name='evacuate', target_resource='s', data={})) print mg.start_plugins_group(ctx, to_run) """ #nv = utils.get_nova_client(ctx) #print utils.get_nova_vms(nv) #print utils.get_nova_vms(nv, tenant_id=22222) #print utils.get_nova_vms(nv, host='ubuntu-SVT13125CLS')
from healing import config from healing import utils from healing import handler_manager from healing.handler_plugins import action_data from healing.engine.alarms import manager from healing.engine.alarms import filters from healing.openstack.common import log as logging logging.setup('heal') config.parse_args() ctx = utils.build_context() mg = handler_manager.get_plugin_handler() to_run = [] for x in range(1,20): to_run.append(action_data.ActionData(name='evacuate', target_resource='s', data={})) print mg.start_plugins_group(ctx, to_run) """ #nv = utils.get_nova_client(ctx) #print utils.get_nova_vms(nv) #print utils.get_nova_vms(nv, tenant_id=22222) #print utils.get_nova_vms(nv, host='ubuntu-SVT13125CLS')