--- a/proxmoxer/core.py 1970-01-01 04:00:01.000000000 +0400 +++ b/proxmoxer/core.py 2018-10-29 15:21:20.241881023 +0400 @@ -76,7 +76,7 @@ if resp.status_code >= 400: raise ResourceException("{0} {1}: {2}".format(resp.status_code, httplib.responses[resp.status_code], - resp.content)) + resp.reason)) elif 200 <= resp.status_code <= 299: return self._store["serializer"].loads(resp) diff --git a/proxmoxer/backends/https.py b/proxmoxer/backends/https.py index ad76a47..e96b822 100644 --- a/proxmoxer/backends/https.py +++ b/proxmoxer/backends/https.py @@ -38,9 +38,10 @@ class AuthenticationError(Exception): class ProxmoxHTTPAuth(AuthBase): - def __init__(self, base_url, username, password, verify_ssl=False): + def __init__(self, base_url, username, password, verify_ssl=False, timeout=5): response_data = requests.post(base_url + "/access/ticket", verify=verify_ssl, + timeout=timeout, data={"username": username, "password": password}).json()["data"] if response_data is None: raise AuthenticationError("Couldn't authenticate user: {0} to {1}".format(username, base_url + "/access/ticket")) @@ -122,7 +123,7 @@ class Backend(object): if auth_token is not None: self.auth = ProxmoxHTTPTokenAuth(auth_token, csrf_token) else: - self.auth = ProxmoxHTTPAuth(self.base_url, user, password, verify_ssl) + self.auth = ProxmoxHTTPAuth(self.base_url, user, password, verify_ssl, timeout) self.verify_ssl = verify_ssl self.mode = mode self.timeout = timeout diff --git a/proxmoxer/backends/base_ssh.py b/proxmoxer/backends/base_ssh.py index da624d9..b3ba1b3 100644 --- a/proxmoxer/backends/base_ssh.py +++ b/proxmoxer/backends/base_ssh.py @@ -41,7 +41,7 @@ class ProxmoxBaseSSHSession(object): data['tmpfilename'] = tmp_filename translated_data = ' '.join(["-{0} {1}".format(k, v) for k, v in chain(data.items(), params.items())]) - full_cmd = 'pvesh {0}'.format(' '.join(filter(None, (cmd, url, translated_data)))) + full_cmd = 'pvesh {0} --output-format json'.format(' '.join(filter(None, (cmd, url, translated_data)))) stdout, stderr = self._exec(full_cmd) match = lambda s: re.match('\d\d\d [a-zA-Z]', s) diff --git a/tests/base/base_ssh_suite.py b/tests/base/base_ssh_suite.py index 943b72f..ddb4bf3 100644 --- a/tests/base/base_ssh_suite.py +++ b/tests/base/base_ssh_suite.py @@ -62,7 +62,7 @@ class BaseSSHSuite(object): } ]""") result = self.proxmox.nodes('proxmox').storage('local').get() - eq_(self._get_called_cmd(), self._called_cmd('pvesh get /nodes/proxmox/storage/local')) + eq_(self._get_called_cmd(), self._called_cmd('pvesh get /nodes/proxmox/storage/local --output-format json')) eq_(result[0]['subdir'], 'status') eq_(result[1]['subdir'], 'content') eq_(result[2]['subdir'], 'upload') @@ -71,13 +71,13 @@ class BaseSSHSuite(object): def test_delete(self): self.proxmox.nodes('proxmox').openvz(100).delete() - eq_(self._get_called_cmd(), self._called_cmd('pvesh delete /nodes/proxmox/openvz/100')) + eq_(self._get_called_cmd(), self._called_cmd('pvesh delete /nodes/proxmox/openvz/100 --output-format json')) self._set_stderr("200 OK") self.proxmox.nodes('proxmox').openvz('101').delete() - eq_(self._get_called_cmd(), self._called_cmd('pvesh delete /nodes/proxmox/openvz/101')) + eq_(self._get_called_cmd(), self._called_cmd('pvesh delete /nodes/proxmox/openvz/101 --output-format json')) self._set_stderr("200 OK") self.proxmox.nodes('proxmox').openvz.delete('102') - eq_(self._get_called_cmd(), self._called_cmd('pvesh delete /nodes/proxmox/openvz/102')) + eq_(self._get_called_cmd(), self._called_cmd('pvesh delete /nodes/proxmox/openvz/102 --output-format json')) def test_post(self): self._set_stderr("200 OK")