Skip to content

Commit b2e3d81

Browse files
committed
Expose OpenStack driver's userdata param
This allows a user to pass a script or cloud-config file that can be used to initialize the server before the server starts up. This is particularly useful in enterprise cloud environments where the available images on openstack might not be fully compatible with the docker-machine provisioners. Signed-off-by: Wade Tandy <wtandy@bloomberg.net>
1 parent 9718d6c commit b2e3d81

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

drivers/openstack/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ func (c *GenericClient) CreateInstance(d *Driver) (string, error) {
6363
Name: d.MachineName,
6464
FlavorRef: d.FlavorId,
6565
ImageRef: d.ImageId,
66+
UserData: d.UserData,
6667
SecurityGroups: d.SecurityGroups,
6768
AvailabilityZone: d.AvailabilityZone,
6869
}

drivers/openstack/openstack.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ type Driver struct {
3737
KeyPairName string
3838
NetworkName string
3939
NetworkId string
40+
UserData []byte
4041
PrivateKeyFile string
4142
SecurityGroups []string
4243
FloatingIpPool string
@@ -161,6 +162,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
161162
Usage: "Private keyfile to use for SSH (absolute path)",
162163
Value: "",
163164
},
165+
mcnflag.StringFlag{
166+
EnvVar: "OS_USER_DATA_FILE",
167+
Name: "openstack-user-data-file",
168+
Usage: "File containing an openstack userdata script",
169+
Value: "",
170+
},
164171
mcnflag.StringFlag{
165172
EnvVar: "OS_NETWORK_NAME",
166173
Name: "openstack-net-name",
@@ -270,6 +277,16 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
270277
d.SSHPort = flags.Int("openstack-ssh-port")
271278
d.KeyPairName = flags.String("openstack-keypair-name")
272279
d.PrivateKeyFile = flags.String("openstack-private-key-file")
280+
281+
if flags.String("openstack-user-data-file") != "" {
282+
userData, err := ioutil.ReadFile(flags.String("openstack-user-data-file"))
283+
if err == nil {
284+
d.UserData = userData
285+
} else {
286+
return err
287+
}
288+
}
289+
273290
d.SetSwarmConfigFromFlags(flags)
274291

275292
return d.checkConfig()

0 commit comments

Comments
 (0)