From d9f9e826f83151b26923bba5279db6ddad9228d7 Mon Sep 17 00:00:00 2001 From: osiu97 Date: Wed, 9 Jan 2019 12:28:39 +0100 Subject: [PATCH] initial commit --- PVEApi.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 PVEApi.py diff --git a/PVEApi.py b/PVEApi.py new file mode 100644 index 0000000..f491f4e --- /dev/null +++ b/PVEApi.py @@ -0,0 +1,30 @@ +import urllib +import urllib2 +import ssl +import json + +USERNAME = "zabbix@pve" +PASSWORD = "zabbix" +HOST = "172.16.3.11:8006" + + +def get_auth(host, username, password): + postdata = urllib.urlencode({'username': username, 'password': password}) + url = "https://" + host + "/api2/json/access/ticket" + req = urllib2.Request(url, postdata) + response = urllib2.urlopen(req, context=ssl._create_unverified_context()) + response = json.load(response) + return response['data']['CSRFPreventionToken'], response['data']['ticket'] + + +class PVEApi(object): + + def __init__(self, host, username, password): + self.host = host + self.csrftoken = get_auth(self.host, username, password)[0] + self.ticket = get_auth(self.host, username, password)[1] + + +conn = PVEApi(HOST, USERNAME, PASSWORD) +print conn.ticket +print conn.csrftoken