cpt

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2019 License: Apache-2.0 Imports: 6 Imported by: 0

README

cloud-provider-tools

GoDoc

Usage

package main

import (
    "context"
    "fmt"
    "time"

    "github.com/sas-fe/cloud-provider-tools"
    "github.com/sas-fe/cloud-provider-tools/common"
)

func main() {
    p, err := cpt.NewCloudProvider(cpt.DIGITALOCEAN)
    if err != nil {
        panic(err)
    }

    ctx := context.TODO()

    serverResp, err := p.CreateServer(ctx, "test-server")
    if err != nil {
        panic(err)
    }

    subDomain := serverResp.Name + "-" + strconv.Itoa(serverResp.ServerID.(int)) + "." + "instances"

    dnsResp, err := p.CreateDNSRecord(ctx, subDomain, serverResp.ServerIP)
    if err != nil {
        panic(err)
    }

    fmt.Println("Sleeping for 120 seconds")
    time.Sleep(120 * time.Second)

    err2 := p.RemoveServer(ctx, serverResp.ServerID)
    if err2 != nil {
        panic(err2)
    }

    err3 := p.RemoveDNSRecord(ctx, dnsResp.SubDomainID)
    if err3 != nil {
        panic(err3)
    }
}

DigitalOcean Provider Settings

Creating DigitalOcean Provider Instance

If using cpt.NewCloudProvider(cpt.DIGITALOCEAN), $DOMAIN and $DO_TOKEN should be set to the target domain and digitalocean API token respectively. Those can also be manually passed in via digitalocean.NewProvider().

Creating DigitalOcean Droplets

The digitalocean provider recognizes several common.ServerOptions to customize droplets. Supported options include:

  • Region: e.g. common.ServerRegion("nyc1")
  • Size: e.g. common.ServerSize("s-1vcpu-1gb")
  • Image ID: e.g. common.ServerImage("31734516")
  • Startup Script/User Data: e.g. common.ServerScript("#!/bin/bash\necho 'Hello, World!'")
  • Tags: e.g. common.ServerTags([]string{"OnDemand"})

Google Compute Engine Provider Settings

Creating GCE Provider Instance

cpt.NewCloudProvider(cpt.GCE) requires several environment variables to be set:

  • $GOOGLE_APPLICATION_CREDENTIALS: service account file path for google ADC
  • $GCP_PROJECT: GCP project to use
  • $GCP_DNS_ZONE: Cloud DNS manage zone to use
  • $DOMAIN: base domain name Those can also be manually passed in via gce.NewProvider().
Creating GCE Instances

The GCE provider recognizes several common.ServerOptions to customize instances. Supported options include:

  • Zone: e.g. common.ServerRegion(us-east1-c)
  • Machine Type: e.g. common.ServerSize("n1-highcpu-4")
  • Source Image: e.g. common.ServerImage("projects/ubuntu-os-cloud/global/images/ubuntu-1604-xenial-v20180912")
  • Startup Script/User Data: e.g. common.ServerScript("#!/bin/bash\necho 'Hello, World!'")
  • Tags: e.g. common.ServerTags([]string{"OnDemand"})

Documentation

Overview

Package cpt provides common interfaces for creating on-demand servers with various providers

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CloudProvider

type CloudProvider interface {
	CreateServer(ctx context.Context, name string, opts ...common.ServerOption) (*common.CreateServerResponse, error)
	RemoveServer(ctx context.Context, server *common.CreateServerResponse) error

	CreateServerGroup(ctx context.Context, name string, opts ...common.ServerOption) (*common.CreateServerGroupResponse, error)
	RemoveServerGroup(ctx context.Context, group *common.CreateServerGroupResponse) error

	CreateK8s(ctx context.Context, name string, opts ...common.ServerOption) (*common.CreateK8sResponse, error)
	RemoveK8s(ctx context.Context, k8s *common.CreateK8sResponse) error

	CreateDNSRecord(ctx context.Context, name string, IP string) (*common.CreateDNSRecordResponse, error)
	RemoveDNSRecord(ctx context.Context, subDomain *common.CreateDNSRecordResponse) error

	CreateStaticIP(ctx context.Context, name string, ipType *common.StaticIPRequest) (*common.CreateStaticIPResponse, error)
	RemoveStaticIP(ctx context.Context, staticIP *common.CreateStaticIPResponse) error
}

CloudProvider implements methods for creating/removing serves

func NewCloudProvider

func NewCloudProvider(pt ProviderType) (CloudProvider, error)

NewCloudProvider returns a CloudProvider instance

type ProviderType

type ProviderType int

ProviderType provides an enum for cloud providers

const (
	// DIGITALOCEAN provider
	DIGITALOCEAN ProviderType = 0
	// AWS provider
	AWS ProviderType = 1
	// GCE provider
	GCE ProviderType = 2
	// AZURE provider
	AZURE ProviderType = 3
)

Directories

Path Synopsis
aws
Package digitalocean implements methods to create servers on DigitalOcean
Package digitalocean implements methods to create servers on DigitalOcean
examples
gce

Jump to

Keyboard shortcuts

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