services.py 29 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081
  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 14.04')
  45. print(image.id, image.name)
  46. :rtype: :class:`.ImageService`
  47. :return: an ImageService object
  48. """
  49. pass
  50. @abstractproperty
  51. def instance_types(self):
  52. """
  53. Provides access to all Instance type related services in this provider.
  54. Example:
  55. .. code-block:: python
  56. # list all instance sizes
  57. for inst_type in provider.compute.instance_types:
  58. print(inst_type.id, inst_type.name)
  59. # find a specific size by name
  60. inst_type = provider.compute.instance_types.find(name='m1.small')
  61. print(inst_type.vcpus)
  62. :rtype: :class:`.InstanceTypeService`
  63. :return: an InstanceTypeService 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 14.04')[0]
  74. size = provider.compute.instance_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, name):
  125. """
  126. Searches for an instance by a given list of attributes.
  127. :rtype: ``object`` of :class:`.Instance`
  128. :return: an Instance object
  129. """
  130. pass
  131. @abstractmethod
  132. def list(self, limit=None, marker=None):
  133. """
  134. List available instances.
  135. The returned results can be limited with limit and marker. If not
  136. specified, the limit defaults to a global default.
  137. See :func:`~interfaces.resources.PageableObjectMixin.list`
  138. for more information on how to page through returned results.
  139. example::
  140. # List instances
  141. instlist = provider.compute.instances.list()
  142. for instance in instlist:
  143. print("Instance Data: {0}", instance)
  144. :type limit: ``int``
  145. :param limit: The maximum number of objects to return
  146. :type marker: ``str``
  147. :param marker: The marker is an opaque identifier used to assist
  148. in paging through very long lists of objects. It is
  149. returned on each invocation of the list method.
  150. :rtype: ``ResultList`` of :class:`.Instance`
  151. :return: A ResultList object containing a list of Instances
  152. """
  153. pass
  154. @abstractmethod
  155. def create(self, name, image, instance_type, network=None, zone=None,
  156. key_pair=None, security_groups=None, user_data=None,
  157. launch_config=None,
  158. **kwargs):
  159. """
  160. Creates a new virtual machine instance.
  161. :type name: ``str``
  162. :param name: The name of the virtual machine instance
  163. :type image: ``MachineImage`` or ``str``
  164. :param image: The MachineImage object or id to boot the virtual machine
  165. with
  166. :type instance_type: ``InstanceType`` or ``str``
  167. :param instance_type: The InstanceType or name, specifying the size of
  168. the instance to boot into
  169. :type network: ``Network`` or ``str``
  170. :param network: The Network or an ID with which the instance should
  171. be associated. If no network was specified, this
  172. method will attempt to find a 'default' one and launch
  173. the instance using that network. A 'default' network
  174. is one tagged as such by the native API. If such tag
  175. or functionality does not exist, an attempt to create
  176. a new network (by default called 'CloudBridgeNet')
  177. will be made. If that falls through, an attempt will
  178. be made to launch the instance without specifying the
  179. network parameter (this is under the assumption the
  180. private networking functionality is not available on
  181. the provider).
  182. :type zone: ``Zone`` or ``str``
  183. :param zone: The Zone or its name, where the instance should be placed.
  184. :type key_pair: ``KeyPair`` or ``str``
  185. :param key_pair: The KeyPair object or its name, to set for the
  186. instance.
  187. :type security_groups: A ``list`` of ``SecurityGroup`` objects or a
  188. list of ``str`` names
  189. :param security_groups: A list of ``SecurityGroup`` objects or a list
  190. of ``SecurityGroup`` names, which should be
  191. assigned to this instance.
  192. :type user_data: ``str``
  193. :param user_data: An extra userdata object which is compatible with
  194. the provider.
  195. :type launch_config: ``LaunchConfig`` object
  196. :param launch_config: A ``LaunchConfig`` object which
  197. describes advanced launch configuration options for an instance.
  198. Currently, this includes only block_device_mappings. To
  199. construct a launch configuration object, call
  200. provider.compute.instances.create_launch_config()
  201. :rtype: ``object`` of :class:`.Instance`
  202. :return: an instance of Instance class
  203. """
  204. pass
  205. def create_launch_config(self):
  206. """
  207. Creates a ``LaunchConfig`` object which can be used
  208. to set additional options when launching an instance, such as
  209. block device mappings and network interfaces.
  210. :rtype: ``object`` of :class:`.LaunchConfig`
  211. :return: an instance of a LaunchConfig class
  212. """
  213. pass
  214. class VolumeService(PageableObjectMixin, CloudService):
  215. """
  216. Base interface for a Volume Service.
  217. """
  218. __metaclass__ = ABCMeta
  219. @abstractmethod
  220. def get(self, volume_id):
  221. """
  222. Returns a volume given its id.
  223. :rtype: ``object`` of :class:`.Volume`
  224. :return: a Volume object or ``None`` if the volume does not exist.
  225. """
  226. pass
  227. @abstractmethod
  228. def find(self, name, limit=None, marker=None):
  229. """
  230. Searches for a volume by a given list of attributes.
  231. :rtype: ``object`` of :class:`.Volume`
  232. :return: a Volume object or ``None`` if not found.
  233. """
  234. pass
  235. @abstractmethod
  236. def list(self, limit=None, marker=None):
  237. """
  238. List all volumes.
  239. :rtype: ``list`` of :class:`.Volume`
  240. :return: a list of Volume objects.
  241. """
  242. pass
  243. @abstractmethod
  244. def create(self, name, size, zone, snapshot=None, description=None):
  245. """
  246. Creates a new volume.
  247. :type name: ``str``
  248. :param name: The name of the volume.
  249. :type size: ``int``
  250. :param size: The size of the volume (in GB).
  251. :type zone: ``str`` or :class:`.PlacementZone` object
  252. :param zone: The availability zone in which the Volume will be created.
  253. :type snapshot: ``str`` or :class:`.Snapshot` object
  254. :param snapshot: An optional reference to a snapshot from which this
  255. volume should be created.
  256. :type description: ``str``
  257. :param description: An optional description that may be supported by
  258. some providers. Providers that do not support this
  259. property will return ``None``.
  260. :rtype: ``object`` of :class:`.Volume`
  261. :return: a newly created Volume object.
  262. """
  263. pass
  264. class SnapshotService(PageableObjectMixin, CloudService):
  265. """
  266. Base interface for a Snapshot Service.
  267. """
  268. __metaclass__ = ABCMeta
  269. @abstractmethod
  270. def get(self, volume_id):
  271. """
  272. Returns a snapshot given its id.
  273. :rtype: ``object`` of :class:`.Snapshot`
  274. :return: a Snapshot object or ``None`` if the snapshot does not exist.
  275. """
  276. pass
  277. @abstractmethod
  278. def find(self, name, limit=None, marker=None):
  279. """
  280. Searches for a snapshot by a given list of attributes.
  281. :rtype: list of :class:`.Snapshot`
  282. :return: a Snapshot object or an empty list if none found.
  283. """
  284. pass
  285. @abstractmethod
  286. def list(self, limit=None, marker=None):
  287. """
  288. List all snapshots.
  289. :rtype: ``list`` of :class:`.Snapshot`
  290. :return: a list of Snapshot objects.
  291. """
  292. pass
  293. @abstractmethod
  294. def create(self, name, volume, description=None):
  295. """
  296. Creates a new snapshot off a volume.
  297. :type name: ``str``
  298. :param name: The name of the snapshot
  299. :type volume: ``str`` or ``Volume``
  300. :param volume: The volume to create a snapshot of.
  301. :type description: ``str``
  302. :param description: An optional description that may be supported by
  303. some providers. Providers that do not support this
  304. property will return None.
  305. :rtype: ``object`` of :class:`.Snapshot`
  306. :return: a newly created Snapshot object.
  307. """
  308. pass
  309. class BlockStoreService(CloudService):
  310. """
  311. The Block Store Service interface provides access to block device services,
  312. such as volume and snapshot services in the provider.
  313. """
  314. __metaclass__ = ABCMeta
  315. @abstractproperty
  316. def volumes(self):
  317. """
  318. Provides access to volumes (i.e., block storage) for this provider.
  319. Example:
  320. .. code-block:: python
  321. # print all volumes
  322. for vol in provider.block_store.volumes:
  323. print(vol.id, vol.name)
  324. # find volume by name
  325. vol = provider.block_store.volumes.find(name='my_vol')[0]
  326. print(vol.id, vol.name)
  327. :rtype: :class:`.VolumeService`
  328. :return: a VolumeService object
  329. """
  330. pass
  331. @abstractproperty
  332. def snapshots(self):
  333. """
  334. Provides access to volume snapshots for this provider.
  335. Example:
  336. .. code-block:: python
  337. # print all snapshots
  338. for snap in provider.block_store.snapshots:
  339. print(snap.id, snap.name)
  340. # find snapshot by name
  341. snap = provider.block_store.snapshots.find(name='my_snap')[0]
  342. print(snap.id, snap.name)
  343. :rtype: :class:`.SnapshotService`
  344. :return: an SnapshotService object
  345. """
  346. pass
  347. class ImageService(PageableObjectMixin, CloudService):
  348. """
  349. Base interface for an Image Service
  350. """
  351. __metaclass__ = ABCMeta
  352. @abstractmethod
  353. def get(self, image_id):
  354. """
  355. Returns an Image given its id. Returns None if the Image does not
  356. exist.
  357. :rtype: ``object`` of :class:`.Image`
  358. :return: an Image instance
  359. """
  360. pass
  361. @abstractmethod
  362. def find(self, name, limit=None, marker=None):
  363. """
  364. Searches for an image by a given list of attributes
  365. :rtype: ``object`` of :class:`.Image`
  366. :return: an Image instance
  367. """
  368. pass
  369. @abstractmethod
  370. def list(self, limit=None, marker=None):
  371. """
  372. List all images.
  373. :rtype: ``list`` of :class:`.Image`
  374. :return: list of image objects
  375. """
  376. pass
  377. class NetworkService(PageableObjectMixin, CloudService):
  378. """
  379. Base interface for a Network Service.
  380. """
  381. __metaclass__ = ABCMeta
  382. @abstractmethod
  383. def get(self, network_id):
  384. """
  385. Returns a Network given its ID or ``None`` if not found.
  386. :type network_id: ``str``
  387. :param network_id: The ID of the network to retrieve.
  388. :rtype: ``object`` of :class:`.Network`
  389. :return: a Network object
  390. """
  391. pass
  392. @abstractmethod
  393. def list(self, limit=None, marker=None):
  394. """
  395. List all networks.
  396. :rtype: ``list`` of :class:`.Network`
  397. :return: list of Network objects
  398. """
  399. pass
  400. @abstractmethod
  401. def create(self, name=None):
  402. """
  403. Create a new network.
  404. :type name: ``str``
  405. :param name: An optional network name. The name will be set if the
  406. provider supports it.
  407. :rtype: ``object`` of :class:`.Network`
  408. :return: A Network object
  409. """
  410. pass
  411. @abstractmethod
  412. def delete(self, network_id):
  413. """
  414. Delete an existing Network.
  415. :type network_id: ``str``
  416. :param network_id: The ID of the network to be deleted.
  417. :rtype: ``bool``
  418. :return: ``True`` if the network does not exist, ``False`` otherwise.
  419. Note that this implies that the network may not have been
  420. deleted by this method but instead has not existed at all.
  421. """
  422. pass
  423. @abstractproperty
  424. def subnets(self):
  425. """
  426. Provides access to subnets.
  427. Example:
  428. .. code-block:: python
  429. # Print all subnets
  430. for s in provider.network.subnets:
  431. print(s.id, s.name)
  432. # Get subnet by ID
  433. s = provider.network.subnets.get('subnet-id')
  434. print(s.id, s.name)
  435. :rtype: :class:`.SubnetService`
  436. :return: a SubnetService object
  437. """
  438. pass
  439. @abstractmethod
  440. def floating_ips(self, network_id=None):
  441. """
  442. List floating (i.e., static) IP addresses.
  443. :type network_id: ``str``
  444. :param network_id: The ID of the network by which to filter the IPs.
  445. :rtype: ``list`` of :class:`FloatingIP`
  446. :return: list of floating IP objects
  447. """
  448. pass
  449. @abstractmethod
  450. def create_floating_ip(self):
  451. """
  452. Allocate a new floating (i.e., static) IP address.
  453. :type network_id: ``str``
  454. :param network_id: The ID of the network with which to associate the
  455. new IP address.
  456. :rtype: :class:`FloatingIP`
  457. :return: floating IP object
  458. """
  459. pass
  460. @abstractmethod
  461. def routers(self):
  462. """
  463. Get a list of available routers.
  464. :rtype: ``list`` of :class: `Router`
  465. :return: list of routers
  466. """
  467. pass
  468. @abstractmethod
  469. def create_router(self, name=None):
  470. """
  471. Create a new router/gateway.
  472. :type name: ``str``
  473. :param name: An optional router name. The name will be set if the
  474. provider supports it.
  475. :rtype: :class:`Router`
  476. :return: a newly created router object
  477. """
  478. pass
  479. class SubnetService(PageableObjectMixin, CloudService):
  480. """
  481. Base interface for a Subnet Service.
  482. """
  483. __metaclass__ = ABCMeta
  484. @abstractmethod
  485. def get(self, subnet_id):
  486. """
  487. Returns a Subnet given its ID or ``None`` if not found.
  488. :type network_id: :class:`.Network` object or ``str``
  489. :param network_id: The ID of the subnet to retrieve.
  490. :rtype: ``object`` of :class:`.Subnet`
  491. return: a Subnet object
  492. """
  493. pass
  494. @abstractmethod
  495. def list(self, network=None, limit=None, marker=None):
  496. """
  497. List all subnets or filter them by the supplied network ID.
  498. :type network: ``str``
  499. :param network: Network object or ID with which to filter the subnets.
  500. :rtype: ``list`` of :class:`.Subnet`
  501. :return: list of Subnet objects
  502. """
  503. pass
  504. @abstractmethod
  505. def create(self, network_id, cidr_block, name=None):
  506. """
  507. Create a new subnet within the supplied network.
  508. :type network: :class:`.Network` object or ``str``
  509. :param network: Network object or ID under which to create the subnet.
  510. :type cidr_block: ``str``
  511. :param cidr_block: CIDR block within the Network to assign to the
  512. subnet.
  513. :type name: ``str``
  514. :param name: An optional subnet name. The name will be set if the
  515. provider supports it.
  516. :rtype: ``object`` of :class:`.Subnet`
  517. :return: A Subnet object
  518. """
  519. pass
  520. @abstractmethod
  521. def delete(self, subnet):
  522. """
  523. Delete an existing Subnet.
  524. :type subnet: :class:`.Subnet` object or ``str``
  525. :param subnet: Subnet object or ID of the subnet to delete.
  526. :rtype: ``bool``
  527. :return: ``True`` if the subnet does not exist, ``False`` otherwise.
  528. Note that this implies that the subnet may not have been
  529. deleted by this method but instead has not existed at all.
  530. """
  531. pass
  532. class ObjectStoreService(PageableObjectMixin, CloudService):
  533. """
  534. The Object Storage Service interface provides access to the underlying
  535. object store capabilities of this provider. This service is optional and
  536. the :func:`CloudProvider.has_service()` method should be used to verify its
  537. availability before using the service.
  538. """
  539. __metaclass__ = ABCMeta
  540. @abstractmethod
  541. def get(self, bucket_id):
  542. """
  543. Returns a bucket given its ID. Returns ``None`` if the bucket
  544. does not exist. On some providers, such as AWS and OpenStack,
  545. the bucket id is the same as its name.
  546. Example:
  547. .. code-block:: python
  548. bucket = provider.object_store.get('my_bucket_id')
  549. print(bucket.id, bucket.name)
  550. :rtype: :class:`.Bucket`
  551. :return: a Bucket instance
  552. """
  553. pass
  554. @abstractmethod
  555. def find(self, name):
  556. """
  557. Searches for a bucket by a given list of attributes.
  558. Example:
  559. .. code-block:: python
  560. buckets = provider.object_store.find(name='my_bucket_name')
  561. for bucket in buckets:
  562. print(bucket.id, bucket.name)
  563. :rtype: :class:`.Bucket`
  564. :return: a Bucket instance
  565. """
  566. pass
  567. @abstractmethod
  568. def list(self, limit=None, marker=None):
  569. """
  570. List all buckets.
  571. Example:
  572. .. code-block:: python
  573. buckets = provider.object_store.find(name='my_bucket_name')
  574. for bucket in buckets:
  575. print(bucket.id, bucket.name)
  576. :rtype: :class:`.Bucket`
  577. :return: list of bucket objects
  578. """
  579. pass
  580. @abstractmethod
  581. def create(self, name, location=None):
  582. """
  583. Create a new bucket.
  584. If a bucket with the specified name already exists, return a reference
  585. to that bucket.
  586. Example:
  587. .. code-block:: python
  588. bucket = provider.object_store.create('my_bucket_name')
  589. print(bucket.name)
  590. :type name: str
  591. :param name: The name of this bucket.
  592. :type location: ``object`` of :class:`.Region`
  593. :param location: The region in which to place this bucket.
  594. :return: a Bucket object
  595. :rtype: ``object`` of :class:`.Bucket`
  596. """
  597. pass
  598. class SecurityService(CloudService):
  599. """
  600. The security service interface can be used to access security related
  601. functions in the provider, such as firewall control and keypairs.
  602. """
  603. __metaclass__ = ABCMeta
  604. @abstractproperty
  605. def key_pairs(self):
  606. """
  607. Provides access to key pairs for this provider.
  608. Example:
  609. .. code-block:: python
  610. # print all keypairs
  611. for kp in provider.security.keypairs:
  612. print(kp.id, kp.name)
  613. # find keypair by name
  614. kp = provider.security.keypairs.find(name='my_key_pair')[0]
  615. print(kp.id, kp.name)
  616. :rtype: :class:`.KeyPairService`
  617. :return: a KeyPairService object
  618. """
  619. pass
  620. @abstractproperty
  621. def security_groups(self):
  622. """
  623. Provides access to security groups for this provider.
  624. Example:
  625. .. code-block:: python
  626. # print all security groups
  627. for sg in provider.security.security_groups:
  628. print(sg.id, sg.name)
  629. # find security group by name
  630. sg = provider.security.security_groups.find(name='my_sg')[0]
  631. print(sg.id, sg.name)
  632. :rtype: :class:`.SecurityGroupService`
  633. :return: a SecurityGroupService object
  634. """
  635. pass
  636. class KeyPairService(PageableObjectMixin, CloudService):
  637. """
  638. Base interface for key pairs.
  639. """
  640. __metaclass__ = ABCMeta
  641. @abstractmethod
  642. def get(self, key_pair_id):
  643. """
  644. Return a KeyPair given its ID or ``None`` if not found.
  645. On some providers, such as AWS and OpenStack, the KeyPair ID is
  646. the same as its name.
  647. Example:
  648. .. code-block:: python
  649. key_pair = provider.security.keypairs.get('my_key_pair_id')
  650. print(key_pair.id, key_pair.name)
  651. :rtype: :class:`.KeyPair`
  652. :return: a KeyPair instance
  653. """
  654. pass
  655. @abstractmethod
  656. def list(self, limit=None, marker=None):
  657. """
  658. List all key pairs associated with this account.
  659. :rtype: ``list`` of :class:`.KeyPair`
  660. :return: list of KeyPair objects
  661. """
  662. pass
  663. @abstractmethod
  664. def find(self, name, limit=None, marker=None):
  665. """
  666. Searches for a key pair by a given list of attributes.
  667. :rtype: ``object`` of :class:`.KeyPair`
  668. :return: a KeyPair object
  669. """
  670. pass
  671. @abstractmethod
  672. def create(self, name):
  673. """
  674. Create a new key pair or raise an exception if one already exists.
  675. :type name: str
  676. :param name: The name of the key pair to be created.
  677. :rtype: ``object`` of :class:`.KeyPair`
  678. :return: A keypair instance or ``None``.
  679. """
  680. pass
  681. @abstractmethod
  682. def delete(self, key_pair_id):
  683. """
  684. Delete an existing SecurityGroup.
  685. :type key_pair_id: str
  686. :param key_pair_id: The id of the key pair to be deleted.
  687. :rtype: ``bool``
  688. :return: ``True`` if the key does not exist, ``False`` otherwise. Note
  689. that this implies that the key may not have been deleted by
  690. this method but instead has not existed at all.
  691. """
  692. pass
  693. class SecurityGroupService(PageableObjectMixin, CloudService):
  694. """
  695. Base interface for security groups.
  696. """
  697. __metaclass__ = ABCMeta
  698. @abstractmethod
  699. def get(self, security_group_id):
  700. """
  701. Returns a SecurityGroup given its ID. Returns ``None`` if the
  702. SecurityGroup does not exist.
  703. Example:
  704. .. code-block:: python
  705. sg = provider.security.security_groups.get('my_sg_id')
  706. print(sg.id, sg.name)
  707. :rtype: :class:`.SecurityGroup`
  708. :return: a SecurityGroup instance
  709. """
  710. pass
  711. @abstractmethod
  712. def list(self, limit=None, marker=None):
  713. """
  714. List all security groups associated with this account.
  715. :rtype: ``list`` of :class:`.SecurityGroup`
  716. :return: list of SecurityGroup objects
  717. """
  718. pass
  719. @abstractmethod
  720. def create(self, name, description, network_id):
  721. """
  722. Create a new SecurityGroup.
  723. :type name: str
  724. :param name: The name of the new security group.
  725. :type description: str
  726. :param description: The description of the new security group.
  727. :type network_id: ``str``
  728. :param network_id: Network ID under which to create the security group.
  729. :rtype: ``object`` of :class:`.SecurityGroup`
  730. :return: A SecurityGroup instance or ``None`` if one was not created.
  731. """
  732. pass
  733. @abstractmethod
  734. def find(self, name, limit=None, marker=None):
  735. """
  736. Get all security groups associated with your account.
  737. :type name: str
  738. :param name: The name of the security group to retrieve.
  739. :rtype: list of :class:`SecurityGroup`
  740. :return: A list of SecurityGroup objects or an empty list if none
  741. found.
  742. """
  743. pass
  744. @abstractmethod
  745. def delete(self, group_id):
  746. """
  747. Delete an existing SecurityGroup.
  748. :type group_id: str
  749. :param group_id: The security group ID to be deleted.
  750. :rtype: ``bool``
  751. :return: ``True`` if the security group does not exist, ``False``
  752. otherwise. Note that this implies that the group may not have
  753. been deleted by this method but instead has not existed in
  754. the first place.
  755. """
  756. pass
  757. class InstanceTypesService(PageableObjectMixin, CloudService):
  758. __metaclass__ = ABCMeta
  759. @abstractmethod
  760. def get(self, instance_type_id):
  761. """
  762. Returns an InstanceType given its ID. Returns ``None`` if the
  763. InstanceType does not exist.
  764. Example:
  765. .. code-block:: python
  766. itype = provider.compute.instance_types.get('my_itype_id')
  767. print(itype.id, itype.name)
  768. :rtype: :class:`.InstanceType`
  769. :return: an InstanceType instance
  770. """
  771. pass
  772. @abstractmethod
  773. def list(self, limit=None, marker=None):
  774. """
  775. List all instance types.
  776. :rtype: ``list`` of :class:`.InstanceType`
  777. :return: list of InstanceType objects
  778. """
  779. pass
  780. @abstractmethod
  781. def find(self, **kwargs):
  782. """
  783. Searches for instances by a given list of attributes.
  784. :rtype: ``list`` of :class:`.InstanceType`
  785. :return: list of InstanceType objects
  786. """
  787. pass
  788. class RegionService(PageableObjectMixin, CloudService):
  789. """
  790. Base interface for a Region service
  791. """
  792. __metaclass__ = ABCMeta
  793. @abstractproperty
  794. def current(self):
  795. """
  796. Returns the current region that this provider is connected to.
  797. If the current region cannot be discovered, return ``None``.
  798. :rtype: ``object`` of :class:`.Region`
  799. :return: a Region instance or ``None``
  800. """
  801. pass
  802. @abstractmethod
  803. def get(self, region_id):
  804. """
  805. Returns a region given its id. Returns None if the region
  806. does not exist.
  807. :rtype: ``object`` of :class:`.Region`
  808. :return: a Region instance
  809. """
  810. pass
  811. @abstractmethod
  812. def list(self, limit=None, marker=None):
  813. """
  814. List all regions.
  815. :rtype: ``list`` of :class:`.Region`
  816. :return: list of region objects
  817. """
  818. pass