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:
- 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:
- 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:
- 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:
- 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:
- Returns:
an VMTypeService object
InstanceService
- class cloudbridge.interfaces.services.InstanceService[source]
Provides access to instances in a provider, including creating, listing and deleting instances.
- abstractmethod 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 (
MachineImageorstr) – The MachineImage object or id to boot the virtual machine withvm_type (
VMTypeorstr) – The VMType or name, specifying the size of the instance to boot intosubnet (
Subnetorstr) –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 (
KeyPairorstr) – The KeyPair object or its id, to set for the instance.vm_firewalls (A
listofVMFirewallobjects or a list ofstrobject IDs) –A list of
VMFirewallobjects or a list ofVMFirewallIDs, which should be assigned to this instance.The VM firewalls must be associated with the same network as the supplied subnet. Use
network.vm_firewallsto retrieve a list of firewalls belonging to a network.user_data (
str) – An extra userdata object which is compatible with the provider.launch_config (
LaunchConfigobject) – ALaunchConfigobject 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:
objectofInstance- Returns:
an instance of Instance class
- create_launch_config()[source]
Creates a
LaunchConfigobject which can be used to set additional options when launching an instance, such as block device mappings and network interfaces.- Return type:
objectofLaunchConfig- Returns:
an instance of a LaunchConfig class
- abstractmethod find(**kwargs)[source]
Searches for an instance by a given list of attributes.
Supported attributes: name, label
- Parameters:
name (
str) – The name to search forlabel (
str) – The label to search for
- Return type:
List of
objectofInstance- Returns:
A list of Instance objects matching the supplied attributes.
- abstractmethod get(instance_id)[source]
Returns an instance given its id. Returns None if the object does not exist.
- Return type:
objectofInstance- Returns:
an Instance object
- abstractmethod 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:
ResultListofInstance- Returns:
A ResultList object containing a list of Instances
VolumeService
- class cloudbridge.interfaces.services.VolumeService[source]
Base interface for a Volume Service.
- abstractmethod 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 (
strorSnapshotobject) – 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 returnNone.
- Return type:
objectofVolume- Returns:
a newly created Volume object.
- delete(volume)[source]
Delete an existing volume.
- Parameters:
volume (
strorVolume) – The object or ID of the volume to be deleted.
- abstractmethod find(**kwargs)[source]
Searches for a volume by a given list of attributes.
Supported attributes: label
- Return type:
objectofVolume- Returns:
a Volume object or
Noneif not found.
SnapshotService
- class cloudbridge.interfaces.services.SnapshotService[source]
Base interface for a Snapshot Service.
- abstractmethod create(label, volume, description=None)[source]
Creates a new snapshot off a volume.
- Parameters:
label (
str) – The label for the snapshot.volume (
strorVolume) – 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:
objectofSnapshot- Returns:
a newly created Snapshot object.
- delete(snapshot)[source]
Delete an existing snapshot.
- Parameters:
snapshot (
strorSnapshot) – The object or ID of the snapshot to be deleted.
- abstractmethod 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.
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:
- 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:
- 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:
- Returns:
a VolumeService object
ImageService
- class cloudbridge.interfaces.services.ImageService[source]
Base interface for an Image Service
- abstractmethod find(**kwargs)[source]
Searches for an image by a given list of attributes
Supported attributes: name, label
- Return type:
objectofImage- Returns:
an Image instance
- abstractmethod get(image_id)[source]
Returns an Image given its id. Returns None if the Image does not exist.
- Return type:
objectofImage- Returns:
an Image instance
- abstractmethod list(filter_by_owner=True, limit=None, marker=None)[source]
List all images.
- Parameters:
filter_by_owner (
bool) – IfTrue, 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:
listofImage- 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:
- Returns:
a Network service object
- abstract property routers
Provides access to all Router related services.
- Return type:
- Returns:
a Router service object
- abstract property subnets
Provides access to all Subnet related services.
- Return type:
- Returns:
a Subnet service object
NetworkService
- class cloudbridge.interfaces.services.NetworkService[source]
Base interface for a Network Service.
- abstractmethod 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:
objectofNetwork- Returns:
A Network object
- abstractmethod delete(network)[source]
Delete an existing Network.
- Parameters:
network (
strorNetwork) – The object or id of the network to be deleted.
- abstractmethod find(**kwargs)[source]
Searches for a network by a given list of attributes.
Supported attributes: name, label
- Return type:
List of
objectofNetwork- Returns:
A list of Network objects matching the supplied attributes.
- abstractmethod get(network_id)[source]
Returns a Network given its ID or
Noneif not found.- Parameters:
network_id (
str) – The ID of the network to retrieve.- Return type:
objectofNetwork- Returns:
a Network object
- abstractmethod list(limit=None, marker=None)[source]
List all networks.
- Return type:
listofNetwork- 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:
- Returns:
a SubnetService object
SubnetService
- class cloudbridge.interfaces.services.SubnetService[source]
Base interface for a Subnet Service.
- abstractmethod create(label, network, cidr_block)[source]
Create a new subnet within the supplied network.
- abstractmethod delete(subnet)[source]
Delete an existing Subnet.
- Parameters:
subnet (
Subnetobject orstr) – Subnet object or ID of the subnet to delete.
- abstractmethod find(**kwargs)[source]
Searches for a subnet by a given list of attributes.
Supported attributes: name, label
- Return type:
List of
objectofSubnet- Returns:
A list of Subnet objects matching the supplied attributes.
- abstractmethod 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:
objectofSubnet- Returns:
A Subnet object
FloatingIPService
- class cloudbridge.interfaces.subservices.FloatingIPSubService[source]
Base interface for a FloatingIP Service.
- abstractmethod create()[source]
Allocate a new floating (i.e., static) IP address.
- Return type:
objectofFloatingIP- Returns:
A FloatingIP object
- abstractmethod delete(fip_id)[source]
Delete an existing FloatingIP.
- Parameters:
fip_id (
str) – The ID of the FloatingIP to be deleted.
- abstractmethod 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
objectofFloatingIP- Returns:
A list of FloatingIP objects matching the supplied attributes.
- abstractmethod get(fip_id)[source]
Returns a FloatingIP given its ID or
Noneif not found.- Parameters:
fip_id (
str) – The ID of the FloatingIP to retrieve.- Return type:
objectofFloatingIP- Returns:
a FloatingIP object
- abstractmethod list(limit=None, marker=None)[source]
List floating (i.e., static) IP addresses.
- Return type:
listofFloatingIP- Returns:
list of FloatingIP objects
RouterService
- class cloudbridge.interfaces.services.RouterService[source]
Manage networking router actions and resources.
- abstractmethod delete(router)[source]
Delete an existing Router.
- Parameters:
router (
Routerobject orstr) – Router object or ID of the router to delete.
- abstractmethod find(**kwargs)[source]
Searches for a router by a given list of attributes.
Supported attributes: label
- Return type:
List of
objectofRouter- Returns:
A list of Router objects matching the supplied attributes.
GatewayService
- class cloudbridge.interfaces.subservices.GatewaySubService[source]
Manage internet gateway resources.
- abstractmethod delete(gateway)[source]
Delete a gateway.
- Parameters:
gateway (
Gatewayobject) – Gateway object to delete.
- abstractmethod 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:
objectofInternetGatewayorNone- Returns:
an InternetGateway object of
Noneif not found.
- abstractmethod list(limit=None, marker=None)[source]
List all available internet gateways.
- Return type:
listofInternetGatewayorNone- 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.- abstractmethod 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)
- abstractmethod 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:
- Returns:
a Bucket instance
- abstractmethod get(bucket_id)[source]
Returns a bucket given its ID. Returns
Noneif 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:
- Returns:
a Bucket instance
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:
- 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:
- Returns:
a VMFirewallService object
KeyPairService
- class cloudbridge.interfaces.services.KeyPairService[source]
Base interface for key pairs.
- abstractmethod 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:
objectofKeyPair- Returns:
A keypair instance or
None.
- abstractmethod delete(key_pair)[source]
Delete an existing keypair.
- Parameters:
key_pair (
strorKeyPair) – The object or id of the key pair to be deleted.- Return type:
bool- Returns:
Trueif the key does not exist,Falseotherwise. Note that this implies that the key may not have been deleted by this method but instead has not existed at all.
- abstractmethod find(**kwargs)[source]
Searches for a key pair by a given list of attributes.
Supported attributes: name
- Return type:
objectofKeyPair- Returns:
a KeyPair object
- abstractmethod get(key_pair_id)[source]
Return a KeyPair given its ID or
Noneif 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:
- Returns:
a KeyPair instance
VMFirewallService
- class cloudbridge.interfaces.services.VMFirewallService[source]
Base interface for VM firewalls.
- abstractmethod 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:
objectofVMFirewall- Returns:
A VMFirewall instance or
Noneif one was not created.
- abstractmethod delete(vm_firewall)[source]
Delete an existing VMFirewall.
- Parameters:
vm_firewall (
strorVMFirewall) – The object or VM firewall ID to be deleted.
- abstractmethod 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.
- abstractmethod get(vm_firewall_id)[source]
Returns a VMFirewall given its ID. Returns
Noneif the VMFirewall does not exist.Example:
fw = provider.security.vm_firewalls.get('my_fw_id') print(fw.id, fw.name)
- Return type:
- Returns:
a VMFirewall instance
- abstractmethod list(limit=None, marker=None)[source]
List all VM firewalls associated with this account.
- Return type:
listofVMFirewall- Returns:
list of VMFirewall objects
VMTypeService
- class cloudbridge.interfaces.services.VMTypeService[source]
- abstractmethod find(**kwargs)[source]
Searches for instances by a given list of attributes.
Supported attributes: name
- Return type:
objectofVMType- Returns:
an Instance object
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:
objectofRegion- Returns:
a Region instance or
None
- abstractmethod find(**kwargs)[source]
Searches for a region by a given list of attributes.
Supported attributes: name
- Return type:
objectofRegion- Returns:
a Region object
DnsService
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.- abstractmethod 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:
objectofDnsZone- Returns:
A DnsZone object
- abstractmethod delete(dns_zone)[source]
Delete an existing DnsHostZone.
- Parameters:
dns_zone (
DnsZoneobject orstr) – DnsZone object or ID of the host zone to delete.
- abstractmethod find(**kwargs)[source]
Searches for a host zone by a given list of attributes.
Supported attributes: label
- Return type:
List of
objectofDnsZone- Returns:
A list of Dns Zone objects matching the supplied attributes.
DnsRecordService
- class cloudbridge.interfaces.services.DnsRecordService[source]
The Dns Record Service interface provides access to the records belonging to a Dns Zone.
- abstractmethod 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:
objectofDnsRecord- Returns:
A DnsRecord object