How to use the proxmoxer.backends.https.ProxmoxHTTPAuth function in proxmoxer

To help you get started, we’ve selected a few proxmoxer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github swayf / proxmoxer / proxmoxer / backends / https.py View on Github external
def __init__(self, base_url, username, password, verify_ssl=False):
        response_data = requests.post(base_url + "/access/ticket",
                                      verify=verify_ssl,
                                      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"))

        self.pve_auth_cookie = response_data["ticket"]
        self.csrf_prevention_token = response_data["CSRFPreventionToken"]

    def __call__(self, r):
        r.headers["CSRFPreventionToken"] = self.csrf_prevention_token
        return r


class ProxmoxHTTPTokenAuth(ProxmoxHTTPAuth):
    """Use existing ticket/token to create a session.

    Overrides ProxmoxHTTPAuth so that an existing auth cookie and csrf token
    may be used instead of passing username/password.
    """
    def __init__(self, auth_token, csrf_token):
        self.pve_auth_cookie = auth_token
        self.csrf_prevention_token = csrf_token


class JsonSerializer(object):

    content_types = [
        "application/json",
        "application/x-javascript",
        "text/javascript",
github swayf / proxmoxer / proxmoxer / backends / https.py View on Github external
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 auth_token is not None:
            self.auth = ProxmoxHTTPTokenAuth(auth_token, csrf_token)
        else:
            self.auth = ProxmoxHTTPAuth(self.base_url, user, password, verify_ssl)
        self.verify_ssl = verify_ssl
        self.mode = mode
        self.timeout = timeout