~ubuntu-branches/ubuntu/trusty/ceilometer/trusty-proposed

« back to all changes in this revision

Viewing changes to ceilometer/storage/models.py

  • Committer: Package Import Robot
  • Author(s): Chuck Short, James Page, Chuck Short
  • Date: 2014-01-23 15:08:11 UTC
  • mfrom: (1.1.11)
  • Revision ID: package-import@ubuntu.com-20140123150811-1zaismsuyh1hcl8y
Tags: 2014.1~b2-0ubuntu1
[ James Page ]
* d/control: Add python-jsonpath-rw to BD's.
* d/p/fix-setup-requirements.patch: Bump WebOb to support < 1.4.
 (LP: #1261101)

[ Chuck Short ]
* New upstream version.
* debian/control, debian/ceilometer-common.install: Split out
  ceilometer-alarm-evaluator and ceilometer-alarm-notifier into their
  own packages. (LP: #1250002)
* debian/ceilometer-agent-central.logrotate,
  debian/ceilometer-agent-compute.logrotate,
  debian/ceilometer-api.logrotate,
  debian/ceilometer-collector.logrotate: Add logrotate files, 
  thanks to Ahmed Rahal. (LP: #1224223)
* Fix typos in upstart files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
"""Model classes for use in the storage API.
19
19
"""
20
20
 
 
21
from ceilometer.openstack.common import timeutils
 
22
 
21
23
 
22
24
class Model(object):
23
25
    """Base class for storage API models.
60
62
                            the Event ID, which comes from the
61
63
                            underlying storage system.
62
64
        :param event_type:  The type of the event.
63
 
        :param generated:   UTC time for when the event occured.
 
65
        :param generated:   UTC time for when the event occurred.
64
66
        :param traits:      list of Traits on this Event.
65
67
        """
66
68
        Model.__init__(self, message_id=message_id, event_type=event_type,
89
91
    FLOAT_TYPE = 3
90
92
    DATETIME_TYPE = 4
91
93
 
 
94
    type_names = {
 
95
        NONE_TYPE: "none",
 
96
        TEXT_TYPE: "string",
 
97
        INT_TYPE: "integer",
 
98
        FLOAT_TYPE: "float",
 
99
        DATETIME_TYPE: "datetime"
 
100
    }
 
101
 
92
102
    def __init__(self, name, dtype, value):
93
103
        if not dtype:
94
104
            dtype = Trait.NONE_TYPE
97
107
    def __repr__(self):
98
108
        return "<Trait: %s %d %s>" % (self.name, self.dtype, self.value)
99
109
 
 
110
    def get_type_name(self):
 
111
        return self.get_name_by_type(self.dtype)
 
112
 
 
113
    @classmethod
 
114
    def get_type_by_name(cls, type_name):
 
115
        return getattr(cls, '%s_TYPE' % type_name.upper(), None)
 
116
 
 
117
    @classmethod
 
118
    def get_type_names(cls):
 
119
        return cls.type_names.values()
 
120
 
 
121
    @classmethod
 
122
    def get_name_by_type(cls, type_id):
 
123
        return cls.type_names.get(type_id, "none")
 
124
 
 
125
    @classmethod
 
126
    def convert_value(cls, trait_type, value):
 
127
        if trait_type is cls.INT_TYPE:
 
128
            return int(value)
 
129
        if trait_type is cls.FLOAT_TYPE:
 
130
            return float(value)
 
131
        if trait_type is cls.DATETIME_TYPE:
 
132
            return timeutils.normalize_time(timeutils.parse_isotime(value))
 
133
        return str(value)
 
134
 
100
135
 
101
136
class Resource(Model):
102
137
    """Something for which sample data has been collected.
105
140
    def __init__(self, resource_id, project_id,
106
141
                 first_sample_timestamp,
107
142
                 last_sample_timestamp,
108
 
                 source, user_id, metadata,
109
 
                 meter):
 
143
                 source, user_id, metadata):
110
144
        """Create a new resource.
111
145
 
112
146
        :param resource_id: UUID of the resource
116
150
        :param source:      the identifier for the user/project id definition
117
151
        :param user_id:     UUID of user owning the resource
118
152
        :param metadata:    most current metadata for the resource (a dict)
119
 
        :param meter:       list of the meters reporting data for the resource,
120
153
        """
121
154
        Model.__init__(self,
122
155
                       resource_id=resource_id,
126
159
                       source=source,
127
160
                       user_id=user_id,
128
161
                       metadata=metadata,
129
 
                       meter=meter,
130
 
                       )
131
 
 
132
 
 
133
 
class ResourceMeter(Model):
134
 
    """The definitions of the meters for which data has been collected
135
 
    for a resource.
136
 
 
137
 
    See Resource.meter field.
138
 
    """
139
 
 
140
 
    def __init__(self, counter_name, counter_type, counter_unit):
141
 
        """Create a new resource meter.
142
 
 
143
 
        :param counter_name: the name of the counter updating the resource
144
 
        :param counter_type: one of gauge, delta, cumulative
145
 
        :param counter_unit: official units name for the sample data
146
 
        """
147
 
        Model.__init__(self,
148
 
                       counter_name=counter_name,
149
 
                       counter_type=counter_type,
150
 
                       counter_unit=counter_unit,
151
162
                       )
152
163
 
153
164