Created
February 8, 2016 02:44
-
-
Save goneri/6c5c0fd8c16114955104 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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