Browse Source

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>
Wade Tandy 3 years ago
parent
commit
c17f42fab5
2 changed files with 18 additions and 0 deletions
  1. 1
    0
      drivers/openstack/client.go
  2. 17
    0
      drivers/openstack/openstack.go

+ 1
- 0
drivers/openstack/client.go View File

@@ -63,6 +63,7 @@ func (c *GenericClient) CreateInstance(d *Driver) (string, error) {
63 63
 		Name:             d.MachineName,
64 64
 		FlavorRef:        d.FlavorId,
65 65
 		ImageRef:         d.ImageId,
66
+		UserData:         d.UserData,
66 67
 		SecurityGroups:   d.SecurityGroups,
67 68
 		AvailabilityZone: d.AvailabilityZone,
68 69
 	}

+ 17
- 0
drivers/openstack/openstack.go View File

@@ -37,6 +37,7 @@ type Driver struct {
37 37
 	KeyPairName      string
38 38
 	NetworkName      string
39 39
 	NetworkId        string
40
+	UserData         []byte
40 41
 	PrivateKeyFile   string
41 42
 	SecurityGroups   []string
42 43
 	FloatingIpPool   string
@@ -161,6 +162,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
161 162
 			Usage:  "Private keyfile to use for SSH (absolute path)",
162 163
 			Value:  "",
163 164
 		},
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
+		},
164 171
 		mcnflag.StringFlag{
165 172
 			EnvVar: "OS_NETWORK_NAME",
166 173
 			Name:   "openstack-net-name",
@@ -270,6 +277,16 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
270 277
 	d.SSHPort = flags.Int("openstack-ssh-port")
271 278
 	d.KeyPairName = flags.String("openstack-keypair-name")
272 279
 	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
+
273 290
 	d.SetSwarmConfigFromFlags(flags)
274 291
 
275 292
 	return d.checkConfig()

Loading…
Cancel
Save