Internet of Things resource management service for OpenStack clouds.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

exposedservice.py 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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. from iotronic.db import api as db_api
  16. from iotronic.objects import base
  17. from iotronic.objects import utils as obj_utils
  18. class ExposedService(base.IotronicObject):
  19. # Version 1.0: Initial version
  20. VERSION = '1.0'
  21. dbapi = db_api.get_instance()
  22. fields = {
  23. 'id': int,
  24. 'board_uuid': obj_utils.str_or_none,
  25. 'service_uuid': obj_utils.str_or_none,
  26. 'public_port': int,
  27. 'pid': int
  28. }
  29. @staticmethod
  30. def _from_db_object(exposed_service, db_exposed_service):
  31. """Converts a database entity to a formal object."""
  32. for field in exposed_service.fields:
  33. exposed_service[field] = db_exposed_service[field]
  34. exposed_service.obj_reset_changes()
  35. return exposed_service
  36. @base.remotable_classmethod
  37. def get_by_id(cls, context, exposed_service_id):
  38. """Find a exposed_service based on its integer id and return a Board object.
  39. :param exposed_service_id: the id of a exposed_service.
  40. :returns: a :class:`exposed_service` object.
  41. """
  42. db_exp_service = cls.dbapi.get_exposed_service_by_id(
  43. exposed_service_id)
  44. exp_service = ExposedService._from_db_object(cls(context),
  45. db_exp_service)
  46. return exp_service
  47. @base.remotable_classmethod
  48. def get_by_board_uuid(cls, context, board_uuid):
  49. """Return a list of ExposedService objects.
  50. :param context: Security context.
  51. :param limit: maximum number of resources to return in a single result.
  52. :param marker: pagination marker for large data sets.
  53. :param sort_key: column to sort results by.
  54. :param sort_dir: direction to sort. "asc" or "desc".
  55. :param filters: Filters to apply.
  56. :returns: a list of :class:`ExposedService` object.
  57. """
  58. db_exps = cls.dbapi.get_exposed_services_by_board_uuid(board_uuid)
  59. return [ExposedService._from_db_object(cls(context), obj)
  60. for obj in db_exps]
  61. @base.remotable_classmethod
  62. def get_by_service_uuid(cls, context, service_uuid):
  63. """Find a exposed_service based on uuid and return a Board object.
  64. :param service_uuid: the uuid of a exposed_service.
  65. :returns: a :class:`exposed_service` object.
  66. """
  67. db_exp_service = cls.dbapi.get_exposed_service_by_service_uuid(
  68. service_uuid)
  69. exp_service = ExposedService._from_db_object(cls(context),
  70. db_exp_service)
  71. return exp_service
  72. @base.remotable_classmethod
  73. def get(cls, context, board_uuid, service_uuid):
  74. """Find a exposed_service based on uuid and return a Service object.
  75. :param board_uuid: the uuid of a exposed_service.
  76. :returns: a :class:`exposed_service` object.
  77. """
  78. db_exp_service = cls.dbapi.get_exposed_service_by_uuids(board_uuid,
  79. service_uuid)
  80. exp_service = ExposedService._from_db_object(cls(context),
  81. db_exp_service)
  82. return exp_service
  83. @base.remotable_classmethod
  84. def list(cls, context, board_uuid):
  85. """Return a list of ExposedService objects.
  86. :param context: Security context.
  87. :param limit: maximum number of resources to return in a single result.
  88. :param marker: pagination marker for large data sets.
  89. :param sort_key: column to sort results by.
  90. :param sort_dir: direction to sort. "asc" or "desc".
  91. :param filters: Filters to apply.
  92. :returns: a list of :class:`ExposedService` object.
  93. """
  94. db_exps = cls.dbapi.get_exposed_service_list(board_uuid)
  95. return [ExposedService._from_db_object(cls(context), obj)
  96. for obj in db_exps]
  97. @base.remotable
  98. def create(self, context=None):
  99. """Create a ExposedService record in the DB.
  100. Column-wise updates will be made based on the result of
  101. self.what_changed(). If target_power_state is provided,
  102. it will be checked against the in-database copy of the
  103. exposed_service before updates are made.
  104. :param context: Security context. NOTE: This should only
  105. be used internally by the indirection_api.
  106. Unfortunately, RPC requires context as the first
  107. argument, even though we don't use it.
  108. A context should be set when instantiating the
  109. object, e.g.: ExposedService(context)
  110. """
  111. values = self.obj_get_changes()
  112. db_exposed_service = self.dbapi.create_exposed_service(values)
  113. self._from_db_object(self, db_exposed_service)
  114. @base.remotable
  115. def destroy(self, context=None):
  116. """Delete the ExposedService from the DB.
  117. :param context: Security context. NOTE: This should only
  118. be used internally by the indirection_api.
  119. Unfortunately, RPC requires context as the first
  120. argument, even though we don't use it.
  121. A context should be set when instantiating the
  122. object, e.g.: ExposedService(context)
  123. """
  124. self.dbapi.destroy_exposed_service(self.id)
  125. self.obj_reset_changes()
  126. @base.remotable
  127. def save(self, context=None):
  128. """Save updates to this ExposedService.
  129. Column-wise updates will be made based on the result of
  130. self.what_changed(). If target_power_state is provided,
  131. it will be checked against the in-database copy of the
  132. exposed_service before updates are made.
  133. :param context: Security context. NOTE: This should only
  134. be used internally by the indirection_api.
  135. Unfortunately, RPC requires context as the first
  136. argument, even though we don't use it.
  137. A context should be set when instantiating the
  138. object, e.g.: ExposedService(context)
  139. """
  140. updates = self.obj_get_changes()
  141. self.dbapi.update_exposed_service(self.id, updates)
  142. self.obj_reset_changes()