Esempio n. 1
0
    def create_resource(self):
        res = {}
        res['resource_id'] = self.resource_id
        res['resource_name'] = self.resource_name
        res['region'] = self.region
        res['consumption'] = 0
        res['deleted'] = 0
        res['status'] = 'active'
        res['tenant_id'] = self.tenant_id
        res['resource_type'] = self.resource_type
        res['created_at'] = self.event_time

        if self.event_type == 'power_off':
            res['status'] = 'shutoff'

        # Convert json to string.
        res['content'] = jsonutils.dumps(self.content)

        description = "Start billing " + self.resource_type
        res['description'] = description

        """Create the new resource."""
        self.resource = self.db_api.resource_create(res)

        return self.resource
Esempio n. 2
0
    def format(self, record):
        message = {'message': record.getMessage(),
                   'asctime': self.formatTime(record, self.datefmt),
                   'name': record.name,
                   'msg': record.msg,
                   'args': record.args,
                   'levelname': record.levelname,
                   'levelno': record.levelno,
                   'pathname': record.pathname,
                   'filename': record.filename,
                   'module': record.module,
                   'lineno': record.lineno,
                   'funcname': record.funcName,
                   'created': record.created,
                   'msecs': record.msecs,
                   'relative_created': record.relativeCreated,
                   'thread': record.thread,
                   'thread_name': record.threadName,
                   'process_name': record.processName,
                   'process': record.process,
                   'traceback': None}

        if hasattr(record, 'extra'):
            message['extra'] = record.extra

        if record.exc_info:
            message['traceback'] = self.formatException(record.exc_info)

        return jsonutils.dumps(message)
Esempio n. 3
0
    def format(self, record):
        message = {
            'message': record.getMessage(),
            'asctime': self.formatTime(record, self.datefmt),
            'name': record.name,
            'msg': record.msg,
            'args': record.args,
            'levelname': record.levelname,
            'levelno': record.levelno,
            'pathname': record.pathname,
            'filename': record.filename,
            'module': record.module,
            'lineno': record.lineno,
            'funcname': record.funcName,
            'created': record.created,
            'msecs': record.msecs,
            'relative_created': record.relativeCreated,
            'thread': record.thread,
            'thread_name': record.threadName,
            'process_name': record.processName,
            'process': record.process,
            'traceback': None
        }

        if hasattr(record, 'extra'):
            message['extra'] = record.extra

        if record.exc_info:
            message['traceback'] = self.formatException(record.exc_info)

        return jsonutils.dumps(message)
Esempio n. 4
0
    def __str__(self):
        """Dumps a string representation of the rules."""

        # Start by building the canonical strings for the rules
        out_rules = {}
        for key, value in self.items():
            # Use empty string for singleton TrueCheck instances
            if isinstance(value, TrueCheck):
                out_rules[key] = ''
            else:
                out_rules[key] = str(value)

        # Dump a pretty-printed JSON representation
        return jsonutils.dumps(out_rules, indent=4)
Esempio n. 5
0
    def audit_base(self):
        """Base audit method."""

        consumption = self.calculate_consumption()
        description = "Resource has been " + self.event_type + 'd'

        record = {}
        record['start_at'] = self.start_at
        record['unit_price'] = self.unit_price
        record['consumption'] = consumption
        record['description'] = description

        updated_resource = {}
        total_consumption = self.exist_resource.consumption + consumption
        updated_resource['consumption'] = total_consumption
        updated_resource['content'] = jsonutils.dumps(self.content)

        if self.event_type != 'exists':
            updated_resource['description'] = description

        return record, updated_resource
Esempio n. 6
0
    def audit_base(self):
        """Base audit method."""

        consumption = self.calculate_consumption()
        description = "Resource has been " + self.event_type + 'd'

        record = {}
        record['start_at'] = self.start_at
        record['unit_price'] = self.unit_price
        record['consumption'] = consumption
        record['description'] = description

        updated_resource = {}
        total_consumption = self.exist_resource.consumption + consumption
        updated_resource['consumption'] = total_consumption
        updated_resource['content'] = jsonutils.dumps(self.content)

        if self.event_type != 'exists':
            updated_resource['description'] = description

        return record, updated_resource
Esempio n. 7
0
    def create_resource(self):
        res = {}
        res['resource_id'] = self.resource_id
        res['resource_name'] = self.resource_name
        res['region'] = self.region
        res['consumption'] = 0
        res['deleted'] = 0
        res['status'] = 'active'
        res['tenant_id'] = self.tenant_id
        res['resource_type'] = self.resource_type
        res['created_at'] = self.event_time

        if self.event_type == 'power_off':
            res['status'] = 'shutoff'

        # Convert json to string.
        res['content'] = jsonutils.dumps(self.content)

        description = "Start billing " + self.resource_type
        res['description'] = description
        """Create the new resource."""
        self.resource = self.db_api.resource_create(res)

        return self.resource