adding 3 new methods, get to retrieve configurational data, monitor to retreieve operational data, execute to perform action (#61331)

This commit is contained in:
Don Yao 2019-08-27 02:54:07 -04:00 committed by Nilashish Chakraborty
parent adb8a0ddc6
commit c0046e7f52

View file

@ -96,6 +96,17 @@ class FortiOSHandler(object):
url += '?vdom=' + vdom
return url
def mon_url(self, path, name, vdom=None, mkey=None):
url = '/api/v2/monitor/' + path + '/' + name
if mkey:
url = url + '/' + str(mkey)
if vdom:
if vdom == "global":
url += '?global=1'
else:
url += '?vdom=' + vdom
return url
def schema(self, path, name, vdom=None):
if vdom is None:
url = self.cmdb_url(path, name) + "?action=schema"
@ -132,6 +143,20 @@ class FortiOSHandler(object):
return None
return mkey
def get(self, path, name, vdom=None, mkey=None, parameters=None):
url = self.cmdb_url(path, name, vdom, mkey=mkey)
status, result_data = self._conn.send_request(url=url, params=parameters, method='GET')
return self.formatresponse(result_data, vdom=vdom)
def monitor(self, path, name, vdom=None, mkey=None, parameters=None):
url = self.mon_url(path, name, vdom, mkey)
status, result_data = self._conn.send_request(url=url, params=parameters, method='GET')
return self.formatresponse(result_data, vdom=vdom)
def set(self, path, name, data, mkey=None, vdom=None, parameters=None):
if not mkey:
@ -158,6 +183,14 @@ class FortiOSHandler(object):
return self.formatresponse(result_data, vdom=vdom)
def execute(self, path, name, data, vdom=None,
mkey=None, parameters=None, timeout=300):
url = self.mon_url(path, name, vdom, mkey=mkey)
status, result_data = self._conn.send_request(url=url, params=parameters, data=json.dumps(data), method='POST', timeout=timeout)
return self.formatresponse(result_data, vdom=vdom)
def delete(self, path, name, vdom=None, mkey=None, parameters=None, data=None):
if not mkey:
mkey = self.get_mkey(path, name, data, vdom=vdom)