Get the 1&1 Go Cloud Server SDK

Table of Contents

Introduction

The 1&1 Cloud Server SDK for Go(lang) provides an extension and easy-to-use interface for the 1&1 Cloud Server REST API. This allows you to automate many of the tasks which are otherwise available through the Cloud Panel UI. The library has no external dependencies. It only requires your 1&1 API key and one import statement in your code.

Features

The 1&1 Go 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.

Waiters

Certain operations on 1&1 REST API, such as creating or destroying a server, might be time-consuming. To help manage this situation, two helper functions are available in the SDK:

  • WaitForState: Provides busy-waiting for types that implement the ApiInstance interface.
  • WaitUntilDeleted: Waits until the instance is deleted for times that implement the ApiInstance interface.

Supported Versions

Not using the latest version of Go? The SDK works with Go version 1.5 and up.

Requirements

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

To get the API key:

  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.

Install the Go language tools. Find the installation package and instructions on the official Go website. Make sure that you have set up the GOPATH environment variable properly, as indicated in the instructions.

Installation

The official Go library is available from the 1&1 GitHub account found here

Use the following Go command to download oneandone-cloudserver-sdk-go to your configured GOPATH:

go get github.com/1and1/oneandone-cloudserver-sdk-go

Import the library in your Go code:

import "github.com/1and1/oneandone-cloudserver-sdk-go"

Authentication

Set the authentication token and create the API client:

token := oneandone.SetToken("82ee732b8d47e451be5c6ad5b7b56c81")
api := oneandone.New(token, oneandone.BaseUrl)

Refer to the Example and Operations sections for additional information.

Comments

Tags: Management