1&1 Compute Driver Documentation

1&1 is one of the world’s largest hosting providers. We offer a range of services, including hosting solutions, domains, and websites.

The data centers/availability zones are located in:

  • United States of America (US)
  • Germany (DE)
  • United Kingdom or Great Britain and Northern Ireland (GB)
  • Spain (ES)

Instantiating a Driver

To instantiate a driver you will need to pass the API key using the following constructor parameter:

  • key - Your 1&1 API Key

You can obtain your API key in the 1&1 Cloud Panel under Management -> Users where an API key will be generated.

With a newly-generated API token you can instantiate a driver using:

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

# First we need to instantiate desired libcoud driver.
cls = get_driver(Provider.ONEANDONE)

token = 'your_token'
# Then pass in your security token
drv = cls(key=token)

1&1 Implementation of Libcloud

The 1&1 driver implements the following NodeDriver functions:

  • list_sizes - Returns a list of NodeSize
  • list_locations - Returns a list of NodeLocation
  • list_images - Returns a list of NodeImage
  • get_image - Returns a NodeImage
  • create_node - Creates a Node
  • list_nodes - Returns a list of Node
  • destroy_node - Destroys an existing Node
  • reboot_node - Reboots a Node

1&1 Extension Functions

Server Functions

  • ex_rename_server - Allows you to change server name and description
  • ex_get_server_hardware - Returns server’s hardware specification
  • ex_modify_server_hardware - Updates server hardware
  • ex_modify_server_hdd - Updates a single server HDD
  • ex_add_hdd - Adds a new HDD to server
  • ex_remove_hdd - Removes a HDD from server
  • ex_list_datacenters - Returns a list of available 1&1 data centers
  • ex_get_server - Gets a server
  • ex_shutdown_server - Shuts down a server
  • ex_get_server_image - Gets server image
  • ex_reinstall_server_image - Installs a new image on the server
  • ex_list_server_ips - Gets all server IP objects
  • ex_assign_server_ip - Assigns a new IP address to the server
  • ex_remove_server_ip - Removes an IP address from the server
  • ex_get_server_firewall_policies - Gets a firewall policy attached to the server’s IP address
  • ex_add_server_firewall_policy - Adds a firewall policy to the server’s IP address

Monitoring Policy Functions

  • ex_list_monitoring_policies - Lists all monitoring policies
  • ex_create_monitoring_policy - Creates a monitoring policy
  • ex_delete_monitoring_policy - Deletes a monitoring policy
  • ex_update_monitoring_policy - Updates monitoring policy
  • ex_get_monitoring_policy - Fetches a monitoring policy
  • ex_get_monitoring_policy_ports - Fetches monitoring policy ports
  • ex_get_monitoring_policy_port - Fetches monitoring policy port
  • ex_remove_monitoring_policy_port - Removes monitoring policy port
  • ex_add_monitoring_policy_ports - Adds monitoring policy ports
  • ex_get_monitoring_policy_processes - Fetches monitoring policy processes
  • ex_get_monitoring_policy_process - Fetches monitoring policy process
  • ex_remove_monitoring_policy_process - Removes monitoring policy process
  • ex_add_monitoring_policy_processes - Adds monitoring policy processes
  • ex_list_monitoring_policy_servers - List all servers that are being monitored by the policy
  • ex_add_servers_to_monitoring_policy - Adds servers to monitoring policy
  • ex_remove_server_from_monitoring_policy - Removes a server from monitoring policy

Shared Storage Functions

  • ex_list_shared_storages - Lists shared storages
  • ex_get_shared_storage - Gets a shared storage
  • ex_create_shared_storage - Creates a shared storage
  • ex_delete_shared_storage - Removes a shared storage
  • ex_attach_server_to_shared_storage - Attaches a single server to a shared storage
  • ex_get_shared_storage_server - Gets a shared storage’s server
  • ex_detach_server_from_shared_storage - Detaches a server from shared storage

Public IP Functions

  • ex_list_public_ips - Lists all public IP addresses
  • ex_create_public_ip - Creates a public IP
  • ex_get_public_ip - Gets a public IP
  • ex_delete_public_ip - Deletes a public IP
  • ex_update_public_ip - Updates a Public IP

Private Network Functions

  • ex_list_private_networks - Lists all private networks
  • ex_create_private_network - Creates a private network
  • ex_delete_private_network - Deletes a private network
  • ex_update_private_network - Updates a private network
  • ex_list_private_network_servers - Lists all private network servers
  • ex_add_private_network_server - Adds servers to private network
  • ex_remove_server_from_private_network - Removes a server from the private network

Load Balancer Functions

  • ex_create_load_balancer - Creates a load balancer
  • ex_update_load_balancer - Updates a load balancer
  • ex_add_servers_to_load_balancer - Adds servers to a load balancers
  • ex_remove_server_from_load_balancer - Removes a server from a load balancer
  • ex_add_load_balancer_rule - Adds a rule to a load balancer
  • ex_remove_load_balancer_rule - Removes a rule from a load balancer
  • ex_list_load_balancers - Lists all load balancers
  • ex_get_load_balancer - Gets a load balancer
  • ex_list_load_balancer_server_ips - Lists load balanced server IP addresses
  • ex_get_load_balancer_server_ip - Gets a balanced server IP address
  • ex_list_load_balancer_rules - Lists load balancer rules
  • ex_get_load_balancer_rule - Gets a load balancer rule
  • ex_delete_load_balancer - Deletes a load balancer

Firewall Policy Functions

  • ex_create_firewall_policy - Creates a firewall policy
  • ex_list_firewall_policies - Lists firewall policies
  • ex_get_firewall_policy - Gets a firewall policy
  • ex_delete_firewall_policy - Deletes a firewall policy

Create a Node

To create a node on 1&1 using Libcloud, follow this example:

import os

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.ONEANDONE)
drv = cls(key=os.environ.get('ONEANDONE_TOKEN'))

# First we need to get all avaliable sizes
sizes = drv.list_sizes()

# Then we select one we want to use to create a node. We pick 'S' as small.
desired_size = [size for size in sizes if size.name == 'S']

# Let's get all available images
images = drv.list_images('IMAGE')

# Now we select an image we want to install on to the node.
# We pick Ubuntu 14.04
desired_image = \
    [img for img in images if 'ubuntu1404-64min' in img.name.lower()]

# This step is optional.
# Then we get the list of available datacenters (locations)
locations = drv.list_locations()

# And we pick one in this case Spain (ES)
desired_location = [loc for loc in locations if loc.name == 'ES']

# Now let's create that node:
node = drv.create_node(name="Libcloud Test Node2",
                       image=desired_image[0],
                       ex_fixed_instance_size_id=desired_size[0].id,
                       location=desired_location[0])

print(node)

This example will create a 1&1 server using ‘S’ as a small instance in the ‘ES’ (spain) data center.

create_node has the following parameters:

Required parameters:

  • name - Desired node name. Must be unique.
  • image - Image ID retrieved from list_images.
  • ex_fixed_instance_size_id - This is an ID of a flavor.

Optional parameters:

  • auth - Password for the server. If none is provided, 1&1 will generate one for you, and return it in the response.
  • location - Desired NodeLocation
  • ex_ip - ID of a public IP address which can be created using ex_create_public_ip.
  • ex_monitoring_policy_id - Id of a monitoring policy which can be created using ex_create_monitoring_policy.
  • ex_firewall_policy_id - Id of a firewall policy which can be create using ex_create_firewall_policy.
  • ex_loadbalancer_id - Id of a load balancer which can be create using ex_create_load_balancer.
  • ex_description - Description for the server.
  • ex_power_on - A boolean indicating whether a server will be POWERED_ON or POWERED_OFF when provisioned.

Create a Firewall Policy

To create a firewall policy, follow this example:

import os

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.ONEANDONE)
drv = cls(key=os.environ.get('ONEANDONE_TOKEN'))

my_rules = [
    {
        "protocol": "TCP",
        "port_from": 80,
        "port_to": 80,
        "source": "0.0.0.0"
    },
    {
        "description": "Testing firewall improvements",
        "protocol": "TCP",
        "port": 443,
        "source": "0.0.0.0"
    }
]

print(type(my_rules))

try:
    fw_policy = drv.ex_create_firewall_policy(
        name='Firewall Policy',
        rules=my_rules,
        description='FW Policy Description')
    print(fw_policy)
except Exception as e:
    print(e)

This example will create a firewall policy with a TCP rule allowing access on port 80.

ex_create_firewall_policy has the following parameters:

Required parameters:

  • name - Desired name for the firewall policy. Must be unique.
  • rules - list of dict: * protocol - One of the follwing protocols can be set TCP, UDP, TCP/UDP, ICMP, IPSEC. * port_from - Port range start. Must be between 1 and 65535. * port_to - Port range end. Must be between 1 and 65535. * source - Source IP address.

Optional parameters:

  • description - Description of the firewall policy.

Create a Monitoring Policy

To create a monitoring policy, follow this example:

import os

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.ONEANDONE)
drv = cls(key=os.environ.get('ONEANDONE_TOKEN'))

ports = [
    {
        "protocol": "TCP",
        "port": 443,
        "alert_if": "NOT_RESPONDING",
        "email_notification": True
    }
]

processes = [
    {
        "process": "httpdeamon",
        "alert_if": "NOT_RUNNING",
        "email_notification": False
    }
]
thresholds = {
    "cpu": {
        "warning": {
            "value": 90,
            "alert": False
        },
        "critical": {
            "value": 95,
            "alert": False
        }
    },
    "ram": {
        "warning": {
            "value": 90,
            "alert": False
        },
        "critical": {
            "value": 95,
            "alert": False
        }
    },
    "disk": {
        "warning": {
            "value": 80,
            "alert": False
        },
        "critical": {
            "value": 90,
            "alert": False
        }
    },
    "transfer": {
        "warning": {
            "value": 1000,
            "alert": False
        },
        "critical": {
            "value": 2000,
            "alert": False
        }
    },
    "internal_ping": {
        "warning": {
            "value": 50,
            "alert": False
        },
        "critical": {
            "value": 100,
            "alert": True
        }
    }
}

try:
    monitoring_policy = drv.ex_create_monitoring_policy(
        name='Monitoring Policy',
        ports=ports,
        thresholds=thresholds,
        processes=processes,
        description='Monitoring Policy Description',
        email="test@test.com",
        agent=True
    )
    print(monitoring_policy)
except Exception as e:
    print(e)

ex_create_monitoring_policy has the following parameters:

Required parameters:

  • name - Desired name for the monitoring policy. Must be unique.
  • thresholds - dict of thresholds to be monitored. See the example
  • ports - list of dict defining which ports are to be monitored. See the example.
  • processes - list of dict defining which processes are to be monitored. See the example.

Optional parameters:

  • description - Description of the monitoring policy.
  • email - Email address where notifications will be sent.
  • agent - Indicating whether an agent application should be installed on the host.

Create a Shared Storage

To create a shared storage, follow this example:

import os

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.ONEANDONE)
drv = cls(key=os.environ.get('ONEANDONE_TOKEN'))

locations = drv.list_locations()

desired_location = [loc for loc in locations if loc.name == 'ES']

try:
    shared_storage = drv.ex_create_shared_storage(
        name="Test Shared Storage", size=50,
        datacenter_id=desired_location[0].id,
        description=None
    )
    print(shared_storage)
except Exception as e:
    print(e)

Required parameters:

  • name - str Desired name for the shared storage. Must be unique.
  • size - int Size of the shared storage.
  • datacenter_id - str 1&1 data center.

Optional parameters:

  • description - Description of the shared storage.

Create a Load Balancer

To create a load balancer, follow this example:

import os

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.ONEANDONE)
drv = cls(key=os.environ.get('ONEANDONE_TOKEN'))

rules = [
    {
        "protocol": "TCP",
        "port_balancer": 80,
        "port_server": 80,
        "source": "0.0.0.0"
    },
    {
        "protocol": "TCP",
        "port_balancer": 9999,
        "port_server": 8888,
        "source": "0.0.0.0"
    }
]

try:
    shared_storage = drv.ex_create_load_balancer(
        name="Test Load Balancer",
        method='ROUND_ROBIN',
        rules=rules,
        persistence=False,
        persistence_time=1200,
        health_check_test='TCP',
        health_check_interval=40)

    print(shared_storage)
except Exception as e:
    print(e)

Required parameters:

  • name - str Desired name for the shared storage. Must be unique.
  • method - str
  • rules - list of dict

Optional parameters:

  • persistence
  • persistence_time
  • health_check_test
  • health_check_interval
  • health_check_path
  • health_check_parser
  • datacenter_id
  • description

Create a Public IP

To create a public IP address, follow this example:

import os

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.ONEANDONE)
drv = cls(key=os.environ.get('ONEANDONE_TOKEN'))

try:
    public_ip = drv.ex_create_public_ip(
        type='IPV4')
    print(public_ip)
except Exception as e:
    print(e)

Required parameters:

  • type - str IPV4 or IPV6

Optional parameters:

  • reverse_dns - str
  • datacenter_id - str 1&1 Datacenter

Create a Private Network

To create a private network, follow this example:

import os

from libcloud.compute.types import Provider
from libcloud.compute.providers import get_driver

cls = get_driver(Provider.ONEANDONE)
drv = cls(key=os.environ.get('ONEANDONE_TOKEN'))

try:
    public_network = drv.ex_create_private_network(
        name='TestPN')
    print(public_network)
except Exception as e:
    print(e)

Required parameters:

  • name - str name of the public network.

Optional parameters:

  • datacenter_id - str
  • network_address
  • subnet_mask