Get the 1&1 Python Cloud Server SDK

Table of Contents

Introduction

The 1&1 Python SDK is a Python library designed for interaction with the 1&1 Cloud platform over the Cloud Server REST API. This allows you to automate many of the tasks which are otherwise available through the Cloud Panel UI.

Features

The 1&1 Python SDK allows you to list and retrieve information about servers, including their hardware, IP addresses, load balancers, private networks, and more. You can create and delete servers, as well as reconfigure them. Hard drives, virtual DVD units, firewall policies, load balancers, and IP addresses can all be added or removed through the API.

The API also allows you to manage server operations. Servers can be added to or removed from private networks. Snapshots can be created, restored, or removed. Images can be created, updated, and deleted. Shared storages, firewall policies, load balancers, IP addresses, private networks, VPNs, monitoring policies, logs, usage, and appliances can all be managed through the API. Users and roles can be added, deleted, and managed, as well.

The wait_for() Method

The wait_for() method can be used on any major class object to poll its resource until one of the following states is returned:

  • ACTIVE
  • ENABLED
  • POWERED_ON
  • POWERED_OFF

This is necessary when chaining together multiple actions that take some time to deploy. The wait_for() method is available on the Server, Image, SharedStorage, Vpn, FirewallPolicy, LoadBalancer, PrivateNetwork, and MonitoringPolicy classes.

You may pass in an optional timeout value (in minutes) which stops the wait_for() method from polling after the given amount of time. timeout is set to 25 minutes by default. You may also set the interval value (in seconds). The default value for interval varies by class.

Supported Versions

The 1&1 Python SDK is designed for Python 3.x.

Requirements

Before you begin, you need to have a 1&1 account.

To enable the API token:

  1. Log in to your 1&1 Control Panel and select the relevant package.
  2. Click 1&1 Cloud Panel from the Cloud Server section of the control panel.
  3. Select Users from the Management section of the Infrastructure menu.
  4. Select the user who needs the API token.
  5. In the API section in the lower part of the screen, click Disabled next to the API KEY.
  6. Click OK to activate the API key.

Installation

The Python Client Library is available on PyPi. You can install the latest stable version using pip:

pip install 1and1

Done!

Authentication

Connecting to 1&1 is handled by first setting up your authentication.

from oneandone.client import OneAndOneService

client = OneAndOneService('API-TOKEN')

You can now use client for any future requests.

Comments

Tags: Management