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

drivers/openstack: added flag openstack-metadata #4603

Merged
merged 1 commit into from
Jan 13, 2019
Merged
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
1 change: 1 addition & 0 deletions drivers/openstack/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ func (c *GenericClient) CreateInstance(d *Driver) (string, error) {
SecurityGroups: d.SecurityGroups,
AvailabilityZone: d.AvailabilityZone,
ConfigDrive: d.ConfigDrive,
Metadata: d.GetMetadata(),
}
if d.NetworkId != "" {
serverOpts.Networks = []servers.Network{
Expand Down
24 changes: 24 additions & 0 deletions drivers/openstack/openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type Driver struct {
FloatingIpPoolId string
IpVersion int
ConfigDrive bool
metadata string
client Client
// 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.
ExistingKey bool
Expand Down Expand Up @@ -233,6 +234,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Name: "openstack-config-drive",
Usage: "Enables the OpenStack config drive for the instance",
},
mcnflag.StringFlag{
EnvVar: "OS_METADATA",
Name: "openstack-metadata",
Usage: "OpenStack Instance Metadata (e.g. key1,value1,key2,value2)",
Value: "",
},
}
}

Expand Down Expand Up @@ -286,6 +293,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.ImageName = flags.String("openstack-image-name")
d.NetworkId = flags.String("openstack-net-id")
d.NetworkName = flags.String("openstack-net-name")
d.metadata = flags.String("openstack-metadata")
if flags.String("openstack-sec-groups") != "" {
d.SecurityGroups = strings.Split(flags.String("openstack-sec-groups"), ",")
}
Expand Down Expand Up @@ -487,6 +495,22 @@ func (d *Driver) Remove() error {
return nil
}

func (d *Driver) GetMetadata() map[string]string {
metadata := make(map[string]string)

if d.metadata != "" {
items := strings.Split(d.metadata, ",")
if len(items) > 0 && len(items)%2 != 0 {
log.Warnf("Metadata are not key value in pairs. %d elements found", len(items))
}
for i := 0; i < len(items)-1; i += 2 {
metadata[items[i]] = items[i+1]
}
}

return metadata
}

const (
errorMandatoryEnvOrOption string = "%s must be specified either using the environment variable %s or the CLI option %s"
errorMandatoryOption string = "%s must be specified using the CLI option %s"
Expand Down