Skip to content
This repository was archived by the owner on Jul 18, 2025. It is now read-only.

Commit 1e3fa2d

Browse files
author
xinau
committed
added flag for openstack metadata
Signed-off-by: xinau <felix.ehrenpfort@codecentric.cloud>
1 parent 15cde71 commit 1e3fa2d

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

‎drivers/openstack/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ func (c *GenericClient) CreateInstance(d *Driver) (string, error) {
6969
SecurityGroups: d.SecurityGroups,
7070
AvailabilityZone: d.AvailabilityZone,
7171
ConfigDrive: d.ConfigDrive,
72+
Metadata: d.GetMetadata(),
7273
}
7374
if d.NetworkId != "" {
7475
serverOpts.Networks = []servers.Network{

‎drivers/openstack/openstack.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ type Driver struct {
4949
FloatingIpPoolId string
5050
IpVersion int
5151
ConfigDrive bool
52+
metadata string
5253
client Client
5354
// ExistingKey keeps track of whether the key was created by us or we used an existing one. If an existing one was used, we shouldn't delete it when the machine is deleted.
5455
ExistingKey bool
@@ -233,6 +234,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
233234
Name: "openstack-config-drive",
234235
Usage: "Enables the OpenStack config drive for the instance",
235236
},
237+
mcnflag.StringFlag{
238+
EnvVar: "OS_METADATA",
239+
Name: "openstack-metadata",
240+
Usage: "OpenStack Instance Metadata (e.g. key1,value1,key2,value2)",
241+
Value: "",
242+
},
236243
}
237244
}
238245

@@ -286,6 +293,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
286293
d.ImageName = flags.String("openstack-image-name")
287294
d.NetworkId = flags.String("openstack-net-id")
288295
d.NetworkName = flags.String("openstack-net-name")
296+
d.metadata = flags.String("openstack-metadata")
289297
if flags.String("openstack-sec-groups") != "" {
290298
d.SecurityGroups = strings.Split(flags.String("openstack-sec-groups"), ",")
291299
}
@@ -487,6 +495,22 @@ func (d *Driver) Remove() error {
487495
return nil
488496
}
489497

498+
func (d *Driver) GetMetadata() map[string]string {
499+
metadata := make(map[string]string)
500+
501+
if d.metadata != "" {
502+
items := strings.Split(d.metadata, ",")
503+
if len(items) > 0 && len(items)%2 != 0 {
504+
log.Warnf("Metadata are not key value in pairs. %d elements found", len(items))
505+
}
506+
for i := 0; i < len(items)-1; i += 2 {
507+
metadata[items[i]] = items[i+1]
508+
}
509+
}
510+
511+
return metadata
512+
}
513+
490514
const (
491515
errorMandatoryEnvOrOption string = "%s must be specified either using the environment variable %s or the CLI option %s"
492516
errorMandatoryOption string = "%s must be specified using the CLI option %s"

0 commit comments

Comments
 (0)