From e69a926b021ffed4fd64f69a1fd5ba2f68901838 Mon Sep 17 00:00:00 2001 From: edersonbrilhante Date: Thu, 26 Nov 2015 17:58:43 -0200 Subject: [PATCH] api v2: pool actions --- AUTHORS.md | 1 + networkapiclient/ApiGenericClient.py | 3 +- networkapiclient/Pool.py | 68 +++++++++++++++++----------- networkapiclient/__init__.py | 2 +- networkapiclient/version_control.py | 2 +- 5 files changed, 46 insertions(+), 30 deletions(-) diff --git a/AUTHORS.md b/AUTHORS.md index f436a62..3224615 100644 --- a/AUTHORS.md +++ b/AUTHORS.md @@ -12,3 +12,4 @@ - Mauricio Leoncio dos Santos - Mateus Constanzo - [Silvano Buback](https://github.com/snbuback) +- [Ederson Brilhante](https://github.com/edersonbrilhante) diff --git a/networkapiclient/ApiGenericClient.py b/networkapiclient/ApiGenericClient.py index e9c761a..9a41b6b 100644 --- a/networkapiclient/ApiGenericClient.py +++ b/networkapiclient/ApiGenericClient.py @@ -120,7 +120,7 @@ def put(self, uri, data=None): error = self._parse(request.text) raise NetworkAPIClientError(error.get('detail', '')) - def delete(self, uri): + def delete(self, uri, data=None): """ Sends a DELETE request. @@ -132,6 +132,7 @@ def delete(self, uri): request = requests.delete( self._url(uri), + data=json.dumps(data), auth=self._auth_basic(), headers=self._header() ) diff --git a/networkapiclient/Pool.py b/networkapiclient/Pool.py index 3291d87..eeb651f 100644 --- a/networkapiclient/Pool.py +++ b/networkapiclient/Pool.py @@ -33,7 +33,6 @@ def __init__(self, networkapi_url, user, password, user_ldap=None): user_ldap ) - def poolmember_state(self, pools): """ Enable/Disable pool member by list @@ -51,20 +50,19 @@ def poolmember_state(self, pools): """ data = dict() - + uri = "api/pools/poolmember_state/" data["pools"] = pools - - return self.post(uri, data=data) + return self.post(uri, data=data) def list_all_members(self, id_pools, checkstatus=False): """ Return pool member list by POST request method - + param: {"id_pools":[], "checkstatus":"<1 or 0>"} - + return: Following dictionary: { "pools": [ { @@ -77,7 +75,7 @@ def list_all_members(self, id_pools, checkstatus=False): } """ data = dict() - + uri = "api/pools/get_all_members/" data["id_pools"] = id_pools @@ -85,7 +83,6 @@ def list_all_members(self, id_pools, checkstatus=False): return self.post(uri, data=data) - def list_all(self, environment_id, pagination): """ List All Pools To Populate Datatable @@ -117,7 +114,6 @@ def list_all(self, environment_id, pagination): return self.post(uri, data=data) - def list_all_by_reqvip(self, id_vip, pagination): """ List All Pools To Populate Datatable @@ -179,9 +175,31 @@ def inserir(self, identifier, default_port, environment, balancing, healthcheck_ return self.post(uri, data=data) + def save_pool(self, pools): + """ + Save pool + param: Following dictionary: { + "pools": [ + { + "server_pool": { + }, + "server_pool_members": [ + ] + } + ] + } + """ + + data = dict() + data["pools"] = pools + + uri = "api/pools/v2/" + + return self.post(uri, data) + def save(self, id, identifier, default_port, environment, balancing, healthcheck_type, healthcheck_expect, - healthcheck_request, maxcom, ip_list_full, nome_equips, id_equips, priorities, - weight, ports_reals, id_pool_member, servicedownaction=None): + healthcheck_request, maxcom, ip_list_full, nome_equips, id_equips, priorities, + weight, ports_reals, id_pool_member, servicedownaction=None): uri = "api/pools/save/" @@ -257,7 +275,7 @@ def update(self, id_server_pool, default_port, balancing, healthcheck_type, heal def list_all_members_by_pool(self, id_server_pool, checkstatus=False, pagination=None): data = dict() - + uri = "api/pools/get_all_members/%s/?checkstatus=%s" % (id_server_pool, checkstatus) if pagination: @@ -271,7 +289,6 @@ def list_all_members_by_pool(self, id_server_pool, checkstatus=False, pagination return self.get(uri) def get_equip_by_ip(self, id_ip): - """ Get equipment by IP id @@ -319,7 +336,7 @@ def list_healthchecks(self): return self.get(uri) - def delete(self, ids): + def delete_pool(self, ids): """ Delete Pools @@ -345,7 +362,7 @@ def get_by_pk(self, pk): return self.get(uri) - def remove(self, ids): + def remove(self, pools): """ Remove Pools Running Script And Update to Not Created @@ -359,17 +376,17 @@ def remove(self, ids): """ data = dict() - data["ids"] = ids + data["pools"] = pools - uri = "api/pools/remove/" + uri = "api/pools/v2/" - return self.post(uri, data) + return self.delete(uri, data) - def create(self, ids): + def create(self, pools): """ Create Pools Running Script And Update to Created - :param ids: List of ids + :param pools: List of pools :return: None on success @@ -380,11 +397,11 @@ def create(self, ids): """ data = dict() - data["ids"] = ids + data["pools"] = pools - uri = "api/pools/create/" + uri = "api/pools/v2/" - return self.post(uri, data) + return self.put(uri, data) def enable(self, ids): """ @@ -499,7 +516,6 @@ def list_by_environmet_vip(self, environment_vip_id): return self.get(uri) - def list_environments_with_pools(self): """ """ @@ -508,7 +524,6 @@ def list_environments_with_pools(self): return self.get(uri) - def list_all_environment_related_environment_vip(self): """ """ @@ -517,9 +532,8 @@ def list_all_environment_related_environment_vip(self): return self.get(uri) def get_available_ips_to_add_server_pool(self, equip_name, id_ambiente): - """ """ uri = "api/pools/getipsbyambiente/{}/{}/".format(equip_name, id_ambiente) - return self.get(uri) \ No newline at end of file + return self.get(uri) diff --git a/networkapiclient/__init__.py b/networkapiclient/__init__.py index a6e8675..f27a1f3 100644 --- a/networkapiclient/__init__.py +++ b/networkapiclient/__init__.py @@ -16,6 +16,6 @@ MAJOR_VERSION = '0' MINOR_VERSION = '6' -PATCH_VERSION = '10' +PATCH_VERSION = '15' VERSION = '.'.join((MAJOR_VERSION, MINOR_VERSION, PATCH_VERSION,)) diff --git a/networkapiclient/version_control.py b/networkapiclient/version_control.py index 28cd207..8009170 100755 --- a/networkapiclient/version_control.py +++ b/networkapiclient/version_control.py @@ -1 +1 @@ -CLIENT_VERSION = '0.6.10' +CLIENT_VERSION = '0.6.15'