Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/vlan bridge parameters #22

Merged
merged 2 commits into from
Jan 23, 2020
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
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ PVE_PASSWD="D0ck3rS3cr3t"
PVE_POOL="docker-machine"
PVE_STORAGE="zfs"
PVE_STORAGE_TYPE="RAW"
PVE_NET_BRIDGE="vmbr0"
PVE_NET_TAG="200"
PVE_IMAGE_FILE="isos:docker-machine-iso/rancheros-proxmoxve.iso"
VM_NAME="proxmox-rancher"

Expand All @@ -44,6 +46,9 @@ docker-machine --debug \
--proxmox-pool $PVE_POOL \
--proxmox-storage-type $PVE_STORAGE_TYPE \
\
--proxmox-net-bridge $PVE_NET_BRIDGE \
--proxmox-net-tag $PVE_NET_TAG \
\
--proxmox-guest-username $GUEST_USERNAME \
--proxmox-guest-password $GUEST_PASSWORD \
\
Expand Down Expand Up @@ -108,4 +113,4 @@ Here is what I use (based on ZFS):

### Version 1

* Initial Version
* Initial Version
40 changes: 37 additions & 3 deletions proxmoxdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ type Driver struct {
Memory int // memory in GB
StorageFilename string

NetBridge string // bridge applied to network interface
NetVlanTag int // vlan tag

VMID string // VM ID only filled by create()
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
Expand Down Expand Up @@ -148,6 +151,18 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "pool to attach to",
Value: "",
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_NET_BRIDGE",
Name: "proxmox-net-bridge",
Usage: "bridge to attach network",
Value: "vmbr0",
},
mcnflag.IntFlag{
EnvVar: "PROXMOX_NET_TAG",
Name: "proxmox-net-tag",
Usage: "vlan tag",
Value: 0,
},
mcnflag.StringFlag{
EnvVar: "PROXMOX_STORAGE_TYPE",
Name: "proxmox-storage-type",
Expand Down Expand Up @@ -220,6 +235,9 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.Memory = flags.Int("proxmox-memory-gb")
d.Memory *= 1024

d.NetBridge = flags.String("proxmox-net-bridge")
d.NetVlanTag = flags.Int("proxmox-net-tag")

d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host")
d.GuestSSHPort = flags.Int("proxmox-guest-ssh-port")
Expand Down Expand Up @@ -255,6 +273,16 @@ func (d *Driver) GetMachineName() string {
return d.MachineName
}

// GetBridge returns the bridge
func (d *Driver) GetNetBridge() string {
return d.NetBridge
}

// GetBridge returns the lvan
func (d *Driver) GetNetVlanTag() int {
return d.NetVlanTag
}

// GetIP returns the ip
func (d *Driver) GetIP() (string, error) {
d.connectAPI()
Expand Down Expand Up @@ -362,8 +390,10 @@ func (d *Driver) Create() error {
return err
}

if !strings.HasSuffix(diskname, d.StorageFilename) {
return fmt.Errorf("returned diskname is not correct: should be '%s' but was '%s'", d.StorageFilename, diskname)
storagefilename := d.Storage + ":" + volume.Filename

if diskname != storagefilename {
return fmt.Errorf("returned diskname is not correct:\n should be '%s' but was '%s'", storagefilename, diskname)
}

npp := NodesNodeQemuPostParameter{
Expand All @@ -373,14 +403,18 @@ func (d *Driver) Create() error {
Memory: d.Memory,
Cores: "4",
Net0: "virtio,bridge=vmbr0",
SCSI0: d.StorageFilename,
SCSI0: storagefilename,
Ostype: "l26",
Name: d.BaseDriver.MachineName,
KVM: "1", // if you test in a nested environment, you may have to change this to 0 if you do not have nested virtualization
Cdrom: d.ImageFile,
Pool: d.Pool,
}

if d.NetVlanTag != 0 {
npp.Net0 = fmt.Sprintf("virtio,bridge=%s,tag=%d", d.NetBridge, d.NetVlanTag)
}

if d.StorageType == "qcow2" {
npp.SCSI0 = d.Storage + ":" + d.VMID + "/" + volume.Filename
}
Expand Down