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 ofNodeSize
list_locations
- Returns a list ofNodeLocation
list_images
- Returns a list ofNodeImage
get_image
- Returns aNodeImage
create_node
- Creates aNode
list_nodes
- Returns a list ofNode
destroy_node
- Destroys an existingNode
reboot_node
- Reboots aNode
1&1 Extension Functions¶
Server Functions¶
ex_rename_server
- Allows you to change server name and descriptionex_get_server_hardware
- Returns server’s hardware specificationex_modify_server_hardware
- Updates server hardwareex_modify_server_hdd
- Updates a single server HDDex_add_hdd
- Adds a new HDD to serverex_remove_hdd
- Removes a HDD from serverex_list_datacenters
- Returns a list of available 1&1 data centersex_get_server
- Gets a serverex_shutdown_server
- Shuts down a serverex_get_server_image
- Gets server imageex_reinstall_server_image
- Installs a new image on the serverex_list_server_ips
- Gets all server IP objectsex_assign_server_ip
- Assigns a new IP address to the serverex_remove_server_ip
- Removes an IP address from the serverex_get_server_firewall_policies
- Gets a firewall policy attached to the server’s IP addressex_add_server_firewall_policy
- Adds a firewall policy to the server’s IP address
Monitoring Policy Functions¶
ex_list_monitoring_policies
- Lists all monitoring policiesex_create_monitoring_policy
- Creates a monitoring policyex_delete_monitoring_policy
- Deletes a monitoring policyex_update_monitoring_policy
- Updates monitoring policyex_get_monitoring_policy
- Fetches a monitoring policyex_get_monitoring_policy_ports
- Fetches monitoring policy portsex_get_monitoring_policy_port
- Fetches monitoring policy portex_remove_monitoring_policy_port
- Removes monitoring policy portex_add_monitoring_policy_ports
- Adds monitoring policy portsex_get_monitoring_policy_processes
- Fetches monitoring policy processesex_get_monitoring_policy_process
- Fetches monitoring policy processex_remove_monitoring_policy_process
- Removes monitoring policy processex_add_monitoring_policy_processes
- Adds monitoring policy processesex_list_monitoring_policy_servers
- List all servers that are being monitored by the policyex_add_servers_to_monitoring_policy
- Adds servers to monitoring policyex_remove_server_from_monitoring_policy
- Removes a server from monitoring policy
Public IP Functions¶
ex_list_public_ips
- Lists all public IP addressesex_create_public_ip
- Creates a public IPex_get_public_ip
- Gets a public IPex_delete_public_ip
- Deletes a public IPex_update_public_ip
- Updates a Public IP
Private Network Functions¶
ex_list_private_networks
- Lists all private networksex_create_private_network
- Creates a private networkex_delete_private_network
- Deletes a private networkex_update_private_network
- Updates a private networkex_list_private_network_servers
- Lists all private network serversex_add_private_network_server
- Adds servers to private networkex_remove_server_from_private_network
- Removes a server from the private network
Load Balancer Functions¶
ex_create_load_balancer
- Creates a load balancerex_update_load_balancer
- Updates a load balancerex_add_servers_to_load_balancer
- Adds servers to a load balancersex_remove_server_from_load_balancer
- Removes a server from a load balancerex_add_load_balancer_rule
- Adds a rule to a load balancerex_remove_load_balancer_rule
- Removes a rule from a load balancerex_list_load_balancers
- Lists all load balancersex_get_load_balancer
- Gets a load balancerex_list_load_balancer_server_ips
- Lists load balanced server IP addressesex_get_load_balancer_server_ip
- Gets a balanced server IP addressex_list_load_balancer_rules
- Lists load balancer rulesex_get_load_balancer_rule
- Gets a load balancer ruleex_delete_load_balancer
- Deletes a load balancer
Firewall Policy Functions¶
ex_create_firewall_policy
- Creates a firewall policyex_list_firewall_policies
- Lists firewall policiesex_get_firewall_policy
- Gets a firewall policyex_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 NodeLocationex_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
ofdict
: *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 exampleports
-list
ofdict
defining which ports are to be monitored. See the example.processes
-list
ofdict
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 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
ofdict
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