Exemple #1
0
    def state_set(self, new_state, reason="state changed"):
        if new_state is self.CREATE_COMPLETE or \
           new_state is self.CREATE_FAILED:
            try:
                rs = {}
                rs['state'] = new_state
                rs['stack_id'] = self.stack.id
                rs['parsed_template_id'] = self.stack.parsed_template_id
                rs['nova_instance'] = self.instance_id
                rs['name'] = self.name
                rs['stack_name'] = self.stack.name
                new_rs = db_api.resource_create(None, rs)
                self.id = new_rs.id

            except Exception as ex:
                logger.warn('db error %s' % str(ex))

        if new_state != self.state:
            ev = {}
            ev['logical_resource_id'] = self.name
            ev['physical_resource_id'] = self.instance_id
            ev['stack_id'] = self.stack.id
            ev['stack_name'] = self.stack.name
            ev['resource_status'] = new_state
            ev['name'] = new_state
            ev['resource_status_reason'] = reason
            ev['resource_type'] = self.t['Type']
            ev['resource_properties'] = self.t['Properties']
            try:
                db_api.event_create(None, ev)
            except Exception as ex:
                logger.warn('db error %s' % str(ex))
            self.state = new_state
Exemple #2
0
 def _add_event(self, new_state, reason):
     '''Add a state change event to the database'''
     ev = {'logical_resource_id': self.name,
           'physical_resource_id': self.resource_id,
           'stack_id': self.stack.id,
           'stack_name': self.stack.name,
           'resource_status': new_state,
           'name': new_state,
           'resource_status_reason': reason,
           'resource_type': self.t['Type'],
           'resource_properties': dict(self.properties)}
     try:
         db_api.event_create(self.context, ev)
     except Exception as ex:
         logger.error('DB error %s' % str(ex))
Exemple #3
0
    def store(self):
        '''Store the Event in the database.'''
        ev = {
            'resource_name': self.resource_name,
            'physical_resource_id': self.physical_resource_id,
            'stack_id': self.stack.id,
            'resource_action': self.action,
            'resource_status': self.status,
            'resource_status_reason': self.reason,
            'resource_type': self.resource_type,
            'resource_properties': self.resource_properties,
        }

        if self.uuid is not None:
            ev['uuid'] = self.uuid

        if self.timestamp is not None:
            ev['created_at'] = self.timestamp

        if self.id is not None:
            LOG.warning(_('Duplicating event'))

        new_ev = db_api.event_create(self.context, ev)
        self.id = new_ev.id
        return self.id
Exemple #4
0
 def event_create(self, context, event):
     stack_name = event['stack']
     resource_name = event['resource']
     stack = db_api.stack_get_by_name(context, stack_name)
     resource = db_api.resource_get_by_name_and_stack(context,
                                                      resource_name,
                                                      stack.id)
     if not resource:
         return ['Unknown resource', None]
     new_event = {
         'name': event['message'],
         'resource_status_reason': event['reason'],
         'StackId': stack.id,
         'LogicalResourceId': resource.name,
         'PhysicalResourceId': None,
         'ResourceType': event['resource_type'],
         'ResourceProperties': {},
     }
     try:
         result = db_api.event_create(context, new_event)
         new_event['id'] = result.id
         return [None, new_event]
     except Exception as ex:
         logger.warn('db error %s' % str(ex))
         msg = 'Error creating event'
         return [msg, None]
Exemple #5
0
 def event_create(self, context, event):
     stack_name = event['stack']
     resource_name = event['resource']
     stack = db_api.stack_get_by_name(context, stack_name)
     resource = db_api.resource_get_by_name_and_stack(
         context, resource_name, stack.id)
     if not resource:
         return ['Unknown resource', None]
     new_event = {
         'name': event['message'],
         'resource_status_reason': event['reason'],
         'StackId': stack.id,
         'LogicalResourceId': resource.name,
         'PhysicalResourceId': None,
         'ResourceType': event['resource_type'],
         'ResourceProperties': {},
     }
     try:
         result = db_api.event_create(context, new_event)
         new_event['id'] = result.id
         return [None, new_event]
     except Exception as ex:
         logger.warn('db error %s' % str(ex))
         msg = 'Error creating event'
         return [msg, None]
Exemple #6
0
 def _add_event(self, new_state, reason):
     '''Add a state change event to the database'''
     self.calculate_properties()
     ev = {
         'logical_resource_id': self.name,
         'physical_resource_id': self.instance_id,
         'stack_id': self.stack.id,
         'stack_name': self.stack.name,
         'resource_status': new_state,
         'name': new_state,
         'resource_status_reason': reason,
         'resource_type': self.t['Type'],
         'resource_properties': dict(self.properties)
     }
     try:
         db_api.event_create(self.context, ev)
     except Exception as ex:
         logger.error('DB error %s' % str(ex))
Exemple #7
0
    def store(self):
        """Store the Event in the database."""
        ev = {
            "resource_name": self.resource_name,
            "physical_resource_id": self.physical_resource_id,
            "stack_id": self.stack.id,
            "resource_action": self.action,
            "resource_status": self.status,
            "resource_status_reason": self.reason,
            "resource_type": self.resource_type,
            "resource_properties": self.resource_properties,
        }

        if self.timestamp is not None:
            ev["created_at"] = self.timestamp

        if self.id is not None:
            logger.warning(_("Duplicating event"))

        new_ev = db_api.event_create(self.context, ev)
        self.id = new_ev.id
        return self.id
Exemple #8
0
    def store(self):
        '''Store the Event in the database'''
        ev = {
            'logical_resource_id': self.resource.name,
            'physical_resource_id': self.physical_resource_id,
            'stack_id': self.stack.id,
            'stack_name': self.stack.name,
            'resource_status': self.new_state,
            'name': self.new_state,
            'resource_status_reason': self.reason,
            'resource_type': self.resource.type(),
            'resource_properties': self.resource_properties,
        }

        if self.timestamp is not None:
            ev['created_at'] = self.timestamp

        if self.id is not None:
            logger.warning('Duplicating event')

        new_ev = db_api.event_create(self.context, ev)
        self.id = new_ev.id
        return self.id
Exemple #9
0
    def store(self):
        '''Store the Event in the database'''
        ev = {
            'logical_resource_id': self.resource.name,
            'physical_resource_id': self.physical_resource_id,
            'stack_id': self.stack.id,
            'stack_name': self.stack.name,
            'resource_status': self.new_state,
            'name': self.new_state,
            'resource_status_reason': self.reason,
            'resource_type': self.resource.type(),
            'resource_properties': self.resource_properties,
        }

        if self.timestamp is not None:
            ev['created_at'] = self.timestamp

        if self.id is not None:
            logger.warning('Duplicating event')

        new_ev = db_api.event_create(self.context, ev)
        self.id = new_ev.id
        return self.id
Exemple #10
0
 def event_create(self, context, event):
     stack_name = event["stack"]
     resource_name = event["resource"]
     stack = db_api.stack_get(None, stack_name)
     resource = db_api.resource_get_by_name_and_stack(None, resource_name, stack.id)
     if not resource:
         return ["Unknown resource", None]
     new_event = {
         "name": event["message"],
         "resource_status_reason": event["reason"],
         "stack_id": stack.id,
         "logical_resource_id": resource.name,
         "physical_resource_id": None,
         "resource_type": event["resource_type"],
         "resource_properties": {},
     }
     try:
         result = db_api.event_create(None, new_event)
         new_event["id"] = result.id
         return [None, new_event]
     except Exception as ex:
         logger.warn("db error %s" % str(ex))
         msg = "Error creating event"
         return [msg, None]
Exemple #11
0
 def create(cls, context, values):
     return cls._from_db_object(context, cls(),
                                db_api.event_create(context, values))
Exemple #12
0
 def create(cls, context, values):
     return cls._from_db_object(context, cls(),
                                db_api.event_create(context, values))