Skip to content

Instantly share code, notes, and snippets.

@goneri goneri/gist:6638262
Last active Feb 8, 2016

Embed
What would you like to do?
A light wrapper around GLPI webservice.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import xmlrpclib
class GLPI:
def __init__(self, url=None, login=None, password=None):
"""
Open a connection
:type url: URL to the xmlrpc.php file (e.g: http://127.0.0.1/glpi/plugins/webservices/xmlrpc.php)
:type login: login of the user
:type password: password of the user
"""
self.server = xmlrpclib.Server(url, allow_none=True)
if login == None or password == None:
raise Exception("Credential required")
params = {
'login_name': login,
'username': login,
'login_password': password,
'password': password
}
response = self.server.glpi.doLogin(params)
self.session = response['session']
def __getattr__(self, name):
def remote(params={}):
params['session'] = self.session
func = self.server.glpi.__getattr__(name)
return func.__call__(params)
return remote
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.