def connect(server_url: str, username: str, *, password: Optional[str] = None, token_name: Optional[str] = None, token_value: Optional[str] = None, verify_ssl: bool = False, use_ssh: bool = False): api = ProxmoxAPI(server_url, user=username, password=password, token_name=token_name, token_value=token_value, verify_ssl=verify_ssl, backend=('ssh_paramiko' if use_ssh else 'https')) # check if API is working. a, b = api.get_tokens() if not (a or b): raise Exception( f"Failed to connect to Proxmox server '{server_url}@{username}', verify credentials" ) return api
def test_https_api_token(): p = ProxmoxAPI('proxmox', user='******', token_name='test', token_value='ab27beeb-9ac4-4df1-aa19-62639f27031e', verify_ssl=False) eq_(p.get_tokens()[0], None) eq_(p.get_tokens()[1], None)
def test_paramiko_tokens(_): p = ProxmoxAPI('proxmox', user='******', backend='ssh_paramiko', port=123) eq_(p.get_tokens()[0], None) eq_(p.get_tokens()[1], None)