services.py 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361
  1. """
  2. Specifications for services available through a provider
  3. """
  4. from abc import ABCMeta, abstractmethod, abstractproperty
  5. from cloudbridge.cloud.interfaces.resources import PageableObjectMixin
  6. class CloudService(object):
  7. """
  8. Base interface for any service supported by a provider. This interface
  9. has a provider property that can be used to access the provider associated
  10. with this service.
  11. """
  12. __metaclass__ = ABCMeta
  13. @abstractproperty
  14. def provider(self):
  15. """
  16. Returns the provider instance associated with this service.
  17. :rtype: :class:`.CloudProvider`
  18. :return: a CloudProvider object
  19. """
  20. pass
  21. class ComputeService(CloudService):
  22. """
  23. The compute service interface is a collection of services that provides
  24. access to the underlying compute related services in a provider. For
  25. example, the compute.instances service can be used to launch a new
  26. instance, and the compute.images service can be used to list available
  27. machine images.
  28. """
  29. __metaclass__ = ABCMeta
  30. @abstractproperty
  31. def images(self):
  32. """
  33. Provides access to all Image related services in this provider.
  34. (e.g. Glance in OpenStack)
  35. Example:
  36. .. code-block:: python
  37. # print all images
  38. for image in provider.compute.images:
  39. print(image.id, image.name, image.label)
  40. # print only first 50 images
  41. for image in provider.compute.images.list(limit=50):
  42. print(image.id, image.name, image.label)
  43. # find image by name
  44. image = provider.compute.images.find(name='Ubuntu 16.04')[0]
  45. print(image.id, image.name, image.label)
  46. :rtype: :class:`.ImageService`
  47. :return: an ImageService object
  48. """
  49. pass
  50. @abstractproperty
  51. def vm_types(self):
  52. """
  53. Provides access to all VM type related services in this provider.
  54. Example:
  55. .. code-block:: python
  56. # list all VM sizes
  57. for vm_type in provider.compute.vm_types:
  58. print(vm_type.id, vm_type.name)
  59. # find a specific size by name
  60. vm_type = provider.compute.vm_types.find(name='m1.small')[0]
  61. print(vm_type.vcpus)
  62. :rtype: :class:`.VMTypeService`
  63. :return: an VMTypeService object
  64. """
  65. pass
  66. @abstractproperty
  67. def instances(self):
  68. """
  69. Provides access to all Instance related services in this provider.
  70. Example:
  71. .. code-block:: python
  72. # launch a new instance
  73. image = provider.compute.images.find(name='Ubuntu 16.04')[0]
  74. size = provider.compute.vm_types.find(name='m1.small')[0]
  75. instance = provider.compute.instances.create('Hello', image, size)
  76. print(instance.id, instance.label)
  77. :rtype: :class:`.InstanceService`
  78. :return: an InstanceService object
  79. """
  80. pass
  81. @abstractproperty
  82. def regions(self):
  83. """
  84. Provides access to all Region related services in this provider.
  85. Example:
  86. .. code-block:: python
  87. for region in provider.compute.regions:
  88. print("Region: ", region.name)
  89. for zone in region.zones:
  90. print("\\tZone: ", zone.name)
  91. :rtype: :class:`.RegionService`
  92. :return: a RegionService object
  93. """
  94. pass
  95. class InstanceService(PageableObjectMixin, CloudService):
  96. """
  97. Provides access to instances in a provider, including creating,
  98. listing and deleting instances.
  99. """
  100. __metaclass__ = ABCMeta
  101. @abstractmethod
  102. def __iter__(self):
  103. """
  104. Iterate through the list of instances.
  105. Example:
  106. ```
  107. for instance in provider.compute.instances:
  108. print(instance.name)
  109. ```
  110. :rtype: ``object`` of :class:`.Instance`
  111. :return: an Instance object
  112. """
  113. pass
  114. @abstractmethod
  115. def get(self, instance_id):
  116. """
  117. Returns an instance given its id. Returns None
  118. if the object does not exist.
  119. :rtype: ``object`` of :class:`.Instance`
  120. :return: an Instance object
  121. """
  122. pass
  123. @abstractmethod
  124. def find(self, **kwargs):
  125. """
  126. Searches for an instance by a given list of attributes.
  127. Supported attributes: name, label
  128. :type name: ``str``
  129. :param name: The name to search for
  130. :type label: ``str``
  131. :param label: The label to search for
  132. :rtype: List of ``object`` of :class:`.Instance`
  133. :return: A list of Instance objects matching the supplied attributes.
  134. """
  135. pass
  136. @abstractmethod
  137. def list(self, limit=None, marker=None):
  138. """
  139. List available instances.
  140. The returned results can be limited with limit and marker. If not
  141. specified, the limit defaults to a global default.
  142. See :func:`~interfaces.resources.PageableObjectMixin.list`
  143. for more information on how to page through returned results.
  144. example::
  145. # List instances
  146. instlist = provider.compute.instances.list()
  147. for instance in instlist:
  148. print("Instance Data: {0}", instance)
  149. :type limit: ``int``
  150. :param limit: The maximum number of objects to return. Note that the
  151. maximum is not guaranteed to be honoured, and a lower
  152. maximum may be enforced depending on the provider. In
  153. such a case, the returned ResultList's is_truncated
  154. property can be used to determine whether more records
  155. are available.
  156. :type marker: ``str``
  157. :param marker: The marker is an opaque identifier used to assist
  158. in paging through very long lists of objects. It is
  159. returned on each invocation of the list method.
  160. :rtype: ``ResultList`` of :class:`.Instance`
  161. :return: A ResultList object containing a list of Instances
  162. """
  163. pass
  164. @abstractmethod
  165. def create(self, label, image, vm_type, subnet, zone=None,
  166. key_pair=None, vm_firewalls=None, user_data=None,
  167. launch_config=None,
  168. **kwargs):
  169. """
  170. Creates a new virtual machine instance.
  171. :type label: ``str``
  172. :param label: The label of the virtual machine instance. The instance
  173. name will be derived from this label.
  174. :type image: ``MachineImage`` or ``str``
  175. :param image: The MachineImage object or id to boot the virtual machine
  176. with
  177. :type vm_type: ``VMType`` or ``str``
  178. :param vm_type: The VMType or name, specifying the size of
  179. the instance to boot into
  180. :type subnet: ``Subnet`` or ``str``
  181. :param subnet: The subnet object or a subnet string ID with which the
  182. instance should be associated. The subnet is a mandatory
  183. parameter, and must be provided when launching an
  184. instance.
  185. Note: Older clouds (with classic networking), may not
  186. have proper subnet support and are not guaranteed to
  187. work. Some providers (e.g. OpenStack) support a null
  188. value but the behaviour is implementation specific.
  189. :type zone: ``Zone`` or ``str``
  190. :param zone: The Zone or its id, where the instance should be placed.
  191. This parameter is provided for legacy compatibility (with
  192. classic networks).
  193. The subnet's placement zone will take precedence over this
  194. parameter, but in its absence, this value will be used.
  195. :type key_pair: ``KeyPair`` or ``str``
  196. :param key_pair: The KeyPair object or its id, to set for the
  197. instance.
  198. :type vm_firewalls: A ``list`` of ``VMFirewall`` objects or a
  199. list of ``str`` object IDs
  200. :param vm_firewalls: A list of ``VMFirewall`` objects or a list
  201. of ``VMFirewall`` IDs, which should be
  202. assigned to this instance.
  203. The VM firewalls must be associated with the
  204. same network as the supplied subnet. Use
  205. ``network.vm_firewalls`` to retrieve a list
  206. of firewalls belonging to a network.
  207. :type user_data: ``str``
  208. :param user_data: An extra userdata object which is compatible with
  209. the provider.
  210. :type launch_config: ``LaunchConfig`` object
  211. :param launch_config: A ``LaunchConfig`` object which
  212. describes advanced launch configuration options for an instance.
  213. Currently, this includes only block_device_mappings. To
  214. construct a launch configuration object, call
  215. provider.compute.instances.create_launch_config()
  216. :rtype: ``object`` of :class:`.Instance`
  217. :return: an instance of Instance class
  218. """
  219. pass
  220. def create_launch_config(self):
  221. """
  222. Creates a ``LaunchConfig`` object which can be used
  223. to set additional options when launching an instance, such as
  224. block device mappings and network interfaces.
  225. :rtype: ``object`` of :class:`.LaunchConfig`
  226. :return: an instance of a LaunchConfig class
  227. """
  228. pass
  229. class VolumeService(PageableObjectMixin, CloudService):
  230. """
  231. Base interface for a Volume Service.
  232. """
  233. __metaclass__ = ABCMeta
  234. @abstractmethod
  235. def get(self, volume_id):
  236. """
  237. Returns a volume given its id.
  238. :rtype: ``object`` of :class:`.Volume`
  239. :return: a Volume object or ``None`` if the volume does not exist.
  240. """
  241. pass
  242. @abstractmethod
  243. def find(self, **kwargs):
  244. """
  245. Searches for a volume by a given list of attributes.
  246. Supported attributes: label
  247. :rtype: ``object`` of :class:`.Volume`
  248. :return: a Volume object or ``None`` if not found.
  249. """
  250. pass
  251. @abstractmethod
  252. def list(self, limit=None, marker=None):
  253. """
  254. List all volumes.
  255. :rtype: ``list`` of :class:`.Volume`
  256. :return: a list of Volume objects.
  257. """
  258. pass
  259. @abstractmethod
  260. def create(self, label, size, zone, snapshot=None, description=None):
  261. """
  262. Creates a new volume.
  263. :type label: ``str``
  264. :param label: The label for the volume.
  265. :type size: ``int``
  266. :param size: The size of the volume (in GB).
  267. :type zone: ``str`` or :class:`.PlacementZone` object
  268. :param zone: The availability zone in which the Volume will be created.
  269. :type snapshot: ``str`` or :class:`.Snapshot` object
  270. :param snapshot: An optional reference to a snapshot from which this
  271. volume should be created.
  272. :type description: ``str``
  273. :param description: An optional description that may be supported by
  274. some providers. Providers that do not support this
  275. property will return ``None``.
  276. :rtype: ``object`` of :class:`.Volume`
  277. :return: a newly created Volume object.
  278. """
  279. pass
  280. class SnapshotService(PageableObjectMixin, CloudService):
  281. """
  282. Base interface for a Snapshot Service.
  283. """
  284. __metaclass__ = ABCMeta
  285. @abstractmethod
  286. def get(self, volume_id):
  287. """
  288. Returns a snapshot given its id.
  289. :rtype: ``object`` of :class:`.Snapshot`
  290. :return: a Snapshot object or ``None`` if the snapshot does not exist.
  291. """
  292. pass
  293. @abstractmethod
  294. def find(self, **kwargs):
  295. """
  296. Searches for a snapshot by a given list of attributes.
  297. Supported attributes: label
  298. :rtype: list of :class:`.Snapshot`
  299. :return: a Snapshot object or an empty list if none found.
  300. """
  301. pass
  302. @abstractmethod
  303. def list(self, limit=None, marker=None):
  304. """
  305. List all snapshots.
  306. :rtype: ``list`` of :class:`.Snapshot`
  307. :return: a list of Snapshot objects.
  308. """
  309. pass
  310. @abstractmethod
  311. def create(self, label, volume, description=None):
  312. """
  313. Creates a new snapshot off a volume.
  314. :type label: ``str``
  315. :param label: The label for the snapshot.
  316. :type volume: ``str`` or ``Volume``
  317. :param volume: The volume to create a snapshot of.
  318. :type description: ``str``
  319. :param description: An optional description that may be supported by
  320. some providers. Providers that do not support this
  321. property will return None.
  322. :rtype: ``object`` of :class:`.Snapshot`
  323. :return: a newly created Snapshot object.
  324. """
  325. pass
  326. class StorageService(CloudService):
  327. """
  328. The Storage Service interface provides access to block device services,
  329. such as volume and snapshot services, as well as object store services,
  330. such as buckets, in the provider.
  331. """
  332. __metaclass__ = ABCMeta
  333. @abstractproperty
  334. def volumes(self):
  335. """
  336. Provides access to volumes (i.e., block storage) for this provider.
  337. Example:
  338. .. code-block:: python
  339. # print all volumes
  340. for vol in provider.storage.volumes:
  341. print(vol.id, vol.name, vol.label)
  342. # find volume by label
  343. vol = provider.storage.volumes.find(label='my_vol')[0]
  344. print(vol.id, vol.name, vol.label)
  345. :rtype: :class:`.VolumeService`
  346. :return: a VolumeService object
  347. """
  348. pass
  349. @abstractproperty
  350. def snapshots(self):
  351. """
  352. Provides access to volume snapshots for this provider.
  353. Example:
  354. .. code-block:: python
  355. # print all snapshots
  356. for snap in provider.storage.snapshots:
  357. print(snap.id, snap.name, snap.label)
  358. # find snapshot by label
  359. snap = provider.storage.snapshots.find(label='my_snap')[0]
  360. print(snap.id, snap.name, snap.label)
  361. :rtype: :class:`.SnapshotService`
  362. :return: a SnapshotService object
  363. """
  364. pass
  365. @abstractproperty
  366. def buckets(self):
  367. """
  368. Provides access to object storage services in this provider.
  369. Example:
  370. .. code-block:: python
  371. # print all buckets
  372. for bucket in provider.storage.buckets:
  373. print(bucket.id, bucket.name)
  374. # find bucket by name
  375. bucket = provider.storage.buckets.find(name='my_bucket')[0]
  376. print(bucket.id, bucket.name)
  377. :rtype: :class:`.BucketService`
  378. :return: a BucketService object
  379. """
  380. pass
  381. class ImageService(PageableObjectMixin, CloudService):
  382. """
  383. Base interface for an Image Service
  384. """
  385. __metaclass__ = ABCMeta
  386. @abstractmethod
  387. def get(self, image_id):
  388. """
  389. Returns an Image given its id. Returns None if the Image does not
  390. exist.
  391. :rtype: ``object`` of :class:`.Image`
  392. :return: an Image instance
  393. """
  394. pass
  395. @abstractmethod
  396. def find(self, **kwargs):
  397. """
  398. Searches for an image by a given list of attributes
  399. Supported attributes: name, label
  400. :rtype: ``object`` of :class:`.Image`
  401. :return: an Image instance
  402. """
  403. pass
  404. @abstractmethod
  405. def list(self, filter_by_owner=True, limit=None, marker=None):
  406. """
  407. List all images.
  408. :type filter_by_owner: ``bool``
  409. :param filter_by_owner: If ``True``, return only images owned
  410. by the current user. Else, return all
  411. public images available from the provider.
  412. Note that fetching all images may take a
  413. long time.
  414. :rtype: ``list`` of :class:`.Image`
  415. :return: list of image objects
  416. """
  417. pass
  418. class NetworkingService(CloudService):
  419. """
  420. Base service interface for networking.
  421. This service offers a collection of networking services that in turn
  422. provide access to networking resources.
  423. """
  424. __metaclass__ = ABCMeta
  425. @abstractproperty
  426. def networks(self):
  427. """
  428. Provides access to all Network related services.
  429. :rtype: :class:`.NetworkService`
  430. :return: a Network service object
  431. """
  432. pass
  433. @abstractproperty
  434. def subnets(self):
  435. """
  436. Provides access to all Subnet related services.
  437. :rtype: :class:`.SubnetService`
  438. :return: a Subnet service object
  439. """
  440. pass
  441. @abstractproperty
  442. def routers(self):
  443. """
  444. Provides access to all Router related services.
  445. :rtype: :class:`.RouterService`
  446. :return: a Router service object
  447. """
  448. pass
  449. class NetworkService(PageableObjectMixin, CloudService):
  450. """
  451. Base interface for a Network Service.
  452. """
  453. __metaclass__ = ABCMeta
  454. @abstractmethod
  455. def get(self, network_id):
  456. """
  457. Returns a Network given its ID or ``None`` if not found.
  458. :type network_id: ``str``
  459. :param network_id: The ID of the network to retrieve.
  460. :rtype: ``object`` of :class:`.Network`
  461. :return: a Network object
  462. """
  463. pass
  464. @abstractmethod
  465. def list(self, limit=None, marker=None):
  466. """
  467. List all networks.
  468. :rtype: ``list`` of :class:`.Network`
  469. :return: list of Network objects
  470. """
  471. pass
  472. @abstractmethod
  473. def find(self, **kwargs):
  474. """
  475. Searches for a network by a given list of attributes.
  476. Supported attributes: name, label
  477. :rtype: List of ``object`` of :class:`.Network`
  478. :return: A list of Network objects matching the supplied attributes.
  479. """
  480. pass
  481. @abstractmethod
  482. def create(self, label, cidr_block):
  483. """
  484. Create a new network.
  485. :type label: ``str``
  486. :param label: A label for the network.
  487. :type cidr_block: ``str``
  488. :param cidr_block: The cidr block for this network. Some providers
  489. will respect this at the network level, while others
  490. will only respect it at subnet level. However, to
  491. write portable code, you should make sure that any
  492. subnets you create fall within this initially
  493. specified range. Note that the block size should be
  494. between a /16 netmask (65,536 IP addresses) and /28
  495. netmask (16 IP addresses). e.g. 10.0.0.0/16
  496. :rtype: ``object`` of :class:`.Network`
  497. :return: A Network object
  498. """
  499. pass
  500. @abstractmethod
  501. def delete(self, network_id):
  502. """
  503. Delete an existing Network.
  504. :type network_id: ``str``
  505. :param network_id: The ID of the network to be deleted.
  506. """
  507. pass
  508. @abstractproperty
  509. def subnets(self):
  510. """
  511. Provides access to subnets.
  512. Example:
  513. .. code-block:: python
  514. # Print all subnets
  515. for s in provider.networking.subnets:
  516. print(s.id, s.name, s.label)
  517. # Get subnet by ID
  518. s = provider.networking.subnets.get('subnet-id')
  519. print(s.id, s.name, s.label)
  520. :rtype: :class:`.SubnetService`
  521. :return: a SubnetService object
  522. """
  523. pass
  524. class SubnetService(PageableObjectMixin, CloudService):
  525. """
  526. Base interface for a Subnet Service.
  527. """
  528. __metaclass__ = ABCMeta
  529. @abstractmethod
  530. def get(self, subnet_id):
  531. """
  532. Returns a Subnet given its ID or ``None`` if not found.
  533. :type subnet_id: :class:`.Network` object or ``str``
  534. :param subnet_id: The ID of the subnet to retrieve.
  535. :rtype: ``object`` of :class:`.Subnet`
  536. return: a Subnet object
  537. """
  538. pass
  539. @abstractmethod
  540. # pylint:disable=arguments-differ
  541. def list(self, network=None, limit=None, marker=None):
  542. """
  543. List all subnets or filter them by the supplied network ID.
  544. :type network: ``str``
  545. :param network: Network object or ID with which to filter the subnets.
  546. :rtype: ``list`` of :class:`.Subnet`
  547. :return: list of Subnet objects
  548. """
  549. pass
  550. @abstractmethod
  551. def find(self, **kwargs):
  552. """
  553. Searches for a subnet by a given list of attributes.
  554. Supported attributes: name, label
  555. :rtype: List of ``object`` of :class:`.Subnet`
  556. :return: A list of Subnet objects matching the supplied attributes.
  557. """
  558. pass
  559. @abstractmethod
  560. def create(self, label, network, cidr_block, zone):
  561. """
  562. Create a new subnet within the supplied network.
  563. :type label: ``str``
  564. :param label: The subnet label.
  565. :type network: :class:`.Network` object or ``str``
  566. :param network: Network object or ID under which to create the subnet.
  567. :type cidr_block: ``str``
  568. :param cidr_block: CIDR block within the Network to assign to the
  569. subnet.
  570. :type zone: ``str``
  571. :param zone: A placement zone for the subnet. Some providers
  572. may not support this, in which case the value is ignored.
  573. :rtype: ``object`` of :class:`.Subnet`
  574. :return: A Subnet object
  575. """
  576. pass
  577. @abstractmethod
  578. def get_or_create_default(self, zone):
  579. """
  580. Return a default subnet for the account or create one if not found.
  581. This provides a convenience method for obtaining a network if you
  582. are not particularly concerned with how the network is structured.
  583. A default network is one marked as such by the provider or matches the
  584. default label used by this library (e.g., cloudbridge-net).
  585. :type zone: :class:`.PlacementZone` object ``str``
  586. :param zone: Placement zone where to look for the subnet.
  587. :rtype: ``object`` of :class:`.Subnet`
  588. :return: A Subnet object
  589. """
  590. pass
  591. @abstractmethod
  592. def delete(self, subnet):
  593. """
  594. Delete an existing Subnet.
  595. :type subnet: :class:`.Subnet` object or ``str``
  596. :param subnet: Subnet object or ID of the subnet to delete.
  597. """
  598. pass
  599. class RouterService(PageableObjectMixin, CloudService):
  600. """
  601. Manage networking router actions and resources.
  602. """
  603. __metaclass__ = ABCMeta
  604. @abstractmethod
  605. def get(self, router_id):
  606. """
  607. Returns a Router object given its ID.
  608. :type router_id: ``str``
  609. :param router_id: The ID of the router to retrieve.
  610. :rtype: ``object`` of :class:`.Router` or ``None``
  611. :return: a Router object of ``None`` if not found.
  612. """
  613. pass
  614. @abstractmethod
  615. def list(self, limit=None, marker=None):
  616. """
  617. List all routers.
  618. :rtype: ``list`` of :class:`.Router`
  619. :return: list of Router objects
  620. """
  621. pass
  622. @abstractmethod
  623. def find(self, **kwargs):
  624. """
  625. Searches for a router by a given list of attributes.
  626. Supported attributes: label
  627. :rtype: List of ``object`` of :class:`.Router`
  628. :return: A list of Router objects matching the supplied attributes.
  629. """
  630. pass
  631. @abstractmethod
  632. def create(self, label, network):
  633. """
  634. Create a new router.
  635. :type label: ``str``
  636. :param label: A router label.
  637. :type network: :class:`.Network` object or ``str``
  638. :param network: Network object or ID under which to create the router.
  639. :rtype: ``object`` of :class:`.Router`
  640. :return: A Router object
  641. """
  642. pass
  643. @abstractmethod
  644. def delete(self, router):
  645. """
  646. Delete an existing Router.
  647. :type router: :class:`.Router` object or ``str``
  648. :param router: Router object or ID of the router to delete.
  649. """
  650. pass
  651. class BucketService(PageableObjectMixin, CloudService):
  652. """
  653. The Bucket Service interface provides access to the underlying
  654. object storage capabilities of this provider. This service is optional and
  655. the :func:`CloudProvider.has_service()` method should be used to verify its
  656. availability before using the service.
  657. """
  658. __metaclass__ = ABCMeta
  659. @abstractmethod
  660. def get(self, bucket_id):
  661. """
  662. Returns a bucket given its ID. Returns ``None`` if the bucket
  663. does not exist. On some providers, such as AWS and OpenStack,
  664. the bucket id is the same as its name.
  665. Example:
  666. .. code-block:: python
  667. bucket = provider.storage.buckets.get('my_bucket_id')
  668. print(bucket.id, bucket.name)
  669. :rtype: :class:`.Bucket`
  670. :return: a Bucket instance
  671. """
  672. pass
  673. @abstractmethod
  674. def find(self, **kwargs):
  675. """
  676. Searches for a bucket by a given list of attributes.
  677. Supported attributes: name
  678. Example:
  679. .. code-block:: python
  680. buckets = provider.storage.buckets.find(name='my_bucket_name')
  681. for bucket in buckets:
  682. print(bucket.id, bucket.name)
  683. :rtype: :class:`.Bucket`
  684. :return: a Bucket instance
  685. """
  686. pass
  687. @abstractmethod
  688. def list(self, limit=None, marker=None):
  689. """
  690. List all buckets.
  691. Example:
  692. .. code-block:: python
  693. buckets = provider.storage.buckets.find(name='my_bucket_name')
  694. for bucket in buckets:
  695. print(bucket.id, bucket.name)
  696. :rtype: :class:`.Bucket`
  697. :return: list of bucket objects
  698. """
  699. pass
  700. @abstractmethod
  701. def create(self, name, location=None):
  702. """
  703. Create a new bucket.
  704. If a bucket with the specified name already exists, return a reference
  705. to that bucket.
  706. Example:
  707. .. code-block:: python
  708. bucket = provider.storage.buckets.create('my_bucket_name')
  709. print(bucket.name)
  710. :type name: str
  711. :param name: The name of this bucket.
  712. :type location: ``object`` of :class:`.Region`
  713. :param location: The region in which to place this bucket.
  714. :return: a Bucket object
  715. :rtype: ``object`` of :class:`.Bucket`
  716. """
  717. pass
  718. class BucketObjectService(PageableObjectMixin, CloudService):
  719. """
  720. The Bucket Object Service interface provides access to the underlying
  721. object storage capabilities of this provider. This service is optional and
  722. the :func:`CloudProvider.has_service()` method should be used to verify its
  723. availability before using the service.
  724. """
  725. __metaclass__ = ABCMeta
  726. @abstractmethod
  727. def get(self, bucket, object_id):
  728. """
  729. Returns a bucket object given its ID and the ID of bucket containing
  730. it. Returns ``None`` if the bucket object or bucket does not exist.
  731. On some providers, such as AWS and OpenStack, the bucket id is the
  732. same as its name.
  733. Example:
  734. .. code-block:: python
  735. bucket = provider.storage.buckets.get('my_bucket_id')
  736. buck_obj = provider.storage.bucket_objects.get('my_object_id',
  737. bucket)
  738. print(buck_obj.id, buck_obj.name)
  739. :rtype: :class:`.BucketObject`
  740. :return: a BucketObject instance
  741. """
  742. pass
  743. @abstractmethod
  744. def find(self, bucket, **kwargs):
  745. """
  746. Searches for a bucket object in a bucket by a given list of attributes.
  747. Supported attributes: name
  748. Example:
  749. .. code-block:: python
  750. bucket = provider.storage.buckets.get('my_bucket_id')
  751. objs = provider.storage.bucket_objects.find(bucket,
  752. name='my_obj_name')
  753. for buck_obj in objs:
  754. print(buck_obj.id, buck_obj.name)
  755. :rtype: :class:`.BucketObject`
  756. :return: a BucketObject instance
  757. """
  758. pass
  759. @abstractmethod
  760. def list(self, bucket, limit=None, marker=None):
  761. """
  762. List all bucket objects within a bucket.
  763. Example:
  764. .. code-block:: python
  765. bucket = provider.storage.buckets.get('my_bucket_id')
  766. objs = provider.storage.bucket_objects.list(bucket)
  767. for buck_obj in objs:
  768. print(buck_obj.id, buck_obj.name)
  769. :rtype: :class:`.BucketObject`
  770. :return: a BucketObject instance
  771. """
  772. pass
  773. @abstractmethod
  774. def create(self, bucket, object_name):
  775. """
  776. Create a new bucket object within a bucket.
  777. Example:
  778. .. code-block:: python
  779. bucket = provider.storage.buckets.get('my_bucket_id')
  780. buck_obj = provider.storage.bucket_objects.create('my_name',
  781. bucket)
  782. print(buck_obj.name)
  783. :type object_name: str
  784. :param object_name: The name of this bucket.
  785. :type bucket: str
  786. :param bucket: A bucket object.
  787. :return: a BucketObject instance
  788. :rtype: ``object`` of :class:`.BucketObject`
  789. """
  790. pass
  791. class SecurityService(CloudService):
  792. """
  793. The security service interface can be used to access security related
  794. functions in the provider, such as firewall control and keypairs.
  795. """
  796. __metaclass__ = ABCMeta
  797. @abstractproperty
  798. def key_pairs(self):
  799. """
  800. Provides access to key pairs for this provider.
  801. Example:
  802. .. code-block:: python
  803. # print all keypairs
  804. for kp in provider.security.keypairs:
  805. print(kp.id, kp.name)
  806. # find keypair by name
  807. kp = provider.security.keypairs.find(name='my_key_pair')[0]
  808. print(kp.id, kp.name)
  809. :rtype: :class:`.KeyPairService`
  810. :return: a KeyPairService object
  811. """
  812. pass
  813. @abstractproperty
  814. def vm_firewalls(self):
  815. """
  816. Provides access to firewalls (security groups) for this provider.
  817. Example:
  818. .. code-block:: python
  819. # print all VM firewalls
  820. for fw in provider.security.vm_firewalls:
  821. print(fw.id, fw.name)
  822. # find firewall by name
  823. fw = provider.security.vm_firewalls.find(name='my_vm_fw')[0]
  824. print(fw.id, fw.name)
  825. :rtype: :class:`.VMFirewallService`
  826. :return: a VMFirewallService object
  827. """
  828. pass
  829. class KeyPairService(PageableObjectMixin, CloudService):
  830. """
  831. Base interface for key pairs.
  832. """
  833. __metaclass__ = ABCMeta
  834. @abstractmethod
  835. def get(self, key_pair_id):
  836. """
  837. Return a KeyPair given its ID or ``None`` if not found.
  838. On some providers, such as AWS and OpenStack, the KeyPair ID is
  839. the same as its name.
  840. Example:
  841. .. code-block:: python
  842. key_pair = provider.security.keypairs.get('my_key_pair_id')
  843. print(key_pair.id, key_pair.name)
  844. :rtype: :class:`.KeyPair`
  845. :return: a KeyPair instance
  846. """
  847. pass
  848. @abstractmethod
  849. def list(self, limit=None, marker=None):
  850. """
  851. List all key pairs associated with this account.
  852. :rtype: ``list`` of :class:`.KeyPair`
  853. :return: list of KeyPair objects
  854. """
  855. pass
  856. @abstractmethod
  857. def find(self, **kwargs):
  858. """
  859. Searches for a key pair by a given list of attributes.
  860. Supported attributes: name
  861. :rtype: ``object`` of :class:`.KeyPair`
  862. :return: a KeyPair object
  863. """
  864. pass
  865. @abstractmethod
  866. def create(self, name, public_key_material=None):
  867. """
  868. Create a new key pair or raise an exception if one already exists.
  869. If the public_key_material is provided, the material will be imported
  870. to create the new keypair. Otherwise, a new public and private key
  871. pair will be generated.
  872. :type name: str
  873. :param name: The name of the key pair to be created.
  874. :type public_key_material: str
  875. :param public_key_material: The key-pair material to import in OpenSSH
  876. format.
  877. :rtype: ``object`` of :class:`.KeyPair`
  878. :return: A keypair instance or ``None``.
  879. """
  880. pass
  881. @abstractmethod
  882. def delete(self, key_pair_id):
  883. """
  884. Delete an existing VMFirewall.
  885. :type key_pair_id: str
  886. :param key_pair_id: The id of the key pair to be deleted.
  887. :rtype: ``bool``
  888. :return: ``True`` if the key does not exist, ``False`` otherwise. Note
  889. that this implies that the key may not have been deleted by
  890. this method but instead has not existed at all.
  891. """
  892. pass
  893. class VMFirewallService(PageableObjectMixin, CloudService):
  894. """
  895. Base interface for VM firewalls.
  896. """
  897. __metaclass__ = ABCMeta
  898. @abstractmethod
  899. def get(self, vm_firewall_id):
  900. """
  901. Returns a VMFirewall given its ID. Returns ``None`` if the
  902. VMFirewall does not exist.
  903. Example:
  904. .. code-block:: python
  905. fw = provider.security.vm_firewalls.get('my_fw_id')
  906. print(fw.id, fw.name)
  907. :rtype: :class:`.VMFirewall`
  908. :return: a VMFirewall instance
  909. """
  910. pass
  911. @abstractmethod
  912. def list(self, limit=None, marker=None):
  913. """
  914. List all VM firewalls associated with this account.
  915. :rtype: ``list`` of :class:`.VMFirewall`
  916. :return: list of VMFirewall objects
  917. """
  918. pass
  919. @abstractmethod
  920. def create(self, label, network, description=None):
  921. """
  922. Create a new VMFirewall.
  923. :type label: str
  924. :param label: The label for the new VM firewall.
  925. :type network: ``str``
  926. :param network: Network ID under which to create the VM firewall.
  927. :type description: str
  928. :param description: The description of the new VM firewall.
  929. :rtype: ``object`` of :class:`.VMFirewall`
  930. :return: A VMFirewall instance or ``None`` if one was not created.
  931. """
  932. pass
  933. @abstractmethod
  934. def find(self, **kwargs):
  935. """
  936. Get VM firewalls associated with your account filtered by name.
  937. Supported attributes: name
  938. :type name: str
  939. :param name: The name of the VM firewall to retrieve.
  940. :rtype: list of :class:`VMFirewall`
  941. :return: A list of VMFirewall objects or an empty list if none
  942. found.
  943. """
  944. pass
  945. @abstractmethod
  946. def delete(self, group_id):
  947. """
  948. Delete an existing VMFirewall.
  949. :type group_id: str
  950. :param group_id: The VM firewall ID to be deleted.
  951. """
  952. pass
  953. class VMTypeService(PageableObjectMixin, CloudService):
  954. __metaclass__ = ABCMeta
  955. @abstractmethod
  956. def get(self, vm_type_id):
  957. """
  958. Returns an VMType given its ID. Returns ``None`` if the
  959. VMType does not exist.
  960. Example:
  961. .. code-block:: python
  962. vm_type = provider.compute.vm_types.get('my_vm_type_id')
  963. print(vm_type.id, vm_type.name)
  964. :rtype: :class:`.VMType`
  965. :return: an VMType instance
  966. """
  967. pass
  968. @abstractmethod
  969. def list(self, limit=None, marker=None):
  970. """
  971. List all VM types.
  972. :rtype: ``list`` of :class:`.VMType`
  973. :return: list of VMType objects
  974. """
  975. pass
  976. @abstractmethod
  977. def find(self, **kwargs):
  978. """
  979. Searches for an instance by a given list of attributes.
  980. Supported attributes: name
  981. :rtype: ``object`` of :class:`.VMType`
  982. :return: an Instance object
  983. """
  984. pass
  985. class RegionService(PageableObjectMixin, CloudService):
  986. """
  987. Base interface for a Region service
  988. """
  989. __metaclass__ = ABCMeta
  990. @abstractproperty
  991. def current(self):
  992. """
  993. Returns the current region that this provider is connected to.
  994. If the current region cannot be discovered, return ``None``.
  995. :rtype: ``object`` of :class:`.Region`
  996. :return: a Region instance or ``None``
  997. """
  998. pass
  999. @abstractmethod
  1000. def get(self, region_id):
  1001. """
  1002. Returns a region given its id. Returns None if the region
  1003. does not exist.
  1004. :rtype: ``object`` of :class:`.Region`
  1005. :return: a Region instance
  1006. """
  1007. pass
  1008. @abstractmethod
  1009. def list(self, limit=None, marker=None):
  1010. """
  1011. List all regions.
  1012. :rtype: ``list`` of :class:`.Region`
  1013. :return: list of region objects
  1014. """
  1015. pass
  1016. @abstractmethod
  1017. def find(self, **kwargs):
  1018. """
  1019. Searches for a region by a given list of attributes.
  1020. Supported attributes: name
  1021. :rtype: ``object`` of :class:`.Region`
  1022. :return: a Region object
  1023. """
  1024. pass