-
Notifications
You must be signed in to change notification settings - Fork 5
/
itop-cli
executable file
·82 lines (70 loc) · 2.45 KB
/
itop-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# -*- coding: utf8 -*-fr
# pylint: disable=invalid-name
"""
itop-cli is a basic CLI interface for iTop REST interface
"""
__version__ = '1.0'
__authors__ = ['Guillaume Philippon <[email protected]>']
from itopapi import ItopapiController, ItopapiConfig, UnsupportedImportFormat
from itopcli import load_configuration_cli, ItopcliConfig, NeedMoreArgs
def main():
"""
Main function
"""
######################
# Load configuration #
######################
try:
load_configuration_cli()
except NeedMoreArgs as e:
print "Error: {}".format(e.message)
exit(1)
####################
# Some value check #
####################
if ItopapiConfig.hostname is None \
or ItopapiConfig.username is None\
or ItopapiConfig.password is None:
print "Error: Hostname/Username/Password missing"
exit(1)
controller = ItopapiController()
######################################
# Retrieve profile from URI if asked #
######################################
if ItopapiConfig.import_uri is not None:
try:
controller.get_data_from_uri(ItopapiConfig.import_uri, ItopapiConfig.format)
except UnsupportedImportFormat as e:
print 'Error: {}'.format(e.message)
exit(1)
######################################
# Retrieve profile from stdin if asked #
######################################
if ItopapiConfig.import_stdin:
try:
controller.get_data_from_stdin(ItopapiConfig.format)
except UnsupportedImportFormat as e:
print 'Error: {}'.format(e.message)
exit(1)
#########################
# Display classes asked #
#########################
if ItopcliConfig.classes is not None:
for itop_class in ItopcliConfig.classes:
if ItopcliConfig.find_instance is None:
controller.load_all(itop_class)
else:
for find in ItopcliConfig.find_instance:
controller.load_one(itop_class, find)
#########################################
# Save or delete data previously loaded #
#########################################
if ItopcliConfig.save:
controller.save(ItopapiConfig.prevent_duplicates)
elif ItopcliConfig.delete_instances:
controller.delete()
else:
controller.display()
if __name__ == "__main__":
main()