Skip to content

Commit

Permalink
Add subnets UUID support (#86)
Browse files Browse the repository at this point in the history
* update go to 1.21

* add subnet UUID support
  • Loading branch information
tuxtof authored Dec 14, 2023
1 parent 02c8eaa commit f4de14e
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 19 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "^1.17"
go-version: "^1.21"

- name: Checkout Code
uses: actions/checkout@v4
Expand All @@ -29,7 +29,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "^1.17"
go-version: "^1.21"

- name: Checkout Code
uses: actions/checkout@v4
Expand All @@ -44,7 +44,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "^1.17"
go-version: "^1.21"

- name: Check out code into the Go module directory
uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "^1.17"
go-version: "^1.21"

- name: Create release on GitHub
uses: goreleaser/goreleaser-action@v5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/synopsys-schedule.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "^1.17"
go-version: "^1.21"

- name: Build Project
run: make build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/synopsys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "^1.17"
go-version: "^1.21"

- name: Build Project
run: make build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/trivy-scan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: "^1.17"
go-version: "^1.21"

- name: Build Project
run: make build
Expand Down
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/nutanix/docker-machine

go 1.18
go 1.21

replace github.com/docker/docker => github.com/docker/engine v17.12.0-ce-rc1.0.20200916142827-bd33bbf0497b+incompatible

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 f4de14e

Please sign in to comment.