resources.py 61 KB

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