resources.py 63 KB

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