Vendor main dependencies.
This commit is contained in:
parent
49a09ab7dd
commit
dd5e3fba01
2738 changed files with 1045689 additions and 0 deletions
42
vendor/github.com/pyr/egoscale/src/egoscale/affinitygroup.go
generated
vendored
Normal file
42
vendor/github.com/pyr/egoscale/src/egoscale/affinitygroup.go
generated
vendored
Normal file
|
@ -0,0 +1,42 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateAffinityGroup(name string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
params.Set("type", "host anti-affinity")
|
||||
|
||||
resp, err := exo.Request("createAffinityGroup", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r CreateAffinityGroupResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobId, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DeleteAffinityGroup(name string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
|
||||
resp, err := exo.Request("deleteAffinityGroup", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r DeleteAffinityGroupResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobId, nil
|
||||
|
||||
}
|
36
vendor/github.com/pyr/egoscale/src/egoscale/async.go
generated
vendored
Normal file
36
vendor/github.com/pyr/egoscale/src/egoscale/async.go
generated
vendored
Normal file
|
@ -0,0 +1,36 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) PollAsyncJob(jobid string) (*QueryAsyncJobResultResponse, error) {
|
||||
params := url.Values{}
|
||||
|
||||
params.Set("jobid", jobid)
|
||||
|
||||
resp, err := exo.Request("queryAsyncJobResult", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r QueryAsyncJobResultResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (exo *Client) AsyncToVirtualMachine(resp QueryAsyncJobResultResponse) (*DeployVirtualMachineResponse, error) {
|
||||
var r DeployVirtualMachineWrappedResponse
|
||||
|
||||
if err := json.Unmarshal(resp.Jobresult, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r.Wrapped, nil
|
||||
}
|
150
vendor/github.com/pyr/egoscale/src/egoscale/dns.go
generated
vendored
Normal file
150
vendor/github.com/pyr/egoscale/src/egoscale/dns.go
generated
vendored
Normal file
|
@ -0,0 +1,150 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateDomain(name string) (*DNSDomain, error) {
|
||||
var hdr = make(http.Header)
|
||||
var domain DNSDomainCreateRequest
|
||||
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey + ":" + exo.apiSecret)
|
||||
domain.Domain.Name = name
|
||||
m, err := json.Marshal(domain); if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := exo.DetailedRequest("/v1/domains", string(m), "POST", hdr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var d *DNSDomain
|
||||
if err := json.Unmarshal(resp, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetDomain(name string) (*DNSDomain, error) {
|
||||
var hdr = make(http.Header)
|
||||
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey + ":" + exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
|
||||
resp, err := exo.DetailedRequest("/v1/domains/" + name, "", "GET", hdr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var d *DNSDomain
|
||||
if err := json.Unmarshal(resp, &d); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return d, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DeleteDomain(name string) (error) {
|
||||
var hdr = make(http.Header)
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey + ":" + exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
|
||||
_, err := exo.DetailedRequest("/v1/domains/" + name, "", "DELETE", hdr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetRecords(name string) ([]*DNSRecordResponse, error) {
|
||||
var hdr = make(http.Header)
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey + ":" + exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
|
||||
resp, err := exo.DetailedRequest("/v1/domains/" + name + "/records", "", "GET", hdr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r []*DNSRecordResponse
|
||||
if err = json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func(exo *Client) CreateRecord(name string, rec DNSRecord) (*DNSRecordResponse, error) {
|
||||
var hdr = make(http.Header)
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey + ":" + exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
hdr.Add("Content-Type", "application/json")
|
||||
|
||||
var rr DNSRecordResponse
|
||||
rr.Record = rec
|
||||
|
||||
body, err := json.Marshal(rr); if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := exo.DetailedRequest("/v1/domains/" + name + "/records", string(body), "POST", hdr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r *DNSRecordResponse
|
||||
if err = json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func(exo *Client) UpdateRecord(name string, rec DNSRecord) (*DNSRecordResponse, error) {
|
||||
var hdr = make(http.Header)
|
||||
id := strconv.FormatInt(rec.Id, 10)
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey + ":" + exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
hdr.Add("Content-Type", "application/json")
|
||||
|
||||
var rr DNSRecordResponse
|
||||
rr.Record = rec
|
||||
|
||||
body, err := json.Marshal(rr); if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
resp, err := exo.DetailedRequest("/v1/domains/" + name + "/records/" + id,
|
||||
string(body), "PUT", hdr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r *DNSRecordResponse
|
||||
if err = json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r, nil
|
||||
}
|
||||
|
||||
func(exo *Client) DeleteRecord(name string, rec DNSRecord) (error) {
|
||||
var hdr = make(http.Header)
|
||||
id := strconv.FormatInt(rec.Id, 10)
|
||||
hdr.Add("X-DNS-TOKEN", exo.apiKey + ":" + exo.apiSecret)
|
||||
hdr.Add("Accept", "application/json")
|
||||
hdr.Add("Content-Type", "application/json")
|
||||
|
||||
_, err := exo.DetailedRequest("/v1/domains/" + name + "/records/" + id,
|
||||
"", "DELETE", hdr)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
9
vendor/github.com/pyr/egoscale/src/egoscale/error.go
generated
vendored
Normal file
9
vendor/github.com/pyr/egoscale/src/egoscale/error.go
generated
vendored
Normal file
|
@ -0,0 +1,9 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (e *Error) Error() error {
|
||||
return fmt.Errorf("exoscale API error %d (internal code: %d): %s", e.ErrorCode, e.CSErrorCode, e.ErrorText)
|
||||
}
|
117
vendor/github.com/pyr/egoscale/src/egoscale/groups.go
generated
vendored
Normal file
117
vendor/github.com/pyr/egoscale/src/egoscale/groups.go
generated
vendored
Normal file
|
@ -0,0 +1,117 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateEgressRule(rule SecurityGroupRule) (*AuthorizeSecurityGroupEgressResponse, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("securitygroupid", rule.SecurityGroupId)
|
||||
params.Set("cidrlist", rule.Cidr)
|
||||
params.Set("protocol", rule.Protocol)
|
||||
|
||||
if rule.Protocol == "ICMP" {
|
||||
params.Set("icmpcode", fmt.Sprintf("%d", rule.IcmpCode))
|
||||
params.Set("icmptype", fmt.Sprintf("%d", rule.IcmpType))
|
||||
} else if rule.Protocol == "TCP" || rule.Protocol == "UDP" {
|
||||
params.Set("startport", fmt.Sprintf("%d", rule.Port))
|
||||
params.Set("endport", fmt.Sprintf("%d", rule.Port))
|
||||
} else {
|
||||
return nil, fmt.Errorf("Invalid Egress rule Protocol: %s", rule.Protocol)
|
||||
}
|
||||
|
||||
resp, err := exo.Request("authorizeSecurityGroupEgress", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r AuthorizeSecurityGroupEgressResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (exo *Client) CreateIngressRule(rule SecurityGroupRule) (*AuthorizeSecurityGroupIngressResponse, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("securitygroupid", rule.SecurityGroupId)
|
||||
params.Set("cidrlist", rule.Cidr)
|
||||
params.Set("protocol", rule.Protocol)
|
||||
|
||||
if rule.Protocol == "ICMP" {
|
||||
params.Set("icmpcode", fmt.Sprintf("%d", rule.IcmpCode))
|
||||
params.Set("icmptype", fmt.Sprintf("%d", rule.IcmpType))
|
||||
} else if rule.Protocol == "TCP" || rule.Protocol == "UDP" {
|
||||
params.Set("startport", fmt.Sprintf("%d", rule.Port))
|
||||
params.Set("endport", fmt.Sprintf("%d", rule.Port))
|
||||
} else {
|
||||
return nil, fmt.Errorf("Invalid Egress rule Protocol: %s", rule.Protocol)
|
||||
}
|
||||
|
||||
resp, err := exo.Request("authorizeSecurityGroupIngress", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r AuthorizeSecurityGroupIngressResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (exo *Client) CreateSecurityGroupWithRules(name string, ingress []SecurityGroupRule, egress []SecurityGroupRule) (*CreateSecurityGroupResponse, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
|
||||
resp, err := exo.Request("createSecurityGroup", params)
|
||||
|
||||
var r CreateSecurityGroupResponseWrapper
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sgid := r.Wrapped.Id
|
||||
|
||||
for _, erule := range egress {
|
||||
erule.SecurityGroupId = sgid
|
||||
_, err = exo.CreateEgressRule(erule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
for _, inrule := range ingress {
|
||||
inrule.SecurityGroupId = sgid
|
||||
_, err = exo.CreateIngressRule(inrule)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return &r.Wrapped, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DeleteSecurityGroup(name string) (error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
|
||||
resp, err := exo.Request("deleteSecurityGroup", params); if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
fmt.Printf("## response: %+v\n", resp)
|
||||
return nil
|
||||
}
|
21
vendor/github.com/pyr/egoscale/src/egoscale/init.go
generated
vendored
Normal file
21
vendor/github.com/pyr/egoscale/src/egoscale/init.go
generated
vendored
Normal file
|
@ -0,0 +1,21 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func NewClient(endpoint string, apiKey string, apiSecret string) *Client {
|
||||
cs := &Client{
|
||||
client: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: false},
|
||||
},
|
||||
},
|
||||
endpoint: endpoint,
|
||||
apiKey: apiKey,
|
||||
apiSecret: apiSecret,
|
||||
}
|
||||
return cs
|
||||
}
|
59
vendor/github.com/pyr/egoscale/src/egoscale/keypair.go
generated
vendored
Normal file
59
vendor/github.com/pyr/egoscale/src/egoscale/keypair.go
generated
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateKeypair(name string) (*CreateSSHKeyPairResponse, error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
|
||||
resp, err := exo.Request("createSSHKeyPair", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r CreateSSHKeyPairWrappedResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r.Wrapped, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DeleteKeypair(name string) (*StandardResponse, error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
|
||||
resp, err := exo.Request("deleteSSHKeyPair", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r StandardResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r, nil
|
||||
|
||||
}
|
||||
|
||||
func (exo *Client) RegisterKeypair(name string, key string) (*CreateSSHKeyPairResponse, error) {
|
||||
params := url.Values{}
|
||||
params.Set("name", name)
|
||||
params.Set("publicKey", key)
|
||||
|
||||
resp, err := exo.Request("registerSSHKeyPair", params)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r CreateSSHKeyPairWrappedResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &r.Wrapped, nil
|
||||
}
|
115
vendor/github.com/pyr/egoscale/src/egoscale/request.go
generated
vendored
Normal file
115
vendor/github.com/pyr/egoscale/src/egoscale/request.go
generated
vendored
Normal file
|
@ -0,0 +1,115 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"crypto/hmac"
|
||||
"crypto/sha1"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func rawValue(b json.RawMessage) (json.RawMessage, error) {
|
||||
var m map[string]json.RawMessage
|
||||
|
||||
if err := json.Unmarshal(b, &m); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
for _, v := range m {
|
||||
return v, nil
|
||||
}
|
||||
//return nil, fmt.Errorf("Unable to extract raw value from:\n\n%s\n\n", string(b))
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func rawValues(b json.RawMessage) (json.RawMessage, error) {
|
||||
var i []json.RawMessage
|
||||
|
||||
if err := json.Unmarshal(b, &i); err != nil {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return i[0], nil
|
||||
}
|
||||
|
||||
func (exo *Client) ParseResponse(resp *http.Response) (json.RawMessage, error) {
|
||||
b, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
a, err := rawValues(b)
|
||||
|
||||
if a == nil {
|
||||
b, err = rawValue(b)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
fmt.Printf("ERROR: %s\n", b)
|
||||
var e Error
|
||||
if err := json.Unmarshal(b, &e); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
/* Need to account for differet error types */
|
||||
if e.ErrorCode != 0 {
|
||||
return nil, e.Error()
|
||||
} else {
|
||||
var de DNSError
|
||||
if err := json.Unmarshal(b, &de); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return nil, fmt.Errorf("Exoscale error (%d): %s", resp.StatusCode, strings.Join(de.Name, "\n"))
|
||||
}
|
||||
}
|
||||
|
||||
return b, nil
|
||||
}
|
||||
|
||||
func (exo *Client) Request(command string, params url.Values) (json.RawMessage, error) {
|
||||
|
||||
mac := hmac.New(sha1.New, []byte(exo.apiSecret))
|
||||
|
||||
params.Set("apikey", exo.apiKey)
|
||||
params.Set("command", command)
|
||||
params.Set("response", "json")
|
||||
|
||||
s := strings.Replace(strings.ToLower(params.Encode()), "+", "%20", -1)
|
||||
mac.Write([]byte(s))
|
||||
signature := url.QueryEscape(base64.StdEncoding.EncodeToString(mac.Sum(nil)))
|
||||
|
||||
s = params.Encode()
|
||||
url := exo.endpoint + "?" + s + "&signature=" + signature
|
||||
|
||||
resp, err := exo.client.Get(url)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer resp.Body.Close()
|
||||
return exo.ParseResponse(resp)
|
||||
}
|
||||
|
||||
|
||||
func (exo *Client) DetailedRequest(uri string, params string, method string, header http.Header) (json.RawMessage, error) {
|
||||
url := exo.endpoint + uri
|
||||
|
||||
req, err := http.NewRequest(method, url, strings.NewReader(params)); if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
req.Header = header
|
||||
|
||||
response, err := exo.client.Do(req); if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
defer response.Body.Close()
|
||||
return exo.ParseResponse(response)
|
||||
}
|
228
vendor/github.com/pyr/egoscale/src/egoscale/topology.go
generated
vendored
Normal file
228
vendor/github.com/pyr/egoscale/src/egoscale/topology.go
generated
vendored
Normal file
|
@ -0,0 +1,228 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (exo *Client) GetSecurityGroups() (map[string]SecurityGroup, error) {
|
||||
var sgs map[string]SecurityGroup
|
||||
params := url.Values{}
|
||||
resp, err := exo.Request("listSecurityGroups", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListSecurityGroupsResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
sgs = make(map[string]SecurityGroup)
|
||||
for _, sg := range r.SecurityGroups {
|
||||
sgs[sg.Name] = *sg
|
||||
}
|
||||
return sgs, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetSecurityGroupId(name string) (string, error) {
|
||||
params := url.Values{}
|
||||
resp, err := exo.Request("listSecurityGroups", params); if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r ListSecurityGroupsResponse
|
||||
err = json.Unmarshal(resp, &r); if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
for _, sg := range r.SecurityGroups {
|
||||
if sg.Name == name {
|
||||
return sg.Id, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetZones() (map[string]string, error) {
|
||||
var zones map[string]string
|
||||
params := url.Values{}
|
||||
resp, err := exo.Request("listZones", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListZonesResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
zones = make(map[string]string)
|
||||
for _, zone := range r.Zones {
|
||||
zones[zone.Name] = zone.Id
|
||||
}
|
||||
return zones, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetProfiles() (map[string]string, error) {
|
||||
|
||||
var profiles map[string]string
|
||||
params := url.Values{}
|
||||
resp, err := exo.Request("listServiceOfferings", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListServiceOfferingsResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
profiles = make(map[string]string)
|
||||
for _, offering := range r.ServiceOfferings {
|
||||
profiles[strings.ToLower(offering.Name)] = offering.Id
|
||||
}
|
||||
|
||||
return profiles, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetKeypairs() ([]SSHKeyPair, error) {
|
||||
params := url.Values{}
|
||||
|
||||
resp, err := exo.Request("listSSHKeyPairs", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListSSHKeyPairsResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var keypairs = make([]SSHKeyPair, r.Count, r.Count)
|
||||
for i, keypair := range r.SSHKeyPairs {
|
||||
keypairs[i] = *keypair
|
||||
}
|
||||
return keypairs, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetAffinityGroups() (map[string]string, error) {
|
||||
var affinitygroups map[string]string
|
||||
params := url.Values{}
|
||||
|
||||
resp, err := exo.Request("listAffinityGroups", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListAffinityGroupsResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
affinitygroups = make(map[string]string)
|
||||
for _, affinitygroup := range r.AffinityGroups {
|
||||
affinitygroups[affinitygroup.Name] = affinitygroup.Id
|
||||
}
|
||||
return affinitygroups, nil
|
||||
|
||||
}
|
||||
|
||||
func (exo *Client) GetImages() (map[string]map[int]string, error) {
|
||||
var images map[string]map[int]string
|
||||
images = make(map[string]map[int]string)
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("templatefilter", "executable")
|
||||
|
||||
resp, err := exo.Request("listTemplates", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListTemplatesResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
re := regexp.MustCompile(`^Linux (?P<name>.+?) (?P<version>[0-9.]+).*$`)
|
||||
for _, template := range r.Templates {
|
||||
size := int(template.Size / (1024 * 1024 * 1024))
|
||||
submatch := re.FindStringSubmatch(template.Name)
|
||||
if len(submatch) > 0 {
|
||||
name := strings.Replace(strings.ToLower(submatch[1]), " ", "-", -1)
|
||||
version := submatch[2]
|
||||
image := fmt.Sprintf("%s-%s", name, version)
|
||||
|
||||
_, present := images[image]
|
||||
if !present {
|
||||
images[image] = make(map[int]string)
|
||||
}
|
||||
images[image][size] = template.Id
|
||||
|
||||
images[fmt.Sprintf("%s-%s", name, version)][size] = template.Id
|
||||
}
|
||||
}
|
||||
return images, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetTopology() (*Topology, error) {
|
||||
|
||||
zones, err := exo.GetZones()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
images, err := exo.GetImages()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
securityGroups, err := exo.GetSecurityGroups()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groups := make(map[string]string)
|
||||
for k,v := range securityGroups {
|
||||
groups[k] = v.Id
|
||||
}
|
||||
|
||||
keypairs, err := exo.GetKeypairs()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
/* Convert the ssh keypair to contain just the name */
|
||||
keynames := make([]string, len(keypairs))
|
||||
for i, k := range keypairs {
|
||||
keynames[i] = k.Name
|
||||
}
|
||||
|
||||
affinitygroups, err := exo.GetAffinityGroups()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
profiles, err := exo.GetProfiles()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
topo := &Topology{
|
||||
Zones: zones,
|
||||
Profiles: profiles,
|
||||
Images: images,
|
||||
Keypairs: keynames,
|
||||
AffinityGroups: affinitygroups,
|
||||
SecurityGroups: groups,
|
||||
}
|
||||
|
||||
return topo, nil
|
||||
}
|
502
vendor/github.com/pyr/egoscale/src/egoscale/types.go
generated
vendored
Normal file
502
vendor/github.com/pyr/egoscale/src/egoscale/types.go
generated
vendored
Normal file
|
@ -0,0 +1,502 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
client *http.Client
|
||||
endpoint string
|
||||
apiKey string
|
||||
apiSecret string
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
ErrorCode int `json:"errorcode"`
|
||||
CSErrorCode int `json:"cserrorcode"`
|
||||
ErrorText string `json:"errortext"`
|
||||
}
|
||||
|
||||
type StandardResponse struct {
|
||||
Success string `json:"success"`
|
||||
DisplayText string `json:"displaytext"`
|
||||
}
|
||||
|
||||
type Topology struct {
|
||||
Zones map[string]string
|
||||
Images map[string]map[int]string
|
||||
Profiles map[string]string
|
||||
Keypairs []string
|
||||
SecurityGroups map[string]string
|
||||
AffinityGroups map[string]string
|
||||
}
|
||||
|
||||
type SecurityGroupRule struct {
|
||||
Cidr string
|
||||
IcmpType int
|
||||
IcmpCode int
|
||||
Port int
|
||||
Protocol string
|
||||
SecurityGroupId string
|
||||
}
|
||||
|
||||
type MachineProfile struct {
|
||||
Name string
|
||||
SecurityGroups []string
|
||||
Keypair string
|
||||
Userdata string
|
||||
ServiceOffering string
|
||||
Template string
|
||||
Zone string
|
||||
AffinityGroups []string
|
||||
}
|
||||
|
||||
type ListZonesResponse struct {
|
||||
Count int `json:"count"`
|
||||
Zones []*Zone `json:"zone"`
|
||||
}
|
||||
|
||||
type Zone struct {
|
||||
Allocationstate string `json:"allocationstate,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Displaytext string `json:"displaytext,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Domainname string `json:"domainname,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Internaldns1 string `json:"internaldns1,omitempty"`
|
||||
Internaldns2 string `json:"internaldns2,omitempty"`
|
||||
Ip6dns1 string `json:"ip6dns1,omitempty"`
|
||||
Ip6dns2 string `json:"ip6dns2,omitempty"`
|
||||
Localstorageenabled bool `json:"localstorageenabled,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Networktype string `json:"networktype,omitempty"`
|
||||
Resourcedetails map[string]string `json:"resourcedetails,omitempty"`
|
||||
Securitygroupsenabled bool `json:"securitygroupsenabled,omitempty"`
|
||||
Vlan string `json:"vlan,omitempty"`
|
||||
Zonetoken string `json:"zonetoken,omitempty"`
|
||||
}
|
||||
|
||||
type ListServiceOfferingsResponse struct {
|
||||
Count int `json:"count"`
|
||||
ServiceOfferings []*ServiceOffering `json:"serviceoffering"`
|
||||
}
|
||||
|
||||
type ServiceOffering struct {
|
||||
Cpunumber int `json:"cpunumber,omitempty"`
|
||||
Cpuspeed int `json:"cpuspeed,omitempty"`
|
||||
Displaytext string `json:"displaytext,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Hosttags string `json:"hosttags,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Iscustomized bool `json:"iscustomized,omitempty"`
|
||||
Issystem bool `json:"issystem,omitempty"`
|
||||
Isvolatile bool `json:"isvolatile,omitempty"`
|
||||
Memory int `json:"memory,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Networkrate int `json:"networkrate,omitempty"`
|
||||
Serviceofferingdetails map[string]string `json:"serviceofferingdetails,omitempty"`
|
||||
}
|
||||
|
||||
type ListTemplatesResponse struct {
|
||||
Count int `json:"count"`
|
||||
Templates []*Template `json:"template"`
|
||||
}
|
||||
|
||||
type Template struct {
|
||||
Account string `json:"account,omitempty"`
|
||||
Accountid string `json:"accountid,omitempty"`
|
||||
Bootable bool `json:"bootable,omitempty"`
|
||||
Checksum string `json:"checksum,omitempty"`
|
||||
Created string `json:"created,omitempty"`
|
||||
CrossZones bool `json:"crossZones,omitempty"`
|
||||
Details map[string]string `json:"details,omitempty"`
|
||||
Displaytext string `json:"displaytext,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Format string `json:"format,omitempty"`
|
||||
Hostid string `json:"hostid,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
Hypervisor string `json:"hypervisor,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"`
|
||||
Isextractable bool `json:"isextractable,omitempty"`
|
||||
Isfeatured bool `json:"isfeatured,omitempty"`
|
||||
Ispublic bool `json:"ispublic,omitempty"`
|
||||
Isready bool `json:"isready,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Ostypeid string `json:"ostypeid,omitempty"`
|
||||
Ostypename string `json:"ostypename,omitempty"`
|
||||
Passwordenabled bool `json:"passwordenabled,omitempty"`
|
||||
Project string `json:"project,omitempty"`
|
||||
Projectid string `json:"projectid,omitempty"`
|
||||
Removed string `json:"removed,omitempty"`
|
||||
Size int64 `json:"size,omitempty"`
|
||||
Sourcetemplateid string `json:"sourcetemplateid,omitempty"`
|
||||
Sshkeyenabled bool `json:"sshkeyenabled,omitempty"`
|
||||
Status string `json:"status,omitempty"`
|
||||
Zoneid string `json:"zoneid,omitempty"`
|
||||
Zonename string `json:"zonename,omitempty"`
|
||||
}
|
||||
|
||||
type ListSSHKeyPairsResponse struct {
|
||||
Count int `json:"count"`
|
||||
SSHKeyPairs []*SSHKeyPair `json:"sshkeypair"`
|
||||
}
|
||||
|
||||
type SSHKeyPair struct {
|
||||
Fingerprint string `json:"fingerprint,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
type ListAffinityGroupsResponse struct {
|
||||
Count int `json:"count"`
|
||||
AffinityGroups []*AffinityGroup `json:"affinitygroup"`
|
||||
}
|
||||
|
||||
type AffinityGroup struct {
|
||||
Name string `json:"name,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
}
|
||||
|
||||
type CreateAffinityGroupResponseWrapper struct {
|
||||
Wrapped AffinityGroup `json:"affinitygroup"`
|
||||
}
|
||||
|
||||
type ListSecurityGroupsResponse struct {
|
||||
Count int `json:"count"`
|
||||
SecurityGroups []*SecurityGroup `json:"securitygroup"`
|
||||
}
|
||||
|
||||
type SecurityGroup struct {
|
||||
Account string `json:"account,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Project string `json:"project,omitempty"`
|
||||
Projectid string `json:"projectid,omitempty"`
|
||||
IngressRules []struct {
|
||||
RuleId string `json:"ruleid,omitempty"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
StartPort int `json:"startport,omitempty"`
|
||||
EndPort int `json:"endport,omitempty"`
|
||||
Cidr string `json:"cidr,omitempty"`
|
||||
IcmpCode int `json:"icmpcode,omitempty"`
|
||||
IcmpType int `json:"icmptype,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
} `json:"ingressrule,omitempty"`
|
||||
EgressRules []struct {
|
||||
RuleId string `json:"ruleid,omitempty"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
StartPort int `json:"startport,omitempty"`
|
||||
EndPort int `json:"endport,omitempty"`
|
||||
Cidr string `json:"cidr,omitempty"`
|
||||
IcmpCode int `json:"icmpcode,omitempty"`
|
||||
IcmpType int `json:"icmptype,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
} `json:"egressrule,omitempty"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
}
|
||||
|
||||
type CreateSecurityGroupResponseWrapper struct {
|
||||
Wrapped CreateSecurityGroupResponse `json:"securitygroup"`
|
||||
}
|
||||
type CreateSecurityGroupResponse struct {
|
||||
Account string `json:"account,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Project string `json:"project,omitempty"`
|
||||
Projectid string `json:"projectid,omitempty"`
|
||||
}
|
||||
|
||||
type AuthorizeSecurityGroupIngressResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
Cidr string `json:"cidr,omitempty"`
|
||||
Endport int `json:"endport,omitempty"`
|
||||
Icmpcode int `json:"icmpcode,omitempty"`
|
||||
Icmptype int `json:"icmptype,omitempty"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
Ruleid string `json:"ruleid,omitempty"`
|
||||
Securitygroupname string `json:"securitygroupname,omitempty"`
|
||||
Startport int `json:"startport,omitempty"`
|
||||
}
|
||||
|
||||
type AuthorizeSecurityGroupEgressResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
Cidr string `json:"cidr,omitempty"`
|
||||
Endport int `json:"endport,omitempty"`
|
||||
Icmpcode int `json:"icmpcode,omitempty"`
|
||||
Icmptype int `json:"icmptype,omitempty"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
Ruleid string `json:"ruleid,omitempty"`
|
||||
Securitygroupname string `json:"securitygroupname,omitempty"`
|
||||
Startport int `json:"startport,omitempty"`
|
||||
}
|
||||
|
||||
type DeployVirtualMachineWrappedResponse struct {
|
||||
Wrapped DeployVirtualMachineResponse `json:"virtualmachine"`
|
||||
}
|
||||
|
||||
type DeployVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
Affinitygroup []struct {
|
||||
Account string `json:"account,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
VirtualmachineIds []string `json:"virtualmachineIds,omitempty"`
|
||||
} `json:"affinitygroup,omitempty"`
|
||||
Cpunumber int `json:"cpunumber,omitempty"`
|
||||
Cpuspeed int `json:"cpuspeed,omitempty"`
|
||||
Cpuused string `json:"cpuused,omitempty"`
|
||||
Created string `json:"created,omitempty"`
|
||||
Details map[string]string `json:"details,omitempty"`
|
||||
Diskioread int64 `json:"diskioread,omitempty"`
|
||||
Diskiowrite int64 `json:"diskiowrite,omitempty"`
|
||||
Diskkbsread int64 `json:"diskkbsread,omitempty"`
|
||||
Diskkbswrite int64 `json:"diskkbswrite,omitempty"`
|
||||
Displayname string `json:"displayname,omitempty"`
|
||||
Displayvm bool `json:"displayvm,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
Groupid string `json:"groupid,omitempty"`
|
||||
Guestosid string `json:"guestosid,omitempty"`
|
||||
Haenable bool `json:"haenable,omitempty"`
|
||||
Hostid string `json:"hostid,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
Hypervisor string `json:"hypervisor,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Instancename string `json:"instancename,omitempty"`
|
||||
Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"`
|
||||
Isodisplaytext string `json:"isodisplaytext,omitempty"`
|
||||
Isoid string `json:"isoid,omitempty"`
|
||||
Isoname string `json:"isoname,omitempty"`
|
||||
Keypair string `json:"keypair,omitempty"`
|
||||
Memory int `json:"memory,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Networkkbsread int64 `json:"networkkbsread,omitempty"`
|
||||
Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
|
||||
Nic []struct {
|
||||
Broadcasturi string `json:"broadcasturi,omitempty"`
|
||||
Gateway string `json:"gateway,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Ipaddress string `json:"ipaddress,omitempty"`
|
||||
Isdefault bool `json:"isdefault,omitempty"`
|
||||
Isolationuri string `json:"isolationuri,omitempty"`
|
||||
Macaddress string `json:"macaddress,omitempty"`
|
||||
Netmask string `json:"netmask,omitempty"`
|
||||
Networkid string `json:"networkid,omitempty"`
|
||||
Networkname string `json:"networkname,omitempty"`
|
||||
Secondaryip []string `json:"secondaryip,omitempty"`
|
||||
Traffictype string `json:"traffictype,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
} `json:"nic,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Passwordenabled bool `json:"passwordenabled,omitempty"`
|
||||
Project string `json:"project,omitempty"`
|
||||
Projectid string `json:"projectid,omitempty"`
|
||||
Publicip string `json:"publicip,omitempty"`
|
||||
Publicipid string `json:"publicipid,omitempty"`
|
||||
Rootdeviceid int64 `json:"rootdeviceid,omitempty"`
|
||||
Rootdevicetype string `json:"rootdevicetype,omitempty"`
|
||||
Serviceofferingid string `json:"serviceofferingid,omitempty"`
|
||||
Serviceofferingname string `json:"serviceofferingname,omitempty"`
|
||||
Servicestate string `json:"servicestate,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Templatedisplaytext string `json:"templatedisplaytext,omitempty"`
|
||||
Templateid string `json:"templateid,omitempty"`
|
||||
Templatename string `json:"templatename,omitempty"`
|
||||
Zoneid string `json:"zoneid,omitempty"`
|
||||
Zonename string `json:"zonename,omitempty"`
|
||||
}
|
||||
|
||||
type QueryAsyncJobResultResponse struct {
|
||||
Accountid string `json:"accountid,omitempty"`
|
||||
Cmd string `json:"cmd,omitempty"`
|
||||
Created string `json:"created,omitempty"`
|
||||
Jobinstanceid string `json:"jobinstanceid,omitempty"`
|
||||
Jobinstancetype string `json:"jobinstancetype,omitempty"`
|
||||
Jobprocstatus int `json:"jobprocstatus,omitempty"`
|
||||
Jobresult json.RawMessage `json:"jobresult,omitempty"`
|
||||
Jobresultcode int `json:"jobresultcode,omitempty"`
|
||||
Jobresulttype string `json:"jobresulttype,omitempty"`
|
||||
Jobstatus int `json:"jobstatus,omitempty"`
|
||||
Userid string `json:"userid,omitempty"`
|
||||
}
|
||||
|
||||
type ListVirtualMachinesResponse struct {
|
||||
Count int `json:"count"`
|
||||
VirtualMachines []*VirtualMachine `json:"virtualmachine"`
|
||||
}
|
||||
|
||||
type VirtualMachine struct {
|
||||
Account string `json:"account,omitempty"`
|
||||
Cpunumber int `json:"cpunumber,omitempty"`
|
||||
Cpuspeed int `json:"cpuspeed,omitempty"`
|
||||
Cpuused string `json:"cpuused,omitempty"`
|
||||
Created string `json:"created,omitempty"`
|
||||
Details map[string]string `json:"details,omitempty"`
|
||||
Diskioread int64 `json:"diskioread,omitempty"`
|
||||
Diskiowrite int64 `json:"diskiowrite,omitempty"`
|
||||
Diskkbsread int64 `json:"diskkbsread,omitempty"`
|
||||
Diskkbswrite int64 `json:"diskkbswrite,omitempty"`
|
||||
Displayname string `json:"displayname,omitempty"`
|
||||
Displayvm bool `json:"displayvm,omitempty"`
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Domainid string `json:"domainid,omitempty"`
|
||||
Forvirtualnetwork bool `json:"forvirtualnetwork,omitempty"`
|
||||
Group string `json:"group,omitempty"`
|
||||
Groupid string `json:"groupid,omitempty"`
|
||||
Guestosid string `json:"guestosid,omitempty"`
|
||||
Haenable bool `json:"haenable,omitempty"`
|
||||
Hostid string `json:"hostid,omitempty"`
|
||||
Hostname string `json:"hostname,omitempty"`
|
||||
Hypervisor string `json:"hypervisor,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Instancename string `json:"instancename,omitempty"`
|
||||
Isdynamicallyscalable bool `json:"isdynamicallyscalable,omitempty"`
|
||||
Isodisplaytext string `json:"isodisplaytext,omitempty"`
|
||||
Isoid string `json:"isoid,omitempty"`
|
||||
Isoname string `json:"isoname,omitempty"`
|
||||
Keypair string `json:"keypair,omitempty"`
|
||||
Memory int `json:"memory,omitempty"`
|
||||
Name string `json:"name,omitempty"`
|
||||
Networkkbsread int64 `json:"networkkbsread,omitempty"`
|
||||
Networkkbswrite int64 `json:"networkkbswrite,omitempty"`
|
||||
Nic []struct {
|
||||
Broadcasturi string `json:"broadcasturi,omitempty"`
|
||||
Gateway string `json:"gateway,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Ip6address string `json:"ip6address,omitempty"`
|
||||
Ip6cidr string `json:"ip6cidr,omitempty"`
|
||||
Ip6gateway string `json:"ip6gateway,omitempty"`
|
||||
Ipaddress string `json:"ipaddress,omitempty"`
|
||||
Isdefault bool `json:"isdefault,omitempty"`
|
||||
Isolationuri string `json:"isolationuri,omitempty"`
|
||||
Macaddress string `json:"macaddress,omitempty"`
|
||||
Netmask string `json:"netmask,omitempty"`
|
||||
Networkid string `json:"networkid,omitempty"`
|
||||
Networkname string `json:"networkname,omitempty"`
|
||||
Secondaryip []string `json:"secondaryip,omitempty"`
|
||||
Traffictype string `json:"traffictype,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
} `json:"nic,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
Passwordenabled bool `json:"passwordenabled,omitempty"`
|
||||
Project string `json:"project,omitempty"`
|
||||
Projectid string `json:"projectid,omitempty"`
|
||||
Publicip string `json:"publicip,omitempty"`
|
||||
Publicipid string `json:"publicipid,omitempty"`
|
||||
Rootdeviceid int64 `json:"rootdeviceid,omitempty"`
|
||||
Rootdevicetype string `json:"rootdevicetype,omitempty"`
|
||||
Serviceofferingid string `json:"serviceofferingid,omitempty"`
|
||||
Serviceofferingname string `json:"serviceofferingname,omitempty"`
|
||||
Servicestate string `json:"servicestate,omitempty"`
|
||||
State string `json:"state,omitempty"`
|
||||
Templatedisplaytext string `json:"templatedisplaytext,omitempty"`
|
||||
Templateid string `json:"templateid,omitempty"`
|
||||
Templatename string `json:"templatename,omitempty"`
|
||||
Zoneid string `json:"zoneid,omitempty"`
|
||||
Zonename string `json:"zonename,omitempty"`
|
||||
}
|
||||
|
||||
type StartVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type StopVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type DestroyVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type RebootVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type CreateSSHKeyPairWrappedResponse struct {
|
||||
Wrapped CreateSSHKeyPairResponse `json:"keypair,omitempty"`
|
||||
}
|
||||
|
||||
type CreateSSHKeyPairResponse struct {
|
||||
Privatekey string `json:"privatekey,omitempty"`
|
||||
}
|
||||
|
||||
type CreateAffinityGroupResponse struct {
|
||||
JobId string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type DeleteAffinityGroupResponse struct {
|
||||
JobId string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type DeleteSSHKeyPairResponse struct {
|
||||
Privatekey string `json:"privatekey,omitempty"`
|
||||
}
|
||||
|
||||
type DNSDomain struct {
|
||||
Id int64 `json:"id"`
|
||||
UserId int64 `json:"user_id"`
|
||||
RegistrantId int64 `json:"registrant_id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
UnicodeName string `json:"unicode_name"`
|
||||
Token string `json:"token"`
|
||||
State string `json:"state"`
|
||||
Language string `json:"language,omitempty"`
|
||||
Lockable bool `json:"lockable"`
|
||||
AutoRenew bool `json:"auto_renew"`
|
||||
WhoisProtected bool `json:"whois_protected"`
|
||||
RecordCount int64 `json:"record_count"`
|
||||
ServiceCount int64 `json:"service_count"`
|
||||
ExpiresOn string `json:"expires_on,omitempty"`
|
||||
CreatedAt string `json:"created_at"`
|
||||
UpdatedAt string `json:"updated_at"`
|
||||
}
|
||||
|
||||
type DNSDomainCreateRequest struct {
|
||||
Domain struct {
|
||||
Name string `json:"name"`
|
||||
} `json:"domain"`
|
||||
}
|
||||
|
||||
type DNSRecord struct {
|
||||
Id int64 `json:"id,omitempty"`
|
||||
DomainId int64 `json:"domain_id,omitempty"`
|
||||
Name string `json:"name"`
|
||||
Ttl int `json:"ttl,omitempty"`
|
||||
CreatedAt string `json:"created_at,omitempty"`
|
||||
UpdatedAt string `json:"updated_at,omitempty"`
|
||||
Content string `json:"content"`
|
||||
RecordType string `json:"record_type"`
|
||||
Prio int `json:"prio,omitempty"`
|
||||
}
|
||||
|
||||
type DNSRecordResponse struct {
|
||||
Record DNSRecord `json:"record"`
|
||||
}
|
||||
|
||||
type DNSError struct {
|
||||
Name []string `json:"name"`
|
||||
}
|
165
vendor/github.com/pyr/egoscale/src/egoscale/vm.go
generated
vendored
Normal file
165
vendor/github.com/pyr/egoscale/src/egoscale/vm.go
generated
vendored
Normal file
|
@ -0,0 +1,165 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateVirtualMachine(p MachineProfile) (string, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("serviceofferingid", p.ServiceOffering)
|
||||
params.Set("templateid", p.Template)
|
||||
params.Set("zoneid", p.Zone)
|
||||
|
||||
params.Set("displayname", p.Name)
|
||||
if len(p.Userdata) > 0 {
|
||||
params.Set("userdata", base64.StdEncoding.EncodeToString([]byte(p.Userdata)))
|
||||
}
|
||||
if len(p.Keypair) > 0 {
|
||||
params.Set("keypair", p.Keypair)
|
||||
}
|
||||
if len(p.AffinityGroups) > 0 {
|
||||
params.Set("affinitygroupnames", strings.Join(p.AffinityGroups, ","))
|
||||
}
|
||||
|
||||
params.Set("securitygroupids", strings.Join(p.SecurityGroups, ","))
|
||||
|
||||
resp, err := exo.Request("deployVirtualMachine", params)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r DeployVirtualMachineResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobID, nil
|
||||
}
|
||||
|
||||
func (exo *Client) StartVirtualMachine(id string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("startVirtualMachine", params)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r StartVirtualMachineResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobID, nil
|
||||
}
|
||||
|
||||
func (exo *Client) StopVirtualMachine(id string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("stopVirtualMachine", params)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r StopVirtualMachineResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobID, nil
|
||||
}
|
||||
|
||||
func (exo *Client) RebootVirtualMachine(id string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("rebootVirtualMachine", params)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r RebootVirtualMachineResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobID, nil
|
||||
}
|
||||
|
||||
func (exo *Client) DestroyVirtualMachine(id string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("destroyVirtualMachine", params)
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r DestroyVirtualMachineResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.JobID, nil
|
||||
}
|
||||
|
||||
func (exo *Client) GetVirtualMachine(id string) (*VirtualMachine, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("listVirtualMachines", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListVirtualMachinesResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(r.VirtualMachines) == 1 {
|
||||
machine := r.VirtualMachines[0]
|
||||
return machine, nil
|
||||
} else {
|
||||
return nil, fmt.Errorf("cannot retrieve virtualmachine with id %s", id)
|
||||
}
|
||||
}
|
||||
|
||||
func (exo *Client) ListVirtualMachines(id string) ([]*VirtualMachine, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("listVirtualMachines", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListVirtualMachinesResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r.VirtualMachines, nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue