resources.py 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780
  1. """
  2. Specifications for data objects exposed through a provider or service
  3. """
  4. from abc import ABCMeta, abstractmethod, abstractproperty
  5. class CloudServiceType(object):
  6. """
  7. Defines possible service types that are offered by providers.
  8. Providers can implement the ``has_service`` method and clients can check
  9. for the availability of a service with::
  10. if (provider.has_service(CloudServiceTypes.OBJECTSTORE))
  11. ...
  12. """
  13. COMPUTE = 'compute'
  14. IMAGE = 'image'
  15. SECURITY = 'security'
  16. VOLUME = 'volume'
  17. BLOCKSTORE = 'block_store'
  18. OBJECTSTORE = 'object_store'
  19. class CloudResource(object):
  20. """
  21. Base interface for any Resource supported by a provider. This interface
  22. has an _provider property that can be used to access the provider
  23. associated with the resource, which is only intended for use by subclasses.
  24. """
  25. __metaclass__ = ABCMeta
  26. @abstractproperty
  27. def _provider(self):
  28. """
  29. Returns the provider instance associated with this resource. Intended
  30. for use by subclasses only.
  31. :rtype: :class:`.CloudProvider`
  32. :return: a CloudProvider object
  33. """
  34. pass
  35. @abstractmethod
  36. def to_json(self):
  37. """
  38. Returns a JSON representation of the CloudResource object.
  39. """
  40. pass
  41. class CloudBridgeBaseException(Exception):
  42. """
  43. Base class for all CloudBridge exceptions
  44. """
  45. pass
  46. class WaitStateException(CloudBridgeBaseException):
  47. """
  48. Marker interface for object wait exceptions.
  49. Thrown when a timeout or errors occurs waiting for an object does not reach
  50. the expected state within a specified time limit.
  51. """
  52. pass
  53. class InvalidConfigurationException(CloudBridgeBaseException):
  54. """
  55. Marker interface for invalid launch configurations.
  56. Thrown when a combination of parameters in a LaunchConfig
  57. object results in an illegal state.
  58. """
  59. pass
  60. class Configuration(dict):
  61. """
  62. Represents a cloudbridge configuration object
  63. """
  64. @abstractproperty
  65. def default_result_limit(self):
  66. """
  67. Get the default maximum number of results to return for a
  68. list method. The default limit will be applied to most list()
  69. and find() methods whenever an explicit limit is not specified.
  70. :rtype: ``int``
  71. :return: The maximum number of results to return
  72. """
  73. pass
  74. @property
  75. def default_wait_timeout(self):
  76. """
  77. Gets the default wait timeout for LifeCycleObjects. The default
  78. wait timeout is applied in wait_for() and wait_till_ready() methods
  79. if no explicit timeout is specified.
  80. :rtype: ``int``
  81. :return: The maximum length of time (in seconds) to wait for the
  82. object to change to desired state.
  83. """
  84. pass
  85. @property
  86. def default_wait_interval(self):
  87. """
  88. Gets the default wait interval for LifeCycleObjects. The default
  89. wait interval is applied in wait_for() and wait_till_ready() methods
  90. if no explicit interval is specified.
  91. :rtype: ``int``
  92. :return: How frequently to poll the object's state
  93. """
  94. pass
  95. @abstractproperty
  96. def debug_mode(self):
  97. """
  98. A flag indicating whether CloudBridge is in debug mode. Setting
  99. this to True will cause the underlying provider's debug
  100. output to be turned on.
  101. The flag can be toggled by sending in the cb_debug value via
  102. the config dictionary, or setting the CB_DEBUG environment variable.
  103. :rtype: ``bool``
  104. :return: Whether debug mode is on.
  105. """
  106. class ObjectLifeCycleMixin(object):
  107. """
  108. A mixin for an object with a defined life-cycle, such as an Instance,
  109. Volume, Image or Snapshot. An object that supports ObjectLifeCycleMixin
  110. will always have a state, defining which point in its lifecycle it is
  111. currently at.
  112. It also defines a wait_till_ready operation, which indicates that the
  113. object is in a state in its lifecycle where it is ready to be used by an
  114. end-user.
  115. A refresh operation allows the object to synchronise its state with the
  116. service provider.
  117. """
  118. __metaclass__ = ABCMeta
  119. @abstractproperty
  120. def _provider(self):
  121. """
  122. Obtain the provider associated with this object. Used internally
  123. to access the provider config and get default timeouts/intervals.
  124. :rtype: :class:``.CloudProvider``
  125. :return: The provider associated with this Resource
  126. """
  127. pass
  128. @abstractproperty
  129. def state(self):
  130. """
  131. Get the current state of this object.
  132. :rtype: ``str``
  133. :return: The current state as a string.
  134. """
  135. pass
  136. @abstractmethod
  137. def refresh(self):
  138. """
  139. Refreshs this object's state and synchronize it with the underlying
  140. service provider.
  141. """
  142. pass
  143. @abstractmethod
  144. def wait_for(self, target_states, terminal_states=None, timeout=None,
  145. interval=None):
  146. """
  147. Wait for a specified timeout for an object to reach a set of desired
  148. target states. If the object does not reach the desired state within
  149. the specified timeout, a ``WaitStateException`` will be raised.
  150. The optional terminal_states property can be used to specify an
  151. additional set of states which, should the object reach one,
  152. the object thereafter will not transition into the desired target
  153. state. Should this happen, a ``WaitStateException`` will be raised.
  154. Example:
  155. .. code-block:: python
  156. instance.wait_for(
  157. [InstanceState.TERMINATED, InstanceState.UNKNOWN],
  158. terminal_states=[InstanceState.ERROR])
  159. :type target_states: ``list`` of states
  160. :param target_states: The list of target states to wait for.
  161. :type terminal_states: ``list`` of states
  162. :param terminal_states: A list of terminal states after which the
  163. object will not transition into a target state. A WaitStateException
  164. will be raised if the object transition into a terminal state.
  165. :type timeout: int
  166. :param timeout: The maximum length of time (in seconds) to wait for the
  167. object to changed to desired state. If no timeout is
  168. specified, the global default_wait_timeout defined in
  169. the provider config will apply.
  170. :type interval: int
  171. :param interval: How frequently to poll the object's state (in
  172. seconds). If no interval is specified, the global
  173. default_wait_interval defined in the provider config
  174. will apply.
  175. :rtype: ``True``
  176. :return: Returns ``True`` if successful. A ``WaitStateException``
  177. exception may be thrown by the underlying service if the
  178. object cannot get into a ready state (e.g. if the object
  179. is in an error state).
  180. """
  181. pass
  182. @abstractmethod
  183. def wait_till_ready(self, timeout, interval):
  184. """
  185. A convenience method to wait till the current object reaches a state
  186. which is ready for use, which is any state where the end-user can
  187. successfully interact with the object.
  188. Will throw a ``WaitStateException`` if the object is not ready within
  189. the specified timeout.
  190. :type timeout: int
  191. :param timeout: The maximum length of time (in seconds) to wait for the
  192. object to become ready.
  193. :type interval: int
  194. :param interval: How frequently to poll the object's ready state (in
  195. seconds).
  196. :rtype: ``True``
  197. :return: Returns ``True`` if successful. A ``WaitStateException``
  198. exception may be thrown by the underlying service if the
  199. object cannot get into a ready state (e.g. if the object
  200. is in an error state).
  201. """
  202. pass
  203. class PageableObjectMixin(object):
  204. """
  205. A marker interface for objects which support paged iteration through
  206. a list of objects with a list(limit, marker) method.
  207. """
  208. @abstractmethod
  209. def __iter__(self):
  210. """
  211. Enables iteration through this object. Typically, an implementation
  212. will call the list(limit, marker) method to transparently page
  213. additional objects in as iteration progresses.
  214. """
  215. pass
  216. @abstractmethod
  217. def list(self, limit=None, marker=None):
  218. """
  219. Returns a list of objects up to a maximum limit.
  220. If a limit and marker are specified, the records will be fetched up to
  221. the limit starting from the marker onwards. The returned list is a list
  222. of class ResultList, which has extra properties like is_truncated,
  223. supports_total and total_records to provide extra information
  224. about record availability.
  225. If limit is not specified, the limit will default to the underlying
  226. provider's default limit. Therefore, you need to check the is_truncated
  227. property to determine whether more records are available.
  228. The total number of results can be determined through the total_results
  229. property. Not all provides will support returning the total_results
  230. property, so the supports_total property can be used to determine
  231. whether a total is supported.
  232. To iterate through all the records, it will be easier to iterate
  233. directly through the instances using __iter__ instead of calling
  234. the list method. The __iter__ method will automatically call the list
  235. method to fetch a batch of records at a time.
  236. Example:
  237. .. code-block:: python
  238. # get first page of results
  239. instlist = provider.compute.instances.list(limit=50)
  240. for instance in instlist:
  241. print("Instance Data: {0}", instance)
  242. if instlist.supports_total:
  243. print("Total results: {0}".format(instlist.total_results))
  244. else:
  245. print("Total records unknown,"
  246. "but has more data?: {0}".format(instlist.is_truncated))
  247. # Page to next set of results
  248. if (instlist.is_truncated)
  249. instlist = provider.compute.instances.list(limit=100,
  250. marker=instlist.marker)
  251. # Alternative: iterate through every available record
  252. for instance in provider.compute.instances:
  253. print(instance)
  254. """
  255. pass
  256. class ResultList(list):
  257. """
  258. This is a wrapper class around a standard Python :py:class:`list` class
  259. and provides some extra properties to aid with paging through a large
  260. number of results.
  261. Example:
  262. .. code-block:: python
  263. # get first page of results
  264. rl = provider.compute.instances.list(limit=50)
  265. for result in rl:
  266. print("Instance Data: {0}", result)
  267. if rl.supports_total:
  268. print("Total results: {0}".format(rl.total_results))
  269. else:
  270. print("Total records unknown,"
  271. "but has more data?: {0}."format(rl.is_truncated))
  272. # Page to next set of results
  273. if (rl.is_truncated)
  274. rl = provider.compute.instances.list(limit=100,
  275. marker=rl.marker)
  276. """
  277. __metaclass__ = ABCMeta
  278. @abstractproperty
  279. def marker(self):
  280. """
  281. This is an opaque identifier used to assist in paging through very long
  282. lists of objects. This marker can be provided to the list method to get
  283. the next set of results.
  284. """
  285. pass
  286. @abstractproperty
  287. def is_truncated(self):
  288. """
  289. Indicates whether this result list has more results
  290. that can be paged in.
  291. """
  292. pass
  293. @abstractproperty
  294. def supports_total(self):
  295. """
  296. Indicates whether the provider supports returning the total number of
  297. available results. The supports_total property should be checked
  298. before accessing the total_results property.
  299. """
  300. pass
  301. @abstractproperty
  302. def total_results(self):
  303. """
  304. Indicates the total number of results for a particular query. The
  305. supports_total property should be used to check whether the provider
  306. supports returning the total number of results, before accessing this
  307. property, or the behaviour is indeterminate.
  308. """
  309. pass
  310. @abstractproperty
  311. def supports_server_paging(self):
  312. """
  313. Indicates whether this ResultList supports client side paging or server
  314. side paging. If server side paging is not supported, the data property
  315. provides direct access to all available data.
  316. """
  317. pass
  318. @abstractproperty
  319. def data(self):
  320. pass
  321. class InstanceState(object):
  322. """
  323. Standard states for a node
  324. :cvar UNKNOWN: Instance state unknown.
  325. :cvar PENDING: Instance is pending
  326. :cvar CONFIGURING: Instance is being reconfigured in some way.
  327. :cvar RUNNING: Instance is running.
  328. :cvar REBOOTING: Instance is rebooting.
  329. :cvar TERMINATED: Instance is terminated. No further operations possible.
  330. :cvar STOPPED: Instance is stopped. Instance can be resumed.
  331. :cvar ERROR: Instance is in an error state. No further operations possible.
  332. """
  333. UNKNOWN = "unknown"
  334. PENDING = "pending"
  335. CONFIGURING = "configuring"
  336. RUNNING = "running"
  337. REBOOTING = "rebooting"
  338. TERMINATED = "terminated"
  339. STOPPED = "stopped"
  340. ERROR = "error"
  341. class Instance(ObjectLifeCycleMixin, CloudResource):
  342. __metaclass__ = ABCMeta
  343. @abstractproperty
  344. def id(self):
  345. """
  346. Get the instance identifier.
  347. :rtype: str
  348. :return: ID for this instance as returned by the cloud middleware.
  349. """
  350. pass
  351. @abstractproperty
  352. def name(self):
  353. """
  354. Get the instance name.
  355. :rtype: str
  356. :return: Name for this instance as returned by the cloud middleware.
  357. """
  358. pass
  359. @name.setter
  360. @abstractmethod
  361. def name(self, value):
  362. """
  363. Set the instance name.
  364. """
  365. pass
  366. @abstractproperty
  367. def public_ips(self):
  368. """
  369. Get all the public IP addresses for this instance.
  370. :rtype: list
  371. :return: A list of public IP addresses associated with this instance.
  372. """
  373. pass
  374. @abstractproperty
  375. def private_ips(self):
  376. """
  377. Get all the private IP addresses for this instance.
  378. :rtype: list
  379. :return: A list of private IP addresses associated with this instance.
  380. """
  381. pass
  382. @abstractproperty
  383. def instance_type(self):
  384. """
  385. Get the instance type.
  386. :rtype: :class:``.InstanceType``
  387. :return: API type of this instance (e.g., ``m1.large``)
  388. """
  389. pass
  390. @abstractmethod
  391. def reboot(self):
  392. """
  393. Reboot this instance (using the cloud middleware API).
  394. :rtype: bool
  395. :return: ``True`` if the reboot was succesful; ``False`` otherwise.
  396. """
  397. pass
  398. @abstractmethod
  399. def terminate(self):
  400. """
  401. Permanently terminate this instance.
  402. :rtype: bool
  403. :return: ``True`` if the termination of the instance was succesfully
  404. initiated; ``False`` otherwise.
  405. """
  406. pass
  407. @abstractproperty
  408. def image_id(self):
  409. """
  410. Get the image ID for this insance.
  411. :rtype: str
  412. :return: Image ID (i.e., AMI) this instance is using.
  413. """
  414. pass
  415. @abstractproperty
  416. def placement_zone(self):
  417. """
  418. Get the placement zone where this instance is running.
  419. :rtype: str
  420. :return: Region/zone/placement where this instance is running.
  421. """
  422. pass
  423. # @abstractproperty
  424. # def mac_address(self):
  425. # """
  426. # Get the MAC address for this instance.
  427. #
  428. # :rtype: str
  429. # :return: MAC address for ths instance.
  430. # """
  431. # pass
  432. @abstractproperty
  433. def security_groups(self):
  434. """
  435. Get the security groups associated with this instance.
  436. :rtype: list or :class:``SecurityGroup`` objects
  437. :return: A list of SecurityGroup objects associated with this instance.
  438. """
  439. pass
  440. @abstractproperty
  441. def key_pair_name(self):
  442. """
  443. Get the name of the key pair associated with this instance.
  444. :rtype: str
  445. :return: Name of the ssh key pair associated with this instance.
  446. """
  447. pass
  448. @abstractmethod
  449. def create_image(self, name):
  450. """
  451. Create a new image based on this instance.
  452. :rtype: :class:``.Image``
  453. :return: an Image object
  454. """
  455. pass
  456. @abstractmethod
  457. def add_floating_ip(self, ip_address):
  458. """
  459. Add a public IP address to this instance.
  460. :type ip_address: str
  461. :param ip_address: The IP address to associate with the instance.
  462. """
  463. pass
  464. @abstractmethod
  465. def remove_floating_ip(self, ip_address):
  466. """
  467. Remove a public IP address from this instance.
  468. :type ip_address: str
  469. :param ip_address: The IP address to remove from the instance.
  470. """
  471. pass
  472. class MachineImageState(object):
  473. """
  474. Standard states for a machine image
  475. :cvar UNKNOWN: Image state unknown.
  476. :cvar PENDING: Image is pending
  477. :cvar AVAILABLE: Image is available
  478. :cvar ERROR: Image is in an error state. Not recoverable.
  479. """
  480. UNKNOWN = "unknown"
  481. PENDING = "pending"
  482. AVAILABLE = "available"
  483. ERROR = "error"
  484. class LaunchConfig(object):
  485. """
  486. Represents an advanced launch configuration object, containing
  487. information such as BlockDeviceMappings, NetworkInterface configurations,
  488. and other advanced options which may be useful when launching an instance.
  489. Example:
  490. .. code-block:: python
  491. lc = provider.compute.instances.create_launch_config()
  492. lc.add_block_device(...)
  493. lc.add_network_interface(...)
  494. inst = provider.compute.instances.create(name, image, instance_type,
  495. launch_config=lc)
  496. """
  497. @abstractmethod
  498. def add_ephemeral_device(self):
  499. """
  500. Adds a new ephemeral block device mapping to the boot configuration.
  501. This can be used to add existing ephemeral devices to the instance.
  502. (The total number of ephemeral devices available for a particular
  503. InstanceType can be determined by querying the InstanceTypes service).
  504. Note that on some services, such as AWS, ephemeral devices must be
  505. added in as a device mapping at instance creation time, and cannot be
  506. added afterwards.
  507. Note that the device name, such as /dev/sda1, cannot be selected at
  508. present, since this tends to be provider and instance type specific.
  509. However, the order of device addition coupled with device type will
  510. generally determine naming order, with devices added first getting
  511. lower letters than instances added later.
  512. Example:
  513. .. code-block:: python
  514. lc = provider.compute.instances.create_launch_config()
  515. # 1. Add all available ephemeral devices
  516. inst_type = provider.compute.instance_types.find(name='m1.tiny')[0]
  517. for i in range(inst_type.num_ephemeral_disks):
  518. lc.add_ephemeral_device()
  519. """
  520. pass
  521. @abstractmethod
  522. def add_volume_device(self, source=None, is_root=None, size=None,
  523. delete_on_terminate=None):
  524. """
  525. Adds a new volume based block device mapping to the boot configuration.
  526. The volume can be based on a snapshot, image, existing volume or
  527. be a blank new volume, and is specified by the source parameter.
  528. The property is_root can be set to True to override any existing root
  529. device mappings. Otherwise, the default behaviour is to add new block
  530. devices to the instance.
  531. Note that the device name, such as /dev/sda1, cannot be selected at
  532. present, since this tends to be provider and instance type specific.
  533. However, the order of device addition coupled with device type will
  534. generally determine naming order, with devices added first getting
  535. lower letters than instances added later (except when is_root is set).
  536. Example:
  537. .. code-block:: python
  538. lc = provider.compute.instances.create_launch_config()
  539. # 1. Create and attach an empty volume of size 100GB
  540. lc.add_volume_device(size=100, delete_on_terminate=True)
  541. # 2. Create and attach a volume based on a snapshot
  542. snap = provider.block_store.snapshots.get('<my_snapshot_id>')
  543. lc.add_volume_device(source=snap)
  544. # 3. Create+attach a volume based on an image and set it as root
  545. img = provider.compute.images.get('<my_image_id>')
  546. lc.add_volume_device(source=img, size=100, is_root=True)
  547. :type source: ``Volume``, ``Snapshot``, ``Image`` or None.
  548. :param source: The source ``block_device`` to add. If ``Volume``, the
  549. volume will be attached directly to the instance.
  550. If ``Snapshot``, a volume will be created based on the
  551. Snapshot and attached to the instance. If ``Image``,
  552. a volume based on the Image will be attached to the
  553. instance. If ``None``, the source is assumed to be
  554. a blank volume.
  555. :type is_root: ``bool``
  556. :param is_root: Determines which device will serve as the root device.
  557. If more than one device is defined as root, an
  558. ``InvalidConfigurationException`` will be thrown.
  559. :type size: ``int``
  560. :param size: The size of the volume to create. An implementation may
  561. ignore this parameter for certain sources like 'Volume'.
  562. :type delete_on_terminate: ``bool``
  563. :param delete_on_terminate: Determines whether to delete or keep the
  564. volume on instance termination.
  565. """
  566. pass
  567. @abstractmethod
  568. def add_network_interface(self, net_id):
  569. """
  570. Add a private network info to the launch configuration.
  571. Example:
  572. .. code-block:: python
  573. lc = provider.compute.instances.create_launch_config()
  574. # 1. Add a VPC subnet for use with AWS
  575. lc.add_network_interface('subnet-c24aeaff')
  576. # 2. Add a network ID for use with OpenStack
  577. lc.add_network_interface('5820c766-75fe-4fc6-96ef-798f67623238')
  578. :type net_id: str
  579. :param net_id: Network ID to launch an instance into. This is a
  580. preliminary implementation (pending full private cloud
  581. support within cloudbridge) so native network IDs need
  582. to be supplied. For OpenStack, this is the Neutron
  583. network ID. For AWS, this is a VPC subnet ID. For the
  584. time being, only a single network interface can be
  585. supplied.
  586. """
  587. pass
  588. class MachineImage(ObjectLifeCycleMixin, CloudResource):
  589. __metaclass__ = ABCMeta
  590. @abstractproperty
  591. def id(self):
  592. """
  593. Get the image identifier.
  594. :rtype: ``str``
  595. :return: ID for this instance as returned by the cloud middleware.
  596. """
  597. pass
  598. @abstractproperty
  599. def name(self):
  600. """
  601. Get the image name.
  602. :rtype: ``str``
  603. :return: Name for this image as returned by the cloud middleware.
  604. """
  605. pass
  606. @abstractproperty
  607. def description(self):
  608. """
  609. Get the image description.
  610. :rtype: ``str``
  611. :return: Description for this image as returned by the cloud
  612. middleware.
  613. """
  614. pass
  615. @abstractmethod
  616. def delete(self):
  617. """
  618. Delete this image
  619. :rtype: ``bool``
  620. :return: ``True`` if the operation succeeded.
  621. """
  622. pass
  623. class NetworkState(object):
  624. """
  625. Standard states for a network.
  626. :cvar UNKNOWN: Network state unknown.
  627. :cvar PENDING: Network is being created.
  628. :cvar AVAILABLE: Network is being available.
  629. :cvar DOWN = Network is not operational.
  630. :cvar ERROR = Network errored.
  631. """
  632. UNKNOWN = "unknown"
  633. PENDING = "pending"
  634. AVAILABLE = "available"
  635. DOWN = "down"
  636. ERROR = "error"
  637. class Network(CloudResource):
  638. """
  639. Represents a software-defined network, like the Virtual Private Cloud.
  640. """
  641. __metaclass__ = ABCMeta
  642. @abstractproperty
  643. def id(self):
  644. """
  645. Get the network identifier.
  646. :rtype: ``str``
  647. :return: ID for this network. Will generally correspond to the cloud
  648. middleware's ID, but should be treated as an opaque value.
  649. """
  650. pass
  651. @abstractproperty
  652. def name(self):
  653. """
  654. Get the network name.
  655. :rtype: ``str``
  656. :return: Name for this network as returned by the cloud middleware.
  657. """
  658. pass
  659. @abstractproperty
  660. def state(self):
  661. """
  662. The state of the network.
  663. :rtype: ``str``
  664. :return: One of ``unknown``, ``pending``, ``available``, ``down`` or
  665. ``error``.
  666. """
  667. pass
  668. @abstractproperty
  669. def cidr_block(self):
  670. """
  671. A CIDR block for this network.
  672. .. note:: OpenStack does not define a CIDR block for networks.
  673. :rtype: ``str``
  674. :return: A CIDR block string.
  675. """
  676. pass
  677. @abstractmethod
  678. def delete(self):
  679. """
  680. Delete this network.
  681. :rtype: ``bool``
  682. :return: ``True`` if successful.
  683. """
  684. pass
  685. @abstractmethod
  686. def subnets(self):
  687. """
  688. The associated subnets.
  689. :rtype: ``list`` of :class:`.Subnet`
  690. :return: List of subnets associated with this network.
  691. """
  692. pass
  693. @abstractmethod
  694. def create_subnet(self, cidr_block, name=None):
  695. """
  696. Create a new network subnet and associate it with this Network.
  697. :type cidr_block: ``str``
  698. :param cidr_block: CIDR block within this Network to assign to the
  699. subnet.
  700. :type name: ``str``
  701. :param name: An optional subnet name. The name will be set if the
  702. provider supports it.
  703. :rtype: ``object`` of :class:`.Subnet`
  704. :return: A Subnet object
  705. """
  706. pass
  707. class Subnet(CloudResource):
  708. """
  709. Represents a subnet, as part of a Network.
  710. """
  711. __metaclass__ = ABCMeta
  712. @abstractproperty
  713. def id(self):
  714. """
  715. Get the subnet identifier.
  716. :rtype: ``str``
  717. :return: ID for this network. Will generally correspond to the cloud
  718. middleware's ID, but should be treated as an opaque value.
  719. """
  720. pass
  721. @abstractproperty
  722. def name(self):
  723. """
  724. Get the subnet name.
  725. :rtype: ``str``
  726. :return: Name for this subnet as returned by the cloud middleware.
  727. """
  728. pass
  729. @abstractproperty
  730. def cidr_block(self):
  731. """
  732. A CIDR block for this subnet.
  733. :rtype: ``str``
  734. :return: A CIDR block string.
  735. """
  736. pass
  737. @abstractproperty
  738. def network_id(self):
  739. """
  740. ID of the network associated with this this subnet.
  741. :rtype: ``str``
  742. :return: Network ID.
  743. """
  744. pass
  745. @abstractmethod
  746. def delete(self):
  747. """
  748. Delete this subnet.
  749. :rtype: ``bool``
  750. :return: ``True`` if successful.
  751. """
  752. pass
  753. class AttachmentInfo(object):
  754. """
  755. Contains attachment information for a volume.
  756. """
  757. @abstractproperty
  758. def volume(self):
  759. """
  760. Get the volume instance related to this attachment.
  761. :rtype: ``Volume``
  762. :return: Volume object that this attachment info belongs to
  763. """
  764. pass
  765. @abstractproperty
  766. def instance_id(self):
  767. """
  768. Get the instance_id related to this attachment.
  769. :rtype: ``str``
  770. :return: Instance id that this attachment info belongs to
  771. """
  772. pass
  773. @abstractproperty
  774. def device(self):
  775. """
  776. Get the device the volume is mapped as.
  777. :rtype: ``str``
  778. :return: Device that the volume is mapped as
  779. """
  780. pass
  781. class VolumeState(object):
  782. """
  783. Standard states for a volume
  784. :cvar UNKNOWN: Volume state unknown.
  785. :cvar CREATING: Volume is being created.
  786. :cvar CONFIGURING: Volume is being configured in some way.
  787. :cvar AVAILABLE: Volume is available and can be attached to an instance.
  788. :cvar IN_USE: Volume is attached and in-use.
  789. :cvar DELETED: Volume has been deleted. No further operations possible.
  790. :cvar ERROR: Volume is in an error state. No further operations possible.
  791. """
  792. UNKNOWN = "unknown"
  793. CREATING = "creating"
  794. CONFIGURING = "configuring"
  795. AVAILABLE = "available"
  796. IN_USE = "in-use"
  797. DELETED = "deleted"
  798. ERROR = "error"
  799. class Volume(ObjectLifeCycleMixin, CloudResource):
  800. __metaclass__ = ABCMeta
  801. @abstractproperty
  802. def id(self):
  803. """
  804. Get the volume identifier.
  805. :rtype: ``str``
  806. :return: ID for this volume. Will generally correspond to the cloud
  807. middleware's ID, but should be treated as an opaque value.
  808. """
  809. pass
  810. @abstractproperty
  811. def name(self):
  812. """
  813. Get the volume name.
  814. :rtype: ``str``
  815. :return: Name for this volume as returned by the cloud middleware.
  816. """
  817. pass
  818. @name.setter
  819. @abstractmethod
  820. def name(self, value):
  821. """
  822. Set the volume name.
  823. """
  824. pass
  825. @abstractproperty
  826. def description(self):
  827. """
  828. Get the volume description. Some cloud providers may not support this
  829. property, and will return the volume name instead.
  830. :rtype: ``str``
  831. :return: Description for this volume as returned by the cloud
  832. middleware.
  833. """
  834. pass
  835. @description.setter
  836. @abstractmethod
  837. def description(self, value):
  838. """
  839. Set the volume description. Some cloud providers may not support this
  840. property, and setting the description may have no effect. (Providers
  841. that do not support this property will always return the volume name
  842. as the description)
  843. """
  844. pass
  845. @abstractproperty
  846. def size(self):
  847. """
  848. Get the volume size (in GB).
  849. :rtype: ``int``
  850. :return: Size for this volume as returned by the cloud middleware.
  851. """
  852. pass
  853. @abstractproperty
  854. def create_time(self):
  855. """
  856. Get the creation data and time for this volume.
  857. :rtype: ``DateTime``
  858. :return: Creation time for this volume as returned by the cloud
  859. middleware.
  860. """
  861. pass
  862. @abstractproperty
  863. def zone_id(self):
  864. """
  865. Get the placement zone id that this volume belongs to.
  866. :rtype: ``str``
  867. :return: PlacementZone for this volume as returned by the cloud
  868. middleware.
  869. """
  870. pass
  871. @abstractproperty
  872. def source(self):
  873. """
  874. If available, get the source that this volume is based on (can be
  875. a Snapshot or an Image). Returns None if no source.
  876. :rtype: ``Snapshot`` or ``Image``
  877. :return: Snapshot or Image source for this volume as returned by the
  878. cloud middleware.
  879. """
  880. pass
  881. @abstractproperty
  882. def attachments(self):
  883. """
  884. Get attachment information for this volume.
  885. :rtype: ``AttachmentInfo``
  886. :return: Returns an AttachmentInfo object.
  887. """
  888. pass
  889. @abstractmethod
  890. def attach(self, instance, device):
  891. """
  892. Attach this volume to an instance.
  893. :type instance: str or :class:``.Instance`` object
  894. :param instance: The ID of an instance or an ``Instance`` object to
  895. which this volume will be attached.
  896. :type device: str
  897. :param device: The device on the instance through which the
  898. volume will be exposed (e.g. /dev/sdh).
  899. :rtype: bool
  900. :return: ``True`` if successful.
  901. """
  902. pass
  903. @abstractmethod
  904. def detach(self, force=False):
  905. """
  906. Detach this volume from an instance.
  907. :type force: bool
  908. :param force: Forces detachment if the previous detachment attempt
  909. did not occur cleanly. This option is supported on select
  910. clouds only. This option can lead to data loss or a
  911. corrupted file system. Use this option only as a last
  912. resort to detach a volume from a failed instance. The
  913. instance will not have an opportunity to flush file
  914. system caches nor file system meta data. If you
  915. use this option, you must perform file system check and
  916. repair procedures.
  917. :rtype: bool
  918. :return: ``True`` if successful.
  919. """
  920. pass
  921. @abstractmethod
  922. def create_snapshot(self, name, description=None):
  923. """
  924. Create a snapshot of this Volume.
  925. :type name: str
  926. :param name: The name of this snapshot.
  927. :type description: str
  928. :param description: A description of the snapshot.
  929. Limited to 256 characters.
  930. :rtype: :class:``.Snapshot``
  931. :return: The created Snapshot object.
  932. """
  933. pass
  934. @abstractmethod
  935. def delete(self):
  936. """
  937. Delete this volume.
  938. :rtype: bool
  939. :return: ``True`` if successful.
  940. """
  941. pass
  942. class SnapshotState(object):
  943. """
  944. Standard states for a snapshot
  945. :cvar UNKNOWN: Snapshot state unknown.
  946. :cvar PENDING: Snapshot is pending.
  947. :cvar CONFIGURING: Snapshot is being configured in some way.
  948. :cvar AVAILABLE: Snapshot has been completed and is ready for use.
  949. :cvar ERROR: Snapshot is in an error state. No further operations possible.
  950. """
  951. UNKNOWN = "unknown"
  952. PENDING = "pending"
  953. CONFIGURING = "configuring"
  954. AVAILABLE = "available"
  955. ERROR = "error"
  956. class Snapshot(ObjectLifeCycleMixin, CloudResource):
  957. __metaclass__ = ABCMeta
  958. @abstractproperty
  959. def id(self):
  960. """
  961. Get the snapshot identifier.
  962. :rtype: ``str``
  963. :return: ID for this snapshot. Will generally correspond to the cloud
  964. middleware's ID, but should be treated as an opaque value.
  965. """
  966. pass
  967. @abstractproperty
  968. def name(self):
  969. """
  970. Get the snapshot name.
  971. """
  972. pass
  973. @name.setter
  974. @abstractmethod
  975. def name(self, value):
  976. """
  977. set the snapshot name.
  978. """
  979. pass
  980. @abstractmethod
  981. def create_volume(self, placement, size=None, volume_type=None, iops=None):
  982. """
  983. Create a new Volume from this Snapshot.
  984. :type placement: str
  985. :param placement: The availability zone where to create the Volume.
  986. :type size: int
  987. :param size: The size of the new volume, in GiB (optional). Defaults to
  988. the size of the snapshot.
  989. :type volume_type: str
  990. :param volume_type: The type of the volume (optional). Availability and
  991. valid values depend on the provider.
  992. :type iops: int
  993. :param iops: The provisioned IOPs you want to associate with
  994. this volume (optional). Availability depends on the
  995. provider.
  996. :rtype: :class:`.Volume`
  997. :return: An instance of the created Volume.
  998. """
  999. pass
  1000. # @abstractmethod
  1001. # def share(self, user_ids=None):
  1002. # """
  1003. # Share this Snapshot.
  1004. #
  1005. # :type user_ids: list of strings
  1006. # :param user_ids: A list of cloud provider compatible user IDs. If no
  1007. # IDs are specified, the snapshot is made public.
  1008. #
  1009. # :rtype: bool
  1010. # :return: ``True`` if successful.
  1011. # """
  1012. # pass
  1013. #
  1014. # @abstractmethod
  1015. # def unshare(self, user_ids=None):
  1016. # """
  1017. # Unshare this Snapshot.
  1018. #
  1019. # :type user_ids: list of strings
  1020. # :param user_ids: A list of cloud provider compatible user IDs. If no
  1021. # IDs are specified, the snapshot is made private.
  1022. #
  1023. # :rtype: bool
  1024. # :return: ``True`` if successful.
  1025. # """
  1026. # pass
  1027. @abstractmethod
  1028. def delete(self):
  1029. """
  1030. Delete this snapshot.
  1031. :rtype: bool
  1032. :return: ``True`` if successful.
  1033. """
  1034. pass
  1035. class KeyPair(CloudResource):
  1036. __metaclass__ = ABCMeta
  1037. @abstractproperty
  1038. def id(self):
  1039. """
  1040. Return the id of this key pair.
  1041. :rtype: ``str``
  1042. :return: ID for this snapshot. Will generally correspond to the cloud
  1043. middleware's name, but should be treated as an opaque value.
  1044. """
  1045. pass
  1046. @abstractproperty
  1047. def name(self):
  1048. """
  1049. Return the name of this key pair.
  1050. :rtype: str
  1051. :return: A name of this ssh key pair.
  1052. """
  1053. pass
  1054. @abstractproperty
  1055. def material(self):
  1056. """
  1057. Unencrypted private key.
  1058. :rtype: str
  1059. :return: Unencrypted private key or ``None`` if not available.
  1060. """
  1061. pass
  1062. @abstractmethod
  1063. def delete(self):
  1064. """
  1065. Delete this key pair.
  1066. :rtype: bool
  1067. :return: ``True`` if successful.
  1068. """
  1069. pass
  1070. class Region(CloudResource):
  1071. """
  1072. Represents a cloud region, typically a separate geographic area and will
  1073. contain at least one placement zone.
  1074. """
  1075. __metaclass__ = ABCMeta
  1076. @abstractproperty
  1077. def id(self):
  1078. """
  1079. The id for this region
  1080. :rtype: str
  1081. :return: ID of the region.
  1082. """
  1083. pass
  1084. @abstractproperty
  1085. def name(self):
  1086. """
  1087. Name of the region.
  1088. :rtype: str
  1089. :return: Name of the region.
  1090. """
  1091. pass
  1092. @abstractproperty
  1093. def zones(self):
  1094. """
  1095. Accesss information about placement zones within this region.
  1096. :rtype: iterable
  1097. :return: Iterable of available placement zones in this region.
  1098. """
  1099. pass
  1100. class PlacementZone(CloudResource):
  1101. """
  1102. Represents a placement zone. A placement zone is contained within a Region.
  1103. """
  1104. __metaclass__ = ABCMeta
  1105. @abstractproperty
  1106. def id(self):
  1107. """
  1108. Name of the placement zone.
  1109. :rtype: str
  1110. :return: Name of the placement zone.
  1111. """
  1112. pass
  1113. @abstractproperty
  1114. def name(self):
  1115. """
  1116. Name of the placement zone.
  1117. :rtype: str
  1118. :return: Name of the placement zone.
  1119. """
  1120. pass
  1121. @abstractproperty
  1122. def region_name(self):
  1123. """
  1124. A region this placement zone is associated with.
  1125. :rtype: str
  1126. :return: The name of the region the zone is associated with.
  1127. """
  1128. pass
  1129. class InstanceType(CloudResource):
  1130. """
  1131. An instance type object.
  1132. """
  1133. __metaclass__ = ABCMeta
  1134. @abstractproperty
  1135. def id(self):
  1136. pass
  1137. @abstractproperty
  1138. def name(self):
  1139. pass
  1140. @abstractproperty
  1141. def family(self):
  1142. """
  1143. The family/group that this instance type belongs to.
  1144. For example, General Purpose Instances or High-Memory Instances. If
  1145. the provider does not support such a grouping, it may return ``None``.
  1146. :rtype: str
  1147. :return: Name of the instance family or ``None``.
  1148. """
  1149. pass
  1150. @abstractproperty
  1151. def vcpus(self):
  1152. """
  1153. The number of VCPUs supported by this instance type.
  1154. :rtype: int
  1155. :return: Number of VCPUs.
  1156. """
  1157. pass
  1158. @abstractproperty
  1159. def ram(self):
  1160. """
  1161. The amount of RAM (in mb) supported by this instance type.
  1162. :rtype: int
  1163. :return: Total RAM (in MB).
  1164. """
  1165. pass
  1166. @abstractproperty
  1167. def size_root_disk(self):
  1168. """
  1169. The size of this instance types's root disk (in GB).
  1170. :rtype: int
  1171. :return: Size of root disk (in GB).
  1172. """
  1173. pass
  1174. @abstractproperty
  1175. def size_ephemeral_disks(self):
  1176. """
  1177. The size of this instance types's total ephemeral storage (in GB).
  1178. :rtype: int
  1179. :return: Size of ephemeral disks (in GB).
  1180. """
  1181. pass
  1182. @abstractproperty
  1183. def num_ephemeral_disks(self):
  1184. """
  1185. The total number of ephemeral disks on this instance type.
  1186. :rtype: int
  1187. :return: Number of ephemeral disks available.
  1188. """
  1189. pass
  1190. @abstractproperty
  1191. def size_total_disk(self):
  1192. """
  1193. The total disk space available on this instance type
  1194. (root_disk + ephemeral).
  1195. :rtype: int
  1196. :return: Size of total disk space (in GB).
  1197. """
  1198. pass
  1199. @abstractproperty
  1200. def extra_data(self):
  1201. """
  1202. A dictionary of extra data about this instance. May contain
  1203. nested dictionaries, but all key value pairs are strings or integers.
  1204. :rtype: dict
  1205. :return: Extra attributes for this instance type.
  1206. """
  1207. pass
  1208. class SecurityGroup(CloudResource):
  1209. __metaclass__ = ABCMeta
  1210. @abstractproperty
  1211. def id(self):
  1212. """
  1213. Get the ID of this security group.
  1214. :rtype: str
  1215. :return: Security group ID.
  1216. """
  1217. pass
  1218. @abstractproperty
  1219. def name(self):
  1220. """
  1221. Return the name of this security group.
  1222. :rtype: str
  1223. :return: A name of this security group.
  1224. """
  1225. pass
  1226. @abstractproperty
  1227. def description(self):
  1228. """
  1229. Return the description of this security group.
  1230. :rtype: str
  1231. :return: A description of this security group.
  1232. """
  1233. pass
  1234. @abstractproperty
  1235. def rules(self):
  1236. """
  1237. Get the list of rules for this security group.
  1238. :rtype: list of :class:``.SecurityGroupRule``
  1239. :return: A list of security group rule objects.
  1240. """
  1241. pass
  1242. @abstractmethod
  1243. def delete(self):
  1244. """
  1245. Delete this security group.
  1246. :rtype: bool
  1247. :return: ``True`` if successful.
  1248. """
  1249. pass
  1250. @abstractmethod
  1251. def add_rule(self, ip_protocol=None, from_port=None, to_port=None,
  1252. cidr_ip=None, src_group=None):
  1253. """
  1254. Create a security group rule.
  1255. You need to pass in either ``src_group`` OR ``ip_protocol``,
  1256. ``from_port``, ``to_port``, and ``cidr_ip``. In other words, either
  1257. you are authorizing another group or you are authorizing some
  1258. ip-based rule.
  1259. :type ip_protocol: str
  1260. :param ip_protocol: Either ``tcp`` | ``udp`` | ``icmp``.
  1261. :type from_port: int
  1262. :param from_port: The beginning port number you are enabling.
  1263. :type to_port: int
  1264. :param to_port: The ending port number you are enabling.
  1265. :type cidr_ip: str or list of strings
  1266. :param cidr_ip: The CIDR block you are providing access to.
  1267. :type src_group: :class:``.SecurityGroup``
  1268. :param src_group: The Security Group object you are granting access to.
  1269. :rtype: bool
  1270. :return: ``True`` if successful.
  1271. """
  1272. pass
  1273. class SecurityGroupRule(CloudResource):
  1274. """
  1275. Represents a security group rule.
  1276. """
  1277. __metaclass__ = ABCMeta
  1278. @abstractproperty
  1279. def ip_protocol(self):
  1280. """
  1281. IP protocol used. Either ``tcp`` | ``udp`` | ``icmp``.
  1282. """
  1283. pass
  1284. @abstractproperty
  1285. def from_port(self):
  1286. """
  1287. Lowest port number opened as part of this rule.
  1288. """
  1289. pass
  1290. @abstractproperty
  1291. def to_port(self):
  1292. """
  1293. Highest port number opened as part of this rule.
  1294. """
  1295. pass
  1296. @abstractproperty
  1297. def cidr_ip(self):
  1298. """
  1299. CIDR block this security group is providing access to.
  1300. """
  1301. pass
  1302. @abstractproperty
  1303. def group(self):
  1304. """
  1305. Security group given access permissions by this rule.
  1306. :rtype: :class:``.SecurityGroup``
  1307. :return: The Security Group with granting access.
  1308. """
  1309. pass
  1310. class BucketObject(CloudResource):
  1311. """
  1312. Represents an object stored within a bucket.
  1313. """
  1314. __metaclass__ = ABCMeta
  1315. @abstractproperty
  1316. def id(self):
  1317. """
  1318. Get this object's id.
  1319. :rtype: id
  1320. :return: id of this object as returned by the cloud middleware.
  1321. """
  1322. pass
  1323. @abstractproperty
  1324. def name(self):
  1325. """
  1326. Get this object's name.
  1327. :rtype: str
  1328. :return: Name of this object as returned by the cloud middleware.
  1329. """
  1330. pass
  1331. @abstractmethod
  1332. def download(self, target_stream):
  1333. """
  1334. Download this object and write its contents to the ``target_stream``.
  1335. :rtype: bool
  1336. :return: ``True`` if successful.
  1337. """
  1338. pass
  1339. @abstractmethod
  1340. def upload(self, source_stream):
  1341. """
  1342. Set the contents of this object to the data read from the source
  1343. stream.
  1344. :rtype: bool
  1345. :return: ``True`` if successful.
  1346. """
  1347. pass
  1348. @abstractmethod
  1349. def delete(self):
  1350. """
  1351. Delete this object.
  1352. :rtype: bool
  1353. :return: ``True`` if successful.
  1354. """
  1355. pass
  1356. class Bucket(PageableObjectMixin, CloudResource):
  1357. __metaclass__ = ABCMeta
  1358. @abstractproperty
  1359. def id(self):
  1360. """
  1361. Get this bucket's id.
  1362. :rtype: id
  1363. :return: id of this bucket as returned by the cloud middleware.
  1364. """
  1365. pass
  1366. @abstractproperty
  1367. def name(self):
  1368. """
  1369. Get this bucket's name.
  1370. :rtype: str
  1371. :return: Name of this bucket as returned by the cloud middleware.
  1372. """
  1373. pass
  1374. @abstractmethod
  1375. def get(self, key):
  1376. """
  1377. Retrieve a given object from this bucket.
  1378. :type key: str
  1379. :param key: the identifier of the object to retrieve
  1380. :rtype: :class:``.BucketObject``
  1381. :return: The BucketObject or ``None`` if it cannot be found.
  1382. """
  1383. pass
  1384. @abstractmethod
  1385. def list(self, limit=None, marker=None):
  1386. """
  1387. List all objects within this bucket.
  1388. :rtype: :class:``.BucketObject``
  1389. :return: List of all available BucketObjects within this bucket.
  1390. """
  1391. pass
  1392. @abstractmethod
  1393. def delete(self, delete_contents=False):
  1394. """
  1395. Delete this bucket.
  1396. :type delete_contents: bool
  1397. :param delete_contents: If ``True``, all objects within the bucket
  1398. will be deleted.
  1399. :rtype: bool
  1400. :return: ``True`` if successful.
  1401. """
  1402. pass