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
6
# http://www.apache.org/licenses/LICENSE-2.0
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
19
from oslo_versionedobjects import base
20
from oslo_versionedobjects import fields
22
from heat.db import api as db_api
25
class Service(base.VersionedObject,
26
base.VersionedObjectDictCompat,
27
base.ComparableVersionedObject):
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)
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()
50
def _from_db_objects(cls, context, list_obj):
51
return map(lambda obj: cls._from_db_object(context,
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)
63
def create(cls, context, values):
64
return cls._from_db_object(
67
db_api.service_create(context, values))
70
def update_by_id(cls, context, service_id, values):
71
return cls._from_db_object(
74
db_api.service_update(context, service_id, values))
77
def delete(cls, context, service_id, soft_delete=True):
78
return db_api.service_delete(context, service_id, soft_delete)
81
def get_all(cls, context):
82
return cls._from_db_objects(context,
83
db_api.service_get_all(context))
86
def get_all_by_args(cls, context, host, binary, hostname):
87
return cls._from_db_objects(
89
db_api.service_get_all_by_args(context,