From d19ff96e5fd268231b62e9815091e627c799205d Mon Sep 17 00:00:00 2001 From: Christophe Jauffret Date: Fri, 17 Apr 2020 18:48:10 +0200 Subject: [PATCH] merge modification to support Rancher 2 (#1) * rancher2 patch * add goreleaser config --- README.md | 2 +- machine/README.md | 6 ++-- machine/driver/driver.go | 63 ++++++++++++++++++++-------------------- 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/README.md b/README.md index 7e6f0bb..8cdfe3f 100755 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ![Integration](https://github.com/nutanix/docker-machine/workflows/Integration/badge.svg) -This repository contains the original docker machine driver and related libraries for nutanix. +This repository contains a modified docker machine driver to support Rancher 2 node driver. * /machine - contains the source code for the Nutanix Docker machine driver * /client - contains Go bindings to the Nutanix API used by the Nutanix Docker machine driver. diff --git a/machine/README.md b/machine/README.md index 72756e7..a9ae06b 100755 --- a/machine/README.md +++ b/machine/README.md @@ -18,8 +18,8 @@ Features 2. Ability to select VM's vCPU count 3. Ability to set a custom name for the newly created VM 4. Ability to set the number of cores per vCPU -5. Ability to specify the network of the VM (Multiple Nics) -6. Ability to specify the disks in the VM by image name (Multiple Disks) +5. Ability to specify the network of the VM +6. Ability to specify the disk in the VM by image name Driver Args ----------- @@ -31,6 +31,6 @@ Driver Args | `--nutanix-vm-mem` |The amount of RAM of the newly created VM |no (default=1G) | | `--nutanix-vm-cpus` |The number of cpus in the newly created VM |no (default=1) | | `--nutanix-vm-cores` |The number of cores per vCPU |no (default=1) | -| `--nutanix-vm-network` |The network to which the vNIC of the VM is attached to |no | +| `--nutanix-vm-network` |The network to which the vNIC of the VM is attached to |yes | | `--nutanix-vm-image` |The name of the Image to clone from |yes | diff --git a/machine/driver/driver.go b/machine/driver/driver.go index c826d12..8b6c4c9 100755 --- a/machine/driver/driver.go +++ b/machine/driver/driver.go @@ -32,8 +32,8 @@ type NutanixDriver struct { VMVCPUs int VMCores int SSHPass string - VLANs []string - Images []string + VLAN string + Image string VMId string } @@ -68,37 +68,36 @@ func (d *NutanixDriver) Create() error { log.Errorf("Error getting networks: [%v]", err) return err } - for _, vLAN := range d.VLANs { - for _, net := range networks.Entities { - if net.Name == vLAN { - n := &mgmt.VMNicSpecDTO{ - NetworkUUID: net.UUID, - } - vmConfig.VMNics = append(vmConfig.VMNics, n) - break + + for _, net := range networks.Entities { + if net.Name == d.VLAN { + n := &mgmt.VMNicSpecDTO{ + NetworkUUID: net.UUID, } + vmConfig.VMNics = append(vmConfig.VMNics, n) + break } } - + images, err := c.GetImageList() if err != nil { log.Errorf("Error getting images: [%v]", err) return err } - for _, image := range d.Images { - for _, img := range images.Entities { - if img.Name == image { - d := &mgmt.VMDiskDTO{ - VMDiskClone: &mgmt.VMDiskSpecCloneDTO{ - VMDiskUUID: img.VMDiskID, - }, - } - vmConfig.VMDisks = append(vmConfig.VMDisks, d) - break + + for _, img := range images.Entities { + if img.Name == d.Image { + d := &mgmt.VMDiskDTO{ + VMDiskClone: &mgmt.VMDiskSpecCloneDTO{ + VMDiskUUID: img.VMDiskID, + }, } + vmConfig.VMDisks = append(vmConfig.VMDisks, d) + break } } + err = ssh.GenerateSSHKey(d.GetSSHKeyPath()) if err != nil { @@ -123,7 +122,7 @@ func (d *NutanixDriver) Create() error { vmId := uuid for i := 0; i < 1200; i++ { vmDTO, err := r.GetVMInfo(uuid) - if err != nil || len(vmDTO.NutanixVirtualDisks) < (len(d.Images)+1) { + if err != nil || len(vmDTO.NutanixVirtualDisks) < (2) { <-time.After(1 * time.Second) continue } @@ -227,13 +226,15 @@ func (d *NutanixDriver) GetCreateFlags() []mcnflag.Flag { Usage: "Number of cores per VCPU of the VM to be created", Value: defaultCores, }, - mcnflag.StringSliceFlag{ + mcnflag.StringFlag{ + EnvVar: "NUTANIX_VM_NETWORK", Name: "nutanix-vm-network", Usage: "The name of the network to attach to the newly created VM", }, - mcnflag.StringSliceFlag{ + mcnflag.StringFlag{ + EnvVar: "NUTANIX_VM_IMAGE", Name: "nutanix-vm-image", - Usage: "The name of the VM disks to clone from, for the newly created VM", + Usage: "The name of the VM disk to clone from, for the newly created VM", }, } } @@ -309,13 +310,13 @@ func (d *NutanixDriver) SetConfigFromFlags(opts drivers.DriverOptions) error { d.VMMem = opts.Int("nutanix-vm-mem") d.VMVCPUs = opts.Int("nutanix-vm-cpus") d.VMCores = opts.Int("nutanix-vm-cores") - d.VLANs = opts.StringSlice("nutanix-vm-network") - d.Images = opts.StringSlice("nutanix-vm-image") - if len(d.Images) == 0 { - return fmt.Errorf("Please specify at least one disk") + d.VLAN = opts.String("nutanix-vm-network") + if d.VLAN == "" { + return fmt.Errorf("nutanix-vm-network cannot be empty") } - if len(d.VLANs) == 0 { - return fmt.Errorf("Please specify at least one network") + d.Image = opts.String("nutanix-vm-image") + if d.Image == "" { + return fmt.Errorf("nutanix-vm-image cannot be empty") } return nil }