~ubuntu-branches/ubuntu/wily/heat/wily-proposed

« back to all changes in this revision

Viewing changes to heat/objects/service.py

  • Committer: Package Import Robot
  • Author(s): James Page, Corey Bryant, James Page
  • Date: 2015-03-30 11:11:18 UTC
  • mfrom: (1.1.23)
  • Revision ID: package-import@ubuntu.com-20150330111118-2qpycylx6swu4yhj
Tags: 2015.1~b3-0ubuntu1
[ Corey Bryant ]
* New upstream milestone release for OpenStack kilo:
  - d/control: Align with upstream dependencies.
  - d/p/sudoers_patch.patch: Rebased.
  - d/p/fix-requirements.patch: Rebased.

[ James Page ]
* d/p/fixup-assert-regex.patch: Tweak test to use assertRegexpMatches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# Licensed under the Apache License, Version 2.0 (the "License"); you may
 
3
# not use this file except in compliance with the License. You may obtain
 
4
# a copy of the License at
 
5
#
 
6
# http://www.apache.org/licenses/LICENSE-2.0
 
7
#
 
8
# Unless required by applicable law or agreed to in writing, software
 
9
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 
10
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 
11
# License for the specific language governing permissions and limitations
 
12
# under the License.
 
13
 
 
14
 
 
15
"""
 
16
Service object
 
17
"""
 
18
 
 
19
from oslo_versionedobjects import base
 
20
from oslo_versionedobjects import fields
 
21
 
 
22
from heat.db import api as db_api
 
23
 
 
24
 
 
25
class Service(base.VersionedObject,
 
26
              base.VersionedObjectDictCompat,
 
27
              base.ComparableVersionedObject):
 
28
    fields = {
 
29
        'id': fields.StringField(),
 
30
        'engine_id': fields.StringField(),
 
31
        'host': fields.StringField(),
 
32
        'hostname': fields.StringField(),
 
33
        'binary': fields.StringField(),
 
34
        'topic': fields.StringField(),
 
35
        'report_interval': fields.IntegerField(),
 
36
        'created_at': fields.DateTimeField(read_only=True),
 
37
        'updated_at': fields.DateTimeField(nullable=True),
 
38
        'deleted_at': fields.DateTimeField(nullable=True)
 
39
    }
 
40
 
 
41
    @staticmethod
 
42
    def _from_db_object(context, service, db_service):
 
43
        for field in service.fields:
 
44
            service[field] = db_service[field]
 
45
        service._context = context
 
46
        service.obj_reset_changes()
 
47
        return service
 
48
 
 
49
    @classmethod
 
50
    def _from_db_objects(cls, context, list_obj):
 
51
        return map(lambda obj: cls._from_db_object(context,
 
52
                                                   cls(context),
 
53
                                                   obj),
 
54
                   list_obj)
 
55
 
 
56
    @classmethod
 
57
    def get_by_id(cls, context, service_id):
 
58
        service_db = db_api.service_get(context, service_id)
 
59
        service = cls._from_db_object(context, cls(), service_db)
 
60
        return service
 
61
 
 
62
    @classmethod
 
63
    def create(cls, context, values):
 
64
        return cls._from_db_object(
 
65
            context,
 
66
            cls(),
 
67
            db_api.service_create(context, values))
 
68
 
 
69
    @classmethod
 
70
    def update_by_id(cls, context, service_id, values):
 
71
        return cls._from_db_object(
 
72
            context,
 
73
            cls(),
 
74
            db_api.service_update(context, service_id, values))
 
75
 
 
76
    @classmethod
 
77
    def delete(cls, context, service_id, soft_delete=True):
 
78
        return db_api.service_delete(context, service_id, soft_delete)
 
79
 
 
80
    @classmethod
 
81
    def get_all(cls, context):
 
82
        return cls._from_db_objects(context,
 
83
                                    db_api.service_get_all(context))
 
84
 
 
85
    @classmethod
 
86
    def get_all_by_args(cls, context, host, binary, hostname):
 
87
        return cls._from_db_objects(
 
88
            context,
 
89
            db_api.service_get_all_by_args(context,
 
90
                                           host,
 
91
                                           binary,
 
92
                                           hostname))