resources.py 68 KB

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