gopherstack

package module
v0.0.0-...-eab5118 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2015 License: MIT Imports: 14 Imported by: 2

README

gopherstack

Cloudstack API library written in Go. Tested towards Cloudstack 3.x and 4.x. Main use so far has been to serve as a library for a Packer.io builder.

Travis CI status GoDoc

Example usage

Showing the IP and state of a virtual machine:

package main

import (
	"fmt"
	"github.com/mindjiver/gopherstack"
	"os"
)

func main() {

	apiurl := os.Getenv("CLOUDSTACK_API_URL")
	if len(apiurl) == 0 {
		fmt.Println("Needed environment variable CLOUDSTACK_API_URL not found, exiting")
		os.Exit(1)
	}
	apikey := os.Getenv("CLOUDSTACK_API_KEY")
	if len(apikey) == 0 {
		fmt.Println("Needed environment variable CLOUDSTACK_API_KEY not found, exiting")
		os.Exit(1)
	}
	secretkey := os.Getenv("CLOUDSTACK_SECRET_KEY")
	if len(secret) == 0 {
		fmt.Println("Needed environment variable CLOUDSTACK_SECRET_KEY not found, exiting")
		os.Exit(1)
	}

	cs := gopherstack.CloudstackClient{}.New(apiurl, apikey, secretkey)

	vmid := "19d2acfb-e281-4a13-8d62-e04ab501271d"
	response, err := cs.ListVirtualMachines(vmid)
	if err != nil {
		fmt.Errorf("Error listing virtual machine: %s", err)
		os.Exit(1)
	}
	
	if len(response.Listvirtualmachinesresponse.Virtualmachine) > 0 {
		ip := response.Listvirtualmachinesresponse.Virtualmachine[0].Nic[0].Ipaddress
		state := response.Listvirtualmachinesresponse.Virtualmachine[0].State
		fmt.Printf("%s has IP : %s and state : %s\n", vmid, ip, state)
	} else {
		fmt.Printf("No VM with UUID: %s found\n", vmid)
	}

}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewRequest

func NewRequest(c CloudstackClient, request string, params url.Values) (interface{}, error)

Types

type AttachIsoResponse

type AttachIsoResponse struct {
}

type CloudstackClient

type CloudstackClient struct {

	// The base URL of the API
	BaseURL string

	// Credentials
	APIKey    string
	SecretKey string
	// contains filtered or unexported fields
}

func (CloudstackClient) AttachIso

func (c CloudstackClient) AttachIso(isoid string, vmid string) (AttachIsoResponse, error)

Deploys a Virtual Machine and returns it's id

func (CloudstackClient) CreateSSHKeyPair

func (c CloudstackClient) CreateSSHKeyPair(name string) (CreateSshKeyPairResponse, error)

Create a SSH key pair

func (CloudstackClient) CreateTags

func (c CloudstackClient) CreateTags(options *CreateTags) (CreateTagsResponse, error)

Add tags to specified resources

func (CloudstackClient) CreateTemplate

func (c CloudstackClient) CreateTemplate(options *CreateTemplate) (CreateTemplateResponse, error)

Creates a Template of a Virtual Machine by it's ID

func (CloudstackClient) DeleteSSHKeyPair

func (c CloudstackClient) DeleteSSHKeyPair(name string) (DeleteSshKeyPairResponse, error)

Deletes an SSH key pair

func (CloudstackClient) DeleteTags

func (c CloudstackClient) DeleteTags(options *DeleteTags) (DeleteTagsResponse, error)

Remove tags from specified resources

func (CloudstackClient) DeleteTemplate

func (c CloudstackClient) DeleteTemplate(id string) (DeleteTemplateResponse, error)

Deletes an template by its ID.

func (CloudstackClient) DeployVirtualMachine

func (c CloudstackClient) DeployVirtualMachine(serviceofferingid string, templateid string, zoneid string, account string, diskofferingid string, displayname string, networkids []string, keypair string, projectid string, userdata string, hypervisor string) (DeployVirtualMachineResponse, error)

Deploys a Virtual Machine and returns it's id

func (CloudstackClient) DestroyVirtualMachine

func (c CloudstackClient) DestroyVirtualMachine(id string) (DestroyVirtualMachineResponse, error)

Destroys a Virtual Machine

func (CloudstackClient) DetachIso

func (c CloudstackClient) DetachIso(vmid string) (DetachIsoResponse, error)

func (CloudstackClient) ListDiskOfferings

func (c CloudstackClient) ListDiskOfferings(domainid string, id string, keyword string, name string, page string, pagesize string) (ListDiskOfferingsResponse, error)

func (CloudstackClient) ListIsos

func (c CloudstackClient) ListIsos() (ListIsosResponse, error)

func (CloudstackClient) ListProjects

func (c CloudstackClient) ListProjects(name string) (ListProjectsResponse, error)

List the available Cloudstack projects

func (CloudstackClient) ListTags

func (c CloudstackClient) ListTags(options *ListTags) (ListTagsResponse, error)

Returns all items with a particular tag

func (CloudstackClient) ListTemplates

func (c CloudstackClient) ListTemplates(name string, filter string) (ListTemplatesResponse, error)

Returns all available templates

func (CloudstackClient) ListVirtualMachines

func (c CloudstackClient) ListVirtualMachines(id string) (ListVirtualMachinesResponse, error)

Returns Cloudstack string representation of the Virtual Machine state

func (CloudstackClient) ListVolumes

func (c CloudstackClient) ListVolumes(vmid string) (ListVolumesResponse, error)

List volumes for Virtual Machine by it's ID

func (CloudstackClient) New

func (cloudstack CloudstackClient) New(apiurl string, apikey string, secretkey string, insecureskipverify bool) *CloudstackClient

Creates a new client for communicating with Cloudstack

func (CloudstackClient) QueryAsyncJobResult

func (c CloudstackClient) QueryAsyncJobResult(jobid string) (QueryAsyncJobResultResponse, error)

Query Cloudstack for the state of a scheduled job

func (CloudstackClient) StopVirtualMachine

func (c CloudstackClient) StopVirtualMachine(id string) (StopVirtualMachineResponse, error)

Stops a Virtual Machine

func (CloudstackClient) UpdateVirtualMachine

func (c CloudstackClient) UpdateVirtualMachine(id string, displayname string, group string, haenable string, ostypeid string, userdata string) (UpdateVirtualMachineResponse, error)

func (CloudstackClient) WaitForAsyncJob

func (c CloudstackClient) WaitForAsyncJob(jobId string, timeout time.Duration) error

waitForAsyncJob simply blocks until the the asynchronous job has executed or has timed out.

func (CloudstackClient) WaitForVirtualMachineState

func (c CloudstackClient) WaitForVirtualMachineState(vmid string, wantedState string, timeout time.Duration) error

WaitForVirtualMachineState simply blocks until the virtual machine is in the specified state.

type CreateSshKeyPairResponse

type CreateSshKeyPairResponse struct {
	Createsshkeypairresponse struct {
		Keypair struct {
			Fingerprint string `json:"fingerprint"`
			Name        string `json:"name"`
			Privatekey  string `json:"privatekey"`
		} `json:"keypair"`
	} `json:"createsshkeypairresponse"`
}

type CreateTags

type CreateTags struct {
	Customer     string   `json:"customer"`
	Resourceids  []string `json:"resourceids"`
	Resourcetype string   `json:"resourcetype`
	Tags         []TagArg `json:"tags`
}

type CreateTagsResponse

type CreateTagsResponse struct {
	Createtagsresponse struct {
		Displaytext string `json:"displaytext"`
		Success     string `json:"success"`
	} `json:"createtagsresponse"`
}

type CreateTemplate

type CreateTemplate struct {
	Displaytext           string `json:"displaytext"`
	Isdynamicallyscalable bool   `json:"isdynamicallyscalable"`
	Isextractable         bool   `json:"isextractable"`
	Isfeatured            bool   `json:"isfeatured"`
	Ispublic              bool   `json:"ispublic"`
	Name                  string `json:"name"`
	Ostypeid              string `json:"ostypeid"`
	Passwordenabled       bool   `json:"passwordenabled"`
	Snapshotid            string `json:"snapshotid"`
	Volumeid              string `json:"volumeid"`
}

type CreateTemplateResponse

type CreateTemplateResponse struct {
	Createtemplateresponse struct {
		ID    string `json:"id"`
		Jobid string `json:"jobid"`
	} `json:"createtemplateresponse"`
}

type DeleteSshKeyPairResponse

type DeleteSshKeyPairResponse struct {
	Deletesshkeypairresponse struct {
		Success string `json:"success"`
	} `json:"deletesshkeypairresponse"`
}

type DeleteTags

type DeleteTags struct {
	Resourceids  []string `json:"resourceids"`
	Resourcetype string   `json:"resourcetype`
	Tags         []TagArg `json:"tags`
}

type DeleteTagsResponse

type DeleteTagsResponse struct {
	Deletetagsresponse struct {
		Displaytext string `json:"displaytext"`
		Success     string `json:"success"`
	} `json:"deletetagsresponse"`
}

type DeleteTemplateResponse

type DeleteTemplateResponse struct {
	Deletetemplateresponse struct {
	}
}

type DeployVirtualMachineResponse

type DeployVirtualMachineResponse struct {
	Deployvirtualmachineresponse struct {
		ID    string `json:"id"`
		Jobid string `json:"jobid"`
	} `json:"deployvirtualmachineresponse"`
}

type DestroyVirtualMachineResponse

type DestroyVirtualMachineResponse struct {
	Destroyvirtualmachineresponse struct {
		Jobid string `json:"jobid"`
	} `json:"destroyvirtualmachineresponse"`
}

type DetachIsoResponse

type DetachIsoResponse struct {
	Detachisoresponse struct {
		Jobid string `json:"jobid"`
	} `json:"detachisoresponse"`
}

type DiskOffering

type DiskOffering struct {
	Created      string  `json:"created"`
	Disksize     float64 `json:"disksize"`
	Displaytext  string  `json:"displaytext"`
	ID           string  `json:"id"`
	Iscustomized bool    `json:"iscustomized"`
	Name         string  `json:"name"`
	Storagetype  string  `json:"storagetype"`
}

type ListDiskOfferingsResponse

type ListDiskOfferingsResponse struct {
	Listdiskofferingsresponse struct {
		Count        float64        `json:"count"`
		Diskoffering []DiskOffering `json:"diskoffering"`
	} `json:"listdiskofferingsresponse"`
}

type ListIsosResponse

type ListIsosResponse struct {
}

type ListProjectsResponse

type ListProjectsResponse struct {
	Listprojectsresponse struct {
		Count   float64   `json:"count"`
		Project []Project `json:"project"`
	} `json:"listprojectsresponse"`
}

type ListTags

type ListTags struct {
	Account      string `json:"account"`
	Customer     string `json:"customer"`
	Domainid     string `json:"domainid"`
	Isrecursive  bool   `json:"isrecursive"`
	Key          string `json:"key"`
	Keyword      string `json:"keyword"`
	Listall      bool   `json:"listall"`
	Page         string `json:"page"`
	Pagesize     string `json:"pagesize"`
	Projectid    string `json:"projectid"`
	Resourceid   string `json:"resourceid"`
	Resourcetype string `json:"resourcetype`
	Value        string `json:"value`
}

type ListTagsResponse

type ListTagsResponse struct {
	Listtagsresponse struct {
		Count float64 `json:"count"`
		Tag   []Tag   `json:"tag"`
	} `json:"listtagsresponse"`
}

type ListTemplatesResponse

type ListTemplatesResponse struct {
	Listtemplatesresponse struct {
		Count    float64    `json:"count"`
		Template []Template `json:"template"`
	} `json:"listtemplatesresponse"`
}

type ListVirtualMachinesResponse

type ListVirtualMachinesResponse struct {
	Listvirtualmachinesresponse struct {
		Count          float64          `json:"count"`
		Virtualmachine []Virtualmachine `json:"virtualmachine"`
	} `json:"listvirtualmachinesresponse"`
}

type ListVolumesResponse

type ListVolumesResponse struct {
	Listvolumesresponse struct {
		Count  float64  `json:"count"`
		Volume []Volume `json:"volume"`
	} `json:"listvolumesresponse"`
}

type Nic

type Nic struct {
	Gateway     string `json:"gateway"`
	ID          string `json:"id"`
	Ipaddress   string `json:"ipaddress"`
	Isdefault   bool   `json:"isdefault"`
	Macaddress  string `json:"macaddress"`
	Netmask     string `json:"netmask"`
	Networkid   string `json:"networkid"`
	Traffictype string `json:"traffictype"`
	Type        string `json:"type"`
}

type Project

type Project struct {
	Account     string        `json:"account"`
	Displaytext string        `json:"displaytext"`
	Domain      string        `json:"domain"`
	Domainid    string        `json:"domainid"`
	ID          string        `json:"id"`
	Name        string        `json:"name"`
	State       string        `json:"state"`
	Tags        []interface{} `json:"tags"`
}

type QueryAsyncJobResultResponse

type QueryAsyncJobResultResponse struct {
	Queryasyncjobresultresponse struct {
		Accountid     string  `json:"accountid"`
		Cmd           string  `json:"cmd"`
		Created       string  `json:"created"`
		Jobid         string  `json:"jobid"`
		Jobprocstatus float64 `json:"jobprocstatus"`
		Jobresultcode float64 `json:"jobresultcode"`
		Jobstatus     float64 `json:"jobstatus"`
		Userid        string  `json:"userid"`
	} `json:"queryasyncjobresultresponse"`
}

type StopVirtualMachineResponse

type StopVirtualMachineResponse struct {
	Stopvirtualmachineresponse struct {
		Jobid string `json:"jobid"`
	} `json:"stopvirtualmachineresponse"`
}

type Tag

type Tag struct {
	Account      string `json:"account"`
	Customer     string `json:"customer"`
	Domain       string `json:"domain"`
	Domainid     string `json:"domainid"`
	Key          string `json:"key"`
	Project      string `json:"project"`
	Projectid    string `json:"projectid"`
	Resourceid   string `json:"resourceid"`
	Resourcetype string `json:"resourcetype`
	Value        string `json:"value`
}

type TagArg

type TagArg struct {
	Key   string `json:"key"`
	Value string `json:"value"`
}

type Template

type Template struct {
	Account          string  `json:"account"`
	Created          string  `json:"created"`
	CrossZones       bool    `json:"crossZones"`
	Displaytext      string  `json:"displaytext"`
	Domain           string  `json:"domain"`
	Domainid         string  `json:"domainid"`
	Format           string  `json:"format"`
	Hypervisor       string  `json:"hypervisor"`
	ID               string  `json:"id"`
	Isextractable    bool    `json:"isextractable"`
	Isfeatured       bool    `json:"isfeatured"`
	Ispublic         bool    `json:"ispublic"`
	Isready          bool    `json:"isready"`
	Name             string  `json:"name"`
	Ostypeid         string  `json:"ostypeid"`
	Ostypename       string  `json:"ostypename"`
	Passwordenabled  bool    `json:"passwordenabled"`
	Size             float64 `json:"size"`
	Sourcetemplateid string  `json:"sourcetemplateid"`
	Sshkeyenabled    bool    `json:"sshkeyenabled"`
	Status           string  `json:"status"`
	Tags             []Tag   `json:"tags"`
	Templatetype     string  `json:"templatetype"`
	Zoneid           string  `json:"zoneid"`
	Zonename         string  `json:"zonename"`
}

type UpdateVirtualMachineResponse

type UpdateVirtualMachineResponse struct {
	Updatevirtualmachineresponse struct {
	}
}

type Virtualmachine

type Virtualmachine struct {
	Account             string        `json:"account"`
	Cpunumber           float64       `json:"cpunumber"`
	Cpuspeed            float64       `json:"cpuspeed"`
	Created             string        `json:"created"`
	Displayname         string        `json:"displayname"`
	Domain              string        `json:"domain"`
	Domainid            string        `json:"domainid"`
	Guestosid           string        `json:"guestosid"`
	Haenable            bool          `json:"haenable"`
	Hypervisor          string        `json:"hypervisor"`
	ID                  string        `json:"id"`
	IsoId               string        `json:"isoid"`
	IsoName             string        `json:"isoname"`
	Keypair             string        `json:"keypair"`
	Memory              float64       `json:"memory"`
	Name                string        `json:"name"`
	Nic                 []Nic         `json:"nic"`
	Passwordenabled     bool          `json:"passwordenabled"`
	Rootdeviceid        float64       `json:"rootdeviceid"`
	Rootdevicetype      string        `json:"rootdevicetype"`
	Securitygroup       []interface{} `json:"securitygroup"`
	Serviceofferingid   string        `json:"serviceofferingid"`
	Serviceofferingname string        `json:"serviceofferingname"`
	State               string        `json:"state"`
	Tags                []interface{} `json:"tags"`
	Templatedisplaytext string        `json:"templatedisplaytext"`
	Templateid          string        `json:"templateid"`
	Templatename        string        `json:"templatename"`
	Zoneid              string        `json:"zoneid"`
	Zonename            string        `json:"zonename"`
}

type Volume

type Volume struct {
	Account                    string        `json:"account"`
	Created                    string        `json:"created"`
	Destroyed                  bool          `json:"destroyed"`
	Deviceid                   float64       `json:"deviceid"`
	Domain                     string        `json:"domain"`
	Domainid                   string        `json:"domainid"`
	ID                         string        `json:"id"`
	Isextractable              bool          `json:"isextractable"`
	Name                       string        `json:"name"`
	Serviceofferingdisplaytext string        `json:"serviceofferingdisplaytext"`
	Serviceofferingid          string        `json:"serviceofferingid"`
	Serviceofferingname        string        `json:"serviceofferingname"`
	Size                       float64       `json:"size"`
	State                      string        `json:"state"`
	Storage                    string        `json:"storage"`
	Storagetype                string        `json:"storagetype"`
	Tags                       []interface{} `json:"tags"`
	Type                       string        `json:"type"`
	Virtualmachineid           string        `json:"virtualmachineid"`
	Vmdisplayname              string        `json:"vmdisplayname"`
	Vmname                     string        `json:"vmname"`
	Vmstate                    string        `json:"vmstate"`
	Zoneid                     string        `json:"zoneid"`
	Zonename                   string        `json:"zonename"`
}

Jump to

Keyboard shortcuts

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