glpi-api 0.4.0__tar.gz → 0.6.0__tar.gz
Sign up to get free protection for your applications and to get access to all the features.
- {glpi-api-0.4.0 → glpi_api-0.6.0}/PKG-INFO +13 -3
- {glpi-api-0.4.0 → glpi_api-0.6.0}/glpi_api.egg-info/PKG-INFO +13 -3
- {glpi-api-0.4.0 → glpi_api-0.6.0}/glpi_api.py +103 -5
- {glpi-api-0.4.0 → glpi_api-0.6.0}/setup.py +2 -2
- {glpi-api-0.4.0 → glpi_api-0.6.0}/LICENSE +0 -0
- {glpi-api-0.4.0 → glpi_api-0.6.0}/README.rst +0 -0
- {glpi-api-0.4.0 → glpi_api-0.6.0}/glpi_api.egg-info/SOURCES.txt +0 -0
- {glpi-api-0.4.0 → glpi_api-0.6.0}/glpi_api.egg-info/dependency_links.txt +0 -0
- {glpi-api-0.4.0 → glpi_api-0.6.0}/glpi_api.egg-info/requires.txt +0 -0
- {glpi-api-0.4.0 → glpi_api-0.6.0}/glpi_api.egg-info/top_level.txt +0 -0
- {glpi-api-0.4.0 → glpi_api-0.6.0}/setup.cfg +0 -0
@@ -1,16 +1,26 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: glpi-api
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.6.0
|
4
4
|
Summary: Wrap calls to GLPI REST API.
|
5
5
|
Home-page: https://github.com/unistra/python-glpi-api
|
6
6
|
Author: François Ménabé
|
7
|
-
Author-email: francois.menabe@
|
7
|
+
Author-email: francois.menabe@gmail.fr
|
8
8
|
License: GPLv3+
|
9
9
|
Keywords: rest,api,glpi
|
10
10
|
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
|
11
11
|
Classifier: Development Status :: 5 - Production/Stable
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
13
13
|
License-File: LICENSE
|
14
|
+
Requires-Dist: requests
|
15
|
+
Dynamic: author
|
16
|
+
Dynamic: author-email
|
17
|
+
Dynamic: classifier
|
18
|
+
Dynamic: description
|
19
|
+
Dynamic: home-page
|
20
|
+
Dynamic: keywords
|
21
|
+
Dynamic: license
|
22
|
+
Dynamic: requires-dist
|
23
|
+
Dynamic: summary
|
14
24
|
|
15
25
|
********
|
16
26
|
glpi-api
|
@@ -1,16 +1,26 @@
|
|
1
|
-
Metadata-Version: 2.
|
1
|
+
Metadata-Version: 2.2
|
2
2
|
Name: glpi-api
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.6.0
|
4
4
|
Summary: Wrap calls to GLPI REST API.
|
5
5
|
Home-page: https://github.com/unistra/python-glpi-api
|
6
6
|
Author: François Ménabé
|
7
|
-
Author-email: francois.menabe@
|
7
|
+
Author-email: francois.menabe@gmail.fr
|
8
8
|
License: GPLv3+
|
9
9
|
Keywords: rest,api,glpi
|
10
10
|
Classifier: License :: OSI Approved :: GNU Lesser General Public License v3 or later (LGPLv3+)
|
11
11
|
Classifier: Development Status :: 5 - Production/Stable
|
12
12
|
Classifier: Programming Language :: Python :: 3
|
13
13
|
License-File: LICENSE
|
14
|
+
Requires-Dist: requests
|
15
|
+
Dynamic: author
|
16
|
+
Dynamic: author-email
|
17
|
+
Dynamic: classifier
|
18
|
+
Dynamic: description
|
19
|
+
Dynamic: home-page
|
20
|
+
Dynamic: keywords
|
21
|
+
Dynamic: license
|
22
|
+
Dynamic: requires-dist
|
23
|
+
Dynamic: summary
|
14
24
|
|
15
25
|
********
|
16
26
|
glpi-api
|
@@ -33,7 +33,7 @@ class GLPIError(Exception):
|
|
33
33
|
"""Exception raised by this module."""
|
34
34
|
|
35
35
|
@contextmanager
|
36
|
-
def connect(url, apptoken, auth, verify_certs=True, use_headers=True):
|
36
|
+
def connect(url, apptoken, auth, verify_certs=True, use_headers=True, user_agent=None):
|
37
37
|
"""Context manager that authenticate to GLPI when enter and kill application
|
38
38
|
session in GLPI when leaving:
|
39
39
|
|
@@ -127,7 +127,8 @@ class GLPI:
|
|
127
127
|
SSL certificates and passing authentication parameters as GET parameters
|
128
128
|
(instead of headers).
|
129
129
|
"""
|
130
|
-
def __init__(self, url, apptoken, auth, verify_certs=True, use_headers=True
|
130
|
+
def __init__(self, url, apptoken, auth, verify_certs=True, use_headers=True,
|
131
|
+
user_agent=None):
|
131
132
|
"""Connect to GLPI and retrieve session token which is put in a
|
132
133
|
``requests`` session as attribute.
|
133
134
|
"""
|
@@ -141,14 +142,18 @@ class GLPI:
|
|
141
142
|
self.session.verify = False
|
142
143
|
|
143
144
|
# Connect and retrieve token.
|
144
|
-
session_token = self._init_session(apptoken, auth,
|
145
|
+
session_token = self._init_session(apptoken, auth, user_agent,
|
146
|
+
use_headers=use_headers)
|
145
147
|
|
146
148
|
# Set required headers.
|
147
|
-
|
149
|
+
headers = {
|
148
150
|
'Content-Type': 'application/json',
|
149
151
|
'Session-Token': session_token,
|
150
152
|
'App-Token': apptoken
|
151
153
|
}
|
154
|
+
if user_agent:
|
155
|
+
headers['User-Agent'] = user_agent
|
156
|
+
self.session.headers = headers
|
152
157
|
|
153
158
|
# Use for caching field id/uid map.
|
154
159
|
self._fields = {}
|
@@ -158,7 +163,7 @@ class GLPI:
|
|
158
163
|
return '/'.join(str(part) for part in [self.url.strip('/'), *endpoints])
|
159
164
|
|
160
165
|
@_catch_errors
|
161
|
-
def _init_session(self, apptoken, auth, use_headers=True):
|
166
|
+
def _init_session(self, apptoken, auth, user_agent, use_headers=True):
|
162
167
|
"""API documentation
|
163
168
|
<https://github.com/glpi-project/glpi/blob/master/apirest.md#init-session>`__
|
164
169
|
|
@@ -170,6 +175,8 @@ class GLPI:
|
|
170
175
|
'Content-Type': 'application/json',
|
171
176
|
'App-Token': apptoken
|
172
177
|
}
|
178
|
+
if user_agent:
|
179
|
+
init_headers['User-Agent'] = user_agent
|
173
180
|
params = {}
|
174
181
|
|
175
182
|
if isinstance(auth, (list, tuple)):
|
@@ -729,6 +736,35 @@ class GLPI:
|
|
729
736
|
401: _glpi_error
|
730
737
|
}.get(response.status_code, _unknown_error)(response)
|
731
738
|
|
739
|
+
@_catch_errors
|
740
|
+
def add_sub_items(self, itemtype, item_id, sub_itemtype, *items):
|
741
|
+
"""`API documentation
|
742
|
+
Same method used as get-sub-items, same parameter
|
743
|
+
<https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
|
744
|
+
|
745
|
+
Add a collection of rows of the ``sub_itemtype`` for the identified
|
746
|
+
item of type ``itemtype`` and id ``item_id``. ``kwargs`` contains
|
747
|
+
additional parameters allowed by the API.
|
748
|
+
|
749
|
+
.. code::
|
750
|
+
|
751
|
+
# Add a operatingsystem of a computer.
|
752
|
+
>>> In [241]: glpi.add_sub_items('Computer',1,'Item_OperatingSystem',{'items_id': 1 ,'itemtype':'Computer','operatingsystems_id':1 })
|
753
|
+
[{'id': 261,
|
754
|
+
'itemtype': 'Computer',
|
755
|
+
'items_id': 1,
|
756
|
+
...
|
757
|
+
"""
|
758
|
+
url = self._set_method(itemtype, item_id, sub_itemtype)
|
759
|
+
response = self.session.post(url,
|
760
|
+
json={'input': items})
|
761
|
+
return {
|
762
|
+
201: lambda r: r.json(),
|
763
|
+
207: lambda r: r.json()[1],
|
764
|
+
400: _glpi_error,
|
765
|
+
401: _glpi_error
|
766
|
+
}.get(response.status_code, _unknown_error)(response)
|
767
|
+
|
732
768
|
@_catch_errors
|
733
769
|
def update(self, itemtype, *items):
|
734
770
|
"""`API documentation
|
@@ -749,11 +785,42 @@ class GLPI:
|
|
749
785
|
json={'input': items})
|
750
786
|
return {
|
751
787
|
200: lambda r: r.json(),
|
788
|
+
201: lambda r: r.json(),
|
752
789
|
207: lambda r: r.json()[1],
|
753
790
|
400: _glpi_error,
|
754
791
|
401: _glpi_error
|
755
792
|
}.get(response.status_code, _unknown_error)(response)
|
756
793
|
|
794
|
+
@_catch_errors
|
795
|
+
def update_sub_items(self, itemtype, item_id, sub_itemtype, *items):
|
796
|
+
"""`API documentation
|
797
|
+
Same method used as get-sub-items, same parameters
|
798
|
+
<https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
|
799
|
+
|
800
|
+
Updates a collection of rows of the ``sub_itemtype`` for the identified
|
801
|
+
item of type ``itemtype`` and id ``item_id``. ``kwargs`` contains
|
802
|
+
additional parameters allowed by the API.
|
803
|
+
|
804
|
+
.. code::
|
805
|
+
|
806
|
+
# update the operatingsystem a computer.
|
807
|
+
>>> In [241]: glpi.update_sub_items('Computer',1,'Item_OperatingSystem' {'id': 1 ,'itemtype':'Computer','operatingsystem_id':1 })
|
808
|
+
[{'id': 261,
|
809
|
+
'itemtype': 'Computer',
|
810
|
+
'items_id': 1,
|
811
|
+
...
|
812
|
+
"""
|
813
|
+
url = self._set_method(itemtype, item_id, sub_itemtype)
|
814
|
+
response = self.session.put(url,
|
815
|
+
json={'input': items})
|
816
|
+
return {
|
817
|
+
200: lambda r: r.json(),
|
818
|
+
201: lambda r: r.json(),
|
819
|
+
207: lambda r: r.json(),
|
820
|
+
400: _glpi_error,
|
821
|
+
401: _glpi_error
|
822
|
+
}.get(response.status_code, _unknown_error)(response)
|
823
|
+
|
757
824
|
@_catch_errors
|
758
825
|
def delete(self, itemtype, *items, **kwargs):
|
759
826
|
"""`API documentation <https://github.com
|
@@ -784,6 +851,37 @@ class GLPI:
|
|
784
851
|
401: _glpi_error
|
785
852
|
}.get(response.status_code, _unknown_error)(response)
|
786
853
|
|
854
|
+
@_catch_errors
|
855
|
+
def delete_sub_items(self, itemtype, item_id, sub_itemtype, *items):
|
856
|
+
"""`API documentation
|
857
|
+
Same method used as get-sub-items, same parameters
|
858
|
+
<https://github.com/glpi-project/glpi/blob/master/apirest.md#get-sub-items>`__
|
859
|
+
|
860
|
+
deletes a collection of rows of the ``sub_itemtype`` for the identified
|
861
|
+
item of type ``itemtype`` and id ``item_id``. ``kwargs`` contains
|
862
|
+
additional parameters allowed by the API.
|
863
|
+
|
864
|
+
.. code::
|
865
|
+
|
866
|
+
# delete the operatingsystem a computer.
|
867
|
+
>>> In [241]: glpi.delete_sub_items('Computer',1,'Item_OperatingSystem' {'id': 1 ,'itemtype':'Computer','operatingsystem_id':1 })
|
868
|
+
[{'id': 261,
|
869
|
+
'itemtype': 'Computer',
|
870
|
+
'items_id': 1,
|
871
|
+
...
|
872
|
+
"""
|
873
|
+
url = self._set_method(itemtype, item_id, sub_itemtype)
|
874
|
+
response = self.session.delete(url,
|
875
|
+
json={'input': items})
|
876
|
+
return {
|
877
|
+
200: lambda r: r.json(),
|
878
|
+
204: lambda r: r.json(),
|
879
|
+
207: lambda r: r.json()[1],
|
880
|
+
400: lambda r: _glpi_error(r) if r.json()[0] != 'ERROR_GLPI_DELETE' else r.json()[1],
|
881
|
+
401: _glpi_error
|
882
|
+
}.get(response.status_code, _unknown_error)(response)
|
883
|
+
|
884
|
+
|
787
885
|
@_catch_errors
|
788
886
|
def upload_document(self, name, filepath):
|
789
887
|
"""`API documentation
|
@@ -4,9 +4,9 @@ from setuptools import setup
|
|
4
4
|
|
5
5
|
setup(
|
6
6
|
name='glpi-api',
|
7
|
-
version='0.
|
7
|
+
version='0.6.0',
|
8
8
|
author='François Ménabé',
|
9
|
-
author_email='francois.menabe@
|
9
|
+
author_email='francois.menabe@gmail.fr',
|
10
10
|
url='https://github.com/unistra/python-glpi-api',
|
11
11
|
license='GPLv3+',
|
12
12
|
description='Wrap calls to GLPI REST API.',
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|