def on_task_state_change(self, task_ex_id, state): return self._client.call( auth_ctx.ctx(), 'on_task_state_change', task_ex_id=task_ex_id, state=state )
def _get_client(self): ctx = context.ctx() LOG.debug("Cinder action security context: %s" % ctx) cinder_endpoint = keystone_utils.get_endpoint_for_project( service_type='volume' ) cinder_url = keystone_utils.format_url( cinder_endpoint.url, {'tenant_id': ctx.project_id} ) client = self._client_class( ctx.user_name, ctx.auth_token, project_id=ctx.project_id, auth_url=cinder_url, region_name=cinder_endpoint.region ) client.client.auth_token = ctx.auth_token client.client.management_url = cinder_url return client
def _get_client(self): ctx = context.ctx() LOG.debug("Nova action security context: %s" % ctx) keystone_endpoint = keystone_utils.get_keystone_endpoint_v2() nova_endpoint = keystone_utils.get_endpoint_for_project('nova') client = self._client_class( username=None, api_key=None, endpoint_type='publicURL', service_type='compute', auth_token=ctx.auth_token, tenant_id=ctx.project_id, region_name=keystone_endpoint.region, auth_url=keystone_endpoint.url ) client.client.management_url = keystone_utils.format_url( nova_endpoint.url, {'tenant_id': ctx.project_id} ) return client
def pause_workflow(self, execution_id): """Stops the workflow with the given execution id. :return: Workflow execution. """ return self._client.call(auth_ctx.ctx(), 'pause_workflow', execution_id=execution_id)
def resume_workflow(self, execution_id): """Resumes the workflow with the given execution id. :return: Workflow execution. """ return self._client.call(auth_ctx.ctx(), 'resume_workflow', execution_id=execution_id)
def rollback_workflow(self, execution_id): """Rolls back the workflow with the given execution id. :return: Workflow execution. """ return self._client.call(auth_ctx.ctx(), 'rollback_workflow', execution_id=execution_id)
def start_workflow(self, wf_name, wf_input, **params): """Starts workflow sending a request to engine over RPC. :return: Workflow execution. """ return self._client.call(auth_ctx.ctx(), 'start_workflow', workflow_name=wf_name, workflow_input=wf_input or {}, params=params)
def _get_client(self): ctx = context.ctx() LOG.debug("Glance action security context: %s" % ctx) glance_endpoint = keystone_utils.get_endpoint_for_project('glance') return self._client_class(glance_endpoint.url, region_name=glance_endpoint.region, token=ctx.auth_token)
def rollback_workflow(self, execution_id): """Rolls back the workflow with the given execution id. :return: Workflow execution. """ return self._client.call( auth_ctx.ctx(), 'rollback_workflow', execution_id=execution_id )
def resume_workflow(self, execution_id): """Resumes the workflow with the given execution id. :return: Workflow execution. """ return self._client.call( auth_ctx.ctx(), 'resume_workflow', execution_id=execution_id )
def pause_workflow(self, execution_id): """Stops the workflow with the given execution id. :return: Workflow execution. """ return self._client.call( auth_ctx.ctx(), 'pause_workflow', execution_id=execution_id )
def _get_client(self): ctx = context.ctx() LOG.debug("Neutron action security context: %s" % ctx) neutron_endpoint = keystone_utils.get_endpoint_for_project('neutron') return self._client_class(endpoint_url=neutron_endpoint.url, region_name=neutron_endpoint.region, token=ctx.auth_token, auth_url=CONF.keystone_authtoken.auth_uri)
def start_workflow(self, wf_name, wf_input, **params): """Starts workflow sending a request to engine over RPC. :return: Workflow execution. """ return self._client.call( auth_ctx.ctx(), 'start_workflow', workflow_name=wf_name, workflow_input=wf_input or {}, params=params )
def _get_client(self): ctx = context.ctx() LOG.debug("Glance action security context: %s" % ctx) glance_endpoint = keystone_utils.get_endpoint_for_project('glance') return self._client_class( glance_endpoint.url, region_name=glance_endpoint.region, token=ctx.auth_token )
def client(): ctx = context.ctx() auth_url = CONF.keystone_authtoken.auth_uri cl = ks_client.Client(username=ctx.user_name, token=ctx.auth_token, tenant_id=ctx.project_id, auth_url=auth_url) cl.management_url = auth_url print cl return cl
def _get_client(self): ctx = context.ctx() LOG.debug("Neutron action security context: %s" % ctx) neutron_endpoint = keystone_utils.get_endpoint_for_project('neutron') return self._client_class( endpoint_url=neutron_endpoint.url, region_name=neutron_endpoint.region, token=ctx.auth_token, auth_url=CONF.keystone_authtoken.auth_uri )
def schedule_call(factory_method_path, target_method_name, run_after, serializers=None, **method_args): """Add this call specification to DB, and then after run_after seconds service CallScheduler invokes the target_method. :param factory_method_path: Full python-specific path to factory method for target object construction. :param target_method_name: Name of target object method which will be invoked. :param run_after: Value in seconds. param serializers: map of argument names and their serializer class paths. Use when an argument is an object of specific type, and needs to be serialized. Example: { "result": "mistral.utils.serializer.ResultSerializer"} Serializer for the object type must implement serializer interface in mistral/utils/serializer.py :param method_args: Target method keyword arguments. """ ctx = context.ctx().to_dict() if context.has_ctx() else {} execution_time = (datetime.datetime.now() + datetime.timedelta(seconds=run_after)) if serializers: for arg_name, serializer_path in serializers.items(): if arg_name not in method_args: raise exc.BlogException("Serializable method argument %s" " not found in method_args=%s" % (arg_name, method_args)) try: serializer = importutils.import_class(serializer_path)() except ImportError as e: raise ImportError("Cannot import class %s: %s" % (serializer_path, e)) method_args[arg_name] = serializer.serialize(method_args[arg_name]) values = { 'factory_method_path': factory_method_path, 'target_method_name': target_method_name, 'execution_time': execution_time, 'auth_context': ctx, 'serializers': serializers, 'method_arguments': method_args } db_api.create_delayed_call(values)
def _get_client(self): ctx = context.ctx() LOG.debug("Heat action security context: %s" % ctx) heat_endpoint = keystone_utils.get_endpoint_for_project('heat') endpoint_url = keystone_utils.format_url(heat_endpoint.url, {'tenant_id': ctx.project_id}) return self._client_class(endpoint_url, region_name=heat_endpoint.region, token=ctx.auth_token, username=ctx.user_name)
def create_trust(): client = keystone.client() ctx = auth_ctx.ctx() trustee_id = keystone.client_for_admin( CONF.keystone_authtoken.admin_tenant_name).user_id return client.trusts.create( trustor_user=client.user_id, trustee_user=trustee_id, impersonation=True, role_names=ctx.roles, project=ctx.project_id )
def run_action(self, action_ex_id, action_class_str, attributes, action_params, target=None): """Sends a request to run action to executor.""" kwargs = { 'action_ex_id': action_ex_id, 'action_class_str': action_class_str, 'attributes': attributes, 'params': action_params } self._client.prepare(topic=self.topic, server=target).cast( auth_ctx.ctx(), 'run_action', **kwargs )
def _get_client(self): ctx = context.ctx() LOG.debug("Heat action security context: %s" % ctx) heat_endpoint = keystone_utils.get_endpoint_for_project('heat') endpoint_url = keystone_utils.format_url( heat_endpoint.url, {'tenant_id': ctx.project_id} ) return self._client_class( endpoint_url, region_name=heat_endpoint.region, token=ctx.auth_token, username=ctx.user_name )
def run_action(self, action_ex_id, action_class_str, attributes, action_params, target=None): """Sends a request to run action to executor.""" kwargs = { 'action_ex_id': action_ex_id, 'action_class_str': action_class_str, 'attributes': attributes, 'params': action_params } self._client.prepare(topic=self.topic, server=target).cast(auth_ctx.ctx(), 'run_action', **kwargs)
def stop_workflow(self, execution_id, state, message=None): """Stops workflow execution with given status. Once stopped, the workflow is complete with SUCCESS or ERROR, and can not be resumed. :param execution_id: Workflow execution id :param state: State assigned to the workflow: SUCCESS or ERROR :param message: Optional information string :return: Workflow execution, model.Execution """ return self._client.call(auth_ctx.ctx(), 'stop_workflow', execution_id=execution_id, state=state, message=message)
def stop_workflow(self, execution_id, state, message=None): """Stops workflow execution with given status. Once stopped, the workflow is complete with SUCCESS or ERROR, and can not be resumed. :param execution_id: Workflow execution id :param state: State assigned to the workflow: SUCCESS or ERROR :param message: Optional information string :return: Workflow execution, model.Execution """ return self._client.call( auth_ctx.ctx(), 'stop_workflow', execution_id=execution_id, state=state, message=message )
def on_action_complete(self, action_ex_id, result): """Conveys action result to Mistral Engine. This method should be used by clients of Mistral Engine to update state of a action execution once action has executed. One of the clients of this method is Mistral REST API server that receives action result from the outside action handlers. Note: calling this method serves an event notifying Mistral that it possibly needs to move the workflow on, i.e. run other workflow tasks for which all dependencies are satisfied. :return: Task. """ return self._client.call(auth_ctx.ctx(), 'on_action_complete', action_ex_id=action_ex_id, result_data=result.data, result_error=result.error)
def _get_client(self): ctx = context.ctx() LOG.debug("Nova action security context: %s" % ctx) keystone_endpoint = keystone_utils.get_keystone_endpoint_v2() nova_endpoint = keystone_utils.get_endpoint_for_project('nova') client = self._client_class(username=None, api_key=None, endpoint_type='publicURL', service_type='compute', auth_token=ctx.auth_token, tenant_id=ctx.project_id, region_name=keystone_endpoint.region, auth_url=keystone_endpoint.url) client.client.management_url = keystone_utils.format_url( nova_endpoint.url, {'tenant_id': ctx.project_id}) return client
def _get_client(self): ctx = context.ctx() LOG.debug("Cinder action security context: %s" % ctx) cinder_endpoint = keystone_utils.get_endpoint_for_project( service_type='volume') cinder_url = keystone_utils.format_url(cinder_endpoint.url, {'tenant_id': ctx.project_id}) client = self._client_class(ctx.user_name, ctx.auth_token, project_id=ctx.project_id, auth_url=cinder_url, region_name=cinder_endpoint.region) client.client.auth_token = ctx.auth_token client.client.management_url = cinder_url return client
def _get_client(self): ctx = context.ctx() LOG.debug("Keystone action security context: %s" % ctx) kwargs = { 'token': ctx.auth_token, 'auth_url': CONF.keystone_authtoken.auth_uri, 'project_id': ctx.project_id, 'cacert': CONF.keystone_authtoken.cafile, } # In case of trust-scoped token explicitly pass endpoint parameter. if (ctx.is_trust_scoped or keystone_utils.is_token_trust_scoped(ctx.auth_token)): kwargs['endpoint'] = CONF.keystone_authtoken.auth_uri client = self._client_class(**kwargs) client.management_url = CONF.keystone_authtoken.auth_uri return client
def on_action_complete(self, action_ex_id, result): """Conveys action result to Mistral Engine. This method should be used by clients of Mistral Engine to update state of a action execution once action has executed. One of the clients of this method is Mistral REST API server that receives action result from the outside action handlers. Note: calling this method serves an event notifying Mistral that it possibly needs to move the workflow on, i.e. run other workflow tasks for which all dependencies are satisfied. :return: Task. """ return self._client.call( auth_ctx.ctx(), 'on_action_complete', action_ex_id=action_ex_id, result_data=result.data, result_error=result.error )
def get_project_id(): if CONF.pecan.auth_enable and auth_ctx.has_ctx(): return auth_ctx.ctx().project_id else: return DEFAULT_PROJECT_ID
def on_task_state_change(self, task_ex_id, state): return self._client.call(auth_ctx.ctx(), 'on_task_state_change', task_ex_id=task_ex_id, state=state)