services.py 34 KB

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