resources.py 56 KB

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