services.py 27 KB

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