From f4de14e2012035854ec407d722a2504a393fc6a3 Mon Sep 17 00:00:00 2001 From: Christophe Jauffret Date: Thu, 14 Dec 2023 18:16:08 +0100 Subject: [PATCH] Add subnets UUID support (#86) * update go to 1.21 * add subnet UUID support --- .github/workflows/integration.yml | 6 ++--- .github/workflows/release.yml | 2 +- .github/workflows/synopsys-schedule.yaml | 2 +- .github/workflows/synopsys.yaml | 2 +- .github/workflows/trivy-scan.yaml | 2 +- README.md | 8 +++---- go.mod | 2 +- machine/driver/driver.go | 30 +++++++++++++++++++----- machine/driver/{yaml.go => utils.go} | 11 ++++++++- 9 files changed, 46 insertions(+), 19 deletions(-) rename machine/driver/{yaml.go => utils.go} (88%) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index c9252c8..3bae0c4 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -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 @@ -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 @@ -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 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d1942e2..98d18d7 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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 diff --git a/.github/workflows/synopsys-schedule.yaml b/.github/workflows/synopsys-schedule.yaml index 9a06040..7c8b869 100644 --- a/.github/workflows/synopsys-schedule.yaml +++ b/.github/workflows/synopsys-schedule.yaml @@ -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 diff --git a/.github/workflows/synopsys.yaml b/.github/workflows/synopsys.yaml index e1dc0f6..aabe88f 100644 --- a/.github/workflows/synopsys.yaml +++ b/.github/workflows/synopsys.yaml @@ -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 diff --git a/.github/workflows/trivy-scan.yaml b/.github/workflows/trivy-scan.yaml index 3de23c2..f7de0fd 100644 --- a/.github/workflows/trivy-scan.yaml +++ b/.github/workflows/trivy-scan.yaml @@ -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 diff --git a/README.md b/README.md index f6e89ff..aa1c128 100755 --- a/README.md +++ b/README.md @@ -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` @@ -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 | | diff --git a/go.mod b/go.mod index 317b268..d5cafff 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/machine/driver/driver.go b/machine/driver/driver.go index 5cfc872..04fddb3 100755 --- a/machine/driver/driver.go +++ b/machine/driver/driver.go @@ -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 { diff --git a/machine/driver/yaml.go b/machine/driver/utils.go similarity index 88% rename from machine/driver/yaml.go rename to machine/driver/utils.go index 33bbd67..01cc2b7 100644 --- a/machine/driver/yaml.go +++ b/machine/driver/utils.go @@ -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