Skip to content

Commit

Permalink
merge modification to support Rancher 2 (#1)
Browse files Browse the repository at this point in the history
* rancher2 patch
* add goreleaser config
  • Loading branch information
tuxtof authored Apr 17, 2020
1 parent 8aa1305 commit d19ff96
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 35 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions machine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------
Expand All @@ -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 |

63 changes: 32 additions & 31 deletions machine/driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ type NutanixDriver struct {
VMVCPUs int
VMCores int
SSHPass string
VLANs []string
Images []string
VLAN string
Image string
VMId string
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand Down Expand Up @@ -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",
},
}
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit d19ff96

Please sign in to comment.