| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337 |
- """
- Specifications for data objects exposed through a provider or service
- """
- from abc import ABCMeta, abstractmethod, abstractproperty
- from enum import Enum
- class CloudServiceType(object):
- """
- Defines possible service types that are offered by providers.
- Providers can implement the ``has_service`` method and clients can check
- for the availability of a service with::
- if (provider.has_service(CloudServiceTypes.BUCKET))
- ...
- """
- COMPUTE = 'compute'
- IMAGE = 'image'
- SECURITY = 'security'
- VOLUME = 'storage.volumes'
- BUCKET = 'storage.buckets'
- class CloudResource(object):
- """
- Base interface for any Resource supported by a provider. This interface
- has a _provider property that can be used to access the provider
- associated with the resource, which is only intended for use by subclasses.
- Every cloudbridge resource also has an id and name property. The id
- property is a unique identifier for the resource. The name property is a
- display value.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def _provider(self):
- """
- Returns the provider instance associated with this resource. Intended
- for use by subclasses only.
- :rtype: :class:`.CloudProvider`
- :return: a CloudProvider object
- """
- pass
- @abstractproperty
- def id(self):
- """
- Get the resource identifier. The id property is used to uniquely
- identify the resource, and is an opaque value which should not be
- interpreted by cloudbridge clients, and is a value meaningful to
- the underlying cloud provider.
- :rtype: ``str``
- :return: ID for this resource as returned by the cloud middleware.
- """
- pass
- @abstractproperty
- def name(self):
- """
- Get the resource name. The name property is typically a user-friendly
- display value for the resource. Some resources may allow the resource
- name to be set.
- The name property adheres to the following restrictions for most
- cloudbridge resources:
- * Names cannot be longer than 63 characters
- * May only contain lowercase letters, numeric characters, underscores,
- and dashes. International characters are allowed.
- Some resources may relax/increase these restrictions (e.g. Buckets)
- depending on their requirements. Consult the resource specific
- documentation for exact restrictions.
- :rtype: ``str``
- :return: Name for this instance as returned by the cloud middleware.
- """
- pass
- @abstractmethod
- def to_json(self):
- """
- Returns a JSON representation of the CloudResource object.
- """
- pass
- class Configuration(dict):
- """
- Represents a cloudbridge configuration object
- """
- @abstractproperty
- def default_result_limit(self):
- """
- Get the default maximum number of results to return for a
- list method. The default limit will be applied to most list()
- and find() methods whenever an explicit limit is not specified.
- :rtype: ``int``
- :return: The maximum number of results to return
- """
- pass
- @property
- def default_wait_timeout(self):
- """
- Gets the default wait timeout for LifeCycleObjects. The default
- wait timeout is applied in wait_for() and wait_till_ready() methods
- if no explicit timeout is specified.
- :rtype: ``int``
- :return: The maximum length of time (in seconds) to wait for the
- object to change to desired state.
- """
- pass
- @property
- def default_wait_interval(self):
- """
- Gets the default wait interval for LifeCycleObjects. The default
- wait interval is applied in wait_for() and wait_till_ready() methods
- if no explicit interval is specified.
- :rtype: ``int``
- :return: How frequently to poll the object's state
- """
- pass
- @abstractproperty
- def debug_mode(self):
- """
- A flag indicating whether CloudBridge is in debug mode. Setting
- this to True will cause the underlying provider's debug
- output to be turned on.
- The flag can be toggled by sending in the cb_debug value via
- the config dictionary, or setting the CB_DEBUG environment variable.
- :rtype: ``bool``
- :return: Whether debug mode is on.
- """
- class ObjectLifeCycleMixin(object):
- """
- A mixin for an object with a defined life-cycle, such as an Instance,
- Volume, Image or Snapshot. An object that supports ObjectLifeCycleMixin
- will always have a state, defining which point in its life cycle it is
- currently at.
- It also defines a wait_till_ready operation, which indicates that the
- object is in a state in its life cycle where it is ready to be used by an
- end-user.
- A refresh operation allows the object to synchronise its state with the
- service provider.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def _provider(self):
- """
- Obtain the provider associated with this object. Used internally
- to access the provider config and get default timeouts/intervals.
- :rtype: :class:`.CloudProvider`
- :return: The provider associated with this Resource
- """
- pass
- @abstractproperty
- def state(self):
- """
- Get the current state of this object.
- :rtype: ``str``
- :return: The current state as a string.
- """
- pass
- @abstractmethod
- def refresh(self):
- """
- Refresh this object's state and synchronize it with the underlying
- service provider.
- """
- pass
- @abstractmethod
- def wait_for(self, target_states, terminal_states=None, timeout=None,
- interval=None):
- """
- Wait for a specified timeout for an object to reach a set of desired
- target states. If the object does not reach the desired state within
- the specified timeout, a ``WaitStateException`` will be raised.
- The optional terminal_states property can be used to specify an
- additional set of states which, should the object reach one,
- the object thereafter will not transition into the desired target
- state. Should this happen, a ``WaitStateException`` will be raised.
- Example:
- .. code-block:: python
- instance.wait_for(
- [InstanceState.DELETED, InstanceState.UNKNOWN],
- terminal_states=[InstanceState.ERROR])
- :type target_states: ``list`` of states
- :param target_states: The list of target states to wait for.
- :type terminal_states: ``list`` of states
- :param terminal_states: A list of terminal states after which the
- object will not transition into a target state.
- A WaitStateException will be raised if the
- object transition into a terminal state.
- :type timeout: ``int``
- :param timeout: The maximum length of time (in seconds) to wait for the
- object to changed to desired state. If no timeout is
- specified, the global default_wait_timeout defined in
- the provider config will apply.
- :type interval: ``int``
- :param interval: How frequently to poll the object's state (in
- seconds). If no interval is specified, the global
- default_wait_interval defined in the provider config
- will apply.
- :rtype: ``True``
- :return: Returns ``True`` if successful. A ``WaitStateException``
- exception may be thrown by the underlying service if the
- object cannot get into a ready state (e.g. if the object
- is in an error state).
- """
- pass
- @abstractmethod
- def wait_till_ready(self, timeout, interval):
- """
- A convenience method to wait till the current object reaches a state
- which is ready for use, which is any state where the end-user can
- successfully interact with the object.
- Will throw a ``WaitStateException`` if the object is not ready within
- the specified timeout.
- :type timeout: ``int``
- :param timeout: The maximum length of time (in seconds) to wait for the
- object to become ready.
- :type interval: ``int``
- :param interval: How frequently to poll the object's ready state (in
- seconds).
- :rtype: ``True``
- :return: Returns ``True`` if successful. A ``WaitStateException``
- exception may be thrown by the underlying service if the
- object cannot get into a ready state (e.g. if the object
- is in an error state).
- """
- pass
- class PageableObjectMixin(object):
- """
- A marker interface for objects which support paged iteration through
- a list of objects with a list(limit, marker) method.
- """
- @abstractmethod
- def __iter__(self):
- """
- Enables iteration through this object. Typically, an implementation
- will call the list(limit, marker) method to transparently page
- additional objects in as iteration progresses.
- """
- pass
- @abstractmethod
- def list(self, limit=None, marker=None):
- """
- Returns a list of objects up to a maximum limit.
- If a limit and marker are specified, the records will be fetched up to
- the limit starting from the marker onwards. The returned list is a list
- of class ResultList, which has extra properties like is_truncated,
- supports_total and total_records to provide extra information
- about record availability.
- If limit is not specified, the limit will default to the underlying
- provider's default limit. Therefore, you need to check the is_truncated
- property to determine whether more records are available.
- The total number of results can be determined through the total_results
- property. Not all provides will support returning the total_results
- property, so the supports_total property can be used to determine
- whether a total is supported.
- To iterate through all the records, it will be easier to iterate
- directly through the instances using __iter__ instead of calling
- the list method. The __iter__ method will automatically call the list
- method to fetch a batch of records at a time.
- Example:
- .. code-block:: python
- # get first page of results
- instlist = provider.compute.instances.list(limit=50)
- for instance in instlist:
- print("Instance Data: {0}", instance)
- if instlist.supports_total:
- print("Total results: {0}".format(instlist.total_results))
- else:
- print("Total records unknown,"
- "but has more data?: {0}".format(instlist.is_truncated))
- # Page to next set of results
- if (instlist.is_truncated)
- instlist = provider.compute.instances.list(limit=100,
- marker=instlist.marker)
- # Alternative: iterate through every available record
- for instance in provider.compute.instances:
- print(instance)
- """
- pass
- class ResultList(list):
- """
- This is a wrapper class around a standard Python :py:class:`list` class
- and provides some extra properties to aid with paging through a large
- number of results.
- Example:
- .. code-block:: python
- # get first page of results
- rl = provider.compute.instances.list(limit=50)
- for result in rl:
- print("Instance Data: {0}", result)
- if rl.supports_total:
- print("Total results: {0}".format(rl.total_results))
- else:
- print("Total records unknown,"
- "but has more data?: {0}."format(rl.is_truncated))
- # Page to next set of results
- if (rl.is_truncated)
- rl = provider.compute.instances.list(limit=100,
- marker=rl.marker)
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def marker(self):
- """
- This is an opaque identifier used to assist in paging through very long
- lists of objects. This marker can be provided to the list method to get
- the next set of results.
- """
- pass
- @abstractproperty
- def is_truncated(self):
- """
- Indicates whether this result list has more results
- that can be paged in.
- """
- pass
- @abstractproperty
- def supports_total(self):
- """
- Indicates whether the provider supports returning the total number of
- available results. The supports_total property should be checked
- before accessing the total_results property.
- """
- pass
- @abstractproperty
- def total_results(self):
- """
- Indicates the total number of results for a particular query. The
- supports_total property should be used to check whether the provider
- supports returning the total number of results, before accessing this
- property, or the behaviour is indeterminate.
- """
- pass
- @abstractproperty
- def supports_server_paging(self):
- """
- Indicates whether this ResultList supports client side paging or server
- side paging. If server side paging is not supported, the data property
- provides direct access to all available data.
- """
- pass
- @abstractproperty
- def data(self):
- pass
- class InstanceState(object):
- """
- Standard states for a node
- :cvar UNKNOWN: Instance state unknown.
- :cvar PENDING: Instance is pending
- :cvar CONFIGURING: Instance is being reconfigured in some way.
- :cvar RUNNING: Instance is running.
- :cvar REBOOTING: Instance is rebooting.
- :cvar DELETED: Instance is deleted. No further operations possible.
- :cvar STOPPED: Instance is stopped. Instance can be resumed.
- :cvar ERROR: Instance is in an error state. No further operations possible.
- """
- UNKNOWN = "unknown"
- PENDING = "pending"
- CONFIGURING = "configuring"
- RUNNING = "running"
- REBOOTING = "rebooting"
- DELETED = "deleted"
- STOPPED = "stopped"
- ERROR = "error"
- class Instance(ObjectLifeCycleMixin, CloudResource):
- __metaclass__ = ABCMeta
- @CloudResource.name.setter
- @abstractmethod
- def name(self, value):
- """
- Set the instance name.
- """
- pass
- @abstractproperty
- def public_ips(self):
- """
- Get all the public IP addresses for this instance.
- :rtype: ``list``
- :return: A list of public IP addresses associated with this instance.
- """
- pass
- @abstractproperty
- def private_ips(self):
- """
- Get all the private IP addresses for this instance.
- :rtype: ``list``
- :return: A list of private IP addresses associated with this instance.
- """
- pass
- @abstractproperty
- def vm_type_id(self):
- """
- Get the vm type id for this instance. This will typically be a
- string value like 'm1.large'. On OpenStack, this may be a number or
- UUID. To get the full :class:``.VMType``
- object, you can use the instance.vm_type property instead.
- :rtype: ``str``
- :return: VM type name for this instance (e.g., ``m1.large``)
- """
- pass
- @abstractproperty
- def vm_type(self):
- """
- Retrieve full VM type information for this instance.
- :rtype: :class:`.VMType`
- :return: VM type for this instance
- """
- pass
- @abstractmethod
- def reboot(self):
- """
- Reboot this instance (using the cloud middleware API).
- :rtype: ``bool``
- :return: ``True`` if the reboot was successful; ``False`` otherwise.
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Permanently delete this instance.
- """
- pass
- @abstractproperty
- def image_id(self):
- """
- Get the image ID for this instance.
- :rtype: ``str``
- :return: Image ID (i.e., AMI) this instance is using.
- """
- pass
- @abstractproperty
- def zone_id(self):
- """
- Get the placement zone ID where this instance is running.
- :rtype: ``str``
- :return: Region/zone/placement where this instance is running.
- """
- pass
- @abstractproperty
- def subnet_id(self):
- """
- Get the subnet ID where this instance is placed.
- :rtype: ``str``
- :return: Subnet ID to which this instance is connected.
- """
- pass
- # @abstractproperty
- # def mac_address(self):
- # """
- # Get the MAC address for this instance.
- #
- # :rtype: str
- # :return: MAC address for ths instance.
- # """
- # pass
- @abstractproperty
- def vm_firewalls(self):
- """
- Get the firewalls (security groups) associated with this instance.
- :rtype: list or :class:`.VMFirewall` objects
- :return: A list of VMFirewall objects associated with this instance.
- """
- pass
- @abstractproperty
- def vm_firewall_ids(self):
- """
- Get the IDs of the VM firewalls associated with this instance.
- :rtype: list or :class:``str``
- :return: A list of the VMFirewall IDs associated with this instance.
- """
- pass
- @abstractproperty
- def key_pair_name(self):
- """
- Get the name of the key pair associated with this instance.
- :rtype: ``str``
- :return: Name of the ssh key pair associated with this instance.
- """
- pass
- @abstractmethod
- def create_image(self, name):
- """
- Create a new image based on this instance.
- :rtype: :class:``.Image``
- :return: an Image object
- """
- pass
- @abstractmethod
- def add_floating_ip(self, floating_ip):
- """
- Add a public IP address to this instance.
- :type floating_ip: :class:``.FloatingIP`` or floating IP ID
- :param floating_ip: The FloatingIP object to associate with the
- instance. Note that is not the actual public IP
- address but the CloudBridge object encapsulating
- the IP or the respective provider ID that
- identifies the address.
- """
- pass
- @abstractmethod
- def remove_floating_ip(self, floating_ip):
- """
- Remove a public IP address from this instance.
- :type floating_ip: :class:``.FloatingIP`` or floating IP ID
- :param floating_ip: The FloatingIP object to remove from the
- instance. Note that is not the actual public IP
- address but the CloudBridge object encapsulating
- the IP or the respective provider ID that
- identifies the address.
- """
- pass
- @abstractmethod
- def add_vm_firewall(self, firewall):
- """
- Add a VM firewall to this instance
- :type firewall: :class:``.VMFirewall``
- :param firewall: The VMFirewall to associate with the instance.
- """
- pass
- @abstractmethod
- def remove_vm_firewall(self, firewall):
- """
- Remove a VM firewall from this instance
- :type firewall: ``VMFirewall``
- :param firewall: The VMFirewall to associate with the instance.
- """
- pass
- class MachineImageState(object):
- """
- Standard states for a machine image
- :cvar UNKNOWN: Image state unknown.
- :cvar PENDING: Image is pending
- :cvar AVAILABLE: Image is available
- :cvar ERROR: Image is in an error state. Not recoverable.
- """
- UNKNOWN = "unknown"
- PENDING = "pending"
- AVAILABLE = "available"
- ERROR = "error"
- class LaunchConfig(object):
- """
- Represents an advanced launch configuration object.
- Theis object can contain information such as BlockDeviceMappings
- configurations, and other advanced options which may be useful when
- launching an instance.
- Example:
- .. code-block:: python
- lc = provider.compute.instances.create_launch_config()
- lc.add_block_device(...)
- inst = provider.compute.instances.create(name, image, vm_type,
- network, launch_config=lc)
- """
- @abstractmethod
- def add_ephemeral_device(self):
- """
- Adds a new ephemeral block device mapping to the boot configuration.
- This can be used to add existing ephemeral devices to the instance.
- (The total number of ephemeral devices available for a particular
- VMType can be determined by querying the VMType service).
- Note that on some services, such as AWS, ephemeral devices must be
- added in as a device mapping at instance creation time, and cannot be
- added afterwards.
- Note that the device name, such as /dev/sda1, cannot be selected at
- present, since this tends to be provider and VM type specific.
- However, the order of device addition coupled with device type will
- generally determine naming order, with devices added first getting
- lower letters than instances added later.
- Example:
- .. code-block:: python
- lc = provider.compute.instances.create_launch_config()
- # 1. Add all available ephemeral devices
- vm_type = provider.compute.vm_types.find(name='m1.tiny')[0]
- for i in range(vm_type.num_ephemeral_disks):
- lc.add_ephemeral_device()
- """
- pass
- @abstractmethod
- def add_volume_device(self, source=None, is_root=None, size=None,
- delete_on_terminate=None):
- """
- Adds a new volume based block device mapping to the boot configuration.
- The volume can be based on a snapshot, image, existing volume or
- be a blank new volume, and is specified by the source parameter.
- The property is_root can be set to True to override any existing root
- device mappings. Otherwise, the default behaviour is to add new block
- devices to the instance.
- Note that the device name, such as /dev/sda1, cannot be selected at
- present, since this tends to be provider and VM type specific.
- However, the order of device addition coupled with device type will
- generally determine naming order, with devices added first getting
- lower letters than instances added later (except when is_root is set).
- Example:
- .. code-block:: python
- lc = provider.compute.instances.create_launch_config()
- # 1. Create and attach an empty volume of size 100GB
- lc.add_volume_device(size=100, delete_on_terminate=True)
- # 2. Create and attach a volume based on a snapshot
- snap = provider.storage.snapshots.get('<my_snapshot_id>')
- lc.add_volume_device(source=snap)
- # 3. Create+attach a volume based on an image and set it as root
- img = provider.compute.images.get('<my_image_id>')
- lc.add_volume_device(source=img, size=100, is_root=True)
- :type source: ``Volume``, ``Snapshot``, ``Image`` or None.
- :param source: The source ``block_device`` to add. If ``Volume``, the
- volume will be attached directly to the instance.
- If ``Snapshot``, a volume will be created based on the
- Snapshot and attached to the instance. If ``Image``,
- a volume based on the Image will be attached to the
- instance. If ``None``, the source is assumed to be
- a blank volume.
- :type is_root: ``bool``
- :param is_root: Determines which device will serve as the root device.
- If more than one device is defined as root, an
- ``InvalidConfigurationException`` will be thrown.
- :type size: ``int``
- :param size: The size of the volume to create. An implementation may
- ignore this parameter for certain sources like 'Volume'.
- :type delete_on_terminate: ``bool``
- :param delete_on_terminate: Determines whether to delete or keep the
- volume on instance termination.
- """
- pass
- class MachineImage(ObjectLifeCycleMixin, CloudResource):
- __metaclass__ = ABCMeta
- @abstractproperty
- def description(self):
- """
- Get the image description.
- :rtype: ``str``
- :return: Description for this image as returned by the cloud
- middleware.
- """
- pass
- @abstractproperty
- def min_disk(self):
- """
- Returns the minimum size of the disk that's required to
- boot this image (in GB)
- :rtype: ``int``
- :return: The minimum disk size needed by this image
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Delete this image
- :rtype: ``bool``
- :return: ``True`` if the operation succeeded.
- """
- pass
- class NetworkState(object):
- """
- Standard states for a network.
- :cvar UNKNOWN: Network state unknown.
- :cvar PENDING: Network is being created.
- :cvar AVAILABLE: Network is available.
- :cvar DOWN: Network is not operational.
- :cvar ERROR: Network errored.
- """
- UNKNOWN = "unknown"
- PENDING = "pending"
- AVAILABLE = "available"
- DOWN = "down"
- ERROR = "error"
- class Network(ObjectLifeCycleMixin, CloudResource):
- """
- Represents a software-defined network, like the Virtual Private Cloud.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def external(self):
- """
- A flag to indicate if this network is capable of Internet-connectivity.
- :rtype: ``bool``
- :return: ``True`` if the network can be connected to the Internet.
- """
- pass
- @abstractproperty
- def state(self):
- """
- The state of the network.
- :rtype: ``str``
- :return: One of ``unknown``, ``pending``, ``available``, ``down`` or
- ``error``.
- """
- pass
- @abstractproperty
- def cidr_block(self):
- """
- A CIDR block for this network.
- .. note:: OpenStack does not define a CIDR block for networks.
- :rtype: ``str``
- :return: A CIDR block string.
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Delete this network.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- @abstractproperty
- def subnets(self):
- """
- The associated subnets.
- :rtype: ``list`` of :class:`.Subnet`
- :return: List of subnets associated with this network.
- """
- pass
- @abstractmethod
- def create_subnet(self, name, cidr_block, zone=None):
- """
- Create a new network subnet and associate it with this Network.
- :type name: ``str``
- :param name: The subnet name. The name will be set if the
- provider supports it.
- :type cidr_block: ``str``
- :param cidr_block: CIDR block within this Network to assign to the
- subnet.
- :type zone: ``str``
- :param zone: Placement zone where to create the subnet. Some providers
- may not support subnet zones, in which case the value is
- ignored.
- :rtype: ``object`` of :class:`.Subnet`
- :return: A Subnet object
- """
- pass
- @abstractproperty
- def gateways(self):
- """
- Provides access to the internet gateways attached to this network.
- :rtype: :class:`.GatewayContainer`
- :return: A GatewayContainer object
- """
- pass
- class SubnetState(object):
- """
- Standard states for a subnet.
- :cvar UNKNOWN: Subnet state unknown.
- :cvar PENDING: Subnet is being created.
- :cvar AVAILABLE: Subnet is available.
- :cvar DOWN: Subnet is not operational.
- :cvar ERROR: Subnet errored.
- """
- UNKNOWN = "unknown"
- PENDING = "pending"
- AVAILABLE = "available"
- DOWN = "down"
- ERROR = "error"
- class Subnet(ObjectLifeCycleMixin, CloudResource):
- """
- Represents a subnet, as part of a Network.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def cidr_block(self):
- """
- A CIDR block for this subnet.
- :rtype: ``str``
- :return: A CIDR block string.
- """
- pass
- @abstractproperty
- def network_id(self):
- """
- ID of the network associated with this this subnet.
- :rtype: ``str``
- :return: Network ID.
- """
- pass
- @abstractproperty
- def zone(self):
- """
- Placement zone of the subnet.
- If the provider does not support subnet placement, return ``None``.
- :rtype: :class:`.PlacementZone` object
- :return: Placement zone of the subnet, or ``None`` if not defined.
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Delete this subnet.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- class FloatingIPContainer(PageableObjectMixin):
- """
- Base interface for a FloatingIP Service.
- """
- __metaclass__ = ABCMeta
- @abstractmethod
- def get(self, fip_id):
- """
- Returns a FloatingIP given its ID or ``None`` if not found.
- :type fip_id: ``str``
- :param fip_id: The ID of the FloatingIP to retrieve.
- :rtype: ``object`` of :class:`.FloatingIP`
- :return: a FloatingIP object
- """
- pass
- @abstractmethod
- def list(self, limit=None, marker=None):
- """
- List floating (i.e., static) IP addresses.
- :rtype: ``list`` of :class:`.FloatingIP`
- :return: list of FloatingIP objects
- """
- pass
- @abstractmethod
- def find(self, **kwargs):
- """
- Searches for a FloatingIP by a given list of attributes.
- Supported attributes: name, public_ip
- Example:
- .. code-block:: python
- fip = provider.networking.gateways.get('id').floating_ips.find(
- public_ip='public_ip')
- :rtype: List of ``object`` of :class:`.FloatingIP`
- :return: A list of FloatingIP objects matching the supplied attributes.
- """
- pass
- @abstractmethod
- def create(self):
- """
- Allocate a new floating (i.e., static) IP address.
- :rtype: ``object`` of :class:`.FloatingIP`
- :return: A FloatingIP object
- """
- pass
- @abstractmethod
- def delete(self, fip_id):
- """
- Delete an existing FloatingIP.
- :type fip_id: ``str``
- :param fip_id: The ID of the FloatingIP to be deleted.
- """
- pass
- class FloatingIpState(object):
- """
- Standard states for a floating ip.
- :cvar UNKNOWN: Floating IP state unknown.
- :cvar AVAILABLE: Floating IP is available.
- :cvar IN_USE: Floating IP is attached to a device.
- :cvar ERROR: Floating IP is in an error state.
- """
- UNKNOWN = "unknown"
- AVAILABLE = "available"
- IN_USE = "in_use"
- ERROR = "error"
- class FloatingIP(ObjectLifeCycleMixin, CloudResource):
- """
- Represents a floating (i.e., static) IP address.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def public_ip(self):
- """
- Public IP address.
- :rtype: ``str``
- :return: IP address.
- """
- pass
- @abstractproperty
- def private_ip(self):
- """
- Private IP address this address is attached to.
- :rtype: ``str``
- :return: IP address or ``None``.
- """
- pass
- @abstractproperty
- def in_use(self):
- """
- Whether the address is in use or not.
- :rtype: ``bool``
- :return: ``True`` if the address is attached to an instance.
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Delete this address.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- class RouterState(object):
- """
- Standard states for a router.
- :cvar UNKNOWN: Router state unknown.
- :cvar ATTACHED: Router is attached to a network and should be operational.
- :cvar DETACHED: Router is detached from a network.
- """
- UNKNOWN = "unknown"
- ATTACHED = "attached"
- DETACHED = "detached"
- class Router(CloudResource):
- """
- Represents a private network router.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def state(self):
- """
- Router state: attached or detached to a network.
- :rtype: ``str``
- :return: ``attached`` or ``detached``.
- """
- pass
- @abstractproperty
- def network_id(self):
- """
- ID of the network to which the router is attached.
- :rtype: ``str``
- :return: ID for the attached network or ``None``.
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Delete this router.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- @abstractmethod
- def attach_subnet(self, subnet):
- """
- Attach this router to a subnet.
- :type subnet: ``Subnet`` or ``str``
- :param subnet: The subnet to which to attach this router.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- @abstractmethod
- def detach_subnet(self, subnet):
- """
- Detach this subnet from a network.
- :type subnet: ``Subnet`` or ``str``
- :param subnet: The subnet to detach from this router.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- @abstractmethod
- def attach_gateway(self, gateway):
- """
- Attach a gateway to this router.
- :type gateway: ``Gateway``
- :param gateway: The Gateway to attach to this router.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- @abstractmethod
- def detach_gateway(self, gateway):
- """
- Detach this router from a gateway.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- class GatewayState(object):
- """
- Standard states for a gateway.
- :cvar UNKNOWN: Gateway state unknown.
- :cvar CONFIGURING: Gateway is being configured
- :cvar AVAILABLE: Gateway is ready
- :cvar ERROR: Gateway is ready
- """
- UNKNOWN = "unknown"
- CONFIGURING = "configuring"
- AVAILABLE = "available"
- ERROR = "error"
- class GatewayContainer(PageableObjectMixin):
- """
- Manage internet gateway resources.
- """
- __metaclass__ = ABCMeta
- @abstractmethod
- def get_or_create_inet_gateway(self, name=None):
- """
- Creates new or returns an existing internet gateway for a network.
- The returned gateway object can subsequently be attached to a router to
- provide internet routing to a network.
- :type name: ``str``
- :param name: The gateway name. This applies only if creating a gateway
- and if the provider supports it.
- :rtype: ``object`` of :class:`.InternetGateway` or ``None``
- :return: an InternetGateway object of ``None`` if not found.
- """
- pass
- @abstractmethod
- def delete(self, gateway):
- """
- Delete a gateway.
- :type gateway: :class:`.Gateway` object
- :param gateway: Gateway object to delete.
- """
- pass
- @abstractmethod
- def list(self, limit=None, marker=None):
- """
- List all available internet gateways.
- :rtype: ``list`` of :class:`.InternetGateway` or ``None``
- :return: Current list of internet gateways.
- """
- pass
- class Gateway(CloudResource):
- """
- Represents a gateway resource.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def network_id(self):
- """
- ID of the network to which the gateway is attached.
- :rtype: ``str``
- :return: ID for the attached network or ``None``.
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Delete this gateway. On some providers, if the gateway
- is public/a singleton, this operation will do nothing.
- """
- pass
- @abstractproperty
- def floating_ips(self):
- """
- Provides access to floating IPs connected to this internet gateway.
- :rtype: :class:`.FloatingIPContainer`
- :return: A FloatingIPContainer object
- """
- pass
- class InternetGateway(ObjectLifeCycleMixin, Gateway):
- """
- Represents an Internet gateway resource.
- """
- __metaclass__ = ABCMeta
- class AttachmentInfo(object):
- """
- Contains attachment information for a volume.
- """
- @abstractproperty
- def volume(self):
- """
- Get the volume instance related to this attachment.
- :rtype: ``Volume``
- :return: Volume object that this attachment info belongs to
- """
- pass
- @abstractproperty
- def instance_id(self):
- """
- Get the instance_id related to this attachment.
- :rtype: ``str``
- :return: Instance id that this attachment info belongs to
- """
- pass
- @abstractproperty
- def device(self):
- """
- Get the device the volume is mapped as.
- :rtype: ``str``
- :return: Device that the volume is mapped as
- """
- pass
- class VolumeState(object):
- """
- Standard states for a volume
- :cvar UNKNOWN: Volume state unknown.
- :cvar CREATING: Volume is being created.
- :cvar CONFIGURING: Volume is being configured in some way.
- :cvar AVAILABLE: Volume is available and can be attached to an instance.
- :cvar IN_USE: Volume is attached and in-use.
- :cvar DELETED: Volume has been deleted. No further operations possible.
- :cvar ERROR: Volume is in an error state. No further operations possible.
- """
- UNKNOWN = "unknown"
- CREATING = "creating"
- CONFIGURING = "configuring"
- AVAILABLE = "available"
- IN_USE = "in-use"
- DELETED = "deleted"
- ERROR = "error"
- class Volume(ObjectLifeCycleMixin, CloudResource):
- __metaclass__ = ABCMeta
- @CloudResource.name.setter
- @abstractmethod
- def name(self, value):
- """
- Set the volume name.
- """
- pass
- @abstractproperty
- def description(self):
- """
- Get the volume description. Some cloud providers may not support this
- property, and will return the volume name instead.
- :rtype: ``str``
- :return: Description for this volume as returned by the cloud
- middleware.
- """
- pass
- @description.setter
- @abstractmethod
- def description(self, value):
- """
- Set the volume description. Some cloud providers may not support this
- property, and setting the description may have no effect. (Providers
- that do not support this property will always return the volume name
- as the description)
- """
- pass
- @abstractproperty
- def size(self):
- """
- Get the volume size (in GB).
- :rtype: ``int``
- :return: Size for this volume as returned by the cloud middleware.
- """
- pass
- @abstractproperty
- def create_time(self):
- """
- Get the creation data and time for this volume.
- :rtype: ``DateTime``
- :return: Creation time for this volume as returned by the cloud
- middleware.
- """
- pass
- @abstractproperty
- def zone_id(self):
- """
- Get the placement zone id that this volume belongs to.
- :rtype: ``str``
- :return: PlacementZone for this volume as returned by the cloud
- middleware.
- """
- pass
- @abstractproperty
- def source(self):
- """
- If available, get the source that this volume is based on (can be
- a Snapshot or an Image). Returns None if no source.
- :rtype: ``Snapshot` or ``Image``
- :return: Snapshot or Image source for this volume as returned by the
- cloud middleware.
- """
- pass
- @abstractproperty
- def attachments(self):
- """
- Get attachment information for this volume.
- :rtype: ``AttachmentInfo``
- :return: Returns an AttachmentInfo object.
- """
- pass
- @abstractmethod
- def attach(self, instance, device):
- """
- Attach this volume to an instance.
- :type instance: ``str`` or :class:`.Instance` object
- :param instance: The ID of an instance or an ``Instance`` object to
- which this volume will be attached.
- :type device: ``str``
- :param device: The device on the instance through which the
- volume will be exposed (e.g. /dev/sdh).
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- @abstractmethod
- def detach(self, force=False):
- """
- Detach this volume from an instance.
- :type force: ``bool``
- :param force: Forces detachment if the previous detachment attempt
- did not occur cleanly. This option is supported on select
- clouds only. This option can lead to data loss or a
- corrupted file system. Use this option only as a last
- resort to detach a volume from a failed instance. The
- instance will not have an opportunity to flush file
- system caches nor file system meta data. If you
- use this option, you must perform file system check and
- repair procedures.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- @abstractmethod
- def create_snapshot(self, name, description=None):
- """
- Create a snapshot of this Volume.
- :type name: ``str``
- :param name: The name of this snapshot.
- :type description: ``str``
- :param description: A description of the snapshot.
- Limited to 256 characters.
- :rtype: :class:`.Snapshot`
- :return: The created Snapshot object.
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Delete this volume.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- class SnapshotState(object):
- """
- Standard states for a snapshot
- :cvar UNKNOWN: Snapshot state unknown.
- :cvar PENDING: Snapshot is pending.
- :cvar CONFIGURING: Snapshot is being configured in some way.
- :cvar AVAILABLE: Snapshot has been completed and is ready for use.
- :cvar ERROR: Snapshot is in an error state. No further operations possible.
- """
- UNKNOWN = "unknown"
- PENDING = "pending"
- CONFIGURING = "configuring"
- AVAILABLE = "available"
- ERROR = "error"
- class Snapshot(ObjectLifeCycleMixin, CloudResource):
- __metaclass__ = ABCMeta
- @CloudResource.name.setter
- @abstractmethod
- def name(self, value):
- """
- Set the snapshot name.
- """
- pass
- @abstractproperty
- def description(self):
- """
- Get the snapshot description. Some cloud providers may not support this
- property, and will return the snapshot name instead.
- :rtype: ``str``
- :return: Description for this snapshot as returned by the cloud
- middleware.
- """
- pass
- @description.setter
- @abstractmethod
- def description(self, value):
- """
- Set the snapshot description.
- Some cloud providers may not support this property, and setting the
- description may have no effect (providers that do not support this
- property will always return the snapshot name as the description).
- :type value: ``str``
- :param value: The value for the snapshot description.
- """
- pass
- @abstractproperty
- def size(self):
- """
- Get the snapshot size (in GB).
- :rtype: ``int``
- :return: Size for this snapshot as returned by the cloud middleware.
- """
- pass
- @abstractproperty
- def volume_id(self):
- """
- Get the id of the volume that this snapshot is based on.
- May return None if the source volume no longer exists.
- :rtype: ``int``
- :return: Id of the volume that this snapshot is based on
- """
- pass
- @abstractproperty
- def create_time(self):
- """
- Get the creation data and time for this snapshot.
- :rtype: ``DateTime``
- :return: Creation time for this snapshot as returned by the cloud
- middleware.
- """
- pass
- @abstractmethod
- def create_volume(self, placement, size=None, volume_type=None, iops=None):
- """
- Create a new Volume from this Snapshot.
- :type placement: ``str``
- :param placement: The availability zone where to create the Volume.
- :type size: ``int``
- :param size: The size of the new volume, in GiB (optional). Defaults to
- the size of the snapshot.
- :type volume_type: ``str``
- :param volume_type: The type of the volume (optional). Availability and
- valid values depend on the provider.
- :type iops: ``int``
- :param iops: The provisioned IOPs you want to associate with
- this volume (optional). Availability depends on the
- provider.
- :rtype: :class:`.Volume`
- :return: An instance of the created Volume.
- """
- pass
- # @abstractmethod
- # def share(self, user_ids=None):
- # """
- # Share this Snapshot.
- #
- # :type user_ids: list of strings
- # :param user_ids: A list of cloud provider compatible user IDs. If no
- # IDs are specified, the snapshot is made public.
- #
- # :rtype: bool
- # :return: ``True`` if successful.
- # """
- # pass
- #
- # @abstractmethod
- # def unshare(self, user_ids=None):
- # """
- # Unshare this Snapshot.
- #
- # :type user_ids: list of strings
- # :param user_ids: A list of cloud provider compatible user IDs. If no
- # IDs are specified, the snapshot is made private.
- #
- # :rtype: bool
- # :return: ``True`` if successful.
- # """
- # pass
- @abstractmethod
- def delete(self):
- """
- Delete this snapshot.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- class KeyPair(CloudResource):
- __metaclass__ = ABCMeta
- @abstractproperty
- def material(self):
- """
- Unencrypted private key.
- :rtype: ``str``
- :return: Unencrypted private key or ``None`` if not available.
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Delete this key pair.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- class Region(CloudResource):
- """
- Represents a cloud region, typically a separate geographic area and will
- contain at least one placement zone.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def zones(self):
- """
- Access information about placement zones within this region.
- :rtype: Iterable
- :return: Iterable of available placement zones in this region.
- """
- pass
- class PlacementZone(CloudResource):
- """
- Represents a placement zone. A placement zone is contained within a Region.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def region_name(self):
- """
- A region this placement zone is associated with.
- :rtype: ``str``
- :return: The name of the region the zone is associated with.
- """
- pass
- class VMType(CloudResource):
- """
- A VM type object.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def family(self):
- """
- The family/group that this VM type belongs to.
- For example, General Purpose Instances or High-Memory Instances. If
- the provider does not support such a grouping, it may return ``None``.
- :rtype: ``str``
- :return: Name of the instance family or ``None``.
- """
- pass
- @abstractproperty
- def vcpus(self):
- """
- The number of VCPUs supported by this VM type.
- :rtype: ``int``
- :return: Number of VCPUs.
- """
- pass
- @abstractproperty
- def ram(self):
- """
- The amount of RAM (in GB) supported by this VM type.
- :rtype: ``float``
- :return: Total RAM (in GB).
- """
- pass
- @abstractproperty
- def size_root_disk(self):
- """
- The size of this VM types's root disk (in GB).
- :rtype: ``int``
- :return: Size of root disk (in GB).
- """
- pass
- @abstractproperty
- def size_ephemeral_disks(self):
- """
- The size of this VM types's total ephemeral storage (in GB).
- :rtype: ``int``
- :return: Size of ephemeral disks (in GB).
- """
- pass
- @abstractproperty
- def num_ephemeral_disks(self):
- """
- The total number of ephemeral disks on this VM type.
- :rtype: ``int``
- :return: Number of ephemeral disks available.
- """
- pass
- @abstractproperty
- def size_total_disk(self):
- """
- The total disk space available on this VM type
- (root_disk + ephemeral).
- :rtype: ``int``
- :return: Size of total disk space (in GB).
- """
- pass
- @abstractproperty
- def extra_data(self):
- """
- A dictionary of extra data about this instance. May contain
- nested dictionaries, but all key value pairs are strings or integers.
- :rtype: ``dict``
- :return: Extra attributes for this VM type.
- """
- pass
- class VMFirewall(CloudResource):
- __metaclass__ = ABCMeta
- @abstractproperty
- def description(self):
- """
- Return the description of this VM firewall.
- :rtype: ``str``
- :return: A description of this VM firewall.
- """
- pass
- @abstractproperty
- def network_id(self):
- """
- Network ID with which this VM firewall is associated.
- :rtype: ``str``
- :return: Provider-supplied network ID or ``None`` is not available.
- """
- pass
- @abstractproperty
- def rules(self):
- """
- Get a container for the rules belonging to this VM firewall. This
- object can be used for further operations on rules, such as get,
- list, create etc.
- :rtype: An object of :class:`.VMFirewallRuleContainer`
- :return: A VMFirewallRuleContainer for further operations
- """
- pass
- class VMFirewallRuleContainer(PageableObjectMixin):
- """
- Base interface for Firewall rules.
- """
- __metaclass__ = ABCMeta
- @abstractmethod
- def get(self, rule_id):
- """
- Returns a firewall rule given its ID. Returns ``None`` if the
- rule does not exist.
- Example:
- .. code-block:: python
- fw = provider.security.vm_firewalls.get('my_fw_id')
- rule = fw.rules.get('rule_id')
- print(rule.id, rule.name)
- :rtype: :class:`.FirewallRule`
- :return: a FirewallRule instance
- """
- pass
- @abstractmethod
- def list(self, limit=None, marker=None):
- """
- List all firewall rules associated with this firewall.
- :rtype: ``list`` of :class:`.FirewallRule`
- :return: list of Firewall rule objects
- """
- pass
- @abstractmethod
- def create(self, direction, protocol=None, from_port=None,
- to_port=None, cidr=None, src_dest_fw=None):
- """
- Create a VM firewall rule. If the rule already exists, simply
- returns it.
- Example:
- .. code-block:: python
- from cloudbridge.cloud.interfaces.resources import TrafficDirection
- fw = provider.security.vm_firewalls.get('my_fw_id')
- fw.rules.create(TrafficDirection.INBOUND, protocol='tcp',
- from_port=80, to_port=80, cidr='10.0.0.0/16')
- fw.rules.create(TrafficDirection.INBOUND, src_dest_fw=fw)
- fw.rules.create(TrafficDirection.OUTBOUND, src_dest_fw=fw)
- You need to pass in either ``src_dest_fw`` OR ``protocol`` AND
- ``from_port``, ``to_port``, ``cidr``. In other words, either
- you are authorizing another group or you are authorizing some
- IP-based rule.
- :type direction: :class:``.TrafficDirection``
- :param direction: Either ``TrafficDirection.INBOUND`` |
- ``TrafficDirection.OUTBOUND``
- :type protocol: ``str``
- :param protocol: Either ``tcp`` | ``udp`` | ``icmp``.
- :type from_port: ``int``
- :param from_port: The beginning port number you are enabling.
- :type to_port: ``int``
- :param to_port: The ending port number you are enabling.
- :type cidr: ``str`` or list of ``str``
- :param cidr: The CIDR block you are providing access to.
- :type src_dest_fw: :class:`.VMFirewall`
- :param src_dest_fw: The VM firewall object which is the
- source/destination of the traffic, depending on
- whether it's ingress/egress traffic.
- :rtype: :class:`.VMFirewallRule`
- :return: Rule object if successful or ``None``.
- """
- pass
- @abstractmethod
- def find(self, **kwargs):
- """
- Find a firewall rule associated with your account filtered by the given
- parameters.
- :type name: str
- :param name: The name of the VM firewall to retrieve.
- :type protocol: ``str``
- :param protocol: Either ``tcp`` | ``udp`` | ``icmp``.
- :type from_port: ``int``
- :param from_port: The beginning port number you are enabling.
- :type to_port: ``int``
- :param to_port: The ending port number you are enabling.
- :type cidr: ``str`` or list of ``str``
- :param cidr: The CIDR block you are providing access to.
- :type src_dest_fw: :class:`.VMFirewall`
- :param src_dest_fw: The VM firewall object which is the
- source/destination of the traffic, depending on
- whether it's ingress/egress traffic.
- :type src_dest_fw_id: :class:`.str`
- :param src_dest_fw_id: The VM firewall id which is the
- source/destination of the traffic, depending on
- whether it's ingress/egress traffic.
- :rtype: list of :class:`VMFirewallRule`
- :return: A list of VMFirewall objects or an empty list if none
- found.
- """
- pass
- @abstractmethod
- def delete(self, rule_id):
- """
- Delete an existing VMFirewall rule.
- :type rule_id: str
- :param rule_id: The VM firewall rule to be deleted.
- """
- pass
- class TrafficDirection(Enum):
- INBOUND = 'inbound'
- OUTBOUND = 'outbound'
- class VMFirewallRule(CloudResource):
- """
- Represents a VM firewall rule.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def direction(self):
- """
- Direction of traffic to which this rule applies.
- Either TrafficDirection.INBOUND | TrafficDirection.OUTBOUND
- :rtype: ``str``
- :return: Direction of traffic to which this rule applies
- """
- pass
- @abstractproperty
- def protocol(self):
- """
- IP protocol used. Either ``tcp`` | ``udp`` | ``icmp``.
- :rtype: ``str``
- :return: Active protocol.
- """
- pass
- @abstractproperty
- def from_port(self):
- """
- Lowest port number opened as part of this rule.
- :rtype: ``int``
- :return: Lowest port number or 0 if not set.
- """
- pass
- @abstractproperty
- def to_port(self):
- """
- Highest port number opened as part of this rule.
- :rtype: ``int``
- :return: Highest port number or 0 if not set.
- """
- pass
- @abstractproperty
- def cidr(self):
- """
- CIDR block this VM firewall is providing access to.
- :rtype: ``str``
- :return: CIDR block.
- """
- pass
- @abstractproperty
- def src_dest_fw_id(self):
- """
- VM firewall id given access permissions by this rule.
- :rtype: ``str``
- :return: The VM firewall granted access.
- """
- pass
- @abstractproperty
- def src_dest_fw(self):
- """
- VM firewall given access permissions by this rule.
- :rtype: :class:``.VMFirewall``
- :return: The VM firewall granted access.
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Delete this rule.
- """
- pass
- class BucketObject(CloudResource):
- """
- Represents an object stored within a bucket.
- """
- __metaclass__ = ABCMeta
- @abstractproperty
- def name(self):
- """
- The bucket object name adheres to a more relaxed naming requirement as
- detailed here: http://docs.aws.amazon.com/AmazonS3/latest/dev/Using
- Metadata.html#object-key-guidelines
- :rtype: ``str``
- :return: Name for this instance as returned by the cloud middleware.
- """
- pass
- @abstractproperty
- def size(self):
- """
- Get this object's size.
- :rtype: ``int``
- :return: Size of this object in bytes.
- """
- pass
- @abstractproperty
- def last_modified(self):
- """
- Get the date and time this object was last modified.
- :rtype: ``str``
- :return: Date and time formatted string %Y-%m-%dT%H:%M:%S.%f
- """
- pass
- @abstractmethod
- def iter_content(self):
- """
- Returns this object's content as an iterable.
- :rtype: Iterable
- :return: An iterable of the file contents
- """
- pass
- @abstractmethod
- def save_content(self, target_stream):
- """
- Save this object and write its contents to the ``target_stream``.
- """
- pass
- @abstractmethod
- def upload(self, source_stream):
- """
- Set the contents of this object to the data read from the source
- stream.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- @abstractmethod
- def upload_from_file(self, path):
- """
- Store the contents of the file pointed by the "path" variable.
- :type path: ``str``
- :param path: Absolute path to the file to be uploaded to S3.
- """
- pass
- @abstractmethod
- def delete(self):
- """
- Delete this object.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- @abstractmethod
- def generate_url(self, expires_in):
- """
- Generate a URL to this object.
- If the object is public, `expires_in` argument is not necessary, but if
- the object is private, the lifetime of URL is set using `expires_in`
- argument.
- :type expires_in: ``int``
- :param expires_in: Time to live of the generated URL in seconds.
- :rtype: ``str``
- :return: A URL to access the object.
- """
- pass
- @abstractmethod
- def refresh(self):
- """
- Refresh this object's state and synchronize it with the underlying
- service provider.
- """
- pass
- class Bucket(CloudResource):
- __metaclass__ = ABCMeta
- @abstractproperty
- def name(self):
- """
- The bucket name adheres to a more relaxed naming requirement as
- detailed here: http://docs.aws.amazon.com/awscloudtrail/latest/userguid
- e/cloudtrail-s3-bucket-naming-requirements.html
- :rtype: ``str``
- :return: Name for this instance as returned by the cloud middleware.
- """
- pass
- @abstractproperty
- def objects(self):
- """
- Get a container for the objects belonging to this Buckets. This
- object can be used to iterate through bucket objects, as well as
- perform further operations on buckets, such as get, list, create etc.
- .. code-block:: python
- # Show all objects in bucket
- print(list(bucket.objects))
- # Find an object by name
- print(bucket.objects.find(name='my_obj.txt'))
- # Get first page of bucket list
- print(bucket.objects.list())
- # Create a new object within this bucket
- obj = bucket.objects.create('my_obj.txt')
- :rtype: :class:`.BucketContainer`
- :return: A BucketContainer for further operations.
- """
- pass
- @abstractmethod
- def delete(self, delete_contents=False):
- """
- Delete this bucket.
- :type delete_contents: ``bool``
- :param delete_contents: If ``True``, all objects within the bucket
- will be deleted.
- :rtype: ``bool``
- :return: ``True`` if successful.
- """
- pass
- class BucketContainer(PageableObjectMixin):
- """
- A container service for objects within a bucket
- """
- __metaclass__ = ABCMeta
- @abstractmethod
- def get(self, name):
- """
- Retrieve a given object from this bucket.
- :type name: ``str``
- :param name: The identifier of the object to retrieve
- :rtype: :class:``.BucketObject``
- :return: The BucketObject or ``None`` if it cannot be found.
- """
- pass
- @abstractmethod
- # pylint:disable=arguments-differ
- def list(self, limit=None, marker=None, prefix=None):
- """
- List objects in this bucket.
- :type limit: ``int``
- :param limit: Maximum number of elements to return.
- :type marker: ``int``
- :param marker: Fetch results after this offset.
- :type prefix: ``str``
- :param prefix: Prefix criteria by which to filter listed objects.
- :rtype: List of ``objects`` of :class:``.BucketObject``
- :return: List of all available BucketObjects within this bucket.
- """
- pass
- @abstractmethod
- def find(self, **kwargs):
- """
- Searches for an object by a given list of attributes.
- Supported attributes: name
- :rtype: List of ``objects`` of :class:`.BucketObject`
- :return: A list of BucketObjects matching the supplied attributes.
- :type limit: ``int``
- :param limit: Maximum number of elements to return.
- :type marker: ``int``
- :param marker: Fetch results after this offset.
- """
- pass
- @abstractmethod
- def create(self, name):
- """
- Create a new object within this bucket.
- :rtype: :class:``.BucketObject``
- :return: The newly created bucket object
- """
- pass
|