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) # print only first 50 images for image in provider.compute.images.list(limit=50): print(image.id, image.name) # find image by name image = provider.compute.images.find(name='Ubuntu 14.04') print(image.id, image.name)
Return type: ImageService
Returns: an ImageService object
-
instance_types
¶ Provides access to all Instance type related services in this provider.
Example:
# list all instance sizes for inst_type in provider.compute.instance_types: print(inst_type.id, inst_type.name) # find a specific size by name inst_type = provider.compute.instance_types.find(name='m1.small') print(inst_type.vcpus)
Return type: InstanceTypeService
Returns: an InstanceTypeService object
-
instances
¶ Provides access to all Instance related services in this provider.
Example:
# launch a new instance image = provider.compute.images.find(name='Ubuntu 14.04')[0] size = provider.compute.instance_types.find(name='m1.small') instance = provider.compute.instances.create('Hello', image, size) print(instance.id, instance.name)
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
-
InstanceService¶
-
class
cloudbridge.cloud.interfaces.services.
InstanceService
[source]¶ Provides access to instances in a provider, including creating, listing and deleting instances.
-
create
(name, image, instance_type, subnet, zone=None, key_pair=None, security_groups=None, user_data=None, launch_config=None, **kwargs)[source]¶ Creates a new virtual machine instance.
Parameters: - name (
str
) – The name of the virtual machine instance - image (
MachineImage
orstr
) – The MachineImage object or id to boot the virtual machine with - instance_type (
InstanceType
orstr
) – The InstanceType or name, specifying the size of the instance to boot into - subnet (
Subnet
orstr
) –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
orstr
) –The Zone or its name, 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
orstr
) – The KeyPair object or its name, to set for the instance. - security_groups (A
list
ofSecurityGroup
objects or a list ofstr
object IDs) –A list of
SecurityGroup
objects or a list ofSecurityGroup
IDs, which should be assigned to this instance.The security groups must be associated with the same network as the supplied subnet. Use
network.security_groups
to retrieve a list of security groups belonging to a network. - user_data (
str
) – An extra userdata object which is compatible with the provider. - launch_config (
LaunchConfig
object) – ALaunchConfig
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
ofInstance
Returns: an instance of Instance class
- name (
-
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
ofLaunchConfig
Returns: an instance of a LaunchConfig class
-
find
(name)[source]¶ Searches for an instance by a given list of attributes.
Return type: List of object
ofInstance
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
ofInstance
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
ofInstance
Returns: A ResultList object containing a list of Instances
- limit (
-
VolumeService¶
-
class
cloudbridge.cloud.interfaces.services.
VolumeService
[source]¶ Base interface for a Volume Service.
-
create
(name, size, zone, snapshot=None, description=None)[source]¶ Creates a new volume.
Parameters: - name (
str
) – The name of the volume. - size (
int
) – The size of the volume (in GB). - zone (
str
orPlacementZone
object) – The availability zone in which the Volume will be created. - snapshot (
str
orSnapshot
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 returnNone
.
Return type: object
ofVolume
Returns: a newly created Volume object.
- name (
-
find
(name, limit=None, marker=None)[source]¶ Searches for a volume by a given list of attributes.
Return type: object
ofVolume
Returns: a Volume object or None
if not found.
-
SnapshotService¶
-
class
cloudbridge.cloud.interfaces.services.
SnapshotService
[source]¶ Base interface for a Snapshot Service.
-
create
(name, volume, description=None)[source]¶ Creates a new snapshot off a volume.
Parameters: - name (
str
) – The name of the snapshot - volume (
str
orVolume
) – 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
ofSnapshot
Returns: a newly created Snapshot object.
- name (
-
find
(name, limit=None, marker=None)[source]¶ Searches for a snapshot by a given list of attributes.
Return type: list of Snapshot
Returns: a Snapshot object or an empty list if none found.
-
BlockStoreService¶
-
class
cloudbridge.cloud.interfaces.services.
BlockStoreService
[source]¶ The Block Store Service interface provides access to block device services, such as volume and snapshot services in the provider.
-
snapshots
¶ Provides access to volume snapshots for this provider.
Example:
# print all snapshots for snap in provider.block_store.snapshots: print(snap.id, snap.name) # find snapshot by name snap = provider.block_store.snapshots.find(name='my_snap')[0] print(snap.id, snap.name)
Return type: SnapshotService
Returns: an SnapshotService object
-
volumes
¶ Provides access to volumes (i.e., block storage) for this provider.
Example:
# print all volumes for vol in provider.block_store.volumes: print(vol.id, vol.name) # find volume by name vol = provider.block_store.volumes.find(name='my_vol')[0] print(vol.id, vol.name)
Return type: VolumeService
Returns: a VolumeService object
-
ImageService¶
-
class
cloudbridge.cloud.interfaces.services.
ImageService
[source]¶ Base interface for an Image Service
-
find
(name, limit=None, marker=None)[source]¶ Searches for an image by a given list of attributes
Return type: object
ofImage
Returns: an Image instance
-
NetworkService¶
-
class
cloudbridge.cloud.interfaces.services.
NetworkService
[source]¶ Base interface for a Network Service.
-
create
(name=None)[source]¶ Create a new network.
Parameters: name ( str
) – An optional network name. The name will be set if the provider supports it.Return type: object
ofNetwork
Returns: A Network object
-
create_floating_ip
()[source]¶ Allocate a new floating (i.e., static) IP address.
Parameters: network_id ( str
) – The ID of the network with which to associate the new IP address.Return type: FloatingIP
Returns: floating IP object
-
create_router
(name=None)[source]¶ Create a new router/gateway.
Parameters: name ( str
) – An optional router name. The name will be set if the provider supports it.Return type: Router
Returns: a newly created router object
-
delete
(network_id)[source]¶ Delete an existing Network.
Parameters: network_id ( str
) – The ID of the network to be deleted.Return type: bool
Returns: True
if the network does not exist,False
otherwise. Note that this implies that the network may not have been deleted by this method but instead has not existed at all.
-
floating_ips
(network_id=None)[source]¶ List floating (i.e., static) IP addresses.
Parameters: network_id ( str
) – The ID of the network by which to filter the IPs.Return type: list
ofFloatingIP
Returns: list of floating IP objects
-
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
ofNetwork
Returns: a Network object
-
list
(limit=None, marker=None)[source]¶ List all networks.
Return type: list
ofNetwork
Returns: list of Network objects
-
routers
()[source]¶ Get a list of available routers.
Return type: list
of :class: RouterReturns: list of routers
-
subnets
¶ Provides access to subnets.
Example:
# Print all subnets for s in provider.network.subnets: print(s.id, s.name) # Get subnet by ID s = provider.network.subnets.get('subnet-id') print(s.id, s.name)
Return type: SubnetService
Returns: a SubnetService object
-
ObjectStoreService¶
-
class
cloudbridge.cloud.interfaces.services.
ObjectStoreService
[source]¶ The Object Storage Service interface provides access to the underlying object store 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.object_store.create('my_bucket_name') print(bucket.name)
Parameters: - name (str) – The name of this bucket.
- location (
object
ofRegion
) – The region in which to place this bucket.
Returns: a Bucket object
Return type: object
ofBucket
-
find
(name)[source]¶ Searches for a bucket by a given list of attributes.
Example:
buckets = provider.object_store.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.object_store.get('my_bucket_id') print(bucket.id, bucket.name)
Return type: Bucket
Returns: a Bucket instance
-
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
-
security_groups
¶ Provides access to security groups for this provider.
Example:
# print all security groups for sg in provider.security.security_groups: print(sg.id, sg.name) # find security group by name sg = provider.security.security_groups.find(name='my_sg')[0] print(sg.id, sg.name)
Return type: SecurityGroupService
Returns: a SecurityGroupService object
-
KeyPairService¶
-
class
cloudbridge.cloud.interfaces.services.
KeyPairService
[source]¶ Base interface for key pairs.
-
create
(name)[source]¶ Create a new key pair or raise an exception if one already exists.
Parameters: name (str) – The name of the key pair to be created. Return type: object
ofKeyPair
Returns: A keypair instance or None
.
-
delete
(key_pair_id)[source]¶ Delete an existing SecurityGroup.
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
(name, limit=None, marker=None)[source]¶ Searches for a key pair by a given list of attributes.
Return type: object
ofKeyPair
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
-
SecurityGroupService¶
-
class
cloudbridge.cloud.interfaces.services.
SecurityGroupService
[source]¶ Base interface for security groups.
-
create
(name, description, network_id)[source]¶ Create a new SecurityGroup.
Parameters: - name (str) – The name of the new security group.
- description (str) – The description of the new security group.
- network_id (
str
) – Network ID under which to create the security group.
Return type: object
ofSecurityGroup
Returns: A SecurityGroup instance or
None
if one was not created.
-
delete
(group_id)[source]¶ Delete an existing SecurityGroup.
Parameters: group_id (str) – The security group ID to be deleted. Return type: bool
Returns: True
if the security group does not exist,False
otherwise. Note that this implies that the group may not have been deleted by this method but instead has not existed in the first place.
-
find
(name, limit=None, marker=None)[source]¶ Get security groups associated with your account filtered by name.
Parameters: name (str) – The name of the security group to retrieve. Return type: list of SecurityGroup
Returns: A list of SecurityGroup objects or an empty list if none found.
-
get
(security_group_id)[source]¶ Returns a SecurityGroup given its ID. Returns
None
if the SecurityGroup does not exist.Example:
sg = provider.security.security_groups.get('my_sg_id') print(sg.id, sg.name)
Return type: SecurityGroup
Returns: a SecurityGroup instance
-
list
(limit=None, marker=None)[source]¶ List all security groups associated with this account.
Return type: list
ofSecurityGroup
Returns: list of SecurityGroup objects
-
InstanceTypesService¶
-
class
cloudbridge.cloud.interfaces.services.
InstanceTypesService
[source]¶ -
find
(**kwargs)[source]¶ Searches for an instance by a given list of attributes.
Return type: object
ofInstanceType
Returns: an Instance object
-
get
(instance_type_id)[source]¶ Returns an InstanceType given its ID. Returns
None
if the InstanceType does not exist.Example:
itype = provider.compute.instance_types.get('my_itype_id') print(itype.id, itype.name)
Return type: InstanceType
Returns: an InstanceType instance
-
list
(limit=None, marker=None)[source]¶ List all instance types.
Return type: list
ofInstanceType
Returns: list of InstanceType 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
ofRegion
Returns: a Region instance or None
-