Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for user-data #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion otc/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package otc
import (
"crypto/md5"
"crypto/rand"
_ "encoding/base64"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
Expand Down Expand Up @@ -70,6 +70,7 @@ type Driver struct {
AdminPass string
KeyName string
JobId string
UserData []byte

//network
ElasticIpBool int
Expand Down Expand Up @@ -204,6 +205,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Value: 0,
EnvVar: "ELASTIC_IP",
},
mcnflag.StringFlag{
EnvVar: "OS_USER_DATA_FILE",
Name: "otc-user-data-file",
Usage: "File containing an openstack userdata script",
Value: "",
},
}
}

Expand All @@ -227,6 +234,15 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.ElasticIpType = flags.String("otc-elasticip-type")
d.SSHUser = flags.String("otc-ssh-user")
d.ElasticIpBool = flags.Int("otc-elastic-ip")
if name := flags.String("otc-user-data-file"); name != "" {
userData, err := ioutil.ReadFile(name)
if err == nil {
d.UserData = userData
} else {
return err
}
}

//fmt.Printf("test for region: %s\n", d.Region)
return d.checkConfig()
}
Expand Down Expand Up @@ -588,6 +604,7 @@ func (d *Driver) createInstance() (ecsModules.CreateCloudServerResp, error) {
instanceDesc.SetKey_name(d.KeyName)
instanceDesc.SetAdminPass(d.AdminPass)
instanceDesc.SetSecurity_groups(sgList)
instanceDesc.SetUser_data(base64.StdEncoding.EncodeToString(d.UserData))

/*log.Debugf("%s | SSH User: %s", d.MachineName, d.SSHUser)
if d.SSHUser != "" {
Expand Down
1 change: 1 addition & 0 deletions otcgo/ecs/instances.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type CreateInstanceAttribute struct {
SecGrps []SecGrp `json:"security_groups"`
AdminPass string `json:"adminPass"`
KeyName string `json:"key_name"`
UserData []byte `json:"user_data"`
}

type CreateInstanceArgs struct {
Expand Down