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.

api.py 16KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529
  1. # -*- encoding: utf-8 -*-
  2. #
  3. # Copyright 2013 Hewlett-Packard Development Company, L.P.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may
  6. # not use this file except in compliance with the License. You may obtain
  7. # a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing, software
  12. # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  13. # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  14. # License for the specific language governing permissions and limitations
  15. # under the License.
  16. """
  17. Base classes for storage engines
  18. """
  19. import abc
  20. from oslo_config import cfg
  21. from oslo_db import api as db_api
  22. import six
  23. _BACKEND_MAPPING = {'sqlalchemy': 'iotronic.db.sqlalchemy.api'}
  24. IMPL = db_api.DBAPI.from_config(cfg.CONF,
  25. backend_mapping=_BACKEND_MAPPING,
  26. lazy=True)
  27. def get_instance():
  28. """Return a DB API instance."""
  29. return IMPL
  30. @six.add_metaclass(abc.ABCMeta)
  31. class Connection(object):
  32. """Base class for storage system connections."""
  33. @abc.abstractmethod
  34. def __init__(self):
  35. """Constructor."""
  36. @abc.abstractmethod
  37. def get_boardinfo_list(self, columns=None, filters=None, limit=None,
  38. marker=None, sort_key=None, sort_dir=None):
  39. """Get specific columns for matching boards.
  40. Return a list of the specified columns for all boards that match the
  41. specified filters.
  42. :param columns: List of column names to return.
  43. Defaults to 'id' column when columns == None.
  44. :param filters: Filters to apply. Defaults to None.
  45. :associated: True | False
  46. :reserved: True | False
  47. :maintenance: True | False
  48. :provision_state: provision state of board
  49. :provisioned_before:
  50. boards with provision_updated_at field before this
  51. interval in seconds
  52. :param limit: Maximum number of boards to return.
  53. :param marker: the last item of the previous page; we return the next
  54. result set.
  55. :param sort_key: Attribute by which results should be sorted.
  56. :param sort_dir: direction in which results should be sorted.
  57. (asc, desc)
  58. :returns: A list of tuples of the specified columns.
  59. """
  60. @abc.abstractmethod
  61. def get_board_list(self, filters=None, limit=None, marker=None,
  62. sort_key=None, sort_dir=None):
  63. """Return a list of boards.
  64. :param filters: Filters to apply. Defaults to None.
  65. :associated: True | False
  66. :reserved: True | False
  67. :maintenance: True | False
  68. :provision_state: provision state of board
  69. :provisioned_before:
  70. boards with provision_updated_at field before this
  71. interval in seconds
  72. :param limit: Maximum number of boards to return.
  73. :param marker: the last item of the previous page; we return the next
  74. result set.
  75. :param sort_key: Attribute by which results should be sorted.
  76. :param sort_dir: direction in which results should be sorted.
  77. (asc, desc)
  78. """
  79. @abc.abstractmethod
  80. def create_board(self, values):
  81. """Create a new board.
  82. :param values: A dict containing several items used to identify
  83. and track the board, and several dicts which are passed
  84. into the Drivers when managing this board. For example:
  85. ::
  86. {
  87. 'uuid': uuidutils.generate_uuid(),
  88. 'instance_uuid': None,
  89. 'power_state': states.POWER_OFF,
  90. 'provision_state': states.AVAILABLE,
  91. 'properties': { ... },
  92. 'extra': { ... },
  93. }
  94. :returns: A board.
  95. """
  96. @abc.abstractmethod
  97. def get_board_by_id(self, board_id):
  98. """Return a board.
  99. :param board_id: The id of a board.
  100. :returns: A board.
  101. """
  102. @abc.abstractmethod
  103. def get_board_by_uuid(self, board_uuid):
  104. """Return a board.
  105. :param board_uuid: The uuid of a board.
  106. :returns: A board.
  107. """
  108. @abc.abstractmethod
  109. def get_board_id_by_uuid(self, board_uuid):
  110. """Return a board id.
  111. :param board_uuid: The uuid of a board.
  112. # :returns: A board.id.
  113. """
  114. @abc.abstractmethod
  115. def get_board_by_name(self, board_name):
  116. """Return a board.
  117. :param board_name: The logical name of a board.
  118. :returns: A board.
  119. """
  120. @abc.abstractmethod
  121. def get_board_by_code(self, instance):
  122. """Return a board.
  123. :param instance: The instance code or uuid to search for.
  124. :returns: A board.
  125. """
  126. @abc.abstractmethod
  127. def destroy_board(self, board_id):
  128. """Destroy a board and all associated interfaces.
  129. :param board_id: The id or uuid of a board.
  130. """
  131. @abc.abstractmethod
  132. def update_board(self, board_id, values):
  133. """Update properties of a board.
  134. :param board_id: The id or uuid of a board.
  135. :param values: Dict of values to update.
  136. :returns: A board.
  137. :raises: BoardAssociated
  138. :raises: BoardNotFound
  139. """
  140. @abc.abstractmethod
  141. def get_conductor(self, hostname):
  142. """Retrieve a conductor's service record from the database.
  143. :param hostname: The hostname of the conductor service.
  144. :returns: A conductor.
  145. :raises: ConductorNotFound
  146. """
  147. @abc.abstractmethod
  148. def unregister_conductor(self, hostname):
  149. """Remove this conductor from the service registry immediately.
  150. :param hostname: The hostname of this conductor service.
  151. :raises: ConductorNotFound
  152. """
  153. @abc.abstractmethod
  154. def touch_conductor(self, hostname):
  155. """Mark a conductor as active by updating its 'updated_at' property.
  156. :param hostname: The hostname of this conductor service.
  157. :raises: ConductorNotFound
  158. """
  159. @abc.abstractmethod
  160. def create_session(self, values):
  161. """Create a new location.
  162. :param values: session_id.
  163. """
  164. @abc.abstractmethod
  165. def update_session(self, session_id, values):
  166. """Update properties of an session.
  167. :param session_id: The id of a session.
  168. :param values: Dict of values to update.
  169. :returns: A session.
  170. """
  171. @abc.abstractmethod
  172. def get_session_by_board_uuid(self, board_uuid, valid):
  173. """Return a Wamp session of a Board
  174. :param board_uuid: Filters to apply. Defaults to None.
  175. :param valid: is valid
  176. :returns: A session.
  177. """
  178. @abc.abstractmethod
  179. def get_session_by_id(self, session_id):
  180. """Return a Wamp session
  181. :param session_id: The id of a session.
  182. :returns: A session.
  183. """
  184. @abc.abstractmethod
  185. def create_location(self, values):
  186. """Create a new location.
  187. :param values: Dict of values.
  188. """
  189. @abc.abstractmethod
  190. def update_location(self, location_id, values):
  191. """Update properties of an location.
  192. :param location_id: The id of a location.
  193. :param values: Dict of values to update.
  194. :returns: A location.
  195. """
  196. @abc.abstractmethod
  197. def destroy_location(self, location_id):
  198. """Destroy an location.
  199. :param location_id: The id or MAC of a location.
  200. """
  201. @abc.abstractmethod
  202. def get_locations_by_board_id(self, board_id, limit=None, marker=None,
  203. sort_key=None, sort_dir=None):
  204. """List all the locations for a given board.
  205. :param board_id: The integer board ID.
  206. :param limit: Maximum number of locations to return.
  207. :param marker: the last item of the previous page; we return the next
  208. result set.
  209. :param sort_key: Attribute by which results should be sorted
  210. :param sort_dir: direction in which results should be sorted
  211. (asc, desc)
  212. :returns: A list of locations.
  213. """
  214. @abc.abstractmethod
  215. def get_valid_wpsessions_list(self):
  216. """Return a list of wpsession."""
  217. @abc.abstractmethod
  218. def get_wampagent(self, hostname):
  219. """Retrieve a wampagent's service record from the database.
  220. :param hostname: The hostname of the wampagent service.
  221. :returns: A wampagent.
  222. :raises: WampAgentNotFound
  223. """
  224. @abc.abstractmethod
  225. def get_registration_wampagent(self):
  226. """Retrieve the registration wampagent record from the database.
  227. :returns: A wampagent.
  228. :raises: WampAgentNotFound
  229. """
  230. @abc.abstractmethod
  231. def unregister_wampagent(self, hostname):
  232. """Remove this wampagent from the service registry immediately.
  233. :param hostname: The hostname of this wampagent service.
  234. :raises: WampAgentNotFound
  235. """
  236. @abc.abstractmethod
  237. def touch_wampagent(self, hostname):
  238. """Mark a wampagent as active by updating its 'updated_at' property.
  239. :param hostname: The hostname of this wampagent service.
  240. :raises: WampAgentNotFound
  241. """
  242. @abc.abstractmethod
  243. def get_wampagent_list(self, filters=None, limit=None, marker=None,
  244. sort_key=None, sort_dir=None):
  245. """Return a list of wampagents.
  246. :param filters: Filters to apply. Defaults to None.
  247. :param limit: Maximum number of wampagents to return.
  248. :param marker: the last item of the previous page; we return the next
  249. result set.
  250. :param sort_key: Attribute by which results should be sorted.
  251. :param sort_dir: direction in which results should be sorted.
  252. (asc, desc)
  253. """
  254. @abc.abstractmethod
  255. def get_plugin_by_id(self, plugin_id):
  256. """Return a plugin.
  257. :param plugin_id: The id of a plugin.
  258. :returns: A plugin.
  259. """
  260. @abc.abstractmethod
  261. def get_plugin_by_uuid(self, plugin_uuid):
  262. """Return a plugin.
  263. :param plugin_uuid: The uuid of a plugin.
  264. :returns: A plugin.
  265. """
  266. @abc.abstractmethod
  267. def get_plugin_by_name(self, plugin_name):
  268. """Return a plugin.
  269. :param plugin_name: The logical name of a plugin.
  270. :returns: A plugin.
  271. """
  272. @abc.abstractmethod
  273. def create_plugin(self, values):
  274. """Create a new plugin.
  275. :param values: A dict containing several items used to identify
  276. and track the plugin
  277. :returns: A plugin.
  278. """
  279. @abc.abstractmethod
  280. def destroy_plugin(self, plugin_id):
  281. """Destroy a plugin and all associated interfaces.
  282. :param plugin_id: The id or uuid of a plugin.
  283. """
  284. @abc.abstractmethod
  285. def update_plugin(self, plugin_id, values):
  286. """Update properties of a plugin.
  287. :param plugin_id: The id or uuid of a plugin.
  288. :param values: Dict of values to update.
  289. :returns: A plugin.
  290. :raises: PluginAssociated
  291. :raises: PluginNotFound
  292. """
  293. @abc.abstractmethod
  294. def get_injection_plugin_by_board_uuid(self, board_uuid):
  295. """get an injection of a plugin using a board_uuid
  296. :param board_uuid: The id or uuid of a board.
  297. :returns: An injection_plugin.
  298. """
  299. @abc.abstractmethod
  300. def get_injection_plugin_by_uuids(self, board_uuid, plugin_uuid):
  301. """get an injection of a plugin using a board_uuid and plugin_uuid
  302. :param board_uuid: The id or uuid of a board.
  303. :param plugin_uuid: The id or uuid of a plugin.
  304. :returns: An injection_plugin.
  305. """
  306. @abc.abstractmethod
  307. def create_injection_plugin(self, values):
  308. """Create a new injection_plugin.
  309. :param values: A dict containing several items used to identify
  310. and track the plugin
  311. :returns: An injection plugin.
  312. """
  313. @abc.abstractmethod
  314. def destroy_injection_plugin(self, injection_plugin_id):
  315. """Destroy an injection plugin and all associated interfaces.
  316. :param injection_plugin_id: The id or uuid of a plugin.
  317. """
  318. @abc.abstractmethod
  319. def update_injection_plugin(self, plugin_injection_id, values):
  320. """Update properties of a plugin.
  321. :param plugin_id: The id or uuid of a plugin.
  322. :param values: Dict of values to update.
  323. :returns: A plugin.
  324. :raises: PluginAssociated
  325. :raises: PluginNotFound
  326. """
  327. @abc.abstractmethod
  328. def get_injection_plugin_list(self, board_uuid):
  329. """Return a list of injection_plugins.
  330. :param board_uuid: The id or uuid of a plugin.
  331. :returns: A list of InjectionPlugins on the board.
  332. """
  333. @abc.abstractmethod
  334. def get_service_by_id(self, service_id):
  335. """Return a service.
  336. :param service_id: The id of a service.
  337. :returns: A service.
  338. """
  339. @abc.abstractmethod
  340. def get_service_by_uuid(self, service_uuid):
  341. """Return a service.
  342. :param service_uuid: The uuid of a service.
  343. :returns: A service.
  344. """
  345. @abc.abstractmethod
  346. def get_service_by_name(self, service_name):
  347. """Return a service.
  348. :param service_name: The logical name of a service.
  349. :returns: A service.
  350. """
  351. @abc.abstractmethod
  352. def create_service(self, values):
  353. """Create a new service.
  354. :param values: A dict containing several items used to identify
  355. and track the service
  356. :returns: A service.
  357. """
  358. @abc.abstractmethod
  359. def destroy_service(self, service_id):
  360. """Destroy a service and all associated interfaces.
  361. :param service_id: The id or uuid of a service.
  362. """
  363. @abc.abstractmethod
  364. def update_service(self, service_id, values):
  365. """Update properties of a service.
  366. :param service_id: The id or uuid of a service.
  367. :param values: Dict of values to update.
  368. :returns: A service.
  369. :raises: ServiceAssociated
  370. :raises: ServiceNotFound
  371. """
  372. @abc.abstractmethod
  373. def get_exposed_services_by_board_uuid(self, board_uuid):
  374. """get an exposed of a service using a board_uuid
  375. :param board_uuid: The id or uuid of a board.
  376. :returns: An exposed_service.
  377. """
  378. @abc.abstractmethod
  379. def get_exposed_service_by_uuids(self, board_uuid, service_uuid):
  380. """get an exposed of a service using a board_uuid and service_uuid
  381. :param board_uuid: The id or uuid of a board.
  382. :param service_uuid: The id or uuid of a service.
  383. :returns: An exposed_service.
  384. """
  385. @abc.abstractmethod
  386. def create_exposed_service(self, values):
  387. """Create a new exposed_service.
  388. :param values: A dict containing several items used to identify
  389. and track the service
  390. :returns: An exposed service.
  391. """
  392. @abc.abstractmethod
  393. def destroy_exposed_service(self, exposed_service_id):
  394. """Destroy an exposed service and all associated interfaces.
  395. :param exposed_service_id: The id or uuid of a service.
  396. """
  397. @abc.abstractmethod
  398. def update_exposed_service(self, service_exposed_id, values):
  399. """Update properties of a service.
  400. :param service_id: The id or uuid of a service.
  401. :param values: Dict of values to update.
  402. :returns: A service.
  403. :raises: ServiceAssociated
  404. :raises: ServiceNotFound
  405. """
  406. @abc.abstractmethod
  407. def get_exposed_service_list(self, board_uuid):
  408. """Return a list of exposed_services.
  409. :param board_uuid: The id or uuid of a service.
  410. :returns: A list of ExposedServices on the board.
  411. """