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.
-
provider¶ Returns the provider instance associated with this service.
Return type: CloudProviderReturns: 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.
-
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: ImageServiceReturns: 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: InstanceServiceReturns: 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: RegionServiceReturns: 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: VMTypeServiceReturns: an VMTypeService object
-
InstanceService¶
-
class
cloudbridge.interfaces.services.InstanceService[source]¶ Provides access to instances in a provider, including creating, listing and deleting instances.
-
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 with - vm_type (
VMTypeorstr) – The VMType or name, specifying the size of the instance to boot into - subnet (
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: objectofInstanceReturns: an instance of Instance class
- label (
-
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: objectofLaunchConfigReturns: 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
objectofInstanceReturns: A list of Instance objects matching the supplied attributes.
- name (
-
get(instance_id)[source]¶ Returns an instance given its id. Returns None if the object does not exist.
Return type: objectofInstanceReturns: 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: ResultListofInstanceReturns: A ResultList object containing a list of Instances
- limit (
-
VolumeService¶
-
class
cloudbridge.interfaces.services.VolumeService[source]¶ Base interface for a Volume Service.
-
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: objectofVolumeReturns: a newly created Volume object.
- label (
-
delete(volume)[source]¶ Delete an existing volume.
Parameters: volume ( strorVolume) – The object or ID of the volume to be deleted.
-
find(**kwargs)[source]¶ Searches for a volume by a given list of attributes.
Supported attributes: label
Return type: objectofVolumeReturns: a Volume object or Noneif not found.
-
SnapshotService¶
-
class
cloudbridge.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 (
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: objectofSnapshotReturns: a newly created Snapshot object.
- label (
-
delete(snapshot)[source]¶ Delete an existing snapshot.
Parameters: snapshot ( strorSnapshot) – The object or ID of the snapshot to be deleted.
-
find(**kwargs)[source]¶ Searches for a snapshot by a given list of attributes.
Supported attributes: label
Return type: list of SnapshotReturns: 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.
-
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: BucketServiceReturns: 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: SnapshotServiceReturns: 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: VolumeServiceReturns: a VolumeService object
-
ImageService¶
-
class
cloudbridge.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: objectofImageReturns: an Image instance
-
get(image_id)[source]¶ Returns an Image given its id. Returns None if the Image does not exist.
Return type: objectofImageReturns: an Image instance
-
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: listofImageReturns: 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.
-
networks¶ Provides access to all Network related services.
Return type: NetworkServiceReturns: a Network service object
-
routers¶ Provides access to all Router related services.
Return type: RouterServiceReturns: a Router service object
-
subnets¶ Provides access to all Subnet related services.
Return type: SubnetServiceReturns: a Subnet service object
-
NetworkService¶
-
class
cloudbridge.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: objectofNetworkReturns: A Network object
- label (
-
delete(network)[source]¶ Delete an existing Network.
Parameters: network ( strorNetwork) – The object or 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 objectofNetworkReturns: A list of Network objects matching the supplied attributes.
-
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: objectofNetworkReturns: a Network object
-
list(limit=None, marker=None)[source]¶ List all networks.
Return type: listofNetworkReturns: 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: SubnetServiceReturns: a SubnetService object
-
SubnetService¶
-
class
cloudbridge.interfaces.services.SubnetService[source]¶ Base interface for a Subnet Service.
-
create(label, network, cidr_block)[source]¶ Create a new subnet within the supplied network.
Parameters: - label (
str) – The subnet label. - network (
Networkobject orstr) – 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: objectofSubnetReturns: A Subnet object
- label (
-
delete(subnet)[source]¶ Delete an existing Subnet.
Parameters: subnet ( Subnetobject orstr) – 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 objectofSubnetReturns: A list of Subnet objects matching the supplied attributes.
-
get(subnet_id)[source]¶ Returns a Subnet given its ID or
Noneif not found.Parameters: subnet_id ( Networkobject orstr) – The ID of the subnet to retrieve.Return type: objectofSubnetReturns: a Subnet object
-
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: objectofSubnetReturns: A Subnet object
-
RouterService¶
-
class
cloudbridge.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 (
Networkobject orstr) – Network object or ID under which to create the router.
Return type: objectofRouterReturns: A Router object
- label (
-
delete(router)[source]¶ Delete an existing Router.
Parameters: router ( Routerobject orstr) – 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 objectofRouterReturns: A list of Router objects matching the supplied attributes.
-
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.-
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 (
objectofRegion) – The region in which to place this bucket.
Returns: a Bucket object
Return type: objectofBucket
-
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: BucketReturns: a Bucket instance
-
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: BucketReturns: 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.
-
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: KeyPairServiceReturns: 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: VMFirewallServiceReturns: a VMFirewallService object
-
KeyPairService¶
-
class
cloudbridge.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: objectofKeyPairReturns: A keypair instance or
None.
-
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: boolReturns: 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.
-
find(**kwargs)[source]¶ Searches for a key pair by a given list of attributes.
Supported attributes: name
Return type: objectofKeyPairReturns: a KeyPair object
-
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: KeyPairReturns: a KeyPair instance
-
VMFirewallService¶
-
class
cloudbridge.interfaces.services.VMFirewallService[source]¶ Base interface for VM firewalls.
-
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: objectofVMFirewallReturns: A VMFirewall instance or
Noneif one was not created.
-
delete(vm_firewall)[source]¶ Delete an existing VMFirewall.
Parameters: vm_firewall ( strorVMFirewall) – The object or 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 VMFirewallReturns: A list of VMFirewall objects or an empty list if none found.
-
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: VMFirewallReturns: a VMFirewall instance
-
list(limit=None, marker=None)[source]¶ List all VM firewalls associated with this account.
Return type: listofVMFirewallReturns: list of VMFirewall objects
-
VMTypeService¶
-
class
cloudbridge.interfaces.services.VMTypeService[source]¶ -
find(**kwargs)[source]¶ Searches for instances by a given list of attributes.
Supported attributes: name
Return type: objectofVMTypeReturns: an Instance object
-
RegionService¶
-
class
cloudbridge.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: objectofRegionReturns: a Region instance or None
-
find(**kwargs)[source]¶ Searches for a region by a given list of attributes.
Supported attributes: name
Return type: objectofRegionReturns: a Region object
-