libcloud.compute.drivers.linode module¶
libcloud driver for the Linode(R) API
This driver implements all libcloud functionality for the Linode API. Since the API is a bit more fine-grained, create_node abstracts a significant amount of work (and may take a while to run).
Linode home page http://www.linode.com/ Linode API documentation http://www.linode.com/api/ Alternate bindings for reference http://github.com/tjfontaine/linode-python
Linode(R) is a registered trademark of Linode, LLC.
- class libcloud.compute.drivers.linode.LinodeNodeDriver(key, secret=None, secure=True, host=None, port=None, api_version='4.0', region=None, **kwargs)[source]¶
Bases:
NodeDriver
- 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
- class libcloud.compute.drivers.linode.LinodeNodeDriverV3(key, secret=None, secure=True, host=None, port=None, api_version='4.0', region=None, **kwargs)[source]¶
Bases:
LinodeNodeDriver
libcloud driver for the Linode API
Rough mapping of which is which:
list_nodes linode.list
reboot_node linode.reboot
destroy_node linode.delete
- create_node linode.create, linode.update,
linode.disk.createfromdistribution, linode.disk.create, linode.config.create, linode.ip.addprivate, linode.boot
list_sizes avail.linodeplans
list_images avail.distributions
list_locations avail.datacenters
list_volumes linode.disk.list
destroy_volume linode.disk.delete
For more information on the Linode API, be sure to read the reference:
Instantiate the driver with the given API key
- Parameters:
key (
str
) – the API key to use (required)- Return type:
None
- LINODE_STATES = {-2: NodeState.UNKNOWN, -1: NodeState.PENDING, 0: NodeState.PENDING, 1: NodeState.RUNNING, 2: NodeState.STOPPED, 3: NodeState.REBOOTING, 4: NodeState.UNKNOWN}¶
- connectionCls¶
alias of
LinodeConnection
- create_node(name, image, size, auth, location=None, ex_swap=None, ex_rsize=None, ex_kernel=None, ex_payment=None, ex_comment=None, ex_private=False, lconfig=None, lroot=None, lswap=None)[source]¶
Create a new Linode, deploy a Linux distribution, and boot
This call abstracts much of the functionality of provisioning a Linode and getting it booted. A global grant to add Linodes to the account is required, as this call will result in a billing charge.
Note that there is a safety valve of 5 Linodes per hour, in order to prevent a runaway script from ruining your day.
- Parameters:
name (
str
) – the name to assign the Linode (mandatory)image (
NodeImage
) – which distribution to deploy on the Linode (mandatory)size (
NodeSize
) – the plan size to create (mandatory)auth (
NodeAuthSSHKey
orNodeAuthPassword
) – an SSH key or root password (mandatory)location (
NodeLocation
) – which datacenter to create the Linode inex_swap (
int
) – size of the swap partition in MB (128)ex_rsize (
int
) – size of the root partition in MB (plan size - swap).ex_kernel (
str
) – a kernel ID from avail.kernels (Latest 2.6 Stable).ex_payment (
int
) – one of 1, 12, or 24; subscription length (1)ex_comment (
str
) – a small comment for the configuration (libcloud)ex_private (
bool
) – whether or not to request a private IP (False)lconfig (
str
) – what to call the configuration (generated)lroot (
str
) – what to call the root image (generated)lswap (
str
) – what to call the swap space (generated)
- Returns:
Node representing the newly-created Linode
- Return type:
Node
- destroy_node(node)[source]¶
Destroy the given Linode
Will remove the Linode from the account and issue a prorated credit. A grant for removing Linodes from the account is required, otherwise this method will fail.
In most cases, all disk images must be removed from a Linode before the Linode can be removed; however, this call explicitly skips those safeguards. There is no going back from this method.
- Parameters:
node (
Node
) – the Linode to destroy- Return type:
bool
- destroy_volume(volume)[source]¶
Destroys disk volume for the Linode. Linode id is to be provided as extra[“LinodeId”] within
StorageVolume
. It can be retrieved bylibcloud.compute.drivers.linode.LinodeNodeDriver .ex_list_volumes()
.- Parameters:
volume (
StorageVolume
) – Volume to be destroyed- Return type:
bool
- ex_create_volume(size, name, node, fs_type)[source]¶
Create disk for the Linode.
- Parameters:
size (
int
) – Size of volume in megabytes (required)name (
str
) – Name of the volume to be creatednode (
Node
) – Node to attach volume to.fs_type (
str
) – The formatted type of this disk. Valid types are: ext3, ext4, swap, raw
- Returns:
StorageVolume representing the newly-created volume
- Return type:
StorageVolume
- ex_list_volumes(node, disk_id=None)[source]¶
List existing disk volumes for for given Linode.
- Parameters:
node (
Node
) – Node to list disk volumes for. (required)disk_id (
int
) – Id for specific disk volume. (optional)
- Return type:
list
ofStorageVolume
- ex_resize_node(node, size)[source]¶
Resizes a Linode from one plan to another
Immediately shuts the Linode down, charges/credits the account, and issue a migration to another host server. Requires a size (numeric), which is the desired PlanID available from avail.LinodePlans() After resize is complete the node needs to be booted
- features: Dict[str, List[str]] = {'create_node': ['ssh_key', 'password']}¶
- 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.
- linode_set_datacenter(dc)[source]¶
Set the default datacenter for Linode creation
Since Linodes must be created in a facility, this function sets the default that
create_node
will use. If a location keyword is not passed tocreate_node
, this method must have already been used.- Parameters:
dc (
NodeLocation
) – the datacenter to create Linodes in unless specified- Return type:
bool
- list_images()[source]¶
List available Linux distributions
Retrieve all Linux distributions that can be deployed to a Linode.
- Return type:
list
ofNodeImage
- list_locations()[source]¶
List available facilities for deployment
Retrieve all facilities that a Linode can be deployed in.
- Return type:
list
ofNodeLocation
- list_nodes()[source]¶
List all Linodes that the API key can access
- This call will return all Linodes that the API key in use has access
to.
If a node is in this list, rebooting will work; however, creation and destruction are a separate grant.
- Returns:
List of node objects that the API key can access
- Return type:
list
ofNode
- list_sizes(location=None)[source]¶
List available Linode plans
Gets the sizes that can be used for creating a Linode. Since available Linode plans vary per-location, this method can also be passed a location to filter the availability.
- Parameters:
location (
NodeLocation
) – the facility to retrieve plans in- Return type:
list
ofNodeSize
- class libcloud.compute.drivers.linode.LinodeNodeDriverV4(key, secret=None, secure=True, host=None, port=None, api_version='4.0', region=None, **kwargs)[source]¶
Bases:
LinodeNodeDriver
- 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
- LINODE_DISK_STATES = {'deleting': StorageVolumeState.DELETING, 'not ready': StorageVolumeState.CREATING, 'ready': StorageVolumeState.AVAILABLE}¶
- LINODE_STATES = {'booting': NodeState.STARTING, 'cloning': NodeState.MIGRATING, 'deleting': NodeState.PENDING, 'migrating': NodeState.MIGRATING, 'offline': NodeState.STOPPED, 'provisioning': NodeState.STARTING, 'rebooting': NodeState.REBOOTING, 'rebuilding': NodeState.UPDATING, 'resizing': NodeState.RECONFIGURING, 'restoring': NodeState.PENDING, 'running': NodeState.RUNNING, 'shutting_down': NodeState.STOPPING, 'stopped': NodeState.STOPPED}¶
- LINODE_VOLUME_STATES = {'active': StorageVolumeState.AVAILABLE, 'contact_support': StorageVolumeState.UNKNOWN, 'creating': StorageVolumeState.CREATING, 'resizing': StorageVolumeState.UPDATING}¶
- attach_volume(node, volume, persist_across_boots=True)[source]¶
Attaches a volume to a node. Volume and node must be located in the same region
- Parameters:
node (
Node
) – Node to attach the volume to(required)volume (
StorageVolume
) – Volume to be attached (required)persist_across_boots (bool) – Whether volume should be attached to node across boots
- Return type:
- class:
StorageVolume
- connectionCls¶
alias of
LinodeConnectionV4
- create_image(disk, name=None, description=None)[source]¶
- Creates a private image from a LinodeDisk.
Images are limited to three per account.
- Parameters:
disk (
LinodeDisk
) – LinodeDisk to create the image from (required)name (str) – A name for the image. Defaults to the name of the disk it is being created from if not provided
description (str) – A description of the image
- Returns:
The newly created NodeImage
- Return type:
NodeImage
- create_key_pair(name, public_key='')[source]¶
Creates an SSH keypair
- Parameters:
name – The name to be given to the keypair (required). :type name: str
public_key (str) – Contents of the public key the the SSH key pair
- Return type:
- class:
KeyPair
- create_node(location, name, size, image, root_pass=None, ex_authorized_keys=None, ex_authorized_users=None, ex_tags=None, ex_backups_enabled=False, ex_private_ip=False, ex_userdata=None)[source]¶
Creates a Linode Instance. In order for this request to complete successfully, the user must have the add_linodes grant as this call will incur a charge.
- Parameters:
location (
NodeLocation
) – which region to create the node insize (
NodeSize
) – the plan size to createimage (
NodeImage
) – which distribution to deploy on the nodename (
str
) – the name to assign to node. Must start with an alpha character. May only consist of alphanumeric characters, dashes (-), underscores (_) or periods (.). Cannot have two dashes (–), underscores (__) or periods (..) in a row.root_pass (
str
) – the root password (required if image is provided)ex_authorized_keys (
list
ofstr
) – a list of public SSH keysex_authorized_users (
list
ofstr
) – a list of usernames. If the usernames have associated SSH keys, the keys will be appended to the root users authorized_keysex_tags (
list
ofstr
) – list of tags for the nodeex_backups_enabled (
bool
) – whether to be enrolled in the Linode Backup service (False)ex_private_ip (
bool
) – whether or not to request a private IPex_userdata – add cloud-config compatible userdata to be
processed by cloud-init inside the Linode instance. NOTE: the contents of this string must be base64 encoded before passing it to this function. :type ex_userdata:
str
- Returns:
Node representing the newly-created node
- Return type:
Node
- create_volume(name, size, location=None, node=None, tags=None)[source]¶
Creates a volume and optionally attaches it to a node.
- Parameters:
name (str) – The name to be given to volume (required). Must start with an alpha character. May only consist of alphanumeric characters, dashes (-), underscores (_) Cannot have two dashes (–), underscores (__) in a row.
size (int) – Size in gigabytes (required)
location (
NodeLocation
) – Location to create the node. Required if node is not given.volume (
Node
) – Node to attach the volume totags (list of str) – tags to apply to volume
- Return type:
- class:
StorageVolume
- delete_image(image)[source]¶
Deletes a private image
- Parameters:
image (
NodeImage
) – NodeImage to delete (required)- Return type:
bool
- destroy_node(node)[source]¶
Deletes a node the API Key has permission to read_write
- Parameters:
node (
Node
) – the Linode to destroy- Return type:
bool
- destroy_volume(volume)[source]¶
Destroys the volume given.
- Parameters:
volume (
StorageVolume
) – Volume to be deleted (required)- Return type:
bool
- detach_volume(volume)[source]¶
Detaches a volume from a node.
- Parameters:
volume (
StorageVolume
) – Volume to be detached (required)- Return type:
bool
- ex_allocate_private_address(node, address_type='ipv4')[source]¶
Allocates a private IPv4 address to node.Only ipv4 is currently supported
- Parameters:
node (
Node
) – Node to attach the IP addressaddress_type (str) – Type of IP address
- Returns:
The newly created LinodeIPAddress
- Return type:
LinodeIPAddress
- ex_clone_volume(volume, name)[source]¶
Clones the volume given
- Parameters:
volume (
StorageVolume
) – Volume to be clonedname (str) – new cloned volume name
- Return type:
StorageVolume
- ex_create_disk(size, name, node, fs_type, image=None, ex_root_pass=None, ex_authorized_keys=None, ex_authorized_users=None, ex_read_only=False)[source]¶
Adds a new disk to node
- Parameters:
size (
int
) – Size of disk in megabytes (required)name (
str
) – Name of the disk to be created (required)node (
Node
) – Node to attach disk to (required)fs_type (
str
) – The formatted type of this disk. Valid types are: ext3, ext4, swap, raw, initrdimage (
NodeImage
) – Image to deploy the volume fromex_root_pass (
str
) – root password,required if an image is providedex_authorized_keys (
list
ofstr
) – a list of SSH keysex_authorized_users (
list
ofstr
) – a list of usernames that will have their SSH keys, if any, automatically appended to the root user’s ~/.ssh/authorized_keys file.ex_read_only (
bool
) – if true, this disk is read-only
- Returns:
LinodeDisk representing the newly-created disk
- Return type:
LinodeDisk
- ex_destroy_disk(node, disk)[source]¶
Destroys disk for the given node.
- Parameters:
node (
Node
) – The Node the disk is attached to. (required)disk (
LinodeDisk
) – LinodeDisk to be destroyed (required)
- Return type:
bool
- ex_get_node(node_id)[source]¶
Return a Node object based on a node ID.
- Parameters:
node_id (
str
) – Node’s ID- Returns:
Created node
:rtype :
Node
- ex_get_volume(volume_id)[source]¶
Return a Volume object based on a volume ID.
- Parameters:
volume_id (
str
) – Volume’s id- Returns:
A StorageVolume object for the volume
- Return type:
StorageVolume
- ex_list_addresses()[source]¶
List IP addresses
- Returns:
LinodeIPAddress list
- Return type:
list of
LinodeIPAddress
- ex_list_disks(node)[source]¶
List disks associated with the node.
- Parameters:
node (
Node
) – Node to list disks. (required)- Return type:
list
ofLinodeDisk
- ex_list_node_addresses(node)[source]¶
List all IPv4 addresses attached to node
- Parameters:
node (
Node
) – Node to list IP addresses- Returns:
LinodeIPAddress list
- Return type:
list of
LinodeIPAddress
- ex_rename_node(node, name)[source]¶
Renames a node
- Parameters:
node (
Node
) – the Linode to resizename (
str
) – the node’s new name
- Returns:
Changed Node
- Return type:
Node
- ex_resize_node(node, size, allow_auto_disk_resize=False)[source]¶
Resizes a node the API Key has read_write permission to a different Type. The following requirements must be met: - The node must not have a pending migration - The account cannot have an outstanding balance - The node must not have more disk allocation than the new size allows
- Parameters:
node (
Node
) – the Linode to resizesize (
NodeSize
) – the size of the new nodeallow_auto_disk_resize (
bool
) – Automatically resize disks when resizing a node.
- Return type:
bool
- ex_resize_volume(volume, size)[source]¶
Resizes the volume given.
- Parameters:
volume (
StorageVolume
) – Volume to be resizedsize (int) – new volume size in gigabytes, must be greater than current size
- Return type:
bool
- Shares an IP with another node.This can be used to allow one Linode
to begin serving requests should another become unresponsive.
- Parameters:
node (
Node
) – Node to share the IP addresses withaddresses – List of IP addresses to share
- Return type:
bool
- get_image(image)[source]¶
Lookup a Linode image
- Parameters:
image – The name to image to be looked up (required). :type name: str
- Return type:
- class:
NodeImage
- list_key_pairs()[source]¶
Provide a list of all the SSH keypairs in your account.
- Return type:
list
of :class: KeyPair
- list_locations()[source]¶
Lists the Regions available for Linode services
- Return type:
list
ofNodeLocation
- list_nodes()[source]¶
Returns a list of Linodes the API key in use has access to view.
- Returns:
List of node objects
- Return type:
list
ofNode
- reboot_node(node)[source]¶
Reboots a node the API Key has permission to modify.
- Parameters:
node (
Node
) – the Linode to destroy- Return type:
bool