go-anxcloud

module
v0.3.28 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2021 License: Apache-2.0

README

Documentation

Go Client for the Anexia API

Go SDK for interacting with the Anexia multi purpose API.

Installing

To use the SDK, just add github.com/anexia-it/go-anxcloud <version> to your Go module.

Getting started

Before using the SDK you should familiarize yourself with the API. See here for more info. I you crave for an example, take a look at the terraform provider for this project

Example

The following code shows how to create a VM. To be able to do that you need to set the environment variable ANEXIA_TOKEN to your access token. Afterwards you can run the following.

package main

import (
	"context"
	"fmt"
	"time"

	anexia "github.com/anexia-it/go-anxcloud/pkg"
	"github.com/anexia-it/go-anxcloud/pkg/client"
	"github.com/anexia-it/go-anxcloud/pkg/vsphere/provisioning/vm"
)

func main() {
	vlan := "<ID of the VLAN the VM should have access to>"
	location := "<ID of the location the VM should be in>"

	// Create client from environment variables, do not unset env afterwards.
	c, err := client.New(client.AuthFromEnv(false))
	if err != nil {
		panic(fmt.Sprintf("could not create client: %v", err))
	}

	// Get some API.
	provisioning := anexia.NewAPI(c).VSphere().Provisioning()

	// Time out after 30 minutes. Yes it really takes that long sometimes.
	ctx, cancel := context.WithTimeout(context.Background(), 30*time.Minute)
	// Look for a free ip in the given VLAN. This IP is not reserved for you so better be quick.
	ips, err := provisioning.IPs().GetFree(ctx, location, vlan)
	defer cancel()
	if err != nil {
		panic(fmt.Sprintf("provisioning vm failed: %v", err))
	}
	if len(ips) < 1 {
		panic(fmt.Sprintf("no IPs left for testing in vlan"))
	}

	// Create a NIC for the VM and connect it to the VLAN.
	networkInterfaces := []vm.Network{{NICType: "vmxnet3", IPs: []string{ips[0].Identifier}, VLAN: vlan}}
	// Create the definition of the new VM. The ID you see here is Flatcar.
	definition := vm.NewAPI(c).NewDefinition(location, "template", "44b38284-6adb-430e-b4a4-1553e29f352f", "developersfirstvm", 2, 2048, 10, networkInterfaces)
	definition.SSH = "<your SSH pub key>"

	// Provision the VM.
	provisionResponse, err := provisioning.VM().Provision(ctx, definition)
	if err != nil {
		panic(fmt.Sprintf("provisioning vm failed: %v", err))
	}

	// Wait for the VM to be ready.
	_, err = provisioning.Progress().AwaitCompletion(ctx, provisionResponse.Identifier)
	if err != nil {
		panic(fmt.Sprintf("waiting for VM provisioning failed: %v", err))
	}
}

Directories

Path Synopsis
pkg
Package pkg contains all API functionality and helpers.
Package pkg contains all API functionality and helpers.
client
Package client provides a client for interacting with the anxcloud API.
Package client provides a client for interacting with the anxcloud API.
clouddns
Package clouddns contains API functionality for clouddns.
Package clouddns contains API functionality for clouddns.
clouddns/zone
Package zone implements API functions residing under /zone.
Package zone implements API functions residing under /zone.
core
Package core contains API functionality for /core.
Package core contains API functionality for /core.
core/location
Package location implements API functions residing under /core/location.json.
Package location implements API functions residing under /core/location.json.
core/resource
Package resource implements API functions residing under /core/resource.
Package resource implements API functions residing under /core/resource.
core/service
Package service implements API functions residing under /cofe/service.
Package service implements API functions residing under /cofe/service.
core/tags
Package tags implements API functions residing under /core/tags.
Package tags implements API functions residing under /core/tags.
ipam
Package ipam implements API functions residing under /ipam.
Package ipam implements API functions residing under /ipam.
ipam/address
Package address implements API functions residing under /ipam/address.
Package address implements API functions residing under /ipam/address.
ipam/prefix
Package prefix implements API functions residing under /ipam/prefix.
Package prefix implements API functions residing under /ipam/prefix.
test
Package test contains API functionality for "testing" the API.
Package test contains API functionality for "testing" the API.
test/echo
Package echo contains API functionality for issuing echo requests to the API.
Package echo contains API functionality for issuing echo requests to the API.
vlan
Package vlan implements API functions residing under /vlan.
Package vlan implements API functions residing under /vlan.
vsphere
Package vsphere contains API functionality for vsphere.
Package vsphere contains API functionality for vsphere.
vsphere/info
Package info implements API functions residing under /info.
Package info implements API functions residing under /info.
vsphere/powercontrol
Package powercontrol implements API functions residing under /powercontrol.
Package powercontrol implements API functions residing under /powercontrol.
vsphere/provisioning
Package provisioning contains APi funcationality for the provisioning of VMs.
Package provisioning contains APi funcationality for the provisioning of VMs.
vsphere/provisioning/cpuperformancetypes
Package templates implements API functions residing under /provisioning/cpuperformancetype.
Package templates implements API functions residing under /provisioning/cpuperformancetype.
vsphere/provisioning/disktype
Package disktype implements API functions residing under /provisioning/disk_type.
Package disktype implements API functions residing under /provisioning/disk_type.
vsphere/provisioning/ips
Package ips implements API functions residing under /provisioning/ips.
Package ips implements API functions residing under /provisioning/ips.
vsphere/provisioning/location
Package location implements API functions residing under /provisioning/location.
Package location implements API functions residing under /provisioning/location.
vsphere/provisioning/nictype
Package nictype implements API functions residing under /provisioning/nictype.
Package nictype implements API functions residing under /provisioning/nictype.
vsphere/provisioning/progress
Package progress implements API functions residing under /provisioning/progress.
Package progress implements API functions residing under /provisioning/progress.
vsphere/provisioning/templates
Package templates implements API functions residing under /provisioning/templates.
Package templates implements API functions residing under /provisioning/templates.
vsphere/provisioning/vm
Package vm implements API functions residing under /provisioning/vm.
Package vm implements API functions residing under /provisioning/vm.
vsphere/search
Package search implements API functions residing under /search.
Package search implements API functions residing under /search.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL