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.

rpcapi.py 9.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. # coding=utf-8
  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. Client side of the conductor RPC API.
  15. """
  16. from iotronic.common import rpc
  17. from iotronic.conductor import manager
  18. from iotronic.objects import base
  19. import oslo_messaging
  20. class ConductorAPI(object):
  21. """Client side of the conductor RPC API.
  22. API version history:
  23. | 1.0 - Initial version.
  24. """
  25. RPC_API_VERSION = '1.0'
  26. def __init__(self, topic=None):
  27. super(ConductorAPI, self).__init__()
  28. self.topic = topic
  29. if self.topic is None:
  30. self.topic = manager.MANAGER_TOPIC
  31. target = oslo_messaging.Target(topic=self.topic,
  32. version='1.0')
  33. serializer = base.IotronicObjectSerializer()
  34. self.client = rpc.get_client(target,
  35. version_cap=self.RPC_API_VERSION,
  36. serializer=serializer)
  37. def echo(self, context, data, topic=None):
  38. """Test
  39. :param context: request context.
  40. :param data: board id or uuid.
  41. :param topic: RPC topic. Defaults to self.topic.
  42. """
  43. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  44. return cctxt.call(context, 'echo', data=data)
  45. def registration(self, context, code, session_num, topic=None):
  46. """Registration of a board.
  47. :param context: request context.
  48. :param code: token used for the first registration
  49. :param session_num: wamp session number
  50. :param topic: RPC topic. Defaults to self.topic.
  51. """
  52. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  53. return cctxt.call(context, 'registration',
  54. code=code, session_num=session_num)
  55. def connection(self, context, uuid, session_num, topic=None):
  56. """Connection of a board.
  57. :param context: request context.
  58. :param uuid: uuid board
  59. :param session_num: wamp session number
  60. :param topic: RPC topic. Defaults to self.topic.
  61. """
  62. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  63. return cctxt.call(context, 'connection',
  64. uuid=uuid, session_num=session_num)
  65. def create_board(self, context, board_obj, location_obj, topic=None):
  66. """Add a board on the cloud
  67. :param context: request context.
  68. :param board_obj: a changed (but not saved) board object.
  69. :param topic: RPC topic. Defaults to self.topic.
  70. :returns: created board object
  71. """
  72. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  73. return cctxt.call(context, 'create_board',
  74. board_obj=board_obj, location_obj=location_obj)
  75. def update_board(self, context, board_obj, topic=None):
  76. """Synchronously, have a conductor update the board's information.
  77. Update the board's information in the database and return
  78. a board object.
  79. Note that power_state should not be passed via this method.
  80. Use change_board_power_state for initiating driver actions.
  81. :param context: request context.
  82. :param board_obj: a changed (but not saved) board object.
  83. :param topic: RPC topic. Defaults to self.topic.
  84. :returns: updated board object, including all fields.
  85. """
  86. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  87. return cctxt.call(context, 'update_board', board_obj=board_obj)
  88. def destroy_board(self, context, board_id, topic=None):
  89. """Delete a board.
  90. :param context: request context.
  91. :param board_id: board id or uuid.
  92. :raises: BoardLocked if board is locked by another conductor.
  93. :raises: BoardAssociated if the board contains an instance
  94. associated with it.
  95. :raises: InvalidState if the board is in the wrong provision
  96. state to perform deletion.
  97. """
  98. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  99. return cctxt.call(context, 'destroy_board', board_id=board_id)
  100. def execute_on_board(self, context, board_uuid, wamp_rpc_call,
  101. wamp_rpc_args=None, topic=None):
  102. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  103. return cctxt.call(context, 'execute_on_board', board_uuid=board_uuid,
  104. wamp_rpc_call=wamp_rpc_call,
  105. wamp_rpc_args=wamp_rpc_args)
  106. def create_plugin(self, context, plugin_obj, topic=None):
  107. """Add a plugin on the cloud
  108. :param context: request context.
  109. :param plugin_obj: a changed (but not saved) plugin object.
  110. :param topic: RPC topic. Defaults to self.topic.
  111. :returns: created plugin object
  112. """
  113. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  114. return cctxt.call(context, 'create_plugin',
  115. plugin_obj=plugin_obj)
  116. def update_plugin(self, context, plugin_obj, topic=None):
  117. """Synchronously, have a conductor update the plugin's information.
  118. Update the plugin's information in the database and
  119. return a plugin object.
  120. :param context: request context.
  121. :param plugin_obj: a changed (but not saved) plugin object.
  122. :param topic: RPC topic. Defaults to self.topic.
  123. :returns: updated plugin object, including all fields.
  124. """
  125. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  126. return cctxt.call(context, 'update_plugin', plugin_obj=plugin_obj)
  127. def destroy_plugin(self, context, plugin_id, topic=None):
  128. """Delete a plugin.
  129. :param context: request context.
  130. :param plugin_id: plugin id or uuid.
  131. :raises: PluginLocked if plugin is locked by another conductor.
  132. :raises: PluginAssociated if the plugin contains an instance
  133. associated with it.
  134. :raises: InvalidState if the plugin is in the wrong provision
  135. state to perform deletion.
  136. """
  137. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  138. return cctxt.call(context, 'destroy_plugin', plugin_id=plugin_id)
  139. def inject_plugin(self, context, plugin_uuid,
  140. board_uuid, onboot=False, topic=None):
  141. """inject a plugin into a board.
  142. :param context: request context.
  143. :param plugin_uuid: plugin id or uuid.
  144. :param board_uuid: board id or uuid.
  145. """
  146. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  147. return cctxt.call(context, 'inject_plugin', plugin_uuid=plugin_uuid,
  148. board_uuid=board_uuid, onboot=onboot)
  149. def remove_plugin(self, context, plugin_uuid, board_uuid, topic=None):
  150. """inject a plugin into a board.
  151. :param context: request context.
  152. :param plugin_uuid: plugin id or uuid.
  153. :param board_uuid: board id or uuid.
  154. """
  155. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  156. return cctxt.call(context, 'remove_plugin', plugin_uuid=plugin_uuid,
  157. board_uuid=board_uuid)
  158. def action_plugin(self, context, plugin_uuid,
  159. board_uuid, action, params, topic=None):
  160. """Action on a plugin into a board.
  161. :param context: request context.
  162. :param plugin_uuid: plugin id or uuid.
  163. :param board_uuid: board id or uuid.
  164. """
  165. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  166. return cctxt.call(context, 'action_plugin', plugin_uuid=plugin_uuid,
  167. board_uuid=board_uuid, action=action, params=params)
  168. def create_service(self, context, service_obj, topic=None):
  169. """Add a service on the cloud
  170. :param context: request context.
  171. :param service_obj: a changed (but not saved) service object.
  172. :param topic: RPC topic. Defaults to self.topic.
  173. :returns: created service object
  174. """
  175. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  176. return cctxt.call(context, 'create_service',
  177. service_obj=service_obj)
  178. def destroy_service(self, context, service_id, topic=None):
  179. """Delete a service.
  180. :param context: request context.
  181. :param service_id: service id or uuid.
  182. :raises: ServiceLocked if service is locked by another conductor.
  183. :raises: ServiceAssociated if the service contains an instance
  184. associated with it.
  185. :raises: InvalidState if the service is in the wrong provision
  186. state to perform deletion.
  187. """
  188. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  189. return cctxt.call(context, 'destroy_service', service_id=service_id)
  190. def update_service(self, context, service_obj, topic=None):
  191. """Synchronously, have a conductor update the service's information.
  192. Update the service's information in the database and
  193. return a service object.
  194. :param context: request context.
  195. :param service_obj: a changed (but not saved) service object.
  196. :param topic: RPC topic. Defaults to self.topic.
  197. :returns: updated service object, including all fields.
  198. """
  199. cctxt = self.client.prepare(topic=topic or self.topic, version='1.0')
  200. return cctxt.call(context, 'update_service', service_obj=service_obj)