Services

CloudService

class cloudbridge.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.

abstract property provider

Returns the provider instance associated with this service.

Return type

CloudProvider

Returns

a CloudProvider object

ComputeService

class cloudbridge.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.

abstract property 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

abstract property 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

abstract property 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

abstract property 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.interfaces.services.InstanceService[source]

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

abstract create(label, image, vm_type, subnet, 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.

  • 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

abstract 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.

abstract 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

abstract 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.interfaces.services.VolumeService[source]

Base interface for a Volume Service.

abstract create(label, size, 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).

  • 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.

delete(volume)[source]

Delete an existing volume.

Parameters

volume (str or Volume) – The object or ID of the volume to be deleted.

abstract 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.

abstract 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.

abstract list(limit=None, marker=None)[source]

List all volumes.

Return type

list of Volume

Returns

a list of Volume objects.

SnapshotService

class cloudbridge.interfaces.services.SnapshotService[source]

Base interface for a Snapshot Service.

abstract 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.

delete(snapshot)[source]

Delete an existing snapshot.

Parameters

snapshot (str or Snapshot) – The object or ID of the snapshot to be deleted.

abstract 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.

abstract get(snapshot_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.

abstract list(limit=None, marker=None)[source]

List all snapshots.

Return type

list of Snapshot

Returns

a list of Snapshot objects.

StorageService

class cloudbridge.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.

abstract property 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

abstract property 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

abstract property 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.interfaces.services.ImageService[source]

Base interface for an Image Service

abstract 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

abstract 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

abstract 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.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.

abstract property networks

Provides access to all Network related services.

Return type

NetworkService

Returns

a Network service object

abstract property routers

Provides access to all Router related services.

Return type

RouterService

Returns

a Router service object

abstract property subnets

Provides access to all Subnet related services.

Return type

SubnetService

Returns

a Subnet service object

NetworkService

class cloudbridge.interfaces.services.NetworkService[source]

Base interface for a Network Service.

abstract 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

abstract delete(network)[source]

Delete an existing Network.

Parameters

network (str or Network) – The object or id of the network to be deleted.

abstract 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.

abstract 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

abstract list(limit=None, marker=None)[source]

List all networks.

Return type

list of Network

Returns

list of Network objects

abstract property 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.interfaces.services.SubnetService[source]

Base interface for a Subnet Service.

abstract create(label, network, cidr_block)[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.

Return type

object of Subnet

Returns

A Subnet object

abstract delete(subnet)[source]

Delete an existing Subnet.

Parameters

subnet (Subnet object or str) – Subnet object or ID of the subnet to delete.

abstract 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.

abstract 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

Returns

a Subnet object

abstract get_or_create_default()[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).

Return type

object of Subnet

Returns

A Subnet object

abstract 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

FloatingIPService

class cloudbridge.interfaces.subservices.FloatingIPSubService[source]

Base interface for a FloatingIP Service.

abstract create()[source]

Allocate a new floating (i.e., static) IP address.

Return type

object of FloatingIP

Returns

A FloatingIP object

abstract delete(fip_id)[source]

Delete an existing FloatingIP.

Parameters

fip_id (str) – The ID of the FloatingIP to be deleted.

abstract find(**kwargs)[source]

Searches for a FloatingIP by a given list of attributes.

Supported attributes: name, public_ip

Example:

fip = provider.networking.gateways.get('id').floating_ips.find(
            public_ip='public_ip')
Return type

List of object of FloatingIP

Returns

A list of FloatingIP objects matching the supplied attributes.

abstract get(fip_id)[source]

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

Parameters

fip_id (str) – The ID of the FloatingIP to retrieve.

Return type

object of FloatingIP

Returns

a FloatingIP object

abstract list(limit=None, marker=None)[source]

List floating (i.e., static) IP addresses.

Return type

list of FloatingIP

Returns

list of FloatingIP objects

RouterService

class cloudbridge.interfaces.services.RouterService[source]

Manage networking router actions and resources.

abstract 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

abstract delete(router)[source]

Delete an existing Router.

Parameters

router (Router object or str) – Router object or ID of the router to delete.

abstract 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.

abstract 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.

abstract list(limit=None, marker=None)[source]

List all routers.

Return type

list of Router

Returns

list of Router objects

GatewayService

class cloudbridge.interfaces.subservices.GatewaySubService[source]

Manage internet gateway resources.

abstract delete(gateway)[source]

Delete a gateway.

Parameters

gateway (Gateway object) – Gateway object to delete.

abstract get_or_create()[source]

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.

Return type

object of InternetGateway or None

Returns

an InternetGateway object of None if not found.

abstract list(limit=None, marker=None)[source]

List all available internet gateways.

Return type

list of InternetGateway or None

Returns

Current list of internet gateways.

BucketService

class cloudbridge.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.

abstract 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

abstract 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

abstract 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

abstract 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.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.

abstract property 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

abstract property 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.interfaces.services.KeyPairService[source]

Base interface for key pairs.

abstract 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.

abstract delete(key_pair)[source]

Delete an existing keypair.

Parameters

key_pair (str or KeyPair) – The object or 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.

abstract 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

abstract 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

abstract 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.interfaces.services.VMFirewallService[source]

Base interface for VM firewalls.

abstract create(label, network, description=None)[source]

Create a new VMFirewall.

Parameters
  • label (str) – The label for the new VM firewall.

  • network (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.

abstract delete(vm_firewall)[source]

Delete an existing VMFirewall.

Parameters

vm_firewall (str or VMFirewall) – The object or VM firewall ID to be deleted.

abstract 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.

abstract 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

abstract 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.interfaces.services.VMTypeService[source]
abstract find(**kwargs)[source]

Searches for instances by a given list of attributes.

Supported attributes: name

Return type

object of VMType

Returns

an Instance object

abstract 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

abstract list(limit=None, marker=None)[source]

List all VM types.

Return type

list of VMType

Returns

list of VMType objects

RegionService

class cloudbridge.interfaces.services.RegionService[source]

Base interface for a Region service

abstract property 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

abstract 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

abstract 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

abstract list(limit=None, marker=None)[source]

List all regions.

Return type

list of Region

Returns

list of region objects

DnsService

class cloudbridge.interfaces.services.DnsService[source]

Base service interface for DNS.

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

abstract property host_zones

Provides access to all dns zones.

Return type

DnsZoneService

Returns

a Dns Host Zone service

DnsZoneService

class cloudbridge.interfaces.services.DnsZoneService[source]

Manage DNS Zone actions and resources. This service is optional and the CloudProvider.has_service() method should be used to verify its availability before using the service.

abstract create(label, admin_email)[source]

Create a new host zone.

Parameters
  • label (str) – A host zone label.

  • admin_email (str) – Email address of this zone’s administrator.

Return type

object of DnsZone

Returns

A DnsZone object

abstract delete(dns_zone)[source]

Delete an existing DnsHostZone.

Parameters

dns_zone (DnsZone object or str) – DnsZone object or ID of the host zone to delete.

abstract find(**kwargs)[source]

Searches for a host zone by a given list of attributes.

Supported attributes: label

Return type

List of object of DnsZone

Returns

A list of Dns Zone objects matching the supplied attributes.

abstract get(dns_zone_id)[source]

Returns a DnsZone object given its ID.

Parameters

dns_zone_id (str) – The ID of the host zone to retrieve.

Return type

object of DnsZone or None

Returns

a DnsZone object of None if not found.

abstract list(limit=None, marker=None)[source]

List all host zones.

Return type

list of DnsZone

Returns

list of DnsZone objects

DnsRecordService

class cloudbridge.interfaces.services.DnsRecordService[source]

The Dns Record Service interface provides access to the records belonging to a Dns Zone.

abstract create(dns_zone, name, type, data, ttl=None)[source]

Create a new record within a zone.

Parameters
  • name (str) – The record name.

  • type (str) – The DnsRecord type. (e.g. A, CNAME, MX etc)

  • data (int) – The corresponding value for the record. The relevant values must be fully qualified (e.g. CNAMEs). If the trailing dot is omitted, it will be automatically added and thus assumed to be fully qualified.

  • data – The ttl (in seconds) for this record.

Return type

object of DnsRecord

Returns

A DnsRecord object

abstract get(dns_zone, rec_id)[source]

Returns a record given its ID and the dns_zone containing it. Returns None if the record does not exist.

Return type

DnsRecord

Returns

a DnsRecord instance

abstract list(dns_zone, limit=None, marker=None)[source]

List all records within a dns zone.

Return type

DnsRecord

Returns

a DnsRecord instance