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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. """Find a exposed_service based on uuid and return a Board object.
  50. :param board_uuid: the uuid of a exposed_service.
  51. :returns: a :class:`exposed_service` object.
  52. """
  53. db_exp_service = cls.dbapi.get_exposed_service_by_board_uuid(
  54. board_uuid)
  55. exp_service = ExposedService._from_db_object(cls(context),
  56. db_exp_service)
  57. return exp_service
  58. @base.remotable_classmethod
  59. def get_by_service_uuid(cls, context, service_uuid):
  60. """Find a exposed_service based on uuid and return a Board object.
  61. :param service_uuid: the uuid of a exposed_service.
  62. :returns: a :class:`exposed_service` object.
  63. """
  64. db_exp_service = cls.dbapi.get_exposed_service_by_service_uuid(
  65. service_uuid)
  66. exp_service = ExposedService._from_db_object(cls(context),
  67. db_exp_service)
  68. return exp_service
  69. @base.remotable_classmethod
  70. def get(cls, context, board_uuid, service_uuid):
  71. """Find a exposed_service based on uuid and return a Service object.
  72. :param board_uuid: the uuid of a exposed_service.
  73. :returns: a :class:`exposed_service` object.
  74. """
  75. db_exp_service = cls.dbapi.get_exposed_service_by_uuids(board_uuid,
  76. service_uuid)
  77. exp_service = ExposedService._from_db_object(cls(context),
  78. db_exp_service)
  79. return exp_service
  80. @base.remotable_classmethod
  81. def list(cls, context, board_uuid):
  82. """Return a list of ExposedService objects.
  83. :param context: Security context.
  84. :param limit: maximum number of resources to return in a single result.
  85. :param marker: pagination marker for large data sets.
  86. :param sort_key: column to sort results by.
  87. :param sort_dir: direction to sort. "asc" or "desc".
  88. :param filters: Filters to apply.
  89. :returns: a list of :class:`ExposedService` object.
  90. """
  91. db_exps = cls.dbapi.get_exposed_service_list(board_uuid)
  92. return [ExposedService._from_db_object(cls(context), obj)
  93. for obj in db_exps]
  94. @base.remotable
  95. def create(self, context=None):
  96. """Create a ExposedService record in the DB.
  97. Column-wise updates will be made based on the result of
  98. self.what_changed(). If target_power_state is provided,
  99. it will be checked against the in-database copy of the
  100. exposed_service before updates are made.
  101. :param context: Security context. NOTE: This should only
  102. be used internally by the indirection_api.
  103. Unfortunately, RPC requires context as the first
  104. argument, even though we don't use it.
  105. A context should be set when instantiating the
  106. object, e.g.: ExposedService(context)
  107. """
  108. values = self.obj_get_changes()
  109. db_exposed_service = self.dbapi.create_exposed_service(values)
  110. self._from_db_object(self, db_exposed_service)
  111. @base.remotable
  112. def destroy(self, context=None):
  113. """Delete the ExposedService from the DB.
  114. :param context: Security context. NOTE: This should only
  115. be used internally by the indirection_api.
  116. Unfortunately, RPC requires context as the first
  117. argument, even though we don't use it.
  118. A context should be set when instantiating the
  119. object, e.g.: ExposedService(context)
  120. """
  121. self.dbapi.destroy_exposed_service(self.id)
  122. self.obj_reset_changes()
  123. @base.remotable
  124. def save(self, context=None):
  125. """Save updates to this ExposedService.
  126. Column-wise updates will be made based on the result of
  127. self.what_changed(). If target_power_state is provided,
  128. it will be checked against the in-database copy of the
  129. exposed_service before updates are made.
  130. :param context: Security context. NOTE: This should only
  131. be used internally by the indirection_api.
  132. Unfortunately, RPC requires context as the first
  133. argument, even though we don't use it.
  134. A context should be set when instantiating the
  135. object, e.g.: ExposedService(context)
  136. """
  137. updates = self.obj_get_changes()
  138. self.dbapi.update_exposed_service(self.id, updates)
  139. self.obj_reset_changes()