diff --git a/proxmoxer/backends/https.py b/proxmoxer/backends/https.py index b870195..6620852 100644 --- a/proxmoxer/backends/https.py +++ b/proxmoxer/backends/https.py @@ -109,7 +109,11 @@ def request(self, method, url, params=None, data=None, headers=None, cookies=Non class Backend(object): def __init__(self, host, user, password, port=8006, verify_ssl=True, mode='json', timeout=5, auth_token=None, csrf_token=None): - self.base_url = "https://{0}:{1}/api2/{2}".format(host, port, mode) + if ':' in host and host.split(':')[1].isdigit(): + self.base_url = "https://{0}/api2/{1}".format(host, mode) + else: + self.base_url = "https://{0}:{1}/api2/{2}".format(host, port, mode) + if auth_token is not None: self.auth = ProxmoxHTTPTokenAuth(auth_token, csrf_token) else: diff --git a/tests/https_tests.py b/tests/https_tests.py index 3efc1fc..1c7b9b6 100644 --- a/tests/https_tests.py +++ b/tests/https_tests.py @@ -20,6 +20,19 @@ def test_https_connection(req_session): eq_(call['verify'], False) +@patch('requests.sessions.Session') +def test_https_connection_wth_port_in_host(req_session): + response = {'ticket': 'ticket', + 'CSRFPreventionToken': 'CSRFPreventionToken'} + req_session.request.return_value = response + ProxmoxAPI('proxmox:123', user='root@pam', password='secret', port=124, verify_ssl=False) + call = req_session.return_value.request.call_args[1] + eq_(call['url'], 'https://proxmox:123/api2/json/access/ticket') + eq_(call['data'], {'username': 'root@pam', 'password': 'secret'}) + eq_(call['method'], 'post') + eq_(call['verify'], False) + + class TestSuite(): proxmox = None serializer = None