Services

CloudService

class cloudbridge.cloud.interfaces.services.CloudService[source]

Base interface for any service supported by a provider. This interface has a provider property that can be used to access the provider associated with this service.

provider

Returns the provider instance associated with this service.

Return type:CloudProvider
Returns:a CloudProvider object

ComputeService

class cloudbridge.cloud.interfaces.services.ComputeService[source]

The compute service interface is a collection of services that provides access to the underlying compute related services in a provider. For example, the compute.instances service can be used to launch a new instance, and the compute.images service can be used to list available machine images.

images

Provides access to all Image related services in this provider. (e.g. Glance in OpenStack)

Example:

# print all images
for image in provider.compute.images:
    print(image.id, image.name, image.label)

# print only first 50 images
for image in provider.compute.images.list(limit=50):
    print(image.id, image.name, image.label)

# find image by name
image = provider.compute.images.find(name='Ubuntu 16.04')[0]
print(image.id, image.name, image.label)
Return type:ImageService
Returns:an ImageService object
instances

Provides access to all Instance related services in this provider.

Example:

# launch a new instance
image = provider.compute.images.find(name='Ubuntu 16.04')[0]
size = provider.compute.vm_types.find(name='m1.small')[0]
instance = provider.compute.instances.create('Hello', image, size)
print(instance.id, instance.label)
Return type:InstanceService
Returns:an InstanceService object
regions

Provides access to all Region related services in this provider.

Example:

for region in provider.compute.regions:
    print("Region: ", region.name)
    for zone in region.zones:
       print("\tZone: ", zone.name)
Return type:RegionService
Returns:a RegionService object
vm_types

Provides access to all VM type related services in this provider.

Example:

# list all VM sizes
for vm_type in provider.compute.vm_types:
    print(vm_type.id, vm_type.name)

# find a specific size by name
vm_type = provider.compute.vm_types.find(name='m1.small')[0]
print(vm_type.vcpus)
Return type:VMTypeService
Returns:an VMTypeService object

InstanceService

class cloudbridge.cloud.interfaces.services.InstanceService[source]

Provides access to instances in a provider, including creating, listing and deleting instances.

create(label, image, vm_type, subnet, zone=None, key_pair=None, vm_firewalls=None, user_data=None, launch_config=None, **kwargs)[source]

Creates a new virtual machine instance.

Parameters:
  • label (str) – The label of the virtual machine instance. The instance name will be derived from this label.
  • image (MachineImage or str) – The MachineImage object or id to boot the virtual machine with
  • vm_type (VMType or str) – The VMType or name, specifying the size of the instance to boot into
  • subnet (Subnet or str) –

    The subnet object or a subnet string ID with which the instance should be associated. The subnet is a mandatory parameter, and must be provided when launching an instance.

    Note: Older clouds (with classic networking), may not have proper subnet support and are not guaranteed to work. Some providers (e.g. OpenStack) support a null value but the behaviour is implementation specific.

  • zone (Zone or str) –

    The Zone or its id, where the instance should be placed. This parameter is provided for legacy compatibility (with classic networks).

    The subnet’s placement zone will take precedence over this parameter, but in its absence, this value will be used.

  • key_pair (KeyPair or str) – The KeyPair object or its id, to set for the instance.
  • vm_firewalls (A list of VMFirewall objects or a list of str object IDs) –

    A list of VMFirewall objects or a list of VMFirewall IDs, which should be assigned to this instance.

    The VM firewalls must be associated with the same network as the supplied subnet. Use network.vm_firewalls to retrieve a list of firewalls belonging to a network.

  • user_data (str) – An extra userdata object which is compatible with the provider.
  • launch_config (LaunchConfig object) – A LaunchConfig object which describes advanced launch configuration options for an instance. Currently, this includes only block_device_mappings. To construct a launch configuration object, call provider.compute.instances.create_launch_config()
Return type:

object of Instance

Returns:

an instance of Instance class

create_launch_config()[source]

Creates a LaunchConfig object which can be used to set additional options when launching an instance, such as block device mappings and network interfaces.

Return type:object of LaunchConfig
Returns:an instance of a LaunchConfig class
find(**kwargs)[source]

Searches for an instance by a given list of attributes.

Supported attributes: name, label

Parameters:
  • name (str) – The name to search for
  • label (str) – The label to search for
Return type:

List of object of Instance

Returns:

A list of Instance objects matching the supplied attributes.

get(instance_id)[source]

Returns an instance given its id. Returns None if the object does not exist.

Return type:object of Instance
Returns:an Instance object
list(limit=None, marker=None)[source]

List available instances.

The returned results can be limited with limit and marker. If not specified, the limit defaults to a global default. See list() for more information on how to page through returned results.

example:

# List instances
instlist = provider.compute.instances.list()
for instance in instlist:
    print("Instance Data: {0}", instance)
Parameters:
  • limit (int) – The maximum number of objects to return. Note that the maximum is not guaranteed to be honoured, and a lower maximum may be enforced depending on the provider. In such a case, the returned ResultList’s is_truncated property can be used to determine whether more records are available.
  • marker (str) – The marker is an opaque identifier used to assist in paging through very long lists of objects. It is returned on each invocation of the list method.
Return type:

ResultList of Instance

Returns:

A ResultList object containing a list of Instances

VolumeService

class cloudbridge.cloud.interfaces.services.VolumeService[source]

Base interface for a Volume Service.

create(label, size, zone, snapshot=None, description=None)[source]

Creates a new volume.

Parameters:
  • label (str) – The label for the volume.
  • size (int) – The size of the volume (in GB).
  • zone (str or PlacementZone object) – The availability zone in which the Volume will be created.
  • snapshot (str or Snapshot object) – An optional reference to a snapshot from which this volume should be created.
  • description (str) – An optional description that may be supported by some providers. Providers that do not support this property will return None.
Return type:

object of Volume

Returns:

a newly created Volume object.

find(**kwargs)[source]

Searches for a volume by a given list of attributes.

Supported attributes: label

Return type:object of Volume
Returns:a Volume object or None if not found.
get(volume_id)[source]

Returns a volume given its id.

Return type:object of Volume
Returns:a Volume object or None if the volume does not exist.
list(limit=None, marker=None)[source]

List all volumes.

Return type:list of Volume
Returns:a list of Volume objects.

SnapshotService

class cloudbridge.cloud.interfaces.services.SnapshotService[source]

Base interface for a Snapshot Service.

create(label, volume, description=None)[source]

Creates a new snapshot off a volume.

Parameters:
  • label (str) – The label for the snapshot.
  • volume (str or Volume) – The volume to create a snapshot of.
  • description (str) – An optional description that may be supported by some providers. Providers that do not support this property will return None.
Return type:

object of Snapshot

Returns:

a newly created Snapshot object.

find(**kwargs)[source]

Searches for a snapshot by a given list of attributes.

Supported attributes: label

Return type:list of Snapshot
Returns:a Snapshot object or an empty list if none found.
get(volume_id)[source]

Returns a snapshot given its id.

Return type:object of Snapshot
Returns:a Snapshot object or None if the snapshot does not exist.
list(limit=None, marker=None)[source]

List all snapshots.

Return type:list of Snapshot
Returns:a list of Snapshot objects.

StorageService

class cloudbridge.cloud.interfaces.services.StorageService[source]

The Storage Service interface provides access to block device services, such as volume and snapshot services, as well as object store services, such as buckets, in the provider.

buckets

Provides access to object storage services in this provider.

Example:

# print all buckets
for bucket in provider.storage.buckets:
    print(bucket.id, bucket.name)

# find bucket by name
bucket = provider.storage.buckets.find(name='my_bucket')[0]
print(bucket.id, bucket.name)
Return type:BucketService
Returns:a BucketService object
snapshots

Provides access to volume snapshots for this provider.

Example:

# print all snapshots
for snap in provider.storage.snapshots:
    print(snap.id, snap.name, snap.label)

# find snapshot by label
snap = provider.storage.snapshots.find(label='my_snap')[0]
print(snap.id, snap.name, snap.label)
Return type:SnapshotService
Returns:a SnapshotService object
volumes

Provides access to volumes (i.e., block storage) for this provider.

Example:

# print all volumes
for vol in provider.storage.volumes:
    print(vol.id, vol.name, vol.label)

# find volume by label
vol = provider.storage.volumes.find(label='my_vol')[0]
print(vol.id, vol.name, vol.label)
Return type:VolumeService
Returns:a VolumeService object

ImageService

class cloudbridge.cloud.interfaces.services.ImageService[source]

Base interface for an Image Service

find(**kwargs)[source]

Searches for an image by a given list of attributes

Supported attributes: name, label

Return type:object of Image
Returns:an Image instance
get(image_id)[source]

Returns an Image given its id. Returns None if the Image does not exist.

Return type:object of Image
Returns:an Image instance
list(filter_by_owner=True, limit=None, marker=None)[source]

List all images.

Parameters:filter_by_owner (bool) – If True, return only images owned by the current user. Else, return all public images available from the provider. Note that fetching all images may take a long time.
Return type:list of Image
Returns:list of image objects

NetworkingService

class cloudbridge.cloud.interfaces.services.NetworkingService[source]

Base service interface for networking.

This service offers a collection of networking services that in turn provide access to networking resources.

networks

Provides access to all Network related services.

Return type:NetworkService
Returns:a Network service object
routers

Provides access to all Router related services.

Return type:RouterService
Returns:a Router service object
subnets

Provides access to all Subnet related services.

Return type:SubnetService
Returns:a Subnet service object

NetworkService

class cloudbridge.cloud.interfaces.services.NetworkService[source]

Base interface for a Network Service.

create(label, cidr_block)[source]

Create a new network.

Parameters:
  • label (str) – A label for the network.
  • cidr_block (str) – The cidr block for this network. Some providers will respect this at the network level, while others will only respect it at subnet level. However, to write portable code, you should make sure that any subnets you create fall within this initially specified range. Note that the block size should be between a /16 netmask (65,536 IP addresses) and /28 netmask (16 IP addresses). e.g. 10.0.0.0/16
Return type:

object of Network

Returns:

A Network object

delete(network_id)[source]

Delete an existing Network.

Parameters:network_id (str) – The ID of the network to be deleted.
find(**kwargs)[source]

Searches for a network by a given list of attributes.

Supported attributes: name, label

Return type:List of object of Network
Returns:A list of Network objects matching the supplied attributes.
get(network_id)[source]

Returns a Network given its ID or None if not found.

Parameters:network_id (str) – The ID of the network to retrieve.
Return type:object of Network
Returns:a Network object
list(limit=None, marker=None)[source]

List all networks.

Return type:list of Network
Returns:list of Network objects
subnets

Provides access to subnets.

Example:

# Print all subnets
for s in provider.networking.subnets:
    print(s.id, s.name, s.label)

# Get subnet by ID
s = provider.networking.subnets.get('subnet-id')
print(s.id, s.name, s.label)
Return type:SubnetService
Returns:a SubnetService object

SubnetService

class cloudbridge.cloud.interfaces.services.SubnetService[source]

Base interface for a Subnet Service.

create(label, network_id, cidr_block, zone)[source]

Create a new subnet within the supplied network.

Parameters:
  • label (str) – The subnet label.
  • network (Network object or str) – Network object or ID under which to create the subnet.
  • cidr_block (str) – CIDR block within the Network to assign to the subnet.
  • zone (str) – A placement zone for the subnet. Some providers may not support this, in which case the value is ignored.
Return type:

object of Subnet

Returns:

A Subnet object

delete(subnet)[source]

Delete an existing Subnet.

Parameters:subnet (Subnet object or str) – Subnet object or ID of the subnet to delete.
find(**kwargs)[source]

Searches for a subnet by a given list of attributes.

Supported attributes: name, label

Return type:List of object of Subnet
Returns:A list of Subnet objects matching the supplied attributes.
get(subnet_id)[source]

Returns a Subnet given its ID or None if not found.

Parameters:subnet_id (Network object or str) – The ID of the subnet to retrieve.
Return type:object of Subnet

return: a Subnet object

get_or_create_default(zone)[source]

Return a default subnet for the account or create one if not found. This provides a convenience method for obtaining a network if you are not particularly concerned with how the network is structured.

A default network is one marked as such by the provider or matches the default label used by this library (e.g., cloudbridge-net).

Parameters:zone (PlacementZone object str) – Placement zone where to look for the subnet.
Return type:object of Subnet
Returns:A Subnet object
list(network=None, limit=None, marker=None)[source]

List all subnets or filter them by the supplied network ID.

Parameters:network (str) – Network object or ID with which to filter the subnets.
Return type:list of Subnet
Returns:list of Subnet objects

RouterService

class cloudbridge.cloud.interfaces.services.RouterService[source]

Manage networking router actions and resources.

create(label, network)[source]

Create a new router.

Parameters:
  • label (str) – A router label.
  • network (Network object or str) – Network object or ID under which to create the router.
Return type:

object of Router

Returns:

A Router object

delete(router)[source]

Delete an existing Router.

Parameters:router (Router object or str) – Router object or ID of the router to delete.
find(**kwargs)[source]

Searches for a router by a given list of attributes.

Supported attributes: label

Return type:List of object of Router
Returns:A list of Router objects matching the supplied attributes.
get(router_id)[source]

Returns a Router object given its ID.

Parameters:router_id (str) – The ID of the router to retrieve.
Return type:object of Router or None
Returns:a Router object of None if not found.
list(limit=None, marker=None)[source]

List all routers.

Return type:list of Router
Returns:list of Router objects

BucketService

class cloudbridge.cloud.interfaces.services.BucketService[source]

The Bucket Service interface provides access to the underlying object storage capabilities of this provider. This service is optional and the CloudProvider.has_service() method should be used to verify its availability before using the service.

create(name, location=None)[source]

Create a new bucket.

If a bucket with the specified name already exists, return a reference to that bucket.

Example:

bucket = provider.storage.buckets.create('my_bucket_name')
print(bucket.name)
Parameters:
  • name (str) – The name of this bucket.
  • location (object of Region) – The region in which to place this bucket.
Returns:

a Bucket object

Return type:

object of Bucket

find(**kwargs)[source]

Searches for a bucket by a given list of attributes.

Supported attributes: name

Example:

buckets = provider.storage.buckets.find(name='my_bucket_name')
for bucket in buckets:
    print(bucket.id, bucket.name)
Return type:Bucket
Returns:a Bucket instance
get(bucket_id)[source]

Returns a bucket given its ID. Returns None if the bucket does not exist. On some providers, such as AWS and OpenStack, the bucket id is the same as its name.

Example:

bucket = provider.storage.buckets.get('my_bucket_id')
print(bucket.id, bucket.name)
Return type:Bucket
Returns:a Bucket instance
list(limit=None, marker=None)[source]

List all buckets.

Example:

buckets = provider.storage.buckets.find(name='my_bucket_name')
for bucket in buckets:
    print(bucket.id, bucket.name)
Return type:Bucket
Returns:list of bucket objects

SecurityService

class cloudbridge.cloud.interfaces.services.SecurityService[source]

The security service interface can be used to access security related functions in the provider, such as firewall control and keypairs.

key_pairs

Provides access to key pairs for this provider.

Example:

# print all keypairs
for kp in provider.security.keypairs:
    print(kp.id, kp.name)

# find keypair by name
kp = provider.security.keypairs.find(name='my_key_pair')[0]
print(kp.id, kp.name)
Return type:KeyPairService
Returns:a KeyPairService object
vm_firewalls

Provides access to firewalls (security groups) for this provider.

Example:

# print all VM firewalls
for fw in provider.security.vm_firewalls:
    print(fw.id, fw.name)

# find firewall by name
fw = provider.security.vm_firewalls.find(name='my_vm_fw')[0]
print(fw.id, fw.name)
Return type:VMFirewallService
Returns:a VMFirewallService object

KeyPairService

class cloudbridge.cloud.interfaces.services.KeyPairService[source]

Base interface for key pairs.

create(name, public_key_material=None)[source]

Create a new key pair or raise an exception if one already exists. If the public_key_material is provided, the material will be imported to create the new keypair. Otherwise, a new public and private key pair will be generated.

Parameters:
  • name (str) – The name of the key pair to be created.
  • public_key_material (str) – The key-pair material to import in OpenSSH format.
Return type:

object of KeyPair

Returns:

A keypair instance or None.

delete(key_pair_id)[source]

Delete an existing VMFirewall.

Parameters:key_pair_id (str) – The id of the key pair to be deleted.
Return type:bool
Returns:True if the key does not exist, False otherwise. Note that this implies that the key may not have been deleted by this method but instead has not existed at all.
find(**kwargs)[source]

Searches for a key pair by a given list of attributes.

Supported attributes: name

Return type:object of KeyPair
Returns:a KeyPair object
get(key_pair_id)[source]

Return a KeyPair given its ID or None if not found.

On some providers, such as AWS and OpenStack, the KeyPair ID is the same as its name.

Example:

key_pair = provider.security.keypairs.get('my_key_pair_id')
print(key_pair.id, key_pair.name)
Return type:KeyPair
Returns:a KeyPair instance
list(limit=None, marker=None)[source]

List all key pairs associated with this account.

Return type:list of KeyPair
Returns:list of KeyPair objects

VMFirewallService

class cloudbridge.cloud.interfaces.services.VMFirewallService[source]

Base interface for VM firewalls.

create(label, network_id, description=None)[source]

Create a new VMFirewall.

Parameters:
  • label (str) – The label for the new VM firewall.
  • network_id (str) – Network ID under which to create the VM firewall.
  • description (str) – The description of the new VM firewall.
Return type:

object of VMFirewall

Returns:

A VMFirewall instance or None if one was not created.

delete(group_id)[source]

Delete an existing VMFirewall.

Parameters:group_id (str) – The VM firewall ID to be deleted.
find(**kwargs)[source]

Get VM firewalls associated with your account filtered by name.

Supported attributes: name

Parameters:name (str) – The name of the VM firewall to retrieve.
Return type:list of VMFirewall
Returns:A list of VMFirewall objects or an empty list if none found.
get(vm_firewall_id)[source]

Returns a VMFirewall given its ID. Returns None if the VMFirewall does not exist.

Example:

fw = provider.security.vm_firewalls.get('my_fw_id')
print(fw.id, fw.name)
Return type:VMFirewall
Returns:a VMFirewall instance
list(limit=None, marker=None)[source]

List all VM firewalls associated with this account.

Return type:list of VMFirewall
Returns:list of VMFirewall objects

VMTypeService

class cloudbridge.cloud.interfaces.services.VMTypeService[source]
find(**kwargs)[source]

Searches for an instance by a given list of attributes.

Supported attributes: name

Return type:object of VMType
Returns:an Instance object
get(vm_type_id)[source]

Returns an VMType given its ID. Returns None if the VMType does not exist.

Example:

vm_type = provider.compute.vm_types.get('my_vm_type_id')
print(vm_type.id, vm_type.name)
Return type:VMType
Returns:an VMType instance
list(limit=None, marker=None)[source]

List all VM types.

Return type:list of VMType
Returns:list of VMType objects

RegionService

class cloudbridge.cloud.interfaces.services.RegionService[source]

Base interface for a Region service

current

Returns the current region that this provider is connected to.

If the current region cannot be discovered, return None.

Return type:object of Region
Returns:a Region instance or None
find(**kwargs)[source]

Searches for a region by a given list of attributes.

Supported attributes: name

Return type:object of Region
Returns:a Region object
get(region_id)[source]

Returns a region given its id. Returns None if the region does not exist.

Return type:object of Region
Returns:a Region instance
list(limit=None, marker=None)[source]

List all regions.

Return type:list of Region
Returns:list of region objects