Merge v1.2.1-master
Signed-off-by: Emile Vauge <emile@vauge.com>
This commit is contained in:
parent
a590155b0b
commit
aeb17182b4
396 changed files with 27271 additions and 9969 deletions
114
vendor/github.com/pyr/egoscale/exo.go
generated
vendored
114
vendor/github.com/pyr/egoscale/exo.go
generated
vendored
|
@ -3,115 +3,37 @@ package main
|
|||
import (
|
||||
"egoscale"
|
||||
"fmt"
|
||||
"flag"
|
||||
"os"
|
||||
"time"
|
||||
)
|
||||
|
||||
var apikey = flag.String("xk", "", "Exoscale API Key")
|
||||
var apisecret = flag.String("xs", "", "Exoscale API Secret")
|
||||
var endpoint = flag.String("xe", "https://api.exoscale.ch/compute", "Exoscale API Endpoint")
|
||||
|
||||
func main() {
|
||||
|
||||
endpoint := os.Getenv("EXOSCALE_ENDPOINT")
|
||||
apiKey := os.Getenv("EXOSCALE_API_KEY")
|
||||
apiSecret := os.Getenv("EXOSCALE_API_SECRET")
|
||||
client := egoscale.NewClient(endpoint, apiKey, apiSecret)
|
||||
flag.Parse()
|
||||
client := egoscale.NewClient(*endpoint, *apikey, *apisecret)
|
||||
|
||||
topo, err := client.GetTopology()
|
||||
|
||||
vms, err := client.ListVirtualMachines()
|
||||
if err != nil {
|
||||
fmt.Printf("got error: %+v\n", err)
|
||||
return
|
||||
fmt.Printf("got error: %s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
rules := []egoscale.SecurityGroupRule{
|
||||
{
|
||||
SecurityGroupId: "",
|
||||
Cidr: "0.0.0.0/0",
|
||||
Protocol: "TCP",
|
||||
Port: 22,
|
||||
},
|
||||
{
|
||||
SecurityGroupId: "",
|
||||
Cidr: "0.0.0.0/0",
|
||||
Protocol: "TCP",
|
||||
Port: 2376,
|
||||
},
|
||||
{
|
||||
SecurityGroupId: "",
|
||||
Cidr: "0.0.0.0/0",
|
||||
Protocol: "ICMP",
|
||||
IcmpType: 8,
|
||||
IcmpCode: 0,
|
||||
},
|
||||
}
|
||||
for _, vm := range(vms) {
|
||||
|
||||
sgid, present := topo.SecurityGroups["egoscale"]
|
||||
if !present {
|
||||
resp, err := client.CreateSecurityGroupWithRules("egoscale", rules, make([]egoscale.SecurityGroupRule, 0, 0))
|
||||
if err != nil {
|
||||
fmt.Printf("got error: %+v\n", err)
|
||||
return
|
||||
fmt.Println("vm:", vm.Displayname)
|
||||
for _, nic := range(vm.Nic) {
|
||||
fmt.Println("ip:", nic.Ipaddress)
|
||||
}
|
||||
sgid = resp.Id
|
||||
}
|
||||
|
||||
agid, present := topo.AffinityGroups["egoscale"]
|
||||
if !present {
|
||||
//Affinity Group Create is an async call
|
||||
jobid, err := client.CreateAffinityGroup("egoscale")
|
||||
|
||||
var resp *egoscale.QueryAsyncJobResultResponse
|
||||
for i := 0; i <= 10; i++ {
|
||||
resp, err = client.PollAsyncJob(jobid)
|
||||
if err != nil {
|
||||
fmt.Printf("got error: %+v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if resp.Jobstatus == 1 {
|
||||
break
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
for _, sg := range(vm.SecurityGroups) {
|
||||
fmt.Println("securitygroup:", sg.Name)
|
||||
}
|
||||
}
|
||||
fmt.Printf("Affinity Group ID :%v\n", agid)
|
||||
os.Exit(0)
|
||||
|
||||
profile := egoscale.MachineProfile{
|
||||
Template: topo.Images["ubuntu-14.04"][10],
|
||||
ServiceOffering: topo.Profiles["large"],
|
||||
SecurityGroups: []string{sgid},
|
||||
Keypair: topo.Keypairs[0],
|
||||
AffinityGroups: []string{"egoscale"},
|
||||
Userdata: "#cloud-config\nmanage_etc_hosts: true\nfqdn: deployed-by-egoscale\n",
|
||||
Zone: topo.Zones["ch-gva-2"],
|
||||
Name: "deployed-by-egoscale",
|
||||
}
|
||||
|
||||
jobid, err := client.CreateVirtualMachine(profile)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("got error: %+v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
var resp *egoscale.QueryAsyncJobResultResponse
|
||||
|
||||
for i := 0; i <= 10; i++ {
|
||||
resp, err = client.PollAsyncJob(jobid)
|
||||
if err != nil {
|
||||
fmt.Printf("got error: %+v\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
if resp.Jobstatus == 1 {
|
||||
break
|
||||
}
|
||||
time.Sleep(5 * time.Second)
|
||||
}
|
||||
|
||||
vm, err := client.AsyncToVirtualMachine(*resp)
|
||||
|
||||
if err != nil {
|
||||
fmt.Printf("got error: %+v\n", err)
|
||||
}
|
||||
|
||||
fmt.Printf("new machine up and running at: %s\n", vm.Nic[0].Ipaddress)
|
||||
|
||||
}
|
||||
|
|
34
vendor/github.com/pyr/egoscale/src/egoscale/groups.go
generated
vendored
34
vendor/github.com/pyr/egoscale/src/egoscale/groups.go
generated
vendored
|
@ -10,9 +10,21 @@ func (exo *Client) CreateEgressRule(rule SecurityGroupRule) (*AuthorizeSecurityG
|
|||
|
||||
params := url.Values{}
|
||||
params.Set("securitygroupid", rule.SecurityGroupId)
|
||||
params.Set("cidrlist", rule.Cidr)
|
||||
params.Set("protocol", rule.Protocol)
|
||||
|
||||
if rule.Cidr != "" {
|
||||
params.Set("cidrlist", rule.Cidr)
|
||||
} else if len(rule.UserSecurityGroupList) > 0 {
|
||||
usg,err := json.Marshal(rule.UserSecurityGroupList)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
params.Set("usersecuritygrouplist", string(usg))
|
||||
} else {
|
||||
return nil, fmt.Errorf("No Egress rule CIDR or Security Group List provided")
|
||||
}
|
||||
|
||||
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))
|
||||
|
@ -40,7 +52,19 @@ func (exo *Client) CreateIngressRule(rule SecurityGroupRule) (*AuthorizeSecurity
|
|||
|
||||
params := url.Values{}
|
||||
params.Set("securitygroupid", rule.SecurityGroupId)
|
||||
params.Set("cidrlist", rule.Cidr)
|
||||
|
||||
if rule.Cidr != "" {
|
||||
params.Set("cidrlist", rule.Cidr)
|
||||
} else if len(rule.UserSecurityGroupList) >0 {
|
||||
for i := 0; i < len(rule.UserSecurityGroupList); i++ {
|
||||
params.Set(fmt.Sprintf("usersecuritygrouplist[%d].account", i), rule.UserSecurityGroupList[i].Account)
|
||||
params.Set(fmt.Sprintf("usersecuritygrouplist[%d].group", i), rule.UserSecurityGroupList[i].Group)
|
||||
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("No Ingress rule CIDR or Security Group List provided")
|
||||
}
|
||||
|
||||
params.Set("protocol", rule.Protocol)
|
||||
|
||||
if rule.Protocol == "ICMP" {
|
||||
|
@ -53,6 +77,8 @@ func (exo *Client) CreateIngressRule(rule SecurityGroupRule) (*AuthorizeSecurity
|
|||
return nil, fmt.Errorf("Invalid Egress rule Protocol: %s", rule.Protocol)
|
||||
}
|
||||
|
||||
fmt.Printf("## params: %+v\n", params)
|
||||
|
||||
resp, err := exo.Request("authorizeSecurityGroupIngress", params)
|
||||
|
||||
if err != nil {
|
||||
|
@ -114,4 +140,4 @@ func (exo *Client) DeleteSecurityGroup(name string) (error) {
|
|||
|
||||
fmt.Printf("## response: %+v\n", resp)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
40
vendor/github.com/pyr/egoscale/src/egoscale/ip.go
generated
vendored
Normal file
40
vendor/github.com/pyr/egoscale/src/egoscale/ip.go
generated
vendored
Normal file
|
@ -0,0 +1,40 @@
|
|||
package egoscale
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (exo *Client) AddIpToNic(nic_id string, ip_address string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("nicid", nic_id)
|
||||
params.Set("ipaddress", ip_address)
|
||||
|
||||
resp, err := exo.Request("addIpToNic", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r AddIpToNicResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
return r.Id, nil
|
||||
}
|
||||
|
||||
func (exo *Client) RemoveIpFromNic(nic_id string) (string, error) {
|
||||
params := url.Values{}
|
||||
params.Set("id", nic_id)
|
||||
|
||||
resp, err := exo.Request("removeIpFromNic", params)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
var r RemoveIpFromNicResponse
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return r.JobID, nil
|
||||
}
|
31
vendor/github.com/pyr/egoscale/src/egoscale/request.go
generated
vendored
31
vendor/github.com/pyr/egoscale/src/egoscale/request.go
generated
vendored
|
@ -10,8 +10,17 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"sort"
|
||||
)
|
||||
|
||||
func csQuotePlus(s string) string {
|
||||
return strings.Replace(s, "+", "%20", -1)
|
||||
}
|
||||
|
||||
func csEncode(s string) string {
|
||||
return csQuotePlus(url.QueryEscape(s))
|
||||
}
|
||||
|
||||
func rawValue(b json.RawMessage) (json.RawMessage, error) {
|
||||
var m map[string]json.RawMessage
|
||||
|
||||
|
@ -21,7 +30,6 @@ func rawValue(b json.RawMessage) (json.RawMessage, error) {
|
|||
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
|
||||
}
|
||||
|
||||
|
@ -51,7 +59,6 @@ func (exo *Client) ParseResponse(resp *http.Response) (json.RawMessage, error) {
|
|||
}
|
||||
|
||||
if resp.StatusCode >= 400 {
|
||||
fmt.Printf("ERROR: %s\n", b)
|
||||
var e Error
|
||||
if err := json.Unmarshal(b, &e); err != nil {
|
||||
return nil, err
|
||||
|
@ -75,17 +82,27 @@ func (exo *Client) ParseResponse(resp *http.Response) (json.RawMessage, error) {
|
|||
func (exo *Client) Request(command string, params url.Values) (json.RawMessage, error) {
|
||||
|
||||
mac := hmac.New(sha1.New, []byte(exo.apiSecret))
|
||||
keys := make([]string, 0)
|
||||
unencoded := make([]string, 0)
|
||||
|
||||
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)))
|
||||
for k, _ := range(params) {
|
||||
keys = append(keys, k)
|
||||
}
|
||||
sort.Strings(keys)
|
||||
for _, k := range(keys) {
|
||||
arg := k + "=" + csEncode(params[k][0])
|
||||
unencoded = append(unencoded, arg)
|
||||
}
|
||||
sign_string := strings.ToLower(strings.Join(unencoded, "&"))
|
||||
|
||||
s = params.Encode()
|
||||
url := exo.endpoint + "?" + s + "&signature=" + signature
|
||||
mac.Write([]byte(sign_string))
|
||||
signature := csEncode(base64.StdEncoding.EncodeToString(mac.Sum(nil)))
|
||||
query := params.Encode()
|
||||
url := exo.endpoint + "?" + csQuotePlus(query) + "&signature=" + signature
|
||||
|
||||
resp, err := exo.client.Get(url)
|
||||
if err != nil {
|
||||
|
|
30
vendor/github.com/pyr/egoscale/src/egoscale/types.go
generated
vendored
30
vendor/github.com/pyr/egoscale/src/egoscale/types.go
generated
vendored
|
@ -39,6 +39,12 @@ type SecurityGroupRule struct {
|
|||
Port int
|
||||
Protocol string
|
||||
SecurityGroupId string
|
||||
UserSecurityGroupList []UserSecurityGroup `json:"usersecuritygrouplist,omitempty"`
|
||||
}
|
||||
|
||||
type UserSecurityGroup struct {
|
||||
Group string `json:"group,omitempty"`
|
||||
Account string `json:"account,omitempty"`
|
||||
}
|
||||
|
||||
type MachineProfile struct {
|
||||
|
@ -397,7 +403,10 @@ type VirtualMachine struct {
|
|||
Netmask string `json:"netmask,omitempty"`
|
||||
Networkid string `json:"networkid,omitempty"`
|
||||
Networkname string `json:"networkname,omitempty"`
|
||||
Secondaryip []string `json:"secondaryip,omitempty"`
|
||||
Secondaryip []struct {
|
||||
Id string `json:"id,omitempty"`
|
||||
IpAddress string `json:"ipaddress,omitempty"`
|
||||
} `json:"secondaryip,omitempty"`
|
||||
Traffictype string `json:"traffictype,omitempty"`
|
||||
Type string `json:"type,omitempty"`
|
||||
} `json:"nic,omitempty"`
|
||||
|
@ -409,6 +418,13 @@ type VirtualMachine struct {
|
|||
Publicipid string `json:"publicipid,omitempty"`
|
||||
Rootdeviceid int64 `json:"rootdeviceid,omitempty"`
|
||||
Rootdevicetype string `json:"rootdevicetype,omitempty"`
|
||||
SecurityGroups []struct {
|
||||
Account string `json:"account,omitempty"`
|
||||
Description string `json:"description,omitempty"`
|
||||
Id string `json:"id,omitempty"`
|
||||
Name string `json:"name,omitemtpy"`
|
||||
Tags []string `json:"tags,omitempty"`
|
||||
} `json:"securitygroup,omitempty"`
|
||||
Serviceofferingid string `json:"serviceofferingid,omitempty"`
|
||||
Serviceofferingname string `json:"serviceofferingname,omitempty"`
|
||||
Servicestate string `json:"servicestate,omitempty"`
|
||||
|
@ -444,6 +460,18 @@ type CreateSSHKeyPairResponse struct {
|
|||
Privatekey string `json:"privatekey,omitempty"`
|
||||
}
|
||||
|
||||
type RemoveIpFromNicResponse struct {
|
||||
JobID string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
||||
type AddIpToNicResponse struct {
|
||||
Id string `json:"id"`
|
||||
IpAddress string `json:"ipaddress"`
|
||||
NetworkId string `json:"networkid"`
|
||||
NicId string `json:"nicid"`
|
||||
VmId string `json:"virtualmachineid"`
|
||||
}
|
||||
|
||||
type CreateAffinityGroupResponse struct {
|
||||
JobId string `json:"jobid,omitempty"`
|
||||
}
|
||||
|
|
10
vendor/github.com/pyr/egoscale/src/egoscale/vm.go
generated
vendored
10
vendor/github.com/pyr/egoscale/src/egoscale/vm.go
generated
vendored
|
@ -125,7 +125,6 @@ func (exo *Client) GetVirtualMachine(id string) (*VirtualMachine, error) {
|
|||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("listVirtualMachines", params)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -144,19 +143,14 @@ func (exo *Client) GetVirtualMachine(id string) (*VirtualMachine, error) {
|
|||
}
|
||||
}
|
||||
|
||||
func (exo *Client) ListVirtualMachines(id string) ([]*VirtualMachine, error) {
|
||||
|
||||
params := url.Values{}
|
||||
params.Set("id", id)
|
||||
|
||||
resp, err := exo.Request("listVirtualMachines", params)
|
||||
func (exo *Client) ListVirtualMachines() ([]*VirtualMachine, error) {
|
||||
|
||||
resp, err := exo.Request("listVirtualMachines", url.Values{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var r ListVirtualMachinesResponse
|
||||
|
||||
if err := json.Unmarshal(resp, &r); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue