mirror of https://github.com/docker/docs.git
godep/exoscale: update egoscale
Signed-off-by: Vincent Bernat <Vincent.Bernat@exoscale.ch>
This commit is contained in:
parent
1f4502e3e0
commit
b35ad0d322
|
@ -132,7 +132,7 @@
|
|||
},
|
||||
{
|
||||
"ImportPath": "github.com/pyr/egoscale/src/egoscale",
|
||||
"Rev": "8bdfe1d0420634bdd37d73d00d51f86f8d08e481"
|
||||
"Rev": "5759f42eb6041d8dbf837a642e6c061c2bb62f47"
|
||||
},
|
||||
{
|
||||
"ImportPath": "github.com/tent/http-link-go",
|
||||
|
|
|
@ -2,8 +2,8 @@ package egoscale
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateEgressRule(rule SecurityGroupRule) (*AuthorizeSecurityGroupEgressResponse, error) {
|
||||
|
@ -16,7 +16,7 @@ func (exo *Client) CreateEgressRule(rule SecurityGroupRule) (*AuthorizeSecurityG
|
|||
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") {
|
||||
} 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 {
|
||||
|
@ -46,7 +46,7 @@ func (exo *Client) CreateIngressRule(rule SecurityGroupRule) (*AuthorizeSecurity
|
|||
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") {
|
||||
} 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 {
|
||||
|
@ -85,18 +85,18 @@ func (exo *Client) CreateSecurityGroupWithRules(name string, ingress []SecurityG
|
|||
|
||||
sgid := r.Wrapped.Id
|
||||
|
||||
for _, erule := range(egress) {
|
||||
for _, erule := range egress {
|
||||
erule.SecurityGroupId = sgid
|
||||
_, err = exo.CreateEgressRule(erule)
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
for _, inrule := range(ingress) {
|
||||
for _, inrule := range ingress {
|
||||
inrule.SecurityGroupId = sgid
|
||||
_, err = exo.CreateIngressRule(inrule)
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,16 +1,16 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"crypto/tls"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func NewClient(endpoint string, apiKey string, apiSecret string) *Client {
|
||||
cs := &Client {
|
||||
client: &http.Client {
|
||||
Transport: &http.Transport {
|
||||
cs := &Client{
|
||||
client: &http.Client{
|
||||
Transport: &http.Transport{
|
||||
Proxy: http.ProxyFromEnvironment,
|
||||
TLSClientConfig: &tls.Config { InsecureSkipVerify: false },
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: false},
|
||||
},
|
||||
},
|
||||
endpoint: endpoint,
|
||||
|
|
|
@ -21,3 +21,21 @@ func (exo *Client) CreateKeypair(name string) (*CreateSSHKeyPairResponse, error)
|
|||
|
||||
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
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ func rawValue(b json.RawMessage) (json.RawMessage, error) {
|
|||
return nil, fmt.Errorf("Unable to extract raw value from:\n\n%s\n\n", string(b))
|
||||
}
|
||||
|
||||
func (exo *Client) Request (command string, params url.Values) (json.RawMessage, error) {
|
||||
func (exo *Client) Request(command string, params url.Values) (json.RawMessage, error) {
|
||||
|
||||
mac := hmac.New(sha1.New, []byte(exo.apiSecret))
|
||||
|
||||
|
|
|
@ -2,10 +2,10 @@ package egoscale
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
"strings"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (exo *Client) GetSecurityGroups() (map[string]string, error) {
|
||||
|
@ -23,7 +23,7 @@ func (exo *Client) GetSecurityGroups() (map[string]string, error) {
|
|||
}
|
||||
|
||||
sgs = make(map[string]string)
|
||||
for _, sg := range(r.SecurityGroups) {
|
||||
for _, sg := range r.SecurityGroups {
|
||||
sgs[sg.Name] = sg.Id
|
||||
}
|
||||
return sgs, nil
|
||||
|
@ -44,7 +44,7 @@ func (exo *Client) GetZones() (map[string]string, error) {
|
|||
}
|
||||
|
||||
zones = make(map[string]string)
|
||||
for _, zone := range(r.Zones) {
|
||||
for _, zone := range r.Zones {
|
||||
zones[zone.Name] = zone.Id
|
||||
}
|
||||
return zones, nil
|
||||
|
@ -66,7 +66,7 @@ func (exo *Client) GetProfiles() (map[string]string, error) {
|
|||
}
|
||||
|
||||
profiles = make(map[string]string)
|
||||
for _, offering := range(r.ServiceOfferings) {
|
||||
for _, offering := range r.ServiceOfferings {
|
||||
profiles[strings.ToLower(offering.Name)] = offering.Id
|
||||
}
|
||||
|
||||
|
@ -90,7 +90,7 @@ func (exo *Client) GetKeypairs() ([]string, error) {
|
|||
}
|
||||
|
||||
keypairs = make([]string, r.Count, r.Count)
|
||||
for i, keypair := range(r.SSHKeyPairs) {
|
||||
for i, keypair := range r.SSHKeyPairs {
|
||||
keypairs[i] = keypair.Name
|
||||
}
|
||||
return keypairs, nil
|
||||
|
@ -115,7 +115,7 @@ func (exo *Client) GetImages() (map[string]map[int]string, error) {
|
|||
}
|
||||
|
||||
re := regexp.MustCompile(`^Linux (?P<name>Ubuntu|Debian) (?P<version>[0-9.]+).*$`)
|
||||
for _, template := range(r.Templates) {
|
||||
for _, template := range r.Templates {
|
||||
size := template.Size / (1024 * 1024 * 1024)
|
||||
submatch := re.FindStringSubmatch(template.Name)
|
||||
if len(submatch) > 0 {
|
||||
|
@ -124,7 +124,7 @@ func (exo *Client) GetImages() (map[string]map[int]string, error) {
|
|||
image := fmt.Sprintf("%s-%s", name, version)
|
||||
|
||||
_, present := images[image]
|
||||
if (!present) {
|
||||
if !present {
|
||||
images[image] = make(map[int]string)
|
||||
}
|
||||
images[image][size] = template.Id
|
||||
|
@ -138,23 +138,23 @@ func (exo *Client) GetImages() (map[string]map[int]string, error) {
|
|||
func (exo *Client) GetTopology() (*Topology, error) {
|
||||
|
||||
zones, err := exo.GetZones()
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
images, err := exo.GetImages()
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
groups, err := exo.GetSecurityGroups()
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
keypairs, err := exo.GetKeypairs()
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
profiles, err := exo.GetProfiles()
|
||||
if (err != nil) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Client struct {
|
||||
|
@ -12,13 +12,17 @@ type Client struct {
|
|||
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
|
||||
|
@ -145,7 +149,6 @@ type SSHKeyPair struct {
|
|||
Name string `json:"name,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
type ListSecurityGroupsResponse struct {
|
||||
Count int `json:"count"`
|
||||
SecurityGroups []*SecurityGroup `json:"securitygroup"`
|
||||
|
@ -218,7 +221,6 @@ type DeployVirtualMachineResponse struct {
|
|||
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"`
|
||||
|
@ -356,7 +358,6 @@ type VirtualMachine struct {
|
|||
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"`
|
||||
|
@ -377,7 +378,6 @@ type VirtualMachine struct {
|
|||
Zonename string `json:"zonename,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
type StartVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
@ -390,7 +390,6 @@ type DestroyVirtualMachineResponse struct {
|
|||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
|
||||
type RebootVirtualMachineResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
@ -402,3 +401,7 @@ type CreateSSHKeyPairWrappedResponse struct {
|
|||
type CreateSSHKeyPairResponse struct {
|
||||
Privatekey string `json:"privatekey,omitempty"`
|
||||
}
|
||||
|
||||
type DeleteSSHKeyPairResponse struct {
|
||||
Privatekey string `json:"privatekey,omitempty"`
|
||||
}
|
||||
|
|
|
@ -3,9 +3,9 @@ package egoscale
|
|||
import (
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func (exo *Client) CreateVirtualMachine(p MachineProfile) (string, error) {
|
||||
|
@ -140,3 +140,23 @@ func (exo *Client) GetVirtualMachine(id string) (*VirtualMachine, error) {
|
|||
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…
Reference in New Issue