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

Allow set PVE API port #36

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion proxmox.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,13 @@ type ProxmoxVE struct {
}

// GetProxmoxVEConnectionByValues is a wrapper for GetProxmoxVEConnection with strings as input
func GetProxmoxVEConnectionByValues(username string, password string, realm string, hostname string) (*ProxmoxVE, error) {
func GetProxmoxVEConnectionByValues(username string, password string, realm string, hostname string, port int) (*ProxmoxVE, error) {
return GetProxmoxVEConnection(&ProxmoxVE{
Username: username,
password: password,
Realm: realm,
Host: hostname,
Port: port,
})
}

Expand Down
16 changes: 8 additions & 8 deletions proxmox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,34 @@ func TestSuccessfulConnection(t *testing.T) {
}
}
func TestWrongPass(t *testing.T) {
username, _, realm, host := GetProxmoxAccess()
_, err := dockermachinedriverproxmoxve.GetProxmoxVEConnectionByValues(username, "wrong_password", realm, host)
username, _, realm, host, port := GetProxmoxAccess()
_, err := dockermachinedriverproxmoxve.GetProxmoxVEConnectionByValues(username, "wrong_password", realm, host, port)
if err == nil {
t.Log(err)
t.Error()
}
}
func TestWrongUser(t *testing.T) {
_, password, realm, host := GetProxmoxAccess()
_, err := dockermachinedriverproxmoxve.GetProxmoxVEConnectionByValues("root", password, realm, host)
_, password, realm, host, port:= GetProxmoxAccess()
_, err := dockermachinedriverproxmoxve.GetProxmoxVEConnectionByValues("root", password, realm, host, port)
if err == nil {
t.Log(err)
t.Error()
}
}

func TestEmptyPass(t *testing.T) {
username, _, realm, host := GetProxmoxAccess()
_, err := dockermachinedriverproxmoxve.GetProxmoxVEConnectionByValues(username, "", realm, host)
username, _, realm, host, port := GetProxmoxAccess()
_, err := dockermachinedriverproxmoxve.GetProxmoxVEConnectionByValues(username, "", realm, host, port)
if err != nil && err.Error() != "You have to provide a password" {
t.Log(err)
t.Error()
}
}

func TestWrongHost(t *testing.T) {
username, password, realm, _ := GetProxmoxAccess()
_, err := dockermachinedriverproxmoxve.GetProxmoxVEConnectionByValues(username, password, realm, "127.0.0.1")
username, password, realm, _, port := GetProxmoxAccess()
_, err := dockermachinedriverproxmoxve.GetProxmoxVEConnectionByValues(username, password, realm, "127.0.0.1", port)
if err == nil {
t.Log(err)
t.Error()
Expand Down
14 changes: 11 additions & 3 deletions proxmoxdriver.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Driver struct {

// Basic Authentication for Proxmox VE
Host string // Host to connect to
Port int // Host port to connect to
Node string // optional, node to create VM on, host used if omitted but must match internal node name
User string // username
Password string // password
Expand Down Expand Up @@ -100,11 +101,11 @@ func (d *Driver) connectAPI() error {
if d.driver == nil {
d.debugf("Create called")

d.debugf("Connecting to %s as %s@%s with password '%s'", d.Host, d.User, d.Realm, d.Password)
c, err := GetProxmoxVEConnectionByValues(d.User, d.Password, d.Realm, d.Host)
d.debugf("Connecting to %s:%d as %s@%s with password '%s'", d.Host, d.Port, d.User, d.Realm, d.Password)
c, err := GetProxmoxVEConnectionByValues(d.User, d.Password, d.Realm, d.Host, d.Port)
d.driver = c
if err != nil {
return fmt.Errorf("Could not connect to host '%s' with '%s@%s'", d.Host, d.User, d.Realm)
return fmt.Errorf("Could not connect to host '%s:%d' with '%s@%s'", d.Host, d.Port, d.User, d.Realm)
}
if d.restyDebug {
c.EnableDebugging()
Expand All @@ -123,6 +124,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Host to connect to",
Value: "192.168.1.253",
},
mcnflag.IntFlag{
EnvVar: "PROXMOXVE_PROXMOX_PORT",
Name: "proxmoxve-proxmox-port",
Usage: "Host port to connect to",
Value: 8006,
},
mcnflag.StringFlag{
EnvVar: "PROXMOXVE_PROXMOX_NODE",
Name: "proxmoxve-proxmox-node",
Expand Down Expand Up @@ -357,6 +364,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {

// PROXMOX API Connection settings
d.Host = flags.String("proxmoxve-proxmox-host")
d.Port = flags.Int("proxmoxve-proxmox-port")
d.Node = flags.String("proxmoxve-proxmox-node")
if len(d.Node) == 0 {
d.Node = d.Host
Expand Down
1 change: 1 addition & 0 deletions testconfig.json.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"host":"10.255.0.5",
"port":"8006",
"user":"root",
"realm": "pam",
"password":"P@ssw0rd",
Expand Down
5 changes: 3 additions & 2 deletions testconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
// ProxmoxConfig represents all needed login information
type ProxmoxConfig struct {
Host string `json:"host"`
Port int `json:"port"`
User string `json:"user"`
Password string `json:"password"`
Realm string `json:"realm"`
Expand All @@ -43,9 +44,9 @@ func GetProxmoxConfigInstance() *ProxmoxConfig {
}

// GetProxmoxAccess gets working proxmox ve access information
func GetProxmoxAccess() (string, string, string, string) {
func GetProxmoxAccess() (string, string, string, string, int) {
i := GetProxmoxConfigInstance()
return i.User, i.Password, i.Realm, i.Host
return i.User, i.Password, i.Realm, i.Host, i.Port
}

// GetProxmoxNode return the defined test node
Expand Down