cloudmesh.google.compute.Provider
¶
Module Contents¶
Classes¶
-
class
cloudmesh.google.compute.Provider.
Provider
(name)¶ Bases:
cloudmesh.abstract.ComputeNodeABC.ComputeNodeABC
-
kind
= google¶
-
sample
= cloudmesh: cloud: {name}: cm: active: true heading: {name} host: https://console.cloud.google.com/compute/instances?project={project_id} label: {name} kind: google version: v1 service: compute default: image: ubuntu-1910 image_project: ubuntu-os-cloud project_name: cloudmesh storage_bucket: cloudmesh-bucket zone: us-central1-a region: us-central1 flavor: g1-small size: 10 resource_group: cloudmesh-group network: global/networks/default credentials: type: {type} auth: json_file: {filename} project_id: {project_id} client_email: {client_email}¶
-
vm_state
= ['PROVISIONING', 'STAGING', 'RUNNING', 'STOPPING', 'STOPPED', 'SUSPENDING', 'SUSPENDED', 'TERMINATED']¶
-
output
¶
-
static
get_kind
()¶
-
get_credentials
(self, client_secret_file, scopes)¶ Method to get the credentials using the Service Account JSON file.
- Parameters
client_secret_file – Service Account JSON File path.
scopes – Scopes needed to provision.
- Returns
-
_get_service
(self, service_type=None, version='v1', scopes=None)¶ Method to get service.
-
_get_compute_service
(self)¶ Method to get compute service.
-
_get_iam_service
(self)¶ Method to get compute service.
-
_key_dict
(self, response)¶
-
_process_status
(self, instance)¶
-
_process_instance
(self, instance)¶ converts the instance json to dict.
- Parameters
instance – JSON with instance details
- Returns
-
update_dict
(self, elements, kind=None)¶ adds a cloudmesh cm dict to each dict in the list elements.
returns an object or list of objects With the dict method this object is converted to a dict. Typically this method is used internally.
- Parameters
elements – the list of original dicts. If elements is a single dict a list with a single element is returned.
kind – for some kinds special attributes are added. This includes key, vm, image, flavor.
- Returns
The list with the modified dicts
-
_format_aggregate_list
(self, instance_list)¶ formats the instance list to flat dict format.
- Parameters
instance_list –
- Returns
dict
-
_format_zone_list
(self, instance_list)¶ formats the instance list to flat dict format.
- Parameters
instance_list –
- Returns
dict
-
_wait_for_operation
(self, compute_service, operation, project, zone=None, name=None)¶
-
start
(self, name=None, **kwargs)¶ start a node
- Parameters
name – the unique node name
- Returns
The dict representing the node
-
stop
(self, name=None, **kwargs)¶ stops the node with the given name
- Parameters
name –
- Returns
The dict representing the node including updated status
-
_raw_instance_info
(self, name, compute_service=None, **kwargs)¶ gets the information of a node with a given name
- Parameters
name –
displayType –
- Returns
-
_info
(self, name, displayType, compute_service=None, **kwargs)¶ gets the information of a node with a given name
- Parameters
name –
displayType –
- Returns
-
info
(self, name=None, **kwargs)¶ gets the information of a node with a given name
- Parameters
name –
- Returns
The dict representing the node including updated status
-
abstract
suspend
(self, name=None)¶ suspends the node with the given name
- Parameters
name – the name of the node
- Returns
The dict representing the node
-
list
(self, **kwargs)¶ list all vms
- Returns
an array of dicts representing the nodes
-
resume
(self, name=None)¶ resume the named node
- Parameters
name – the name of the node
- Returns
the dict of the node
-
destroy
(self, name=None, **kwargs)¶ destroys the node
- Parameters
name – the name of the node
- Returns
the dict of the node
-
_get_compute_config
(self, vm_name, project_id, zone, machine_type, disk_image, storage_bucket, startup_script, diskSize, secgroup)¶
-
_create_instance
(self, compute_service, project, zone, name, bucket, disk_image, machineType, startup_script, diskSize, secgroup)¶ create a VM instance for given name.
- Parameters
compute_service –
project –
zone –
name –
bucket –
disk_image –
machineType –
startup_script –
diskSize –
secgroup –
- Returns
-
create
(self, name=None, image=None, size=10, timeout=360, group=None, **kwargs)¶ creates a named node.
- Parameters
name – the name of the node
image – the image used
size – the size of the image
timeout – a timeout in seconds that is invoked in case the image does not boot. The default is set to 3 minutes.
group – a list of groups the vm belongs to
kwargs – additional arguments passed along at time of boot
- Returns
-
set_server_metadata
(self, name, **keys)¶ sets the metadata for the server
- Parameters
name – name of the fm
metadata – the metadata
- Returns
-
get_server_metadata
(self, name)¶ gets the metadata for the server
- Parameters
name – name of the fm
- Returns
-
_update_metadata
(self, project_id, zone, name, instance_metadata)¶ adds/updates/deletes the instance metadata
- Parameters
project_id –
zone –
name –
instance_metadata –
- Returns
-
delete_server_metadata
(self, name, key)¶ gets the metadata for the server
- Parameters
name – name of the fm
- Returns
-
abstract
rename
(self, name=None, destination=None)¶ rename a node
- Parameters
destination –
name – the current name
- Returns
the dict with the new name
-
_get_project_metadata
(self, project_id)¶ gets a list of keys from google project.
- Parameters
project_id – Project Id to get info for.
- Returns
-
_get_instance_metadata
(self, name)¶ get a list of keys from google project.
- Parameters
project_id – Project Id to get info for.
- Returns
-
_get_keys
(self, cloud)¶ get s keys on google cloud from DB.
- Parameters
cloud –
- Returns
-
_key_already_exists
(self, cloud, name, public_key)¶ checks if the key with name already exists.
- Parameters
name – Name of the key to be added and checked.
- Returns
-
keys
(self)¶ Lists the keys on the cloud
- Returns
dict
-
key_upload
(self, key=None)¶ uploads the key specified in the yaml configuration to the cloud
- Parameters
key –
- Returns
-
key_delete
(self, name=None)¶ deletes the key with the given name
- Parameters
name – The name of the key
- Returns
-
images
(self, **kwargs)¶ Lists the images on the cloud
- Returns
dict
-
image
(self, name=None, **kwargs)¶ Gets the image with a given name
- Parameters
name – The name of the image
- Returns
the dict of the image
-
flavor
(self, name, **kwargs)¶ Gets the flavor with a given name
- Parameters
name – The name of the flavor
- Returns
The dict of the flavor
-
_get_flavor
(self, compute_service, project_id, zone, name)¶
-
flavors
(self, **kwargs)¶ Lists the flavors on the cloud
- Returns
dict of flavors
-
_get_flavors
(self, compute_service, project_id, zone)¶
-
abstract
reboot
(self, name=None)¶ Reboot a list of nodes with the given names
- Parameters
name – A list of node names
- Returns
A list of dict representing the nodes
-
abstract
attach_public_ip
(self, name=None, ip=None)¶ adds a public ip to the named vm
- Parameters
name – Name of the vm
ip – The ip address
- Returns
-
abstract
detach_public_ip
(self, name=None, ip=None)¶ adds a public ip to the named vm
- Parameters
name – Name of the vm
ip – The ip address
- Returns
-
delete_public_ip
(self, ip=None)¶ Deletes the ip address
- Parameters
ip – the ip address, if None than all will be deleted
- Returns
-
list_public_ips
(self, available=False)¶ Lists the public ip addresses.
- Parameters
available – if True only those that are not allocated will be returned.
- Returns
-
create_public_ip
(self)¶ Creates a new public IP address to use
- Returns
The ip address information
-
find_available_public_ip
(self)¶ Returns a single public available ip address.
- Returns
The ip
-
get_public_ip
(self, name=None)¶ returns the public ip
- Parameters
name – name of the server
- Returns
-
abstract
list_secgroups
(self, name=None)¶ List the named security group
- Parameters
name – The name of the group, if None all will be returned
- Returns
-
abstract
list_secgroup_rules
(self, name='default')¶ List the named security group
- Parameters
name – The name of the group, if None all will be returned
- Returns
-
abstract
upload_secgroup
(self, name=None)¶
-
abstract
add_secgroup
(self, name=None, description=None)¶
-
abstract
add_secgroup_rule
(self, name=None, port=None, protocol=None, ip_range=None)¶
-
abstract
remove_secgroup
(self, name=None)¶
-
abstract
add_rules_to_secgroup
(self, name=None, rules=None)¶
-
abstract
remove_rules_from_secgroup
(self, name=None, rules=None)¶
-
abstract
wait
(self, vm=None, interval=None, timeout=None)¶ wait till the given VM can be logged into
- Parameters
vm – name of the vm
interval – interval for checking
timeout – timeout
- Returns
-
abstract
console
(self, vm=None)¶ gets the output from the console
- Parameters
vm – name of the VM
- Returns
-
abstract
log
(self, vm=None)¶
-
ssh
(self, vm=None, command=None)¶
-
static
json_to_yaml
(cls, name, filename='~/.cloudmesh/security/google.json')¶ Given a json file downloaded from google, copies the content into the cloudmesh yaml file, while overwriting or creating a new compute provider
- Parameters
cls –
name –
filename – Service Account Key file downloaded from google cloud.
- Returns
None
-