Skip to content

Commit

Permalink
[openstack] Config drive auto-detection
Browse files Browse the repository at this point in the history
Signed-off-by: Andrey Klimentyev <andrey.klimentyev@flant.com>
  • Loading branch information
zuzzas committed Apr 29, 2020
1 parent 8ec2a7f commit dc76d79
Show file tree
Hide file tree
Showing 6 changed files with 623 additions and 0 deletions.
35 changes: 35 additions & 0 deletions pkg/driver/driver_openstack.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"github.com/gophercloud/gophercloud/openstack/compute/v2/images"
"github.com/gophercloud/gophercloud/openstack/compute/v2/servers"
"github.com/gophercloud/gophercloud/openstack/networking/v2/ports"
"github.com/gophercloud/gophercloud/openstack/networking/v2/subnets"
"github.com/gophercloud/gophercloud/pagination"
"github.com/gophercloud/utils/client"
"github.com/gophercloud/utils/openstack/clientconfig"
Expand Down Expand Up @@ -160,6 +161,29 @@ func (d *OpenStackDriver) Create() (string, string, error) {

metrics.APIRequestCount.With(prometheus.Labels{"provider": "openstack", "service": "nova"}).Inc()

var useConfigDrive *bool
if len(serverNetworks) > 0 {
mainNetworkID := serverNetworks[0].UUID
allSubnetsPagesForMainNet, err := subnets.List(nwClient, subnets.ListOpts{NetworkID: mainNetworkID}).AllPages()
if err != nil {
metrics.APIFailedRequestCount.With(prometheus.Labels{"provider": "openstack", "service": "neutron"}).Inc()
return "", "", fmt.Errorf("failed to get subnets for networkID %q: %s", mainNetworkID, err)
}
metrics.APIRequestCount.With(prometheus.Labels{"provider": "openstack", "service": "neutron"}).Inc()

allSubnetsForMainNet, err := subnets.ExtractSubnets(allSubnetsPagesForMainNet)
if err != nil {
return "", "", fmt.Errorf("failed to extract subnets for networkID %q: %s", mainNetworkID, err)
}

for _, subnet := range allSubnetsForMainNet {
if !subnet.EnableDHCP {
trueVal := true
useConfigDrive = &trueVal
}
}
}

createOpts = &servers.CreateOpts{
ServiceClient: client,
Name: d.MachineName,
Expand All @@ -170,6 +194,7 @@ func (d *OpenStackDriver) Create() (string, string, error) {
Metadata: metadata,
UserData: []byte(d.UserData),
AvailabilityZone: availabilityZone,
ConfigDrive: useConfigDrive,
}

createOpts = &keypairs.CreateOptsExt{
Expand Down Expand Up @@ -606,3 +631,13 @@ func resourceInstanceBlockDevicesV2(rootDiskSize int, imageID string) ([]bootfro
klog.V(2).Infof("[DEBUG] Block Device Options: %+v", blockDeviceOpts)
return blockDeviceOpts, nil
}

func dhcpDisabled(subnets []subnets.Subnet) bool {
for _, subnet := range subnets {
if !subnet.EnableDHCP {
return true
}
}

return false
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dc76d79

Please sign in to comment.