gridscale Compute Driver Documentation¶
gridscale is a German cloud provider with focus on awesome user experience.

Instantiating a driver¶
The gridscale driver requires your User_Uuid and your API-Token. You will have to generate a API-Token first, to be able to do that, you want to make an account and create a token under the API-Key option in the panel.
from libcloud.compute.type import Provider
from libcloud.compute.providers import get_driver
driver = get_driver(Provider.GRIDSCALE)
driver = driver("USER-UUID", "API-TOKEN")
Creating a Server¶
from libcloud.compute.base import NodeSize
from libcloud.compute.type import Provider
from libcloud.compute.providers import get_driver
cls = get_driver(Provider.GRIDSCALE)
driver = cls("USER-UUID", "API-TOKEN")
# We don't feature packages containing a fix size so you will have to
# built your own size object. Make sure to use a multiple of 1024MB when
# asigning RAM
size_name = "my-node-size"
ram = 1024 # amout of ram In MB
disk = 10 # disk size in GB
cores = 1 # numer of cores node should have
size = NodeSize(
id=0,
bandwidth=0,
price=0,
name=size_name,
ram=ram,
disk=disk,
driver=driver,
extra={"cores": cores},
)
ssh_key = driver.list_key_pairs()[0]
ssh_key_uuid = ssh_key.fingerprint
node_name = "MyServer"
images = driver.list_images()
image = [i for i in images if i.name == "Ubuntu 18.04 LTS"][0]
locations = driver.list_locations()
location = [loc for loc in locations if loc.name == "de/fra"][0]
node = driver.create_node(
name=node_name, size=size, image=image, location=location, ex_ssh_key_ids=ssh_key
)
Create a server, SSH into it and run deployment script on it¶
import os
from libcloud.compute.base import NodeSize
from libcloud.compute.type import Provider
from libcloud.compute.providers import get_driver
from libcloud.compute.deployment import ScriptDeployment
cls = get_driver(Provider.GRIDSCALE)
driver = cls("USER-UUID", "API-TOKEN")
# We don't feature packages containing a fix size so you will have to
# built your own size object. Make sure to use a multiple of 1024MB when
# asigning RAM
size_name = "my-node-size"
ram = 1024 # amout of ram In MB
disk = 10 # disk size in GB
cores = 1 # numer of cores node should have
size = NodeSize(
id=0,
bandwidth=0,
price=0,
name=size_name,
ram=ram,
disk=disk,
driver=driver,
extra={"cores": cores},
)
ssh_key = driver.list_key_pairs()[0]
ssh_key_uuid = ssh_key.fingerprint
node_name = "MyServer"
images = driver.list_images()
image = [i for i in images if i.name == "Ubuntu 18.04 LTS"][0]
locations = driver.list_locations()
location = [loc for loc in locations if loc.name == "de/fra"][0]
# Check if a key pair object with the provided name already exists
# If it already exists, using an existing key, otherwise import a new one
key_pair_name = "libcloud-key-pair"
key_pairs = driver.list_key_pairs()
key_pairs = [kp for kp in key_pairs if kp.name == key_pair_name]
public_key_file_path = os.path.expanduser("~/.ssh/id_rsa_gridscale.pub")
private_key_file_path = os.path.expanduser("~/.ssh/id_rsa_gridscale")
if key_pairs:
print("Re-using existing SSH Key")
key_pair = key_pairs[0]
else:
print("Importing / creating new SSH Key")
key_pair = driver.import_key_pair_from_file(
name=key_pair_name, key_file_path=public_key_file_path
) # NOQA
step = ScriptDeployment("echo whoami ; date ; ls -la")
node = driver.deploy_node(
name=node_name,
size=size,
image=image,
location=location,
ex_ssh_key_ids=[key_pair.fingerprint],
deploy=step,
ssh_key=private_key_file_path,
)
print(node)
API Docs¶
API¶
- class libcloud.compute.drivers.gridscale.GridscaleNodeDriver(user_id, key, **kwargs)[source]¶
create and entry in libcloud/compute/providers for gridscale
- Parameters:
key (
str
) – API key or username to be used (required)secret (
str
) – Secret password to be used (required)secure (
bool
) – Whether to use HTTPS or HTTP. Note: Some providers only support HTTPS, and it is on by default.host (
str
) – Override hostname used for connections.port (
int
) – Override port used for connections.api_version (
str
) – Optional API version. Only used by drivers which support multiple API versions.region (
str
) – Optional driver region. Only used by drivers which support multiple regions.
- Return type:
None
- attach_volume(node, volume)[source]¶
Attaches volume to node.
- Parameters:
node (
Node
) – Node to attach volume to.volume (
StorageVolume
) – Volume to attach.
- Rytpe:
bool
- connectionCls¶
alias of
GridscaleConnection
- copy_image(source_region: str, node_image: NodeImage, name: str, description: Optional[str] = None) NodeImage ¶
Copies an image from a source region to the current region.
- create_key_pair(name: str) KeyPair ¶
Create a new key pair object.
- Parameters:
name (
str
) – Key pair name.- Return type:
KeyPair
object
- create_node(name, size, image, location, ex_ssh_key_ids=None, **kwargs)[source]¶
Create a simple node with a name, cores, memory at the designated location.
- Parameters:
name (
str
) – Name of the server.size (
NodeSize
) – Nodesize object.image (
GridscaleTemplate
) – OS image to attach to the storage.location (
NodeLocation
) – The data center to create a node in.ex_ssh_key_ids (
list
ofstr
) – List of SSH key IDs to add to the server.
- Returns:
The newly created Node.
- Return type:
- create_volume(size, name, location=None, snapshot=None)[source]¶
Create a new volume.
- Parameters:
size (
int
) – Integer in GB.name (
str
) – Name of the volume.location (
NodeLocation
) – The server location.snapshot (
VolumeSnapshot
) – Snapshot from which to create the new volume. (optional)
- Returns:
Newly created StorageVolume.
- Return type:
- create_volume_snapshot(volume, name)[source]¶
Creates a snapshot of the current state of your volume, you can rollback to.
- Parameters:
volume (
StorageVolume
) – Volume you want to create a snapshot of.name (
str
) – Name of the snapshot.
- Returns:
VolumeSnapshot.
- Return type:
- delete_image(node_image)[source]¶
Destroy an image.
- Parameters:
node_image (
NodeImage
) – Node image object.- Returns:
True if the destroy was successful, otherwise False
- Return type:
bool
- delete_key_pair(key_pair: KeyPair) bool ¶
Delete an existing key pair.
- Parameters:
key_pair (
KeyPair
) – Key pair object.- Return type:
bool
- deploy_node(deploy: Deployment, ssh_username: str = 'root', ssh_alternate_usernames: Optional[List[str]] = None, ssh_port: int = 22, ssh_timeout: int = 10, ssh_key: Optional[T_Ssh_key] = None, ssh_key_password: Optional[str] = None, auth: T_Auth = None, timeout: int = 300, max_tries: int = 3, ssh_interface: str = 'public_ips', at_exit_func: Callable = None, wait_period: int = 5, **create_node_kwargs) Node ¶
Create a new node, and start deployment.
In order to be able to SSH into a created node access credentials are required.
A user can pass either a
NodeAuthPassword
orNodeAuthSSHKey
to theauth
argument. If thecreate_node
implementation supports that kind if credential (as declared inself.features['create_node']
) then it is passed on tocreate_node
. Otherwise it is not passed on tocreate_node
and it is only used for authentication.If the
auth
parameter is not supplied but the driver declares it supportsgenerates_password
then the password returned bycreate_node
will be used to SSH into the server.Finally, if the
ssh_key_file
is supplied that key will be used to SSH into the server.This function may raise a
DeploymentException
, if a create_node call was successful, but there is a later error (like SSH failing or timing out). This exception includes a Node object which you may want to destroy if incomplete deployments are not desirable.>>> from libcloud.compute.drivers.dummy import DummyNodeDriver >>> from libcloud.compute.deployment import ScriptDeployment >>> from libcloud.compute.deployment import MultiStepDeployment >>> from libcloud.compute.base import NodeAuthSSHKey >>> driver = DummyNodeDriver(0) >>> key = NodeAuthSSHKey('...') # read from file >>> script = ScriptDeployment("yum -y install emacs strace tcpdump") >>> msd = MultiStepDeployment([key, script]) >>> def d(): ... try: ... driver.deploy_node(deploy=msd) ... except NotImplementedError: ... print ("not implemented for dummy driver") >>> d() not implemented for dummy driver
Deploy node is typically not overridden in subclasses. The existing implementation should be able to handle most such.
- Parameters:
deploy (
Deployment
) – Deployment to run once machine is online and available to SSH.ssh_username (
str
) – Optional name of the account which is used when connecting to SSH server (default is root)ssh_alternate_usernames (
list
) – Optional list of ssh usernames to try to connect with if using the default one failsssh_port (
int
) – Optional SSH server port (default is 22)ssh_timeout (
float
) – Optional SSH connection timeout in seconds (default is 10)auth (
NodeAuthSSHKey
orNodeAuthPassword
) – Initial authentication information for the node (optional)ssh_key (
str
orlist
ofstr
) – A path (or paths) to an SSH private key with which to attempt to authenticate. (optional)ssh_key_password (
str
) – Optional password used for encrypted keys.timeout (
int
) – How many seconds to wait before timing out. (default is 600)max_tries (
int
) – How many times to retry if a deployment fails before giving up (default is 3)ssh_interface (
str
) – The interface to wait for. Default is ‘public_ips’, other option is ‘private_ips’.at_exit_func (
func
) –Optional atexit handler function which will be registered and called with created node if user cancels the deploy process (e.g. CTRL+C), after the node has been created, but before the deploy process has finished.
This method gets passed in two keyword arguments:
driver -> node driver in question
node -> created Node object
Keep in mind that this function will only be called in such scenario. In case the method finishes (this includes throwing an exception), at exit handler function won’t be called.
wait_period (
int
) – How many seconds to wait between each iteration while waiting for node to transition into running state and have IP assigned. (default is 5)
- destroy_node(node, ex_destroy_associated_resources=False)[source]¶
Destroy node.
- Parameters:
node (
Node
) – Node object.ex_destroy_associated_resources – True to destroy associated
resources such as storage volumes and IPs. :type ex_destroy_associated_resources:
bool
- Returns:
True if the destroy was successful, otherwise False.
- Return type:
bool
- destroy_volume(volume)[source]¶
Delete volume.
- Parameters:
volume (
StorageVolume
) – Volume to be destroyed.- Returns:
True if the destroy was successful, otherwise False.
- Return type:
bool
- destroy_volume_snapshot(snapshot)[source]¶
Destroy a snapshot.
- Parameters:
snapshot (:class:'.VolumeSnapshot`) – The snapshot to delete.
- Returns:
True if the destroy was successful, otherwise False.
- Return type:
bool
- detach_volume(volume)[source]¶
Detaches a volume from a node.
- Parameters:
volume (
StorageVolume
) – Volume to be detached- Return type:
bool
- ex_create_ip(family, location, name)[source]¶
Create either an ip_v4 ip or a ip_v6.
- Parameters:
family (
int
) – Defines if the ip is v4 or v6 with int 4 or int 6.location (
NodeLocation
) – Defines which datacenter the created ip responds with.name (
str
) – Name of your Ip.
- Returns:
Ip
- Return type:
- ex_create_networks(name, location)[source]¶
Create a network at the data center location.
- Parameters:
name (
str
) – Name of the network.location (
NodeLocation
) – Location.
- Returns:
Network.
- Return type:
- ex_destroy_ip(ip)[source]¶
Delete an ip.
- Parameters:
ip (
GridscaleIp
) – IP object.- Returns:
True
if delete_image was successful,False
otherwise.- Return type:
bool
- ex_destroy_network(network)[source]¶
Delete network.
- Parameters:
network (
GridscaleNetwork
) – Network object.- Returns:
True
if destroyed successfully, otherwiseFalse
- Return type:
bool
- ex_link_ip_to_node(node, ip)[source]¶
links a existing ip with a node
- Parameters:
node (
object
) – node objectip (
object
) – ip object
- Returns:
Request ID
- Return type:
str
- ex_link_isoimage_to_node(node, isoimage)[source]¶
link and isoimage to a node
- Parameters:
node (
object
) – Node you want to link the iso image toisoimage (
object
) – isomiage you want to link
- Returns:
None -> success
- Return type:
None
- ex_link_network_to_node(node, network)[source]¶
Link a network to a node.
- Parameters:
node (
Node
) – Node object to link networks to.network (
GridscaleNetwork
) – Network you want to link.
- Returns:
True
if linked sucessfully, otherwiseFalse
- Return type:
bool
- ex_list_ips()[source]¶
Lists all IPs available.
- Returns:
List of IP objects.
- Return type:
list
ofGridscaleIp
- ex_list_ips_for_node(node)[source]¶
Return a list of associated IPs for the provided node.
- Rype:
list
ofGridscaleIp
- ex_list_networks()[source]¶
List all networks.
- Returns:
List of objects.
- Return type:
list
ofGridscaleNetwork
- ex_list_volumes_for_node(node)[source]¶
Return a list of associated volumes for the provided node.
- Return type:
list
ofStorageVolume
- ex_rename_network(network, name)[source]¶
Modify networks name.
- Parameters:
network (
GridscaleNetwork
) – Network.name (
str
) – New network name.
- Returns:
True
orFalse
- Return type:
bool
- ex_rename_node(node, name)[source]¶
Modify node name.
- Parameters:
name (
str
) – New node name.node (
Node
) – Node
- Returns:
True
orFalse
- Return type:
bool
- ex_rename_volume(volume, name)[source]¶
Modify storage volume name
- Parameters:
volume (:class:.`StorageVolume`) – Storage.
name (
str
) – New storage name.
- Returns:
True
orFalse
- Return type:
bool
- ex_storage_rollback(volume, snapshot, rollback)[source]¶
initiate a rollback on your storage
- Parameters:
volume (
string
) – storage uuidsnapshot (
string
) – snapshot uuidrollback (
bool
) – variable
- Returns:
RequestID
- Return type:
str
- ex_unlink_ip_from_node(node, ip)[source]¶
unlink ips from server
- Parameters:
node (
object
) – node you want to unlink the ip fromip (
object
) – the ip you want to unlink
- Returns:
None -> success
- Return type:
None
- ex_unlink_isoimage_from_node(node, isoimage)[source]¶
unlink isoimages from server
- Parameters:
node (
object
) – node you want to unlink the image fromisoimage (
object
) – isoimage you want to unlink
- Returns:
None -> success
- Return type:
None
- features: Dict[str, List[str]] = {'create_node': ['ssh_key']}¶
- List of available features for a driver.
libcloud.compute.base.NodeDriver.create_node()
ssh_key: Supports
NodeAuthSSHKey
as an authentication method for nodes.password: Supports
NodeAuthPassword
as an authentication method for nodes.generates_password: Returns a password attribute on the Node object returned from creation.
- get_image(image_id)[source]¶
Get an image based on an image_id.
- Parameters:
image_id (
str
) – Image identifier.- Returns:
A NodeImage object.
- Return type:
- get_key_pair(name: str) KeyPair ¶
Retrieve a single key pair.
- Parameters:
name (
str
) – Name of the key pair to retrieve.- Return type:
- import_key_pair_from_file(name: str, key_file_path: str) KeyPair ¶
Import a new public key from string.
- Parameters:
name (
str
) – Key pair name.key_file_path (
str
) – Path to the public key file.
- Return type:
KeyPair
object
- import_key_pair_from_string(name, key_material)[source]¶
Import a new public key from string.
- Parameters:
name (
str
) – Key pair name.key_material (
str
) – Public key material.
- Return type:
KeyPair
object
- list_images()[source]¶
List images.
- Returns:
List of node image objects
- Return type:
list
ofNodeImage
- list_locations()[source]¶
List all available data centers.
- Returns:
List of node location objects
- Return type:
list
ofNodeLocation
- list_sizes(location: Optional[NodeLocation] = None) List[NodeSize] ¶
List sizes on a provider
- Parameters:
location (
NodeLocation
) – The location at which to list sizes- Returns:
list of node size objects
- Return type:
list
ofNodeSize
- list_volume_snapshots(volume)[source]¶
Lists all snapshots for storage volume.
- Parameters:
volume (
StorageVolume
) – storage the snapshot is attached to- Returns:
Snapshots
- Return type:
list
ofVolumeSnapshot
- list_volumes()[source]¶
List all volumes.
- Returns:
List of StorageVolume object
- Return type:
list
ofStorageVolume
- reboot_node(node, ex_sleep_interval=3)[source]¶
Reboot a node.
- Parameters:
node (
Node
) – Node object.ex_sleep_interval (
int
) – time to let the shutdown process finish
- Returns:
True if the reboot was successful, otherwise False.
- Return type:
bool
- start_node(node)[source]¶
Start a node.
- Parameters:
node (
Node
) – The node to be started- Returns:
True if the start was successful, otherwise False
- Return type:
bool
- stop_node(node: Node) bool ¶
Stop a node
- Parameters:
node (
Node
) – The node to be stopped.- Returns:
True if the stop was successful, otherwise False
- Return type:
bool
- wait_until_running(nodes: List[Node], wait_period: float = 5, timeout: int = 600, ssh_interface: str = 'public_ips', force_ipv4: bool = True, ex_list_nodes_kwargs: Optional[Dict] = None) List[Tuple[Node, List[str]]] ¶
Block until the provided nodes are considered running.
Node is considered running when it’s state is “running” and when it has at least one IP address assigned.
- Parameters:
nodes (
list
ofNode
) – List of nodes to wait for.wait_period (
int
) – How many seconds to wait between each loop iteration. (default is 3)timeout (
int
) – How many seconds to wait before giving up. (default is 600)ssh_interface (
str
) – Which attribute on the node to use to obtain an IP address. Valid options: public_ips, private_ips. Default is public_ips.force_ipv4 (
bool
) – Ignore IPv6 addresses (default is True).ex_list_nodes_kwargs (
dict
) – Optional driver-specific keyword arguments which are passed to thelist_nodes
method.
- Returns:
[(Node, ip_addresses)]
list of tuple of Node instance and list of ip_address on success.- Return type:
list
oftuple