cca

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2019 License: MIT Imports: 4 Imported by: 0

README

go-cloudca

A cloud.ca client for the Go programming language

GoDoc

How to use

Import

	import "github.com/cloud-ca/go-cloudca"
	
	/* import the services you need */
	import "github.com/cloud-ca/go-cloudca/services/cloudca"

Create a new CcaClient.

	ccaClient := cca.NewCcaClient("[your-api-key]")

Retrieve the list of environments

	environments, _ := ccaClient.Environments.List()

Get the ServiceResources object for a specific environment and service. Here, we assume that it is a cloudca service.

	resources, _ := ccaClient.GetResources("[service-code]", "[environment-name]")
	ccaResources := resources.(cloudca.Resources)

Now with the cloudca ServiceResources object, we can execute operations on cloudca resources in the specified environment.

Retrieve the list of instances in the environment.

	instances, _ := ccaResources.Instances.List()

Get a specific volume in the environment.

	volume, _ := ccaResources.Volumes.Get("[some-volume-id]")

Create a new instance in the environment.

	createdInstance, _ := ccaResources.Instances.Create(cloudca.Instance{
			Name: "[new-instance-name]",
			TemplateId: "[some-template-id]",
			ComputeOfferingId:"[some-compute-offering-id]",
			NetworkId:"[some-network-id]",
		})

#Handling Errors

When trying to get a volume with a bogus id, an error will be returned.

	//Get a volume with a bogus id
	_, err := ccaResources.Volumes.Get("[some-volume-id]")

Two types of error can occur: an unexpected error (ex: unable to connect to server) or an API error (ex: service resource not found) If an error has occured, then we first try to cast the error into a CcaErrorResponse. This object contains the HTTP status code returned by the server, an error code and a list of CcaError objects. If it's not a CcaErrorResponse, then the error was not returned by the API.

	if err != nil {
		if errorResponse, ok := err.(api.CcaErrorResponse); ok {
			if errorResponse.StatusCode == api.NOT_FOUND {
				fmt.Println("Volume was not found")
			} else {
				//Can get more details from the CcaErrors
				fmt.Println(errorResponse.Errors)
			}
		} else {
			//handle unexpected error
			panic("Unexpected error")
		}
	}

#License

This project is licensed under the terms of the MIT license.

Documentation

Index

Constants

View Source
const (
	DEFAULT_API_URL = "https://api.cloud.ca/v1/"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CcaClient

type CcaClient struct {
	Tasks              services.TaskService
	Environments       configuration.EnvironmentService
	Users              configuration.UserService
	ServiceConnections configuration.ServiceConnectionService
	Organizations      configuration.OrganizationService
	// contains filtered or unexported fields
}

func NewCcaClient

func NewCcaClient(apiKey string) *CcaClient

Create a CcaClient with the default URL

func NewCcaClientWithApiClient

func NewCcaClientWithApiClient(apiClient api.ApiClient) *CcaClient

func NewCcaClientWithURL

func NewCcaClientWithURL(apiURL string, apiKey string) *CcaClient

Create a CcaClient with a custom URL

func NewInsecureCcaClientWithURL

func NewInsecureCcaClientWithURL(apiURL string, apiKey string) *CcaClient

Create a CcaClient with a custom URL that accepts insecure connections

func (CcaClient) GetApiClient

func (c CcaClient) GetApiClient() api.ApiClient

Get the API Client used by all the services

func (CcaClient) GetApiKey

func (c CcaClient) GetApiKey() string

Get the API key used in the calls

func (CcaClient) GetApiURL

func (c CcaClient) GetApiURL() string

Get the API url used to do he calls

func (CcaClient) GetResources

func (c CcaClient) GetResources(serviceCode string, environmentName string) (services.ServiceResources, error)

Get the Resources for a specific serviceCode and environmentName For now it assumes that the serviceCode belongs to a cloud.ca service type

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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