resources.py 57 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155
  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 life cycle 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 life cycle 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.
  164. A WaitStateException will be raised if the
  165. object transition into a terminal state.
  166. :type timeout: ``int``
  167. :param timeout: The maximum length of time (in seconds) to wait for the
  168. object to changed to desired state. If no timeout is
  169. specified, the global default_wait_timeout defined in
  170. the provider config will apply.
  171. :type interval: ``int``
  172. :param interval: How frequently to poll the object's state (in
  173. seconds). If no interval is specified, the global
  174. default_wait_interval defined in the provider config
  175. will apply.
  176. :rtype: ``True``
  177. :return: Returns ``True`` if successful. A ``WaitStateException``
  178. exception may be thrown by the underlying service if the
  179. object cannot get into a ready state (e.g. if the object
  180. is in an error state).
  181. """
  182. pass
  183. @abstractmethod
  184. def wait_till_ready(self, timeout, interval):
  185. """
  186. A convenience method to wait till the current object reaches a state
  187. which is ready for use, which is any state where the end-user can
  188. successfully interact with the object.
  189. Will throw a ``WaitStateException`` if the object is not ready within
  190. the specified timeout.
  191. :type timeout: ``int``
  192. :param timeout: The maximum length of time (in seconds) to wait for the
  193. object to become ready.
  194. :type interval: ``int``
  195. :param interval: How frequently to poll the object's ready state (in
  196. seconds).
  197. :rtype: ``True``
  198. :return: Returns ``True`` if successful. A ``WaitStateException``
  199. exception may be thrown by the underlying service if the
  200. object cannot get into a ready state (e.g. if the object
  201. is in an error state).
  202. """
  203. pass
  204. class PageableObjectMixin(object):
  205. """
  206. A marker interface for objects which support paged iteration through
  207. a list of objects with a list(limit, marker) method.
  208. """
  209. @abstractmethod
  210. def __iter__(self):
  211. """
  212. Enables iteration through this object. Typically, an implementation
  213. will call the list(limit, marker) method to transparently page
  214. additional objects in as iteration progresses.
  215. """
  216. pass
  217. @abstractmethod
  218. def list(self, limit=None, marker=None):
  219. """
  220. Returns a list of objects up to a maximum limit.
  221. If a limit and marker are specified, the records will be fetched up to
  222. the limit starting from the marker onwards. The returned list is a list
  223. of class ResultList, which has extra properties like is_truncated,
  224. supports_total and total_records to provide extra information
  225. about record availability.
  226. If limit is not specified, the limit will default to the underlying
  227. provider's default limit. Therefore, you need to check the is_truncated
  228. property to determine whether more records are available.
  229. The total number of results can be determined through the total_results
  230. property. Not all provides will support returning the total_results
  231. property, so the supports_total property can be used to determine
  232. whether a total is supported.
  233. To iterate through all the records, it will be easier to iterate
  234. directly through the instances using __iter__ instead of calling
  235. the list method. The __iter__ method will automatically call the list
  236. method to fetch a batch of records at a time.
  237. Example:
  238. .. code-block:: python
  239. # get first page of results
  240. instlist = provider.compute.instances.list(limit=50)
  241. for instance in instlist:
  242. print("Instance Data: {0}", instance)
  243. if instlist.supports_total:
  244. print("Total results: {0}".format(instlist.total_results))
  245. else:
  246. print("Total records unknown,"
  247. "but has more data?: {0}".format(instlist.is_truncated))
  248. # Page to next set of results
  249. if (instlist.is_truncated)
  250. instlist = provider.compute.instances.list(limit=100,
  251. marker=instlist.marker)
  252. # Alternative: iterate through every available record
  253. for instance in provider.compute.instances:
  254. print(instance)
  255. """
  256. pass
  257. class ResultList(list):
  258. """
  259. This is a wrapper class around a standard Python :py:class:`list` class
  260. and provides some extra properties to aid with paging through a large
  261. number of results.
  262. Example:
  263. .. code-block:: python
  264. # get first page of results
  265. rl = provider.compute.instances.list(limit=50)
  266. for result in rl:
  267. print("Instance Data: {0}", result)
  268. if rl.supports_total:
  269. print("Total results: {0}".format(rl.total_results))
  270. else:
  271. print("Total records unknown,"
  272. "but has more data?: {0}."format(rl.is_truncated))
  273. # Page to next set of results
  274. if (rl.is_truncated)
  275. rl = provider.compute.instances.list(limit=100,
  276. marker=rl.marker)
  277. """
  278. __metaclass__ = ABCMeta
  279. @abstractproperty
  280. def marker(self):
  281. """
  282. This is an opaque identifier used to assist in paging through very long
  283. lists of objects. This marker can be provided to the list method to get
  284. the next set of results.
  285. """
  286. pass
  287. @abstractproperty
  288. def is_truncated(self):
  289. """
  290. Indicates whether this result list has more results
  291. that can be paged in.
  292. """
  293. pass
  294. @abstractproperty
  295. def supports_total(self):
  296. """
  297. Indicates whether the provider supports returning the total number of
  298. available results. The supports_total property should be checked
  299. before accessing the total_results property.
  300. """
  301. pass
  302. @abstractproperty
  303. def total_results(self):
  304. """
  305. Indicates the total number of results for a particular query. The
  306. supports_total property should be used to check whether the provider
  307. supports returning the total number of results, before accessing this
  308. property, or the behaviour is indeterminate.
  309. """
  310. pass
  311. @abstractproperty
  312. def supports_server_paging(self):
  313. """
  314. Indicates whether this ResultList supports client side paging or server
  315. side paging. If server side paging is not supported, the data property
  316. provides direct access to all available data.
  317. """
  318. pass
  319. @abstractproperty
  320. def data(self):
  321. pass
  322. class InstanceState(object):
  323. """
  324. Standard states for a node
  325. :cvar UNKNOWN: Instance state unknown.
  326. :cvar PENDING: Instance is pending
  327. :cvar CONFIGURING: Instance is being reconfigured in some way.
  328. :cvar RUNNING: Instance is running.
  329. :cvar REBOOTING: Instance is rebooting.
  330. :cvar TERMINATED: Instance is terminated. No further operations possible.
  331. :cvar STOPPED: Instance is stopped. Instance can be resumed.
  332. :cvar ERROR: Instance is in an error state. No further operations possible.
  333. """
  334. UNKNOWN = "unknown"
  335. PENDING = "pending"
  336. CONFIGURING = "configuring"
  337. RUNNING = "running"
  338. REBOOTING = "rebooting"
  339. TERMINATED = "terminated"
  340. STOPPED = "stopped"
  341. ERROR = "error"
  342. class Instance(ObjectLifeCycleMixin, CloudResource):
  343. __metaclass__ = ABCMeta
  344. @abstractproperty
  345. def id(self):
  346. """
  347. Get the instance identifier.
  348. :rtype: ``str``
  349. :return: ID for this instance as returned by the cloud middleware.
  350. """
  351. pass
  352. @abstractproperty
  353. def name(self):
  354. """
  355. Get the instance name.
  356. :rtype: ``str``
  357. :return: Name for this instance as returned by the cloud middleware.
  358. """
  359. pass
  360. @name.setter
  361. @abstractmethod
  362. def name(self, value):
  363. """
  364. Set the instance name.
  365. """
  366. pass
  367. @abstractproperty
  368. def public_ips(self):
  369. """
  370. Get all the public IP addresses for this instance.
  371. :rtype: ``list``
  372. :return: A list of public IP addresses associated with this instance.
  373. """
  374. pass
  375. @abstractproperty
  376. def private_ips(self):
  377. """
  378. Get all the private IP addresses for this instance.
  379. :rtype: ``list``
  380. :return: A list of private IP addresses associated with this instance.
  381. """
  382. pass
  383. @abstractproperty
  384. def instance_type_id(self):
  385. """
  386. Get the instance type id for this instance. This will typically be a
  387. string value like 'm1.large'. On OpenStack, this may be a number or
  388. UUID. To get the full :class:``.InstanceType``
  389. object, you can use the instance.instance_type property instead.
  390. :rtype: ``str``
  391. :return: Instance type name for this instance (e.g., ``m1.large``)
  392. """
  393. pass
  394. @abstractproperty
  395. def instance_type(self):
  396. """
  397. Retrieve full instance type information for this instance.
  398. :rtype: :class:`.InstanceType`
  399. :return: Instance type for this instance
  400. """
  401. pass
  402. @abstractmethod
  403. def reboot(self):
  404. """
  405. Reboot this instance (using the cloud middleware API).
  406. :rtype: ``bool``
  407. :return: ``True`` if the reboot was successful; ``False`` otherwise.
  408. """
  409. pass
  410. @abstractmethod
  411. def terminate(self):
  412. """
  413. Permanently terminate this instance.
  414. :rtype: ``bool``
  415. :return: ``True`` if the termination of the instance was successfully
  416. initiated; ``False`` otherwise.
  417. """
  418. pass
  419. @abstractproperty
  420. def image_id(self):
  421. """
  422. Get the image ID for this instance.
  423. :rtype: ``str``
  424. :return: Image ID (i.e., AMI) this instance is using.
  425. """
  426. pass
  427. @abstractproperty
  428. def zone_id(self):
  429. """
  430. Get the placement zone ID where this instance is running.
  431. :rtype: ``str``
  432. :return: Region/zone/placement where this instance is running.
  433. """
  434. pass
  435. # @abstractproperty
  436. # def mac_address(self):
  437. # """
  438. # Get the MAC address for this instance.
  439. #
  440. # :rtype: str
  441. # :return: MAC address for ths instance.
  442. # """
  443. # pass
  444. @abstractproperty
  445. def security_groups(self):
  446. """
  447. Get the security groups associated with this instance.
  448. :rtype: list or :class:`.SecurityGroup` objects
  449. :return: A list of SecurityGroup objects associated with this instance.
  450. """
  451. pass
  452. @abstractproperty
  453. def security_group_ids(self):
  454. """
  455. Get the IDs of the security groups associated with this instance.
  456. :rtype: list or :class:``str``
  457. :return: A list of the SecurityGroup IDs associated with this instance.
  458. """
  459. pass
  460. @abstractproperty
  461. def key_pair_name(self):
  462. """
  463. Get the name of the key pair associated with this instance.
  464. :rtype: ``str``
  465. :return: Name of the ssh key pair associated with this instance.
  466. """
  467. pass
  468. @abstractmethod
  469. def create_image(self, name):
  470. """
  471. Create a new image based on this instance.
  472. :rtype: :class:``.Image``
  473. :return: an Image object
  474. """
  475. pass
  476. @abstractmethod
  477. def add_floating_ip(self, ip_address):
  478. """
  479. Add a public IP address to this instance.
  480. :type ip_address: ``str``
  481. :param ip_address: The IP address to associate with the instance.
  482. """
  483. pass
  484. @abstractmethod
  485. def remove_floating_ip(self, ip_address):
  486. """
  487. Remove a public IP address from this instance.
  488. :type ip_address: ``str``
  489. :param ip_address: The IP address to remove from the instance.
  490. """
  491. pass
  492. class MachineImageState(object):
  493. """
  494. Standard states for a machine image
  495. :cvar UNKNOWN: Image state unknown.
  496. :cvar PENDING: Image is pending
  497. :cvar AVAILABLE: Image is available
  498. :cvar ERROR: Image is in an error state. Not recoverable.
  499. """
  500. UNKNOWN = "unknown"
  501. PENDING = "pending"
  502. AVAILABLE = "available"
  503. ERROR = "error"
  504. class LaunchConfig(object):
  505. """
  506. Represents an advanced launch configuration object, containing
  507. information such as BlockDeviceMappings, NetworkInterface configurations,
  508. and other advanced options which may be useful when launching an instance.
  509. Example:
  510. .. code-block:: python
  511. lc = provider.compute.instances.create_launch_config()
  512. lc.add_block_device(...)
  513. lc.add_network_interface(...)
  514. inst = provider.compute.instances.create(name, image, instance_type,
  515. launch_config=lc)
  516. """
  517. @abstractmethod
  518. def add_ephemeral_device(self):
  519. """
  520. Adds a new ephemeral block device mapping to the boot configuration.
  521. This can be used to add existing ephemeral devices to the instance.
  522. (The total number of ephemeral devices available for a particular
  523. InstanceType can be determined by querying the InstanceTypes service).
  524. Note that on some services, such as AWS, ephemeral devices must be
  525. added in as a device mapping at instance creation time, and cannot be
  526. added afterwards.
  527. Note that the device name, such as /dev/sda1, cannot be selected at
  528. present, since this tends to be provider and instance type specific.
  529. However, the order of device addition coupled with device type will
  530. generally determine naming order, with devices added first getting
  531. lower letters than instances added later.
  532. Example:
  533. .. code-block:: python
  534. lc = provider.compute.instances.create_launch_config()
  535. # 1. Add all available ephemeral devices
  536. inst_type = provider.compute.instance_types.find(name='m1.tiny')[0]
  537. for i in range(inst_type.num_ephemeral_disks):
  538. lc.add_ephemeral_device()
  539. """
  540. pass
  541. @abstractmethod
  542. def add_volume_device(self, source=None, is_root=None, size=None,
  543. delete_on_terminate=None):
  544. """
  545. Adds a new volume based block device mapping to the boot configuration.
  546. The volume can be based on a snapshot, image, existing volume or
  547. be a blank new volume, and is specified by the source parameter.
  548. The property is_root can be set to True to override any existing root
  549. device mappings. Otherwise, the default behaviour is to add new block
  550. devices to the instance.
  551. Note that the device name, such as /dev/sda1, cannot be selected at
  552. present, since this tends to be provider and instance type specific.
  553. However, the order of device addition coupled with device type will
  554. generally determine naming order, with devices added first getting
  555. lower letters than instances added later (except when is_root is set).
  556. Example:
  557. .. code-block:: python
  558. lc = provider.compute.instances.create_launch_config()
  559. # 1. Create and attach an empty volume of size 100GB
  560. lc.add_volume_device(size=100, delete_on_terminate=True)
  561. # 2. Create and attach a volume based on a snapshot
  562. snap = provider.block_store.snapshots.get('<my_snapshot_id>')
  563. lc.add_volume_device(source=snap)
  564. # 3. Create+attach a volume based on an image and set it as root
  565. img = provider.compute.images.get('<my_image_id>')
  566. lc.add_volume_device(source=img, size=100, is_root=True)
  567. :type source: ``Volume``, ``Snapshot``, ``Image`` or None.
  568. :param source: The source ``block_device`` to add. If ``Volume``, the
  569. volume will be attached directly to the instance.
  570. If ``Snapshot``, a volume will be created based on the
  571. Snapshot and attached to the instance. If ``Image``,
  572. a volume based on the Image will be attached to the
  573. instance. If ``None``, the source is assumed to be
  574. a blank volume.
  575. :type is_root: ``bool``
  576. :param is_root: Determines which device will serve as the root device.
  577. If more than one device is defined as root, an
  578. ``InvalidConfigurationException`` will be thrown.
  579. :type size: ``int``
  580. :param size: The size of the volume to create. An implementation may
  581. ignore this parameter for certain sources like 'Volume'.
  582. :type delete_on_terminate: ``bool``
  583. :param delete_on_terminate: Determines whether to delete or keep the
  584. volume on instance termination.
  585. """
  586. pass
  587. @abstractmethod
  588. def add_network_interface(self, net_id):
  589. """
  590. Add a private network info to the launch configuration.
  591. Example:
  592. .. code-block:: python
  593. lc = provider.compute.instances.create_launch_config()
  594. # 1. Add a VPC subnet for use with AWS
  595. lc.add_network_interface('subnet-c24aeaff')
  596. # 2. Add a network ID for use with OpenStack
  597. lc.add_network_interface('5820c766-75fe-4fc6-96ef-798f67623238')
  598. :type net_id: ``str``
  599. :param net_id: Network ID to launch an instance into. This is a
  600. preliminary implementation (pending full private cloud
  601. support within CloudBridge) so native network IDs need
  602. to be supplied. For OpenStack, this is the Neutron
  603. network ID. For AWS, this is a VPC subnet ID. For the
  604. time being, only a single network interface can be
  605. supplied.
  606. """
  607. pass
  608. class MachineImage(ObjectLifeCycleMixin, CloudResource):
  609. __metaclass__ = ABCMeta
  610. @abstractproperty
  611. def id(self):
  612. """
  613. Get the image identifier.
  614. :rtype: ``str``
  615. :return: ID for this instance as returned by the cloud middleware.
  616. """
  617. pass
  618. @abstractproperty
  619. def name(self):
  620. """
  621. Get the image name.
  622. :rtype: ``str``
  623. :return: Name for this image as returned by the cloud middleware.
  624. """
  625. pass
  626. @abstractproperty
  627. def description(self):
  628. """
  629. Get the image description.
  630. :rtype: ``str``
  631. :return: Description for this image as returned by the cloud
  632. middleware.
  633. """
  634. pass
  635. @abstractmethod
  636. def delete(self):
  637. """
  638. Delete this image
  639. :rtype: ``bool``
  640. :return: ``True`` if the operation succeeded.
  641. """
  642. pass
  643. class NetworkState(object):
  644. """
  645. Standard states for a network.
  646. :cvar UNKNOWN: Network state unknown.
  647. :cvar PENDING: Network is being created.
  648. :cvar AVAILABLE: Network is being available.
  649. :cvar DOWN = Network is not operational.
  650. :cvar ERROR = Network errored.
  651. """
  652. UNKNOWN = "unknown"
  653. PENDING = "pending"
  654. AVAILABLE = "available"
  655. DOWN = "down"
  656. ERROR = "error"
  657. class Network(CloudResource):
  658. """
  659. Represents a software-defined network, like the Virtual Private Cloud.
  660. """
  661. __metaclass__ = ABCMeta
  662. @abstractproperty
  663. def id(self):
  664. """
  665. Get the network identifier.
  666. :rtype: ``str``
  667. :return: ID for this network. Will generally correspond to the cloud
  668. middleware's ID, but should be treated as an opaque value.
  669. """
  670. pass
  671. @abstractproperty
  672. def name(self):
  673. """
  674. Get the network name.
  675. :rtype: ``str``
  676. :return: Name for this network as returned by the cloud middleware.
  677. """
  678. pass
  679. @abstractproperty
  680. def state(self):
  681. """
  682. The state of the network.
  683. :rtype: ``str``
  684. :return: One of ``unknown``, ``pending``, ``available``, ``down`` or
  685. ``error``.
  686. """
  687. pass
  688. @abstractproperty
  689. def cidr_block(self):
  690. """
  691. A CIDR block for this network.
  692. .. note:: OpenStack does not define a CIDR block for networks.
  693. :rtype: ``str``
  694. :return: A CIDR block string.
  695. """
  696. pass
  697. @abstractmethod
  698. def delete(self):
  699. """
  700. Delete this network.
  701. :rtype: ``bool``
  702. :return: ``True`` if successful.
  703. """
  704. pass
  705. @abstractmethod
  706. def subnets(self):
  707. """
  708. The associated subnets.
  709. :rtype: ``list`` of :class:`.Subnet`
  710. :return: List of subnets associated with this network.
  711. """
  712. pass
  713. @abstractmethod
  714. def create_subnet(self, cidr_block, name=None):
  715. """
  716. Create a new network subnet and associate it with this Network.
  717. :type cidr_block: ``str``
  718. :param cidr_block: CIDR block within this Network to assign to the
  719. subnet.
  720. :type name: ``str``
  721. :param name: An optional subnet name. The name will be set if the
  722. provider supports it.
  723. :rtype: ``object`` of :class:`.Subnet`
  724. :return: A Subnet object
  725. """
  726. pass
  727. class Subnet(CloudResource):
  728. """
  729. Represents a subnet, as part of a Network.
  730. """
  731. __metaclass__ = ABCMeta
  732. @abstractproperty
  733. def id(self):
  734. """
  735. Get the subnet identifier.
  736. :rtype: ``str``
  737. :return: ID for this network. Will generally correspond to the cloud
  738. middleware's ID, but should be treated as an opaque value.
  739. """
  740. pass
  741. @abstractproperty
  742. def name(self):
  743. """
  744. Get the subnet name.
  745. :rtype: ``str``
  746. :return: Name for this subnet as returned by the cloud middleware.
  747. """
  748. pass
  749. @abstractproperty
  750. def cidr_block(self):
  751. """
  752. A CIDR block for this subnet.
  753. :rtype: ``str``
  754. :return: A CIDR block string.
  755. """
  756. pass
  757. @abstractproperty
  758. def network_id(self):
  759. """
  760. ID of the network associated with this this subnet.
  761. :rtype: ``str``
  762. :return: Network ID.
  763. """
  764. pass
  765. @abstractmethod
  766. def delete(self):
  767. """
  768. Delete this subnet.
  769. :rtype: ``bool``
  770. :return: ``True`` if successful.
  771. """
  772. pass
  773. class FloatingIP(CloudResource):
  774. """
  775. Represents a floating (i.e., static) IP address.
  776. """
  777. __metaclass__ = ABCMeta
  778. @abstractproperty
  779. def id(self):
  780. """
  781. Get the address identifier.
  782. :rtype: ``str``
  783. :return: ID for this network. Will generally correspond to the cloud
  784. middleware's ID, but should be treated as an opaque value.
  785. """
  786. pass
  787. @abstractproperty
  788. def public_ip(self):
  789. """
  790. Public IP address.
  791. :rtype: ``str``
  792. :return: IP address.
  793. """
  794. pass
  795. @abstractproperty
  796. def private_ip(self):
  797. """
  798. Private IP address this address is attached to.
  799. :rtype: ``str``
  800. :return: IP address or ``None``.
  801. """
  802. pass
  803. @abstractmethod
  804. def in_use(self):
  805. """
  806. Whether the address is in use or not.
  807. :rtype: ``bool``
  808. :return: ``True`` if the address is attached to an instance.
  809. """
  810. pass
  811. @abstractmethod
  812. def delete(self):
  813. """
  814. Delete this address.
  815. :rtype: ``bool``
  816. :return: ``True`` if successful.
  817. """
  818. pass
  819. class RouterState(object):
  820. """
  821. Standard states for a router.
  822. :cvar UNKNOWN: Router state unknown.
  823. :cvar ATTACHED: Router is attached to a network and should be operational.
  824. :cvar DETACHED: Router is detached from a network.
  825. """
  826. UNKNOWN = "unknown"
  827. ATTACHED = "attached"
  828. DETACHED = "detached"
  829. class Router(CloudResource):
  830. """
  831. Represents a private network router.
  832. """
  833. __metaclass__ = ABCMeta
  834. @abstractproperty
  835. def id(self):
  836. """
  837. Get the router identifier.
  838. :rtype: ``str``
  839. :return: ID for this router. Will generally correspond to the cloud
  840. middleware's ID, but should be treated as an opaque value.
  841. """
  842. pass
  843. @abstractproperty
  844. def name(self):
  845. """
  846. Get the router name, if available.
  847. :rtype: ``str``
  848. :return: Name for this router.
  849. """
  850. pass
  851. @abstractmethod
  852. def refresh(self):
  853. """
  854. Update this object.
  855. """
  856. pass
  857. @abstractproperty
  858. def state(self):
  859. """
  860. Router state: attached or detached to a network.
  861. :rtype: ``str``
  862. :return: ``attached`` or ``detached``.
  863. """
  864. pass
  865. @abstractproperty
  866. def network_id(self):
  867. """
  868. ID of the network to which the router is attached.
  869. :rtype: ``str``
  870. :return: ID for the attached network or ``None``.
  871. """
  872. pass
  873. @abstractmethod
  874. def delete(self):
  875. """
  876. Delete this router.
  877. :rtype: ``bool``
  878. :return: ``True`` if successful.
  879. """
  880. pass
  881. @abstractmethod
  882. def attach_network(self, network_id):
  883. """
  884. Attach this router to a network.
  885. :type network_id: ``str``
  886. :param network_id: The ID of a network to which to attach this router.
  887. :rtype: ``bool``
  888. :return: ``True`` if successful.
  889. """
  890. pass
  891. @abstractmethod
  892. def detach_network(self):
  893. """
  894. Detach this router from a network.
  895. :rtype: ``bool``
  896. :return: ``True`` if successful.
  897. """
  898. pass
  899. @abstractmethod
  900. def add_route(self, subnet_id):
  901. """
  902. Add a route to this router.
  903. Note that a router must be attached to a network (to which the supplied
  904. subnet belongs to) before a route can be added.
  905. :type subnet_id: ``str``
  906. :param subnet_id: The ID of a subnet to add to this router.
  907. :rtype: ``bool``
  908. :return: ``True`` if successful.
  909. """
  910. pass
  911. @abstractmethod
  912. def remove_route(self, subnet_id):
  913. """
  914. Remove a route from this router.
  915. :type subnet_id: ``str``
  916. :param subnet_id: The ID of a subnet to remove to this router.
  917. :rtype: ``bool``
  918. :return: ``True`` if successful.
  919. """
  920. pass
  921. class AttachmentInfo(object):
  922. """
  923. Contains attachment information for a volume.
  924. """
  925. @abstractproperty
  926. def volume(self):
  927. """
  928. Get the volume instance related to this attachment.
  929. :rtype: ``Volume``
  930. :return: Volume object that this attachment info belongs to
  931. """
  932. pass
  933. @abstractproperty
  934. def instance_id(self):
  935. """
  936. Get the instance_id related to this attachment.
  937. :rtype: ``str``
  938. :return: Instance id that this attachment info belongs to
  939. """
  940. pass
  941. @abstractproperty
  942. def device(self):
  943. """
  944. Get the device the volume is mapped as.
  945. :rtype: ``str``
  946. :return: Device that the volume is mapped as
  947. """
  948. pass
  949. class VolumeState(object):
  950. """
  951. Standard states for a volume
  952. :cvar UNKNOWN: Volume state unknown.
  953. :cvar CREATING: Volume is being created.
  954. :cvar CONFIGURING: Volume is being configured in some way.
  955. :cvar AVAILABLE: Volume is available and can be attached to an instance.
  956. :cvar IN_USE: Volume is attached and in-use.
  957. :cvar DELETED: Volume has been deleted. No further operations possible.
  958. :cvar ERROR: Volume is in an error state. No further operations possible.
  959. """
  960. UNKNOWN = "unknown"
  961. CREATING = "creating"
  962. CONFIGURING = "configuring"
  963. AVAILABLE = "available"
  964. IN_USE = "in-use"
  965. DELETED = "deleted"
  966. ERROR = "error"
  967. class Volume(ObjectLifeCycleMixin, CloudResource):
  968. __metaclass__ = ABCMeta
  969. @abstractproperty
  970. def id(self):
  971. """
  972. Get the volume identifier.
  973. :rtype: ``str``
  974. :return: ID for this volume. Will generally correspond to the cloud
  975. middleware's ID, but should be treated as an opaque value.
  976. """
  977. pass
  978. @abstractproperty
  979. def name(self):
  980. """
  981. Get the volume name.
  982. :rtype: ``str``
  983. :return: Name for this volume as returned by the cloud middleware.
  984. """
  985. pass
  986. @name.setter
  987. @abstractmethod
  988. def name(self, value):
  989. """
  990. Set the volume name.
  991. """
  992. pass
  993. @abstractproperty
  994. def description(self):
  995. """
  996. Get the volume description. Some cloud providers may not support this
  997. property, and will return the volume name instead.
  998. :rtype: ``str``
  999. :return: Description for this volume as returned by the cloud
  1000. middleware.
  1001. """
  1002. pass
  1003. @description.setter
  1004. @abstractmethod
  1005. def description(self, value):
  1006. """
  1007. Set the volume description. Some cloud providers may not support this
  1008. property, and setting the description may have no effect. (Providers
  1009. that do not support this property will always return the volume name
  1010. as the description)
  1011. """
  1012. pass
  1013. @abstractproperty
  1014. def size(self):
  1015. """
  1016. Get the volume size (in GB).
  1017. :rtype: ``int``
  1018. :return: Size for this volume as returned by the cloud middleware.
  1019. """
  1020. pass
  1021. @abstractproperty
  1022. def create_time(self):
  1023. """
  1024. Get the creation data and time for this volume.
  1025. :rtype: ``DateTime``
  1026. :return: Creation time for this volume as returned by the cloud
  1027. middleware.
  1028. """
  1029. pass
  1030. @abstractproperty
  1031. def zone_id(self):
  1032. """
  1033. Get the placement zone id that this volume belongs to.
  1034. :rtype: ``str``
  1035. :return: PlacementZone for this volume as returned by the cloud
  1036. middleware.
  1037. """
  1038. pass
  1039. @abstractproperty
  1040. def source(self):
  1041. """
  1042. If available, get the source that this volume is based on (can be
  1043. a Snapshot or an Image). Returns None if no source.
  1044. :rtype: ``Snapshot` or ``Image``
  1045. :return: Snapshot or Image source for this volume as returned by the
  1046. cloud middleware.
  1047. """
  1048. pass
  1049. @abstractproperty
  1050. def attachments(self):
  1051. """
  1052. Get attachment information for this volume.
  1053. :rtype: ``AttachmentInfo``
  1054. :return: Returns an AttachmentInfo object.
  1055. """
  1056. pass
  1057. @abstractmethod
  1058. def attach(self, instance, device):
  1059. """
  1060. Attach this volume to an instance.
  1061. :type instance: ``str`` or :class:`.Instance` object
  1062. :param instance: The ID of an instance or an ``Instance`` object to
  1063. which this volume will be attached.
  1064. :type device: ``str``
  1065. :param device: The device on the instance through which the
  1066. volume will be exposed (e.g. /dev/sdh).
  1067. :rtype: ``bool``
  1068. :return: ``True`` if successful.
  1069. """
  1070. pass
  1071. @abstractmethod
  1072. def detach(self, force=False):
  1073. """
  1074. Detach this volume from an instance.
  1075. :type force: ``bool``
  1076. :param force: Forces detachment if the previous detachment attempt
  1077. did not occur cleanly. This option is supported on select
  1078. clouds only. This option can lead to data loss or a
  1079. corrupted file system. Use this option only as a last
  1080. resort to detach a volume from a failed instance. The
  1081. instance will not have an opportunity to flush file
  1082. system caches nor file system meta data. If you
  1083. use this option, you must perform file system check and
  1084. repair procedures.
  1085. :rtype: ``bool``
  1086. :return: ``True`` if successful.
  1087. """
  1088. pass
  1089. @abstractmethod
  1090. def create_snapshot(self, name, description=None):
  1091. """
  1092. Create a snapshot of this Volume.
  1093. :type name: ``str``
  1094. :param name: The name of this snapshot.
  1095. :type description: ``str``
  1096. :param description: A description of the snapshot.
  1097. Limited to 256 characters.
  1098. :rtype: :class:`.Snapshot`
  1099. :return: The created Snapshot object.
  1100. """
  1101. pass
  1102. @abstractmethod
  1103. def delete(self):
  1104. """
  1105. Delete this volume.
  1106. :rtype: ``bool``
  1107. :return: ``True`` if successful.
  1108. """
  1109. pass
  1110. class SnapshotState(object):
  1111. """
  1112. Standard states for a snapshot
  1113. :cvar UNKNOWN: Snapshot state unknown.
  1114. :cvar PENDING: Snapshot is pending.
  1115. :cvar CONFIGURING: Snapshot is being configured in some way.
  1116. :cvar AVAILABLE: Snapshot has been completed and is ready for use.
  1117. :cvar ERROR: Snapshot is in an error state. No further operations possible.
  1118. """
  1119. UNKNOWN = "unknown"
  1120. PENDING = "pending"
  1121. CONFIGURING = "configuring"
  1122. AVAILABLE = "available"
  1123. ERROR = "error"
  1124. class Snapshot(ObjectLifeCycleMixin, CloudResource):
  1125. __metaclass__ = ABCMeta
  1126. @abstractproperty
  1127. def id(self):
  1128. """
  1129. Get the snapshot identifier.
  1130. :rtype: ``str``
  1131. :return: ID for this snapshot. Will generally correspond to the cloud
  1132. middleware's ID, but should be treated as an opaque value.
  1133. """
  1134. pass
  1135. @abstractproperty
  1136. def name(self):
  1137. """
  1138. Get the snapshot name.
  1139. """
  1140. pass
  1141. @name.setter
  1142. @abstractmethod
  1143. def name(self, value):
  1144. """
  1145. Set the snapshot name.
  1146. """
  1147. pass
  1148. @abstractproperty
  1149. def description(self):
  1150. """
  1151. Get the snapshot description. Some cloud providers may not support this
  1152. property, and will return the snapshot name instead.
  1153. :rtype: ``str``
  1154. :return: Description for this snapshot as returned by the cloud
  1155. middleware.
  1156. """
  1157. pass
  1158. @description.setter
  1159. @abstractmethod
  1160. def description(self, value):
  1161. """
  1162. Set the snapshot description.
  1163. Some cloud providers may not support this property, and setting the
  1164. description may have no effect (providers that do not support this
  1165. property will always return the snapshot name as the description).
  1166. :type value: ``str``
  1167. :param value: The value for the snapshot description.
  1168. """
  1169. pass
  1170. @abstractproperty
  1171. def size(self):
  1172. """
  1173. Get the snapshot size (in GB).
  1174. :rtype: ``int``
  1175. :return: Size for this snapshot as returned by the cloud middleware.
  1176. """
  1177. pass
  1178. @abstractproperty
  1179. def volume_id(self):
  1180. """
  1181. Get the id of the volume that this snapshot is based on.
  1182. May return None if the source volume no longer exists.
  1183. :rtype: ``int``
  1184. :return: Id of the volume that this snapshot is based on
  1185. """
  1186. pass
  1187. @abstractproperty
  1188. def create_time(self):
  1189. """
  1190. Get the creation data and time for this snapshot.
  1191. :rtype: ``DateTime``
  1192. :return: Creation time for this snapshot as returned by the cloud
  1193. middleware.
  1194. """
  1195. pass
  1196. @abstractmethod
  1197. def create_volume(self, placement, size=None, volume_type=None, iops=None):
  1198. """
  1199. Create a new Volume from this Snapshot.
  1200. :type placement: ``str``
  1201. :param placement: The availability zone where to create the Volume.
  1202. :type size: ``int``
  1203. :param size: The size of the new volume, in GiB (optional). Defaults to
  1204. the size of the snapshot.
  1205. :type volume_type: ``str``
  1206. :param volume_type: The type of the volume (optional). Availability and
  1207. valid values depend on the provider.
  1208. :type iops: ``int``
  1209. :param iops: The provisioned IOPs you want to associate with
  1210. this volume (optional). Availability depends on the
  1211. provider.
  1212. :rtype: :class:`.Volume`
  1213. :return: An instance of the created Volume.
  1214. """
  1215. pass
  1216. # @abstractmethod
  1217. # def share(self, user_ids=None):
  1218. # """
  1219. # Share this Snapshot.
  1220. #
  1221. # :type user_ids: list of strings
  1222. # :param user_ids: A list of cloud provider compatible user IDs. If no
  1223. # IDs are specified, the snapshot is made public.
  1224. #
  1225. # :rtype: bool
  1226. # :return: ``True`` if successful.
  1227. # """
  1228. # pass
  1229. #
  1230. # @abstractmethod
  1231. # def unshare(self, user_ids=None):
  1232. # """
  1233. # Unshare this Snapshot.
  1234. #
  1235. # :type user_ids: list of strings
  1236. # :param user_ids: A list of cloud provider compatible user IDs. If no
  1237. # IDs are specified, the snapshot is made private.
  1238. #
  1239. # :rtype: bool
  1240. # :return: ``True`` if successful.
  1241. # """
  1242. # pass
  1243. @abstractmethod
  1244. def delete(self):
  1245. """
  1246. Delete this snapshot.
  1247. :rtype: ``bool``
  1248. :return: ``True`` if successful.
  1249. """
  1250. pass
  1251. class KeyPair(CloudResource):
  1252. __metaclass__ = ABCMeta
  1253. @abstractproperty
  1254. def id(self):
  1255. """
  1256. Return the id of this key pair.
  1257. :rtype: ``str``
  1258. :return: ID for this snapshot. Will generally correspond to the cloud
  1259. middleware's name, but should be treated as an opaque value.
  1260. """
  1261. pass
  1262. @abstractproperty
  1263. def name(self):
  1264. """
  1265. Return the name of this key pair.
  1266. :rtype: ``str``
  1267. :return: A name of this ssh key pair.
  1268. """
  1269. pass
  1270. @abstractproperty
  1271. def material(self):
  1272. """
  1273. Unencrypted private key.
  1274. :rtype: ``str``
  1275. :return: Unencrypted private key or ``None`` if not available.
  1276. """
  1277. pass
  1278. @abstractmethod
  1279. def delete(self):
  1280. """
  1281. Delete this key pair.
  1282. :rtype: ``bool``
  1283. :return: ``True`` if successful.
  1284. """
  1285. pass
  1286. class Region(CloudResource):
  1287. """
  1288. Represents a cloud region, typically a separate geographic area and will
  1289. contain at least one placement zone.
  1290. """
  1291. __metaclass__ = ABCMeta
  1292. @abstractproperty
  1293. def id(self):
  1294. """
  1295. The id for this region
  1296. :rtype: ``str``
  1297. :return: ID of the region.
  1298. """
  1299. pass
  1300. @abstractproperty
  1301. def name(self):
  1302. """
  1303. Name of the region.
  1304. :rtype: ``str``
  1305. :return: Name of the region.
  1306. """
  1307. pass
  1308. @abstractproperty
  1309. def zones(self):
  1310. """
  1311. Access information about placement zones within this region.
  1312. :rtype: Iterable
  1313. :return: Iterable of available placement zones in this region.
  1314. """
  1315. pass
  1316. class PlacementZone(CloudResource):
  1317. """
  1318. Represents a placement zone. A placement zone is contained within a Region.
  1319. """
  1320. __metaclass__ = ABCMeta
  1321. @abstractproperty
  1322. def id(self):
  1323. """
  1324. Name of the placement zone.
  1325. :rtype: ``str``
  1326. :return: Name of the placement zone.
  1327. """
  1328. pass
  1329. @abstractproperty
  1330. def name(self):
  1331. """
  1332. Name of the placement zone.
  1333. :rtype: ``str``
  1334. :return: Name of the placement zone.
  1335. """
  1336. pass
  1337. @abstractproperty
  1338. def region_name(self):
  1339. """
  1340. A region this placement zone is associated with.
  1341. :rtype: ``str``
  1342. :return: The name of the region the zone is associated with.
  1343. """
  1344. pass
  1345. class InstanceType(CloudResource):
  1346. """
  1347. An instance type object.
  1348. """
  1349. __metaclass__ = ABCMeta
  1350. @abstractproperty
  1351. def id(self):
  1352. pass
  1353. @abstractproperty
  1354. def name(self):
  1355. pass
  1356. @abstractproperty
  1357. def family(self):
  1358. """
  1359. The family/group that this instance type belongs to.
  1360. For example, General Purpose Instances or High-Memory Instances. If
  1361. the provider does not support such a grouping, it may return ``None``.
  1362. :rtype: ``str``
  1363. :return: Name of the instance family or ``None``.
  1364. """
  1365. pass
  1366. @abstractproperty
  1367. def vcpus(self):
  1368. """
  1369. The number of VCPUs supported by this instance type.
  1370. :rtype: ``int``
  1371. :return: Number of VCPUs.
  1372. """
  1373. pass
  1374. @abstractproperty
  1375. def ram(self):
  1376. """
  1377. The amount of RAM (in MB) supported by this instance type.
  1378. :rtype: ``int``
  1379. :return: Total RAM (in MB).
  1380. """
  1381. pass
  1382. @abstractproperty
  1383. def size_root_disk(self):
  1384. """
  1385. The size of this instance types's root disk (in GB).
  1386. :rtype: ``int``
  1387. :return: Size of root disk (in GB).
  1388. """
  1389. pass
  1390. @abstractproperty
  1391. def size_ephemeral_disks(self):
  1392. """
  1393. The size of this instance types's total ephemeral storage (in GB).
  1394. :rtype: ``int``
  1395. :return: Size of ephemeral disks (in GB).
  1396. """
  1397. pass
  1398. @abstractproperty
  1399. def num_ephemeral_disks(self):
  1400. """
  1401. The total number of ephemeral disks on this instance type.
  1402. :rtype: ``int``
  1403. :return: Number of ephemeral disks available.
  1404. """
  1405. pass
  1406. @abstractproperty
  1407. def size_total_disk(self):
  1408. """
  1409. The total disk space available on this instance type
  1410. (root_disk + ephemeral).
  1411. :rtype: ``int``
  1412. :return: Size of total disk space (in GB).
  1413. """
  1414. pass
  1415. @abstractproperty
  1416. def extra_data(self):
  1417. """
  1418. A dictionary of extra data about this instance. May contain
  1419. nested dictionaries, but all key value pairs are strings or integers.
  1420. :rtype: ``dict``
  1421. :return: Extra attributes for this instance type.
  1422. """
  1423. pass
  1424. class SecurityGroup(CloudResource):
  1425. __metaclass__ = ABCMeta
  1426. @abstractproperty
  1427. def id(self):
  1428. """
  1429. Get the ID of this security group.
  1430. :rtype: ``str``
  1431. :return: Security group ID.
  1432. """
  1433. pass
  1434. @abstractproperty
  1435. def name(self):
  1436. """
  1437. Return the name of this security group.
  1438. :rtype: ``str``
  1439. :return: A name of this security group.
  1440. """
  1441. pass
  1442. @abstractproperty
  1443. def description(self):
  1444. """
  1445. Return the description of this security group.
  1446. :rtype: ``str``
  1447. :return: A description of this security group.
  1448. """
  1449. pass
  1450. @abstractproperty
  1451. def rules(self):
  1452. """
  1453. Get the list of rules for this security group.
  1454. :rtype: list of :class:`.SecurityGroupRule`
  1455. :return: A list of security group rule objects.
  1456. """
  1457. pass
  1458. @abstractmethod
  1459. def delete(self):
  1460. """
  1461. Delete this security group.
  1462. :rtype: ``bool``
  1463. :return: ``True`` if successful.
  1464. """
  1465. pass
  1466. @abstractmethod
  1467. def add_rule(self, ip_protocol=None, from_port=None, to_port=None,
  1468. cidr_ip=None, src_group=None):
  1469. """
  1470. Create a security group rule. If the rule already exists, simply
  1471. returns it.
  1472. You need to pass in either ``src_group`` OR ``ip_protocol``,
  1473. ``from_port``, ``to_port``, and ``cidr_ip``. In other words, either
  1474. you are authorizing another group or you are authorizing some
  1475. ip-based rule.
  1476. :type ip_protocol: ``str``
  1477. :param ip_protocol: Either ``tcp`` | ``udp`` | ``icmp``.
  1478. :type from_port: ``int``
  1479. :param from_port: The beginning port number you are enabling.
  1480. :type to_port: ``int``
  1481. :param to_port: The ending port number you are enabling.
  1482. :type cidr_ip: ``str`` or list of ``str``
  1483. :param cidr_ip: The CIDR block you are providing access to.
  1484. :type src_group: :class:`.SecurityGroup`
  1485. :param src_group: The Security Group object you are granting access to.
  1486. :rtype: :class:`.SecurityGroupRule`
  1487. :return: Rule object if successful or ``None``.
  1488. """
  1489. pass
  1490. def get_rule(self, ip_protocol=None, from_port=None, to_port=None,
  1491. cidr_ip=None, src_group=None):
  1492. """
  1493. Get a security group rule with the specified parameters.
  1494. You need to pass in either ``src_group`` OR ``ip_protocol``,
  1495. ``from_port``, ``to_port``, and ``cidr_ip``. Note that when retrieving
  1496. a group rule, this method will return only one rule although possibly
  1497. several rules exist for the group rule. In that case, use the
  1498. ``.rules`` property and filter the results as desired.
  1499. :type ip_protocol: ``str``
  1500. :param ip_protocol: Either ``tcp`` | ``udp`` | ``icmp``.
  1501. :type from_port: ``int``
  1502. :param from_port: The beginning port number you are enabling.
  1503. :type to_port: ``int``
  1504. :param to_port: The ending port number you are enabling.
  1505. :type cidr_ip: ``str`` or list of ``str``
  1506. :param cidr_ip: The CIDR block you are providing access to.
  1507. :type src_group: :class:`.SecurityGroup`
  1508. :param src_group: The Security Group object you are granting access to.
  1509. :rtype: :class:`.SecurityGroupRule`
  1510. :return: Role object if one can be found or ``None``.
  1511. """
  1512. pass
  1513. class SecurityGroupRule(CloudResource):
  1514. """
  1515. Represents a security group rule.
  1516. """
  1517. __metaclass__ = ABCMeta
  1518. @abstractproperty
  1519. def id(self):
  1520. """
  1521. ID for this rule.
  1522. Note that this may be a CloudBridge-specific ID if the underlying
  1523. provider does not support rule IDs.
  1524. :rtype: ``str``
  1525. :return: Role ID.
  1526. """
  1527. pass
  1528. @abstractproperty
  1529. def ip_protocol(self):
  1530. """
  1531. IP protocol used. Either ``tcp`` | ``udp`` | ``icmp``.
  1532. :rtype: ``str``
  1533. :return: Active protocol.
  1534. """
  1535. pass
  1536. @abstractproperty
  1537. def from_port(self):
  1538. """
  1539. Lowest port number opened as part of this rule.
  1540. :rtype: ``int``
  1541. :return: Lowest port number or 0 if not set.
  1542. """
  1543. pass
  1544. @abstractproperty
  1545. def to_port(self):
  1546. """
  1547. Highest port number opened as part of this rule.
  1548. :rtype: ``int``
  1549. :return: Highest port number or 0 if not set.
  1550. """
  1551. pass
  1552. @abstractproperty
  1553. def cidr_ip(self):
  1554. """
  1555. CIDR block this security group is providing access to.
  1556. :rtype: ``str``
  1557. :return: CIDR block.
  1558. """
  1559. pass
  1560. @abstractproperty
  1561. def group(self):
  1562. """
  1563. Security group given access permissions by this rule.
  1564. :rtype: :class:``.SecurityGroup``
  1565. :return: The Security Group with granting access.
  1566. """
  1567. pass
  1568. @abstractmethod
  1569. def delete(self):
  1570. """
  1571. Delete this rule.
  1572. """
  1573. pass
  1574. class BucketObject(CloudResource):
  1575. """
  1576. Represents an object stored within a bucket.
  1577. """
  1578. __metaclass__ = ABCMeta
  1579. @abstractproperty
  1580. def id(self):
  1581. """
  1582. Get this object's id.
  1583. :rtype: ``str``
  1584. :return: id of this object as returned by the cloud middleware.
  1585. """
  1586. pass
  1587. @abstractproperty
  1588. def name(self):
  1589. """
  1590. Get this object's name.
  1591. :rtype: ``str``
  1592. :return: Name of this object as returned by the cloud middleware.
  1593. """
  1594. pass
  1595. @abstractproperty
  1596. def size(self):
  1597. """
  1598. Get this object's size.
  1599. :rtype: ``int``
  1600. :return: Size of this object in bytes.
  1601. """
  1602. pass
  1603. @abstractproperty
  1604. def last_modified(self):
  1605. """
  1606. Get the date and time this object was last modified.
  1607. :rtype: ``str``
  1608. :return: Date and time formatted string %Y-%m-%dT%H:%M:%S.%f
  1609. """
  1610. pass
  1611. @abstractmethod
  1612. def iter_content(self):
  1613. """
  1614. Returns this object's content as an iterable.
  1615. :rtype: Iterable
  1616. :return: An iterable of the file contents
  1617. """
  1618. pass
  1619. @abstractmethod
  1620. def save_content(self, target_stream):
  1621. """
  1622. Save this object and write its contents to the ``target_stream``.
  1623. """
  1624. pass
  1625. @abstractmethod
  1626. def upload(self, source_stream):
  1627. """
  1628. Set the contents of this object to the data read from the source
  1629. stream.
  1630. :rtype: ``bool``
  1631. :return: ``True`` if successful.
  1632. """
  1633. pass
  1634. @abstractmethod
  1635. def delete(self):
  1636. """
  1637. Delete this object.
  1638. :rtype: ``bool``
  1639. :return: ``True`` if successful.
  1640. """
  1641. pass
  1642. class Bucket(PageableObjectMixin, CloudResource):
  1643. __metaclass__ = ABCMeta
  1644. @abstractproperty
  1645. def id(self):
  1646. """
  1647. Get this bucket's id.
  1648. :rtype: ``str``
  1649. :return: ID of this bucket as returned by the cloud middleware.
  1650. """
  1651. pass
  1652. @abstractproperty
  1653. def name(self):
  1654. """
  1655. Get this bucket's name.
  1656. :rtype: ``str``
  1657. :return: Name of this bucket as returned by the cloud middleware.
  1658. """
  1659. pass
  1660. @abstractmethod
  1661. def get(self, key):
  1662. """
  1663. Retrieve a given object from this bucket.
  1664. :type key: ``str``
  1665. :param key: the identifier of the object to retrieve
  1666. :rtype: :class:``.BucketObject``
  1667. :return: The BucketObject or ``None`` if it cannot be found.
  1668. """
  1669. pass
  1670. @abstractmethod
  1671. def list(self, limit=None, marker=None):
  1672. """
  1673. List all objects within this bucket.
  1674. :rtype: :class:``.BucketObject``
  1675. :return: List of all available BucketObjects within this bucket.
  1676. """
  1677. pass
  1678. @abstractmethod
  1679. def delete(self, delete_contents=False):
  1680. """
  1681. Delete this bucket.
  1682. :type delete_contents: ``bool``
  1683. :param delete_contents: If ``True``, all objects within the bucket
  1684. will be deleted.
  1685. :rtype: ``bool``
  1686. :return: ``True`` if successful.
  1687. """
  1688. pass
  1689. @abstractmethod
  1690. def create_object(self, name):
  1691. """
  1692. Creates a new object within this bucket.
  1693. :rtype: :class:``.BucketObject``
  1694. :return: The newly created bucket object
  1695. """
  1696. pass