def _create_trigger(self): trigger_info = { 'name': 'daily', 'project_id': '123', 'type': 'time', 'properties': {} } trigger = objects.Trigger(self.context, **trigger_info) trigger.create() return trigger
def _create_one_trigger(self): trigger_info = { 'project_id': "123", "name": "123", "type": "time", "properties": { "format": "crontab", "pattern": "* * * * *" }, } trigger = objects.Trigger(self.ctxt, **trigger_info) trigger.create() return trigger
def create(self, req, body): """Creates a new trigger.""" LOG.debug('Create trigger start') if not self.is_valid_body(body, 'trigger_info'): raise exc.HTTPUnprocessableEntity() LOG.debug('Create a trigger, request body: %s', body) context = req.environ['smaug.context'] check_policy(context, 'create') trigger_info = body['trigger_info'] trigger_name = trigger_info.get("name", None) trigger_type = trigger_info.get("type", None) trigger_property = trigger_info.get("properties", None) if not trigger_name or not trigger_type or not trigger_property: msg = _("Trigger name or type or property is not provided.") raise exc.HTTPBadRequest(explanation=msg) self.validate_name_and_description(trigger_info) trigger_definition = { 'id': str(uuid.uuid4()), 'name': trigger_name, 'project_id': context.project_id, 'type': trigger_type, 'properties': trigger_property, } try: trigger = objects.Trigger(context=context, **trigger_definition) self.operationengine_api.create_trigger(context, trigger) trigger.create() except exception.Invalid as ex: raise exc.HTTPBadRequest(explanation=ex.msg) except Exception as ex: self._raise_unknown_exception(ex) return self._view_builder.detail(req, trigger)
def _from_db_object(context, op, db_op, expected_attrs=[]): special_fields = set(['operation_definition'] + op.INSTANCE_OPTIONAL_JOINED_FIELDS) normal_fields = set(op.fields) - special_fields for name in normal_fields: op[name] = db_op.get(name) op_definition = db_op['operation_definition'] if op_definition: op['operation_definition'] = jsonutils.loads(op_definition) if 'trigger' in expected_attrs: if db_op.get('trigger', None) is None: op.trigger = None else: if not op.obj_attr_is_set('trigger'): op.trigger = objects.Trigger(context) op.trigger._from_db_object(context, op.trigger, db_op['trigger']) op._context = context op.obj_reset_changes() return op