summaryrefslogtreecommitdiff
path: root/iotronic/objects/exposedservice.py
diff options
context:
space:
mode:
Diffstat (limited to 'iotronic/objects/exposedservice.py')
-rw-r--r--iotronic/objects/exposedservice.py165
1 files changed, 165 insertions, 0 deletions
diff --git a/iotronic/objects/exposedservice.py b/iotronic/objects/exposedservice.py
new file mode 100644
index 0000000..7e96cda
--- /dev/null
+++ b/iotronic/objects/exposedservice.py
@@ -0,0 +1,165 @@
1# coding=utf-8
2#
3#
4# Licensed under the Apache License, Version 2.0 (the "License"); you may
5# not use this file except in compliance with the License. You may obtain
6# a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13# License for the specific language governing permissions and limitations
14# under the License.
15
16from iotronic.db import api as db_api
17from iotronic.objects import base
18from iotronic.objects import utils as obj_utils
19
20
21class ExposedService(base.IotronicObject):
22 # Version 1.0: Initial version
23 VERSION = '1.0'
24
25 dbapi = db_api.get_instance()
26
27 fields = {
28 'id': int,
29 'board_uuid': obj_utils.str_or_none,
30 'service_uuid': obj_utils.str_or_none,
31 'public_port': int,
32 'pid': int
33 }
34
35 @staticmethod
36 def _from_db_object(exposed_service, db_exposed_service):
37 """Converts a database entity to a formal object."""
38 for field in exposed_service.fields:
39 exposed_service[field] = db_exposed_service[field]
40 exposed_service.obj_reset_changes()
41 return exposed_service
42
43 @base.remotable_classmethod
44 def get_by_id(cls, context, exposed_service_id):
45 """Find a exposed_service based on its integer id and return a Board object.
46
47 :param exposed_service_id: the id of a exposed_service.
48 :returns: a :class:`exposed_service` object.
49 """
50 db_exp_service = cls.dbapi.get_exposed_service_by_id(
51 exposed_service_id)
52 exp_service = ExposedService._from_db_object(cls(context),
53 db_exp_service)
54 return exp_service
55
56 @base.remotable_classmethod
57 def get_by_board_uuid(cls, context, board_uuid):
58 """Find a exposed_service based on uuid and return a Board object.
59
60 :param board_uuid: the uuid of a exposed_service.
61 :returns: a :class:`exposed_service` object.
62 """
63 db_exp_service = cls.dbapi.get_exposed_service_by_board_uuid(
64 board_uuid)
65 exp_service = ExposedService._from_db_object(cls(context),
66 db_exp_service)
67 return exp_service
68
69 @base.remotable_classmethod
70 def get_by_service_uuid(cls, context, service_uuid):
71 """Find a exposed_service based on uuid and return a Board object.
72
73 :param service_uuid: the uuid of a exposed_service.
74 :returns: a :class:`exposed_service` object.
75 """
76 db_exp_service = cls.dbapi.get_exposed_service_by_service_uuid(
77 service_uuid)
78 exp_service = ExposedService._from_db_object(cls(context),
79 db_exp_service)
80 return exp_service
81
82 @base.remotable_classmethod
83 def get(cls, context, board_uuid, service_uuid):
84 """Find a exposed_service based on uuid and return a Service object.
85
86 :param board_uuid: the uuid of a exposed_service.
87 :returns: a :class:`exposed_service` object.
88 """
89 db_exp_service = cls.dbapi.get_exposed_service_by_uuids(board_uuid,
90 service_uuid)
91 exp_service = ExposedService._from_db_object(cls(context),
92 db_exp_service)
93 return exp_service
94
95 @base.remotable_classmethod
96 def list(cls, context, board_uuid):
97 """Return a list of ExposedService objects.
98
99 :param context: Security context.
100 :param limit: maximum number of resources to return in a single result.
101 :param marker: pagination marker for large data sets.
102 :param sort_key: column to sort results by.
103 :param sort_dir: direction to sort. "asc" or "desc".
104 :param filters: Filters to apply.
105 :returns: a list of :class:`ExposedService` object.
106
107 """
108 db_exps = cls.dbapi.get_exposed_service_list(board_uuid)
109 return [ExposedService._from_db_object(cls(context), obj)
110 for obj in db_exps]
111
112 @base.remotable
113 def create(self, context=None):
114 """Create a ExposedService record in the DB.
115
116 Column-wise updates will be made based on the result of
117 self.what_changed(). If target_power_state is provided,
118 it will be checked against the in-database copy of the
119 exposed_service before updates are made.
120
121 :param context: Security context. NOTE: This should only
122 be used internally by the indirection_api.
123 Unfortunately, RPC requires context as the first
124 argument, even though we don't use it.
125 A context should be set when instantiating the
126 object, e.g.: ExposedService(context)
127
128 """
129 values = self.obj_get_changes()
130 db_exposed_service = self.dbapi.create_exposed_service(values)
131 self._from_db_object(self, db_exposed_service)
132
133 @base.remotable
134 def destroy(self, context=None):
135 """Delete the ExposedService from the DB.
136
137 :param context: Security context. NOTE: This should only
138 be used internally by the indirection_api.
139 Unfortunately, RPC requires context as the first
140 argument, even though we don't use it.
141 A context should be set when instantiating the
142 object, e.g.: ExposedService(context)
143 """
144 self.dbapi.destroy_exposed_service(self.id)
145 self.obj_reset_changes()
146
147 @base.remotable
148 def save(self, context=None):
149 """Save updates to this ExposedService.
150
151 Column-wise updates will be made based on the result of
152 self.what_changed(). If target_power_state is provided,
153 it will be checked against the in-database copy of the
154 exposed_service before updates are made.
155
156 :param context: Security context. NOTE: This should only
157 be used internally by the indirection_api.
158 Unfortunately, RPC requires context as the first
159 argument, even though we don't use it.
160 A context should be set when instantiating the
161 object, e.g.: ExposedService(context)
162 """
163 updates = self.obj_get_changes()
164 self.dbapi.update_exposed_service(self.id, updates)
165 self.obj_reset_changes()