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 6796d4e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 11 deletions.
8 changes: 4 additions & 4 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 Expand Up @@ -74,7 +74,7 @@ If you want to use Nutanix Node Driver, you need add it in order to start using
| `nutanix-vm-mem` | The amount of RAM of the newly created VM (MB) | no | 2 GB |
| `nutanix-vm-cpus` | The number of cpus in the newly created VM (core) | no | 2 |
| `nutanix-vm-cores` | The number of cores per vCPU | no | 1 |
| `nutanix-vm-network` | The network(s) to which the VM is attached to | yes | |
| `nutanix-vm-network` | The network(s) to which the VM is attached to ( name or UUID ) | yes | |
| `nutanix-vm-image` | The name of the Disk Image template we use for the newly created VM (must support cloud-init) | yes | |
| `nutanix-vm-image-size` | The new size of the Image we use as a template (in GiB) | no | |
| `nutanix-vm-categories` | The name of the categories who will be applied to the newly created VM | no | |
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 6796d4e

Please sign in to comment.