resources.py 58 KB

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