Skip to content

Commit 11a72a0

Browse files
authored
Merge pull request swayf#54 from pvanagtmaal/port-in-hostname
Add option to specify port in host
2 parents 9d2cb76 + c9f6ba0 commit 11a72a0

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

proxmoxer/backends/https.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ def request(self, method, url, params=None, data=None, headers=None, cookies=Non
113113
class Backend(object):
114114
def __init__(self, host, user, password, port=8006, verify_ssl=True,
115115
mode='json', timeout=5, auth_token=None, csrf_token=None):
116+
if ':' in host:
117+
host, host_port = host.split(':')
118+
port = host_port if host_port.isdigit() else port
119+
116120
self.base_url = "https://{0}:{1}/api2/{2}".format(host, port, mode)
121+
117122
if auth_token is not None:
118123
self.auth = ProxmoxHTTPTokenAuth(auth_token, csrf_token)
119124
else:

tests/https_tests.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,32 @@ def test_https_connection(req_session):
2020
eq_(call['verify'], False)
2121

2222

23+
@patch('requests.sessions.Session')
24+
def test_https_connection_wth_port_in_host(req_session):
25+
response = {'ticket': 'ticket',
26+
'CSRFPreventionToken': 'CSRFPreventionToken'}
27+
req_session.request.return_value = response
28+
ProxmoxAPI('proxmox:123', user='root@pam', password='secret', port=124, verify_ssl=False)
29+
call = req_session.return_value.request.call_args[1]
30+
eq_(call['url'], 'https://proxmox:123/api2/json/access/ticket')
31+
eq_(call['data'], {'username': 'root@pam', 'password': 'secret'})
32+
eq_(call['method'], 'post')
33+
eq_(call['verify'], False)
34+
35+
36+
@patch('requests.sessions.Session')
37+
def test_https_connection_wth_bad_port_in_host(req_session):
38+
response = {'ticket': 'ticket',
39+
'CSRFPreventionToken': 'CSRFPreventionToken'}
40+
req_session.request.return_value = response
41+
ProxmoxAPI('proxmox:notaport', user='root@pam', password='secret', port=124, verify_ssl=False)
42+
call = req_session.return_value.request.call_args[1]
43+
eq_(call['url'], 'https://proxmox:124/api2/json/access/ticket')
44+
eq_(call['data'], {'username': 'root@pam', 'password': 'secret'})
45+
eq_(call['method'], 'post')
46+
eq_(call['verify'], False)
47+
48+
2349
class TestSuite():
2450
proxmox = None
2551
serializer = None

0 commit comments

Comments
 (0)