Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ The incomplete state is over, as I have a working configuration:
$ docker-machine create --driver proxmox-ve --help | grep -c proxmox
16

* Use a recent, e.g. `1.5.4` version of [RancherOS](https://github.com/rancher/os/releases) and copy the
`rancheros-proxmoxve.iso` to your iso image storage on your PVE
* Use a recent, e.g. `1.5.3` version of [RancherOS](https://github.com/rancher/os/releases) and copy the
`rancheros-proxmoxve-autoformat.iso` to your iso image storage on your PVE
* Create a script with the following contents and adapt to your needs:

```sh
Expand All @@ -22,7 +22,7 @@ PVE_PASSWD="D0ck3rS3cr3t"
PVE_POOL="docker-machine"
PVE_STORAGE="zfs"
PVE_STORAGE_TYPE="RAW"
PVE_IMAGE_FILE="isos:docker-machine-iso/rancheros-proxmoxve.iso"
PVE_IMAGE_FILE="isos:docker-machine-iso/rancheros-proxmoxve-autoformat.iso"
VM_NAME="proxmox-rancher"

GUEST_USERNAME="docker"
Expand All @@ -32,26 +32,26 @@ docker-machine rm --force $VM_NAME >/dev/null 2>&1 || true

docker-machine --debug \
create \
--driver proxmox-ve \
--proxmox-host $PVE_HOST \
--proxmox-user $PVE_USER \
--proxmox-realm $PVE_REALM \
--proxmox-password $PVE_PASSWD \
--proxmox-node $PVE_NODE \
--proxmox-memory-gb $PVE_MEMORY \
--proxmox-image-file "$PVE_IMAGE_FILE" \
--proxmox-storage $PVE_STORAGE \
--proxmox-pool $PVE_POOL \
--driver proxmoxve \
--proxmoxve-proxmox-host $PVE_HOST \
--proxmoxve-proxmox-user $PVE_USER \
--proxmoxve-proxmox-realm $PVE_REALM \
--proxmoxve-proxmox-user-password $PVE_PASSWD \
--proxmoxve-proxmox-node $PVE_NODE \
--proxmoxve-proxmox-pool $PVE_POOL \
--proxmoxve-vm-memory $PVE_MEMORY \
--proxmoxve-vm-image-file "$PVE_IMAGE_FILE" \
--proxmoxve-vm-storage-type $PVE_STORAGE \
--proxmox-storage-type $PVE_STORAGE_TYPE \
\
--proxmox-guest-username $GUEST_USERNAME \
--proxmox-guest-password $GUEST_PASSWORD \
--proxmox-ssh-username $GUEST_USERNAME \
--proxmox-ssh-password $GUEST_PASSWORD \
\
--proxmox-resty-debug \
--proxmox-driver-debug \
\
$* \
$VM_NAME
$VM_NAME

eval $(docker-machine env $VM_NAME)

Expand Down Expand Up @@ -93,6 +93,14 @@ Here is what I use (based on ZFS):

## Changes

### Version 3

* Renaming driver from `proxmox-ve` to `proxmoxve` due to identification problem with RancherOS's K8S implementation (Thanks to [`@Sellto` for reporting #16](https://github.com/lnxbil/docker-machine-driver-proxmox-ve/issues/16))
* fixing issue with created disk detection (Thanks to [`@Sellto` for reporting #16](https://github.com/lnxbil/docker-machine-driver-proxmox-ve/issues/16))
* Add `IPAddress` property needed by rancher to know the ip address of the created VM.
* Change the name of each flag for better display in the rancher `Node Templates`
* Add number of `CPU corese configuration paramater`.

### Version 2

* exclusive RancherOS support due to their special Proxmox VE iso files
Expand All @@ -103,4 +111,4 @@ Here is what I use (based on ZFS):

### Version 1

* Initial Version
* Initial Version
4 changes: 2 additions & 2 deletions cmd/docker-machine-driver-proxmox-ve/Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
all:
GOOS=linux GOARCH=amd64 go build -o docker-machine-driver-proxmox-ve.linux-amd64
GOOS=darwin GOARCH=amd64 go build -o docker-machine-driver-proxmox-ve.macos-amd64
GOOS=linux GOARCH=amd64 go build -o docker-machine-driver-proxmoxve.linux-amd64
GOOS=darwin GOARCH=amd64 go build -o docker-machine-driver-proxmoxve.macos-amd64
4 changes: 2 additions & 2 deletions cmd/docker-machine-driver-proxmox-ve/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package main

import (
"github.com/docker/machine/libmachine/drivers/plugin"
proxmox "github.com/lnxbil/docker-machine-driver-proxmox-ve"
proxmoxve "../.."
)

func main() {
plugin.RegisterDriver(proxmox.NewDriver("default", ""))
plugin.RegisterDriver(proxmoxve.NewDriver("default", ""))
}
150 changes: 85 additions & 65 deletions proxmoxdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ type Driver struct {
GuestUsername string // user to log into the guest OS to copy the public key
GuestPassword string // password to log into the guest OS to copy the public key
GuestSSHPort int // ssh port to log into the guest OS to copy the public key

Cores string
driverDebug bool // driver debugging
restyDebug bool // enable resty debugging
}
Expand Down Expand Up @@ -89,92 +89,98 @@ func (d *Driver) connectAPI() error {
func (d *Driver) GetCreateFlags() []mcnflag.Flag {
return []mcnflag.Flag{
mcnflag.StringFlag{
EnvVar: "PROXMOX_HOST",
Name: "proxmox-host",
EnvVar: "PROXMOXVE_PROXMOX_HOST",
Name: "proxmoxve-proxmox-host",
Usage: "Host to connect to",
Value: "192.168.1.253",
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_DISKSIZE_GB",
Name: "proxmox-disksize-gb",
Usage: "disk size in GB",
Value: "16",
},
mcnflag.IntFlag{
EnvVar: "PROXMOX_MEMORY_GB",
Name: "proxmox-memory-gb",
Usage: "memory in GB",
Value: 8,
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_STORAGE",
Name: "proxmox-storage",
Usage: "storage to create the VM volume on",
Value: "local",
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_NODE",
Name: "proxmox-node",
EnvVar: "PROXMOXVE_PROXMOX_NODE",
Name: "proxmoxve-proxmox-node",
Usage: "to to use (defaults to host)",
Value: "",
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_USER",
Name: "proxmox-user",
EnvVar: "PROXMOXVE_PROXMOX_USER_NAME",
Name: "proxmoxve-proxmox-user-name",
Usage: "User to connect as",
Value: "root",
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_REALM",
Name: "proxmox-realm",
EnvVar: "PROXMOXVE_PROXMOX_USER_PASSWORD",
Name: "proxmoxve-proxmox-user-password",
Usage: "Password to connect with",
Value: "",
},
mcnflag.StringFlag{
EnvVar: "PROXMOXVE_PROXMOX_REALM",
Name: "proxmoxve-proxmox-realm",
Usage: "Realm to connect to (default: pam)",
Value: "pam",
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_PASSWORD",
Name: "proxmox-password",
Usage: "Password to connect with",
EnvVar: "PROXMOXVE_PROXMOX_POOL",
Name: "proxmoxve-proxmox-pool",
Usage: "pool to attach to",
Value: "",
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_IMAGE_FILE",
Name: "proxmox-image-file",
Usage: "storage of the image file (e.g. local:iso/rancheros-proxmoxve-autoformat.iso)",
Value: "",
EnvVar: "PROXMOXVE_VM_STORAGE_PATH",
Name: "proxmoxve-vm-storage-path",
Usage: "storage to create the VM volume on",
Value: "local",
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_POOL",
Name: "proxmox-pool",
Usage: "pool to attach to",
Value: "",
EnvVar: "PROXMOXVE_VM_STORAGE_SIZE",
Name: "proxmoxve-vm-storage-size",
Usage: "disk size in GB",
Value: "16",
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_STORAGE_TYPE",
Name: "proxmox-storage-type",
EnvVar: "PROXMOXVE_VM_STORAGE_TYPE",
Name: "proxmoxve-vm-storage-type",
Usage: "storage type to use (QCOW2 or RAW)",
Value: "raw",
},
mcnflag.IntFlag{
EnvVar: "PROXMOXVE_MEMORY",
Name: "proxmoxve-vm-memory",
Usage: "memory in GB",
Value: 8,
},
mcnflag.StringFlag{
EnvVar: "PROXMOXVE_CPU",
Name: "proxmoxve-vm-cpu-cores",
Usage: "number of cpu cores",
Value: "2",
},
mcnflag.StringFlag{
Name: "proxmox-guest-username",
EnvVar: "PROXMOXVE_IMAGE_FILE",
Name: "proxmoxve-vm-image-file",
Usage: "storage of the image file (e.g. local:iso/rancheros-proxmoxve-autoformat.iso)",
Value: "",
},
mcnflag.StringFlag{
Name: "proxmoxve-ssh-username",
Usage: "Username to log in to the guest OS (default docker for rancheros)",
Value: "docker",
},
mcnflag.StringFlag{
Name: "proxmox-guest-password",
Name: "proxmoxve-ssh-password",
Usage: "Password to log in to the guest OS (default tcuser for rancheros)",
Value: "tcuser",
},
mcnflag.IntFlag{
Name: "proxmox-guest-ssh-port",
Name: "proxmoxve-ssh-port",
Usage: "SSH port in the guest to log in to (defaults to 22)",
Value: 22,
},
mcnflag.BoolFlag{
Name: "proxmox-resty-debug",
Name: "proxmoxve-debug-resty",
Usage: "enables the resty debugging",
},
mcnflag.BoolFlag{
Name: "proxmox-driver-debug",
Name: "proxmoxve-debug-driver",
Usage: "enables debugging in the driver",
},
}
Expand All @@ -198,36 +204,43 @@ func (d *Driver) ping() bool {

// DriverName returns the name of the driver
func (d *Driver) DriverName() string {
return "proxmox-ve"
return "proxmoxve"
}

// SetConfigFromFlags configures all command line arguments
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.debug("SetConfigFromFlags called")
d.ImageFile = flags.String("proxmox-image-file")
d.Host = flags.String("proxmox-host")
d.Node = flags.String("proxmox-node")
// PROXMOX API Connection settings
d.Host = flags.String("proxmoxve-proxmox-host")
d.Node = flags.String("proxmoxve-proxmox-node")
if len(d.Node) == 0 {
d.Node = d.Host
}
d.User = flags.String("proxmox-user")
d.Realm = flags.String("proxmox-realm")
d.Pool = flags.String("proxmox-pool")
d.Password = flags.String("proxmox-password")
d.DiskSize = flags.String("proxmox-disksize-gb")
d.Storage = flags.String("proxmox-storage")
d.StorageType = strings.ToLower(flags.String("proxmox-storage-type"))
d.Memory = flags.Int("proxmox-memory-gb")
d.Memory *= 1024
d.User = flags.String("proxmoxve-proxmox-user-name")
d.Password = flags.String("proxmoxve-proxmox-user-password")
d.Realm = flags.String("proxmoxve-proxmox-realm")
d.Pool = flags.String("proxmoxve-proxmox-pool")

// VM configuration
d.DiskSize = flags.String("proxmoxve-vm-storage-size")
d.Storage = flags.String("proxmoxve-vm-storage-path")
d.StorageType = strings.ToLower(flags.String("proxmoxve-vm-storage-type"))
d.Memory = flags.Int("proxmoxve-vm-memory")
d.Memory *= 1024
d.ImageFile = flags.String("proxmoxve-vm-image-file")
d.Cores = flags.String("proxmoxve-vm-cpu-cores")
//SSH connection settings
d.GuestSSHPort = flags.Int("proxmoxve-ssh-port")
d.GuestUsername = flags.String("proxmoxve-ssh-username")
d.GuestPassword = flags.String("proxmoxve-ssh-password")

//SWARM Settings
d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host")
d.GuestSSHPort = flags.Int("proxmox-guest-ssh-port")
d.GuestUsername = flags.String("proxmox-guest-username")
d.GuestPassword = flags.String("proxmox-guest-password")

d.driverDebug = flags.Bool("proxmox-driver-debug")
d.restyDebug = flags.Bool("proxmox-resty-debug")
//Debug option
d.driverDebug = flags.Bool("proxmoxve-debug-driver")
d.restyDebug = flags.Bool("proxmoxve-debug-resty")

if d.restyDebug {
d.debug("enabling Resty debugging")
Expand Down Expand Up @@ -371,7 +384,7 @@ func (d *Driver) Create() error {
Agent: "1",
Autostart: "1",
Memory: d.Memory,
Cores: "4",
Cores: d.Cores,
Net0: "virtio,bridge=vmbr0",
SCSI0: d.StorageFilename,
Ostype: "l26",
Expand All @@ -394,14 +407,15 @@ func (d *Driver) Create() error {
if err != nil {
return err
}

err = d.Start()
if err != nil {
return err
}


return d.waitAndPrepareSSH()
}

func (d *Driver) waitAndPrepareSSH() error {
d.debugf("waiting for VM to become active, first wait 10 seconds")
time.Sleep(10 * time.Second)
Expand Down Expand Up @@ -434,7 +448,13 @@ func (d *Driver) waitAndPrepareSSH() error {
if err != nil {
return err
}
ip, err := d.GetIP()
if err != nil {
return err

}
d.IPAddress = ip
d.debugf("driver IP is set as '%s'", d.IPAddress)
var stdoutBuf bytes.Buffer
session.Stdout = &stdoutBuf
session.Run("mkdir -p " + sshbasedir)
Expand Down