From c0046e7f52878e42911b31907f8ed5d3eb23422b Mon Sep 17 00:00:00 2001 From: Don Yao <41839531+fortinetps@users.noreply.github.com> Date: Tue, 27 Aug 2019 02:54:07 -0400 Subject: [PATCH] adding 3 new methods, get to retrieve configurational data, monitor to retreieve operational data, execute to perform action (#61331) --- .../module_utils/network/fortios/fortios.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/lib/ansible/module_utils/network/fortios/fortios.py b/lib/ansible/module_utils/network/fortios/fortios.py index 879921bbd94..95dbc89fe7d 100644 --- a/lib/ansible/module_utils/network/fortios/fortios.py +++ b/lib/ansible/module_utils/network/fortios/fortios.py @@ -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)