PVE-Zabbix/PVEApi.py

31 lines
847 B
Python

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