Add http request sample to itop. Boulala....
Bobo tete....
This commit is contained in:
parent
bc4675efc6
commit
0ee7e29dfd
@ -5,8 +5,8 @@ port=8080
|
|||||||
[itop]
|
[itop]
|
||||||
drvtype=cmdb
|
drvtype=cmdb
|
||||||
endpoint=http://itop/rest
|
endpoint=http://itop/rest
|
||||||
loginItop=itopuser
|
loginItop=admin
|
||||||
passwordItop=itoppassword
|
passwordItop=linux1
|
||||||
|
|
||||||
[redfish]
|
[redfish]
|
||||||
drvtype=hw
|
drvtype=hw
|
||||||
|
@ -60,3 +60,6 @@ class AlexandriaConfiguration(object):
|
|||||||
|
|
||||||
def get_alexandria_port(self):
|
def get_alexandria_port(self):
|
||||||
return self.config.get("alexandria", "port")
|
return self.config.get("alexandria", "port")
|
||||||
|
|
||||||
|
def get_driver_parameters(self, drivername, parameters):
|
||||||
|
return self.config.get(drivername, parameters)
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
|
||||||
import types
|
|
||||||
import pprint
|
import pprint
|
||||||
import config
|
import config
|
||||||
import json
|
import json
|
||||||
|
import urllib
|
||||||
|
import requests
|
||||||
|
import types
|
||||||
|
|
||||||
|
|
||||||
class Driver(object):
|
class Driver(object):
|
||||||
@ -16,21 +18,57 @@ class Driver(object):
|
|||||||
def get_driver_type(self):
|
def get_driver_type(self):
|
||||||
return self.driver_type
|
return self.driver_type
|
||||||
|
|
||||||
def get_ci(self,ci):
|
def get_ci(self, ci):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def push_ci(self,ci):
|
def push_ci(self, ci):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class Itop(Driver):
|
class Itop(Driver):
|
||||||
|
|
||||||
def get_ci(self,ci):
|
def get_ci(self, ci):
|
||||||
print "Get from itop"
|
print "Get from itop"
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def push_ci(self,ci):
|
def push_ci(self, ci):
|
||||||
pass
|
username = config.alexandria.conf_file.get_driver_parameters("itop", "loginItop")
|
||||||
|
password = config.alexandria.conf_file.get_driver_parameters("itop", "passwordItop")
|
||||||
|
config.logger.debug("login : {}, password : {}".format(
|
||||||
|
username,
|
||||||
|
password
|
||||||
|
)
|
||||||
|
)
|
||||||
|
# Craft request body and header
|
||||||
|
urlbase = "http://10.3.8.40/itop/webservices/rest.php"
|
||||||
|
request = '{"operation":"core/update","comment":"boulalala","class":"Server","key":{"name":"Server1"},"output_fields":"id,friendlyname,ram","fields":{"ram":"28"}}'
|
||||||
|
|
||||||
|
urlparam = {'version' : '1.0',
|
||||||
|
'auth_user' : username,
|
||||||
|
'auth_pwd' : password,
|
||||||
|
'json_data' : request
|
||||||
|
}
|
||||||
|
|
||||||
|
header = {'Content-type': 'application/json'}
|
||||||
|
|
||||||
|
url = urlbase + '?' + urllib.urlencode(urlparam)
|
||||||
|
|
||||||
|
config.logger.debug(url)
|
||||||
|
|
||||||
|
#=======================================================================
|
||||||
|
# answer = requests.post(url,
|
||||||
|
# headers=header,
|
||||||
|
# verify="False"
|
||||||
|
# )
|
||||||
|
#=======================================================================
|
||||||
|
answer = requests.post(url,
|
||||||
|
auth=(username,password)
|
||||||
|
)
|
||||||
|
|
||||||
|
config.logger.debug(answer.status_code)
|
||||||
|
config.logger.debug(answer.text)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Redfish(Driver):
|
class Redfish(Driver):
|
||||||
|
|
||||||
@ -48,9 +86,9 @@ class Mondorescue(Driver):
|
|||||||
|
|
||||||
|
|
||||||
class Fakecmdb(Driver):
|
class Fakecmdb(Driver):
|
||||||
def push_ci(self, ci):
|
def push_ci(self, ci):
|
||||||
# Determine ci type so we can do the proper action.
|
# Determine ci type so we can do the proper action.
|
||||||
pp = pprint.PrettyPrinter(indent=4)
|
pp = pprint.PrettyPrinter(indent=4)
|
||||||
if ci.ci_type == "Manager":
|
if ci.ci_type == "Manager":
|
||||||
print "We are in Fakecmdb driver !"
|
print "We are in Fakecmdb driver !"
|
||||||
pp.pprint(ci.data)
|
pp.pprint(ci.data)
|
||||||
@ -59,33 +97,33 @@ class Fakecmdb(Driver):
|
|||||||
json.dump(ci.data, jsonfile, indent=4)
|
json.dump(ci.data, jsonfile, indent=4)
|
||||||
jsonfile.close()
|
jsonfile.close()
|
||||||
|
|
||||||
#
|
#
|
||||||
#=======================================================================
|
#=======================================================================
|
||||||
|
|
||||||
class Fakeprovider(Driver):
|
class Fakeprovider(Driver):
|
||||||
|
|
||||||
def get_ci(self,ci):
|
def get_ci(self, ci):
|
||||||
# Simulate a driver that will provide Manager data.
|
# Simulate a driver that will provide Manager data.
|
||||||
|
|
||||||
# TODO a connect method must be implemented
|
# TODO a connect method must be implemented
|
||||||
|
|
||||||
# Assuming the connection is ok.
|
# Assuming the connection is ok.
|
||||||
|
|
||||||
# Now create a copy of manager model from reference model.
|
# Now create a copy of manager model from reference model.
|
||||||
ci.ci_type = "Manager"
|
ci.ci_type = "Manager"
|
||||||
ci.data = config.alexandria.model.get_model("Manager")
|
ci.data = config.alexandria.model.get_model("Manager")
|
||||||
|
|
||||||
# Update the structure with data
|
# Update the structure with data
|
||||||
# TODO : think to encapsulate to not edit ci.data directly.
|
# TODO : think to encapsulate to not edit ci.data directly.
|
||||||
# This could be also a way to check source of truth.
|
# This could be also a way to check source of truth.
|
||||||
# If data provided by our driver is not the source of truth
|
# If data provided by our driver is not the source of truth
|
||||||
# then discard it.
|
# then discard it.
|
||||||
|
|
||||||
|
|
||||||
ci.data["ManagerType"] = "BMC"
|
ci.data["ManagerType"] = "BMC"
|
||||||
ci.data["Model"] = "Néné Manager"
|
ci.data["Model"] = "Néné Manager"
|
||||||
ci.data["FirmwareVersion"] = "1.00"
|
ci.data["FirmwareVersion"] = "1.00"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -93,7 +131,7 @@ class Fakeprovider(Driver):
|
|||||||
# print "identical"
|
# print "identical"
|
||||||
|
|
||||||
pp = pprint.PrettyPrinter(indent=4)
|
pp = pprint.PrettyPrinter(indent=4)
|
||||||
|
|
||||||
pp.pprint(ci.ci_type)
|
pp.pprint(ci.ci_type)
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user