interfaces.py 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945
  1. class CloudProviderServiceType(object):
  2. """
  3. Defines possible service types that are offered by providers.
  4. Providers can implement the ``has_service`` method and clients can check
  5. for the availability of a service with::
  6. if (provider.has_service(CloudProviderServiceTypes.OBJECTSTORE))
  7. ...
  8. """
  9. COMPUTE = 'compute'
  10. IMAGE = 'image'
  11. SECURITY = 'security'
  12. VOLUME = 'volume'
  13. BLOCKSTORE = 'block_store'
  14. OBJECTSTORE = 'object_store'
  15. class CloudProvider(object):
  16. """
  17. Base interface for a cloud provider
  18. """
  19. def __init__(self, config):
  20. """
  21. Create a new provider implementation given a dictionary of configuration
  22. attributes.
  23. :type config: an object with required fields
  24. :param config: This can be a Bunch or any other object whose fields can
  25. be accessed using dot notation. See specific provider
  26. implementation for the required fields.
  27. :rtype: ``object`` of :class:`.CloudProvider`
  28. :return: a concrete provider instance
  29. """
  30. raise NotImplementedError(
  31. '__init__ not implemented by this provider')
  32. def config(self):
  33. """
  34. Returns the config object associated with this provider.
  35. :rtype: ``object``
  36. :return: The config object used to initialize this provider
  37. """
  38. raise NotImplementedError(
  39. 'CloudProvider.config not implemented by this provider')
  40. def has_service(self, service_type):
  41. """
  42. Checks whether this provider supports a given service.
  43. :type service_type: str or :class:``.CloudProviderServiceType``
  44. :param service_type: Type of service the check support for.
  45. :rtype: bool
  46. :return: ``True`` if the service type is supported.
  47. """
  48. raise NotImplementedError(
  49. 'CloudProvider.has_service not implemented by this provider')
  50. def account(self):
  51. """
  52. Provides access to all user account related services in this provider.
  53. This includes listing available tenancies.
  54. :rtype: ``object`` of :class:`.ComputeService`
  55. :return: a ComputeService object
  56. """
  57. raise NotImplementedError(
  58. 'CloudProvider.Compute not implemented by this provider')
  59. def compute(self):
  60. """
  61. Provides access to all compute related services in this provider.
  62. :rtype: ``object`` of :class:`.ComputeService`
  63. :return: a ComputeService object
  64. """
  65. raise NotImplementedError(
  66. 'CloudProvider.compute not implemented by this provider')
  67. def image(self):
  68. """
  69. Provides access to all Image related services in this provider.
  70. (e.g. Glance in Openstack)
  71. :rtype: ``object`` of :class:`.ImageService`
  72. :return: an ImageService object
  73. """
  74. raise NotImplementedError(
  75. 'CloudProvider.image not implemented by this provider')
  76. def security(self):
  77. """
  78. Provides access to keypair management and firewall control
  79. :rtype: ``object`` of :class:`.SecurityService`
  80. :return: a SecurityService object
  81. """
  82. raise NotImplementedError(
  83. 'CloudProvider.security not implemented by this provider')
  84. def volume(self):
  85. """
  86. Provides access to the volume/elastic block store services in this
  87. provider.
  88. :rtype: ``object`` of :class:`.VolumeService`
  89. :return: a VolumeService object
  90. """
  91. raise NotImplementedError(
  92. 'CloudProvider.volume not implemented by this provider')
  93. def object_store(self):
  94. """
  95. Provides access to object storage services in this provider.
  96. :rtype: ``object`` of :class:`.ObjectStoreService`
  97. :return: an ObjectStoreService object
  98. """
  99. raise NotImplementedError(
  100. 'CloudProvider.object_store not implemented by this provider')
  101. class ProviderService(object):
  102. """
  103. Base interface for any service supported by a provider
  104. """
  105. def provider(self):
  106. """
  107. Returns the provider instance associated with this service.
  108. :rtype: ``object`` of :class:`.CloudProvider`
  109. :return: a Provider object
  110. """
  111. raise NotImplementedError(
  112. 'ComputeService.Provider not implemented by this provider')
  113. class ComputeService(ProviderService):
  114. """
  115. Base interface for compute service supported by a provider
  116. """
  117. def get_instance(self, id):
  118. """
  119. Returns an instance given its id.
  120. :rtype: ``object`` of :class:`.Instance`
  121. :return: an Instance object
  122. """
  123. raise NotImplementedError(
  124. 'get_instance not implemented by this provider')
  125. def find_instance(self, name):
  126. """
  127. Searches for an instance by a given list of attributes.
  128. :rtype: ``object`` of :class:`.Instance`
  129. :return: an Instance object
  130. """
  131. raise NotImplementedError(
  132. 'find_instance not implemented by this provider')
  133. def list_instances(self):
  134. """
  135. List all instances.
  136. :rtype: ``list`` of :class:`.Instance`
  137. :return: list of Instance objects
  138. """
  139. raise NotImplementedError(
  140. 'list_instances not implemented by this provider')
  141. def instance_types(self):
  142. """
  143. Provides access to all Instance type related services in this provider.
  144. :rtype: ``object`` of :class:`.InstanceTypeService`
  145. :return: an InstanceTypeService object
  146. """
  147. raise NotImplementedError(
  148. 'instance_types not implemented by this provider')
  149. def list_regions(self):
  150. """
  151. List all data center regions for this provider.
  152. :rtype: ``list`` of :class:`.Region`
  153. :return: list of Region objects
  154. """
  155. raise NotImplementedError(
  156. 'list_regions not implemented by this provider')
  157. def create_instance(self, name, image, instance_type, zone=None, keypair=None, security_groups=None,
  158. user_data=None, block_device_mapping=None, network_interfaces=None, **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 with
  165. :type instance_type: ``InstanceType`` or ``str``
  166. :param instance_type: The InstanceType or name, specifying the size of
  167. the instance to boot into
  168. :type zone: ``Zone`` or ``str``
  169. :param zone: The Zone or its name, where the instance should be placed.
  170. :type keypair: ``KeyPair`` or ``str``
  171. :param keypair: The KeyPair object or its name, to set for the instance.
  172. :type security_groups: A ``list`` of ``SecurityGroup`` objects or a
  173. list of ``str`` names
  174. :param security_groups: A list of ``SecurityGroup`` objects or a list
  175. of ``SecurityGroup`` names, which should be
  176. assigned to this instance.
  177. :type user_data: ``str``
  178. :param user_data: An extra userdata object which is compatible with
  179. the provider.
  180. :type block_device_mapping: ``BlockDeviceMapping`` object
  181. :param block_device_mapping: A ``BlockDeviceMapping`` object which
  182. describes additional block device mappings
  183. for this instance.
  184. :type network_interfaces: ``NetworkInterfaceList`` object
  185. :param network_interfaces: A ``NetworkInterfaceList`` object which
  186. describes network interfaces for this
  187. instance.
  188. :rtype: `object`` of :class:`.Instance`
  189. :return: an instance of Instance class
  190. """
  191. raise NotImplementedError(
  192. 'create_instance not implemented by this provider')
  193. class VolumeService(ProviderService):
  194. """
  195. Base interface for a Volume Service
  196. """
  197. def get_volume(self, id):
  198. """
  199. Returns a volume given its id.
  200. :rtype: ``object`` of :class:`.Volume`
  201. :return: a Volume object
  202. """
  203. raise NotImplementedError(
  204. 'get_volume not implemented by this provider')
  205. def find_volume(self, name):
  206. """
  207. Searches for a volume by a given list of attributes.
  208. :rtype: ``object`` of :class:`.Instance`
  209. :return: an Instance object or ``None`` if not found
  210. """
  211. raise NotImplementedError(
  212. 'find_volume not implemented by this provider')
  213. def list_volumes(self):
  214. """
  215. List all volumes.
  216. :rtype: ``list`` of :class:`.Volume`
  217. :return: a list of Volume objects
  218. """
  219. raise NotImplementedError(
  220. 'list_volumes not implemented by this provider')
  221. def list_volume_snapshots(self):
  222. """
  223. List all volume snapshots.
  224. :rtype: ``list`` of :class:`.Snapshot`
  225. :return: a list of Snapshot objects
  226. """
  227. raise NotImplementedError(
  228. 'list_volume_snapshots not implemented by this provider')
  229. def create_volume(self):
  230. """
  231. Creates a new volume.
  232. :rtype: ``list`` of :class:`.Volume`
  233. :return: a newly created Volume object
  234. """
  235. raise NotImplementedError(
  236. 'create_volume not implemented by this provider')
  237. class ImageService(ProviderService):
  238. """
  239. Base interface for an Image Service
  240. """
  241. def get_image(self, id):
  242. """
  243. Returns an Image given its id
  244. :rtype: ``object`` of :class:`.Image`
  245. :return: an Image instance
  246. """
  247. raise NotImplementedError(
  248. 'get_image implemented by this provider')
  249. def find_image(self, name):
  250. """
  251. Searches for an image by a given list of attributes
  252. :rtype: ``object`` of :class:`.Image`
  253. :return: an Image instance
  254. """
  255. raise NotImplementedError(
  256. 'find_image not implemented by this provider')
  257. def list_images(self):
  258. """
  259. List all images.
  260. :rtype: ``list`` of :class:`.Image`
  261. :return: list of image objects
  262. """
  263. raise NotImplementedError(
  264. 'list_images not implemented by this provider')
  265. def create_image(self):
  266. """
  267. Create a new image.
  268. :return: an Image object
  269. :rtype: ``object`` of :class:`.Image`
  270. """
  271. raise NotImplementedError(
  272. 'create_image not implemented by this provider')
  273. class ObjectStoreService(ProviderService):
  274. """
  275. Base interface for an Object Storage Service
  276. """
  277. def get_container(self, id):
  278. """
  279. Returns a container given its id
  280. :rtype: ``object`` of :class:`.Container`
  281. :return: a Container instance
  282. """
  283. raise NotImplementedError(
  284. 'get_container implemented by this provider')
  285. def find_container(self, name):
  286. """
  287. Searches for a container by a given list of attributes
  288. :rtype: ``object`` of :class:`.Container`
  289. :return: a Container instance
  290. """
  291. raise NotImplementedError(
  292. 'find_container not implemented by this provider')
  293. def list_containers(self):
  294. """
  295. List all containers.
  296. :rtype: ``list`` of :class:`.Container`
  297. :return: list of container objects
  298. """
  299. raise NotImplementedError(
  300. 'list_containers not implemented by this provider')
  301. def create_container(self):
  302. """
  303. Create a new container.
  304. :return: a Container object
  305. :rtype: ``object`` of :class:`.Container`
  306. """
  307. raise NotImplementedError(
  308. 'create_container not implemented by this provider')
  309. class SecurityService(ProviderService):
  310. """
  311. Base interface for an Image Service
  312. """
  313. def list_key_pairs(self):
  314. """
  315. List all key pairs associated with this account.
  316. :rtype: ``list`` of :class:`.KeyPair`
  317. :return: list of KeyPair objects
  318. """
  319. raise NotImplementedError(
  320. 'list_key_pairs not implemented by this provider')
  321. def create_key_pair(self):
  322. """
  323. Create a new keypair.
  324. :rtype: ``object`` of :class:`.KeyPair`
  325. :return: A keypair instance
  326. """
  327. raise NotImplementedError(
  328. 'create_key_pair not implemented by this provider')
  329. def list_security_groups(self):
  330. """
  331. Create a new SecurityGroup.
  332. :rtype: ``object`` of :class:`.SecurityGroup`
  333. :return: A SecurityGroup instance
  334. """
  335. raise NotImplementedError(
  336. 'list_security_groups not implemented by this provider')
  337. def create_security_group(self):
  338. """
  339. Create a new SecurityGroup.
  340. :rtype: ``object`` of :class:`.KeyPair`
  341. :return: A keypair instance
  342. """
  343. raise NotImplementedError(
  344. 'create_security_group not implemented by this provider')
  345. def delete_security_group(self):
  346. """
  347. Delete an existing SecurityGroup.
  348. :rtype: ``bool``
  349. :return: True if successful, false otherwise
  350. """
  351. raise NotImplementedError(
  352. 'delete_security_group not implemented by this provider')
  353. class Instance(object):
  354. def instance_id(self):
  355. """
  356. Get the instance identifier.
  357. :rtype: str
  358. :return: ID for this instance as returned by the cloud middleware.
  359. """
  360. raise NotImplementedError(
  361. 'instance_id not implemented by this provider')
  362. def name(self):
  363. """
  364. Get the instance name.
  365. :rtype: str
  366. :return: Name for this instance as returned by the cloud middleware.
  367. """
  368. raise NotImplementedError(
  369. 'name not implemented by this provider')
  370. def public_ips(self):
  371. """
  372. Get all the public IP addresses for this instance.
  373. :rtype: list
  374. :return: A list of public IP addresses associated with this instance.
  375. """
  376. raise NotImplementedError(
  377. 'public_ips not implemented by this provider')
  378. def private_ips(self):
  379. """
  380. Get all the private IP addresses for this instance.
  381. :rtype: list
  382. :return: A list of private IP addresses associated with this instance.
  383. """
  384. raise NotImplementedError(
  385. 'private_ips not implemented by this provider')
  386. def instance_type(self):
  387. """
  388. Get the instance type.
  389. :rtype: str
  390. :return: API type of this instance (e.g., ``m1.large``)
  391. """
  392. raise NotImplementedError(
  393. 'type not implemented by this provider')
  394. def reboot(self):
  395. """
  396. Reboot this instance (using the cloud middleware API).
  397. :rtype: bool
  398. :return: ``True`` if the reboot was succesful; ``False`` otherwise.
  399. """
  400. raise NotImplementedError(
  401. 'reboot not implemented by this provider')
  402. def terminate(self):
  403. """
  404. Permanently terminate this instance.
  405. :rtype: bool
  406. :return: ``True`` if the termination of the instance was succesfully
  407. initiated; ``False`` otherwise.
  408. """
  409. raise NotImplementedError(
  410. 'terminate not implemented by this provider')
  411. def image_id(self):
  412. """
  413. Get the image ID for this insance.
  414. :rtype: str
  415. :return: Image ID (i.e., AMI) this instance is using.
  416. """
  417. raise NotImplementedError(
  418. 'image_id not implemented by this provider')
  419. def placement_zone(self):
  420. """
  421. Get the placement zone where this instance is running.
  422. :rtype: str
  423. :return: Region/zone/placement where this instance is running.
  424. """
  425. raise NotImplementedError(
  426. 'placement not implemented by this provider')
  427. def mac_address(self):
  428. """
  429. Get the MAC address for this instance.
  430. :rtype: str
  431. :return: MAC address for ths instance.
  432. """
  433. raise NotImplementedError(
  434. 'mac_address not implemented by this provider')
  435. def security_group_ids(self):
  436. """
  437. Get the security group IDs associated with this instance.
  438. :rtype: list
  439. :return: A list of security group IDs associated with this instance.
  440. """
  441. raise NotImplementedError(
  442. 'security_group_ids not implemented by this provider')
  443. def key_pair_name(self):
  444. """
  445. Get the name of the key pair associated with this instance.
  446. :rtype: str
  447. :return: Name of the ssh key pair associated with this instance.
  448. """
  449. raise NotImplementedError(
  450. 'key_pair_name not implemented by this provider')
  451. class MachineImage(object):
  452. def image_id(self):
  453. """
  454. Get the image identifier.
  455. :rtype: ``str``
  456. :return: ID for this instance as returned by the cloud middleware.
  457. """
  458. raise NotImplementedError(
  459. 'MachineImage.image_id not implemented by this provider')
  460. def name(self):
  461. """
  462. Get the image name.
  463. :rtype: ``str``
  464. :return: Name for this image as returned by the cloud middleware.
  465. """
  466. raise NotImplementedError(
  467. 'MachineImage.name not implemented by this provider')
  468. def description(self):
  469. """
  470. Get the image description.
  471. :rtype: ``str``
  472. :return: Description for this image as returned by the cloud middleware
  473. """
  474. raise NotImplementedError(
  475. 'MachineImage.description not implemented by this provider')
  476. class Volume(object):
  477. def attach(self, instance_id, device):
  478. """
  479. Attach this volume to an instance.
  480. :type instance_id: str
  481. :param instance_id: The ID of the instance to which it will
  482. be attached.
  483. :type device: str
  484. :param device: The device on the instance through which the
  485. volume will be exposed (e.g. /dev/sdh)
  486. :rtype: bool
  487. :return: True if successful
  488. """
  489. raise NotImplementedError(
  490. 'attach not implemented by this provider')
  491. def detach(self, force=False):
  492. """
  493. Detach this volume from an instance.
  494. :type force: bool
  495. :param force: Forces detachment if the previous detachment
  496. attempt did not occur cleanly. This option is supported on select
  497. clouds only. This option can lead to data loss or a corrupted file
  498. system. Use this option only as a last resort to detach a volume
  499. from a failed instance. The instance will not have an opportunity
  500. to flush file system caches nor file system meta data. If you
  501. use this option, you must perform file system check and
  502. repair procedures.
  503. :rtype: bool
  504. :return: True if successful
  505. """
  506. raise NotImplementedError(
  507. 'detach not implemented by this provider')
  508. def snapshot(self, description=None):
  509. """
  510. Create a snapshot of this Volume.
  511. :type description: str
  512. :param description: A description of the snapshot.
  513. Limited to 256 characters.
  514. :rtype: :class:`.Snapshot`
  515. :return: The created Snapshot object
  516. """
  517. raise NotImplementedError(
  518. 'snapshot not implemented by this provider')
  519. def delete(self):
  520. """
  521. Delete this volume.
  522. :rtype: bool
  523. :return: True if successful
  524. """
  525. raise NotImplementedError(
  526. 'delete not implemented by this provider')
  527. class Snapshot(object):
  528. def create_volume(self, placement, size=None, volume_type=None, iops=None):
  529. """
  530. Create a new Volume from this Snapshot.
  531. :type zone: str
  532. :param zone: The availability zone in which the Volume will be created.
  533. :type size: int
  534. :param size: The size of the new volume, in GiB (optional). Defaults to
  535. the size of the snapshot.
  536. :type volume_type: str
  537. :param volume_type: The type of the volume (optional). Availability and
  538. valid values depend on the provider.
  539. :type iops: int
  540. :param iops: The provisioned IOPs you want to associate with
  541. this volume (optional). Availability depends on the
  542. provider.
  543. :rtype: :class:`.Volume`
  544. :return: An instance of the created Volume
  545. """
  546. raise NotImplementedError(
  547. 'create_volume not implemented by this provider')
  548. def share(self, user_ids=None):
  549. """
  550. Share this Snapshot.
  551. :type user_ids: list of strings
  552. :param user_ids: A list of cloud provider compatible user IDs. If no
  553. IDs are specified, the snapshot is made public.
  554. :rtype: bool
  555. :return: True if successful
  556. """
  557. raise NotImplementedError('share not implemented by this provider')
  558. def unshare(self, user_ids=None):
  559. """
  560. Unshare this Snapshot.
  561. :type user_ids: list of strings
  562. :param user_ids: A list of cloud provider compatible user IDs. If no
  563. IDs are specified, the snapshot is made private.
  564. :rtype: bool
  565. :return: True if successful
  566. """
  567. raise NotImplementedError('unshare not implemented by this provider')
  568. def delete(self):
  569. """
  570. Delete this snapshot.
  571. :rtype: bool
  572. :return: True if successful
  573. """
  574. raise NotImplementedError('delete not implemented by this provider')
  575. class KeyPair(object):
  576. def name(self):
  577. """
  578. Return the name of this key pair.
  579. :rtype: str
  580. :return: A name of this ssh key pair
  581. """
  582. raise NotImplementedError(
  583. 'name not implemented by this provider')
  584. def material(self):
  585. """
  586. Unencrypted private key.
  587. :rtype: str
  588. :return: Unencrypted private key.
  589. """
  590. raise NotImplementedError(
  591. 'material not implemented by this provider')
  592. class Region(object):
  593. """
  594. Represents a cloud region, typically a separate geographic area and will
  595. contain at least one placement zone.
  596. """
  597. def name(self):
  598. """
  599. Name of the region.
  600. :rtype: str
  601. :return: Name of the region.
  602. """
  603. raise NotImplementedError(
  604. 'name not implemented by this provider')
  605. def list_zones(self):
  606. """
  607. List all available placement zones within this region.
  608. :rtype: list
  609. :return: List of all the available placement zones.
  610. """
  611. raise NotImplementedError(
  612. 'list_zones not implemented by this provider')
  613. class PlacementZone(object):
  614. """
  615. Represents a placement zone. A placement zone is contained within a Region.
  616. """
  617. def name(self):
  618. """
  619. Name of the placement zone.
  620. :rtype: str
  621. :return: Name of the placement zone.
  622. """
  623. raise NotImplementedError(
  624. 'PlacementZone.name not implemented by this provider')
  625. def region_name(self):
  626. """
  627. A region this placement zone is associated with.
  628. :rtype: str
  629. :return: The name of the region the zone is associated with.
  630. """
  631. raise NotImplementedError(
  632. 'region_name not implemented by this provider')
  633. class InstanceTypesService(object):
  634. def list(self):
  635. """
  636. List all instance types.
  637. :rtype: ``list`` of :class:`.InstanceType`
  638. :return: list of InstanceType objects
  639. """
  640. raise NotImplementedError(
  641. 'InstanceTypesService.list not implemented by this provider')
  642. def find_by_name(self, name):
  643. """
  644. Searches for an instance by a given list of attributes.
  645. :rtype: ``object`` of :class:`.InstanceType`
  646. :return: an Instance object
  647. """
  648. raise NotImplementedError(
  649. 'InstanceTypesService.find_instance not implemented by this provider')
  650. class InstanceType(object):
  651. """
  652. An instance type object.
  653. """
  654. def id(self):
  655. raise NotImplementedError(
  656. 'InstanceType.id not implemented by this provider')
  657. def name(self):
  658. raise NotImplementedError(
  659. 'InstanceType.name not implemented by this provider')
  660. class SecurityGroup(object):
  661. def name(self):
  662. """
  663. Return the name of this security group.
  664. :rtype: str
  665. :return: A name of this security group.
  666. """
  667. raise NotImplementedError(
  668. 'name not implemented by this provider')
  669. def create(self, name, description):
  670. """
  671. Create a new security group under the current account.
  672. :type name: str
  673. :param name: The name of the new security group.
  674. :type description: str
  675. :param description: The description of the new security group.
  676. :rtype: ``object`` of :class:`.SecurityGroup`
  677. :return: a SecurityGroup object
  678. """
  679. raise NotImplementedError(
  680. 'create not implemented by this provider')
  681. def delete(self):
  682. """
  683. Delete this security group.
  684. """
  685. raise NotImplementedError(
  686. 'delete not implemented by this provider')
  687. def add_rule(self, ip_protocol=None, from_port=None, to_port=None,
  688. cidr_ip=None, group_id=None):
  689. """
  690. Create a security group rule
  691. :type ip_protocol: str
  692. :param ip_protocol: Either ``tcp`` | ``udp`` | ``icmp``
  693. :type from_port: int
  694. :param from_port: The beginning port number you are enabling
  695. :type to_port: int
  696. :param to_port: The ending port number you are enabling
  697. :type cidr_ip: str or list of strings
  698. :param cidr_ip: The CIDR block you are providing access to.
  699. :type group_id: ``object`` of :class:`.SecurityGroup`
  700. :param group_id: The Security Group you are granting access to.
  701. :rtype: bool
  702. :return: True if successful.
  703. """
  704. raise NotImplementedError(
  705. 'add_rule not implemented by this provider')
  706. class ContainerProvider(object):
  707. """
  708. Represents a container instance, such as Docker or LXC
  709. """
  710. def create_container(self):
  711. raise NotImplementedError(
  712. 'create_container not implemented by this provider')
  713. def delete_container(self):
  714. raise NotImplementedError(
  715. 'delete_container not implemented by this provider')
  716. class DeploymentProvider(object):
  717. """
  718. Represents a deployment provider, such as Ansible or Shell script provider
  719. """
  720. def deploy(self, target):
  721. """
  722. Deploys on given target, where target is an Instance or Container
  723. """
  724. raise NotImplementedError(
  725. 'deploy not implemented by this provider')