Skip to content
This repository has been archived by the owner on Sep 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #4457 from exoscale/exoscale/fixes
Browse files Browse the repository at this point in the history
Exoscale/fixes
  • Loading branch information
dgageot authored May 12, 2018
2 parents cb2b414 + a61bafe commit 0331899
Show file tree
Hide file tree
Showing 58 changed files with 3,326 additions and 2,159 deletions.
6 changes: 3 additions & 3 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

[[constraint]]
name = "github.com/exoscale/egoscale"
version = "0.9.14"
version = "0.9.23"

[[constraint]]
branch = "master"
Expand Down
55 changes: 35 additions & 20 deletions drivers/exoscale/exoscale.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Driver struct {
Password string
PublicKey string
UserDataFile string
UserData []byte
ID string `json:"Id"`
}

Expand Down Expand Up @@ -199,6 +200,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SSHUser = flags.String("exoscale-ssh-user")
d.SSHKey = flags.String("exoscale-ssh-key")
d.UserDataFile = flags.String("exoscale-userdata")
d.UserData = []byte(defaultCloudInit)
d.SetSwarmConfigFromFlags(flags)

if d.URL == "" {
Expand Down Expand Up @@ -416,47 +418,55 @@ func (d *Driver) Create() error {
zone := zones.Zone[0].ID
log.Debugf("Availability zone %v = %s", d.AvailabilityZone, zone)

// Image UUID
var tpl string
// Image
template := egoscale.Template{
IsFeatured: true,
ZoneID: "1", // GVA2
}

resp, err = client.RequestWithContext(context.TODO(), &egoscale.ListTemplates{
TemplateFilter: "featured",
ZoneID: "1", // GVA2
})
templates, err := client.ListWithContext(context.TODO(), &template)
if err != nil {
return err
}

image := strings.ToLower(d.Image)
re := regexp.MustCompile(`^Linux (?P<name>.+?) (?P<version>[0-9.]+)\b`)
for _, template := range resp.(*egoscale.ListTemplatesResponse).Template {

for _, t := range templates {
tpl := t.(*egoscale.Template)

// Keep only 10GiB images
if template.Size>>30 != 10 {
if tpl.Size>>30 != 10 {
continue
}

fullname := strings.ToLower(template.Name)
fullname := strings.ToLower(tpl.Name)
if image == fullname {
tpl = template.ID
template = *tpl
break
}

submatch := re.FindStringSubmatch(template.Name)
submatch := re.FindStringSubmatch(tpl.Name)
if len(submatch) > 0 {
name := strings.Replace(strings.ToLower(submatch[1]), " ", "-", -1)
version := submatch[2]
shortname := fmt.Sprintf("%s-%s", name, version)

if image == shortname {
tpl = template.ID
template = *tpl
break
}
}
}
if tpl == "" {
if template.ID == "" {
return fmt.Errorf("Unable to find image %v", d.Image)
}
log.Debugf("Image %v(10) = %s", d.Image, tpl)

// Reading the username from the template
if name, ok := template.Details["username"]; ok {
d.SSHUser = name
}
log.Debugf("Image %v(10) = %s (%s)", d.Image, template.ID, d.SSHUser)

// Profile UUID
resp, err = client.RequestWithContext(context.TODO(), &egoscale.ListServiceOfferings{
Expand Down Expand Up @@ -531,8 +541,11 @@ func (d *Driver) Create() error {
return fmt.Errorf("SSH Key pair creation failed %s", err)
}
keyPair := resp.(*egoscale.CreateSSHKeyPairResponse).KeyPair
if err = os.MkdirAll(filepath.Dir(d.GetSSHKeyPath()), 0750); err != nil {
return fmt.Errorf("Cannot create the folder to store the SSH private key. %s", err)
}
if err = ioutil.WriteFile(d.GetSSHKeyPath(), []byte(keyPair.PrivateKey), 0600); err != nil {
return fmt.Errorf("SSH public key could not be written %s", err)
return fmt.Errorf("SSH private key could not be written. %s", err)
}
d.KeyPair = keyPairName
} else {
Expand Down Expand Up @@ -574,12 +587,13 @@ ssh_authorized_keys:
log.Debugf("%s", string(cloudInit))

// Base64 encode the userdata
userData := base64.StdEncoding.EncodeToString(cloudInit)
d.UserData = cloudInit
encodedUserData := base64.StdEncoding.EncodeToString(d.UserData)

req := &egoscale.DeployVirtualMachine{
TemplateID: tpl,
TemplateID: template.ID,
ServiceOfferingID: profile,
UserData: userData,
UserData: encodedUserData,
ZoneID: zone,
Name: d.MachineName,
KeyPair: d.KeyPair,
Expand Down Expand Up @@ -688,9 +702,10 @@ func (d *Driver) Remove() error {
// Build a cloud-init user data string that will install and run
// docker.
func (d *Driver) getCloudInit() ([]byte, error) {
var err error
if d.UserDataFile != "" {
return ioutil.ReadFile(d.UserDataFile)
d.UserData, err = ioutil.ReadFile(d.UserDataFile)
}

return []byte(defaultCloudInit), nil
return d.UserData, err
}
1 change: 1 addition & 0 deletions vendor/github.com/exoscale/egoscale/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion vendor/github.com/exoscale/egoscale/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions vendor/github.com/exoscale/egoscale/AUTHORS

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

78 changes: 78 additions & 0 deletions vendor/github.com/exoscale/egoscale/CHANGELOG.md

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

100 changes: 13 additions & 87 deletions vendor/github.com/exoscale/egoscale/accounts.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 0331899

Please sign in to comment.