Skip to content

Commit

Permalink
add subnet UUID support
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxtof committed Dec 14, 2023
1 parent 7fc4c3c commit 941e7e8
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 10 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ If you want to use Nutanix Node Driver, you need add it in order to start using
2. Click *Add Node Driver*.
3. Complete the Add Node Driver form. Then click Create.

- *Download URL*: `https://github.com/nutanix/docker-machine/releases/download/v3.5.0/docker-machine-driver-nutanix`
- *Custom UI URL*: `https://nutanix.github.io/rancher-ui-driver/v3.5.0/component.js`
- *Checksum*: `9555aadd060204ec510bb99e1dc9fed94af9780b2a409680888ee928982542cf`
- *Download URL*: `https://github.com/nutanix/docker-machine/releases/download/v3.6.0/docker-machine-driver-nutanix`
- *Custom UI URL*: `https://nutanix.github.io/rancher-ui-driver/v3.6.0/component.js`
- *Checksum*: ``
- *Whitelist Domains*: `nutanix.github.io`


Expand Down
30 changes: 24 additions & 6 deletions machine/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,25 +192,43 @@ func (d *NutanixDriver) Create() error {

subnetFilter := ""

// Create subnets filter query and add UUID subnets directly
for _, subnet := range d.Subnet {
if len(subnetFilter) != 0 {
subnetFilter += ","

if isUUID(subnet) {
n := &v3.VMNic{
SubnetReference: utils.BuildReference(*utils.StringPtr(subnet), "subnet"),
}

res.NicList = append(res.NicList, n)
log.Infof("UUID subnet added %s", subnet)
} else {
if len(subnetFilter) != 0 {
subnetFilter += ","
}

t := &url.URL{Path: subnet}
encodedSubnet := t.String()
subnetFilter += fmt.Sprintf("name==%s", encodedSubnet)
}

t := &url.URL{Path: subnet}
encodedSubnet := t.String()
subnetFilter += fmt.Sprintf("name==%s", encodedSubnet)
}

// Retrieve all subnets
responseSubnets, err := conn.V3.ListAllSubnet(subnetFilter, getEmptyClientSideFilter())
if err != nil {
log.Errorf("Error getting subnets: [%v]", err)
return err
}

// Validate filtered Subnets
// Search for non UUID Subnets
for _, query := range d.Subnet {
if isUUID(query) {
continue
}

log.Infof("Searching subnet %s", query)

for _, subnet := range responseSubnets.Entities {

if *subnet.Spec.Name == query {
Expand Down
11 changes: 10 additions & 1 deletion machine/driver/yaml.go → machine/driver/utils.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
package driver

import "gopkg.in/yaml.v3"
import (
"regexp"

"gopkg.in/yaml.v3"
)

func isUUID(uuid string) bool {
uuidPattern := regexp.MustCompile(`^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$`)
return uuidPattern.MatchString(uuid)
}

func iterateNode(node *yaml.Node, identifier string) *yaml.Node {
returnNode := false
Expand Down

0 comments on commit 941e7e8

Please sign in to comment.