diff --git a/README.md b/README.md index 6fb717de..14f8da87 100644 --- a/README.md +++ b/README.md @@ -93,8 +93,6 @@ $ tox ## Issues and Inquiries For all issues, please send an email to support@a10networks.com -For general inquiries, please send an email to opensource@a10networks.com - ## Helpful links diff --git a/acos_client/errors.py b/acos_client/errors.py index 562f9d87..ccc980f1 100644 --- a/acos_client/errors.py +++ b/acos_client/errors.py @@ -113,3 +113,11 @@ class KeyParsingFailed(ACOSException): class FeatureNotSupported(ACOSException): pass + + +class ACOSSystemNotReady(ACOSException): + pass + + +class ACOSSystemIsBusy(ACOSException): + pass diff --git a/acos_client/tests/unit/v30/test_bladeparam.py b/acos_client/tests/unit/v30/test_bladeparam.py index a5df3246..03ffcc5e 100644 --- a/acos_client/tests/unit/v30/test_bladeparam.py +++ b/acos_client/tests/unit/v30/test_bladeparam.py @@ -83,21 +83,21 @@ def _build_ipv6gateway(self, ip_address, priority_cost=1): def test_blade_get(self): self.target.get(0) self.client.http.request.assert_called_with("GET", self.url_prefix.format(0), {}, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_create(self): self.target.create(4) self.client.http.request.assert_called_with( "POST", self.url_prefix.format(4), self._expected_payload(), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_create_priority(self): self.target.create(4, 122) self.client.http.request.assert_called_with( "POST", self.url_prefix.format(4), self._expected_payload(122), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_create_interface(self): interface = self._build_interface() @@ -107,7 +107,7 @@ def test_blade_create_interface(self): self.client.http.request.assert_called_with( "POST", self.url_prefix.format(4), self._expected_payload(interface=interface), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_create_gateway(self): gateway = self._build_ipv4gateway('1.1.1.1') @@ -117,7 +117,7 @@ def test_blade_create_gateway(self): self.client.http.request.assert_called_with( "POST", self.url_prefix.format(4), self._expected_payload(gateway=gateway), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_create_gateway_ipv6(self): gateway = self._build_ipv6gateway('1.1.1.1') @@ -127,7 +127,7 @@ def test_blade_create_gateway_ipv6(self): self.client.http.request.assert_called_with( "POST", self.url_prefix.format(4), self._expected_payload(gateway=gateway), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_create_interface_gateway(self): interface = self._build_interface() @@ -139,21 +139,21 @@ def test_blade_create_interface_gateway(self): self.client.http.request.assert_called_with( "POST", self.url_prefix.format(4), self._expected_payload(interface=interface, gateway=gateway), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_update(self): self.target.update(4) self.client.http.request.assert_called_with( "PUT", self.url_prefix.format(4), self._expected_payload(), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_update_priority(self): self.target.update(4, 122) self.client.http.request.assert_called_with( "PUT", self.url_prefix.format(4), self._expected_payload(122), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_update_interface(self): interface = self._build_interface() @@ -163,7 +163,7 @@ def test_blade_update_interface(self): self.client.http.request.assert_called_with( "PUT", self.url_prefix.format(4), self._expected_payload(interface=interface), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_update_gateway(self): gateway = self._build_ipv4gateway('1.1.1.1') @@ -173,7 +173,7 @@ def test_blade_update_gateway(self): self.client.http.request.assert_called_with( "PUT", self.url_prefix.format(4), self._expected_payload(gateway=gateway), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_update_gateway_ipv6(self): gateway = self._build_ipv6gateway('1.1.1.1') @@ -183,7 +183,7 @@ def test_blade_update_gateway_ipv6(self): self.client.http.request.assert_called_with( "PUT", self.url_prefix.format(4), self._expected_payload(gateway=gateway), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_blade_update_interface_gateway(self): interface = self._build_interface() @@ -195,4 +195,4 @@ def test_blade_update_interface_gateway(self): self.client.http.request.assert_called_with( "PUT", self.url_prefix.format(4), self._expected_payload(interface=interface, gateway=gateway), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) diff --git a/acos_client/tests/unit/v30/test_dns.py b/acos_client/tests/unit/v30/test_dns.py index 4ba1ea16..1ede339d 100644 --- a/acos_client/tests/unit/v30/test_dns.py +++ b/acos_client/tests/unit/v30/test_dns.py @@ -38,7 +38,7 @@ def test_primary_ipv4(self): self.client.http.request.assert_called_with("POST", self.url_prefix + 'primary', expected_payload, mock.ANY, axapi_args=None, - max_retries=None, timeout=None) + max_retries=None, timeout=mock.ANY) def test_primary_ipv6(self): expected = '0:0:0:0:0:FFFF:129.144.52.38' @@ -48,7 +48,7 @@ def test_primary_ipv6(self): self.client.http.request.assert_called_with("POST", self.url_prefix + 'primary', expected_payload, mock.ANY, axapi_args=None, - max_retries=None, timeout=None) + max_retries=None, timeout=mock.ANY) def test_secondary_ipv4(self): expected = '192.0.2.5' @@ -58,7 +58,7 @@ def test_secondary_ipv4(self): self.client.http.request.assert_called_with("POST", self.url_prefix + 'secondary', expected_payload, mock.ANY, axapi_args=None, - max_retries=None, timeout=None) + max_retries=None, timeout=mock.ANY) def test_secondary_ipv6(self): expected = '0:0:0:0:0:FFFF:129.144.52.39' @@ -68,7 +68,7 @@ def test_secondary_ipv6(self): self.client.http.request.assert_called_with("POST", self.url_prefix + 'secondary', expected_payload, mock.ANY, axapi_args=None, - max_retries=None, timeout=None) + max_retries=None, timeout=mock.ANY) def test_suffix(self): expected = 'example.com' @@ -78,4 +78,4 @@ def test_suffix(self): self.client.http.request.assert_called_with("POST", self.url_prefix + 'suffix', expected_payload, mock.ANY, axapi_args=None, - max_retries=None, timeout=None) + max_retries=None, timeout=mock.ANY) diff --git a/acos_client/tests/unit/v30/test_interface.py b/acos_client/tests/unit/v30/test_interface.py index 21e8132d..61a612ea 100644 --- a/acos_client/tests/unit/v30/test_interface.py +++ b/acos_client/tests/unit/v30/test_interface.py @@ -33,12 +33,12 @@ def setUp(self): def test_interface_get_list(self): self.target.get_list() self.client.http.request.assert_called_with("GET", self.url_prefix, {}, mock.ANY, axapi_args=None, - max_retries=None, timeout=None) + max_retries=None, timeout=mock.ANY) def test_interface_get(self): self.target.get() self.client.http.request.assert_called_with("GET", self.url_prefix, {}, mock.ANY, axapi_args=None, - max_retries=None, timeout=None) + max_retries=None, timeout=mock.ANY) def _test_interface_create_dhcp(self, dhcp=True): expected = 1 if dhcp else 0 @@ -47,7 +47,7 @@ def _test_interface_create_dhcp(self, dhcp=True): self.target.create(ifnum, dhcp=dhcp) self.client.http.request.assert_called_with("POST", self.url_prefix, # URL + ifnum expected expected_payload, mock.ANY, axapi_args=None, - max_retries=None, timeout=None) + max_retries=None, timeout=mock.ANY) def test_interface_create_dhcp_negative(self): self._test_interface_create_dhcp(False) @@ -61,14 +61,14 @@ def test_interface_create_ipaddress(self): ip_netmask = "255.255.255.0" self.target.create(ifnum, dhcp=False, ip_address=ip_address, ip_netmask=ip_netmask) self.client.http.request.assert_called_with("POST", self.url_prefix, mock.ANY, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_interface_delete(self): ifnum = 1 self.target.delete(1) self.client.http.request.assert_called_with("DELETE", self.url_prefix + str(ifnum), mock.ANY, mock.ANY, axapi_args=None, max_retries=None, - timeout=None) + timeout=mock.ANY) def test_interface_update(self): ifnum = 1 @@ -79,7 +79,7 @@ def test_interface_update(self): self.client.http.request.assert_called_with("POST", self.url_prefix + str(ifnum), mock.ANY, mock.ANY, axapi_args=None, max_retries=None, - timeout=None) + timeout=mock.ANY) def test_interface_enable_positive(self): ifnum = 1 @@ -94,7 +94,7 @@ def test_interface_enable_positive(self): self.client.http.request.assert_called_with("POST", self.url_prefix + str(ifnum), mock.ANY, mock.ANY, axapi_args=None, max_retries=None, - timeout=None) + timeout=mock.ANY) def test_interface_enable_negative(self): ifnum = 1 @@ -110,7 +110,7 @@ def test_interface_enable_negative(self): self.client.http.request.assert_called_with("POST", self.url_prefix + str(ifnum), mock.ANY, mock.ANY, axapi_args=None, max_retries=None, - timeout=None) + timeout=mock.ANY) class TestEthernetInterface(TestInterface): diff --git a/acos_client/tests/unit/v30/test_slb_aflex.py b/acos_client/tests/unit/v30/test_slb_aflex.py index 0050dab2..a634319c 100644 --- a/acos_client/tests/unit/v30/test_slb_aflex.py +++ b/acos_client/tests/unit/v30/test_slb_aflex.py @@ -56,8 +56,8 @@ def test_aflex_create(self, mocked_get): self.assertEqual(len(responses.calls), 2) self.assertEqual(responses.calls[1].request.method, responses.POST) self.assertEqual(responses.calls[1].request.url, CREATE_URL) - self.assertIn(filename, responses.calls[1].request.body.decode('UTF-8')) - self.assertIn(action, responses.calls[1].request.body.decode('UTF-8')) + self.assertIn(filename, responses.calls[1].request.body.decode("utf-8")) + self.assertIn(action, responses.calls[1].request.body.decode("utf-8")) @mock.patch('acos_client.v30.slb.aflex_policy.AFlexPolicy.get') @responses.activate @@ -76,8 +76,8 @@ def test_aflex_update(self, mocked_get): self.assertEqual(len(responses.calls), 2) self.assertEqual(responses.calls[1].request.method, responses.POST) self.assertEqual(responses.calls[1].request.url, CREATE_URL) - self.assertIn(filename, responses.calls[1].request.body.decode('UTF-8')) - self.assertIn(action, responses.calls[1].request.body.decode('UTF-8')) + self.assertIn(filename, responses.calls[1].request.body.decode("utf-8")) + self.assertIn(action, responses.calls[1].request.body.decode("utf-8")) @mock.patch('acos_client.v30.slb.aflex_policy.AFlexPolicy.get') @responses.activate @@ -93,5 +93,5 @@ def test_aflex_delete(self, mocked_get): self.assertEqual(len(responses.calls), 2) self.assertEqual(responses.calls[1].request.method, responses.POST) self.assertEqual(responses.calls[1].request.url, CREATE_URL) - self.assertIn(filename, responses.calls[1].request.body.decode('UTF-8')) - self.assertIn('delete', responses.calls[1].request.body.decode('UTF-8')) + self.assertIn(filename, responses.calls[1].request.body.decode("utf-8")) + self.assertIn('delete', responses.calls[1].request.body.decode("utf-8")) diff --git a/acos_client/tests/unit/v30/test_vlan.py b/acos_client/tests/unit/v30/test_vlan.py index a10ce17b..53c0315c 100644 --- a/acos_client/tests/unit/v30/test_vlan.py +++ b/acos_client/tests/unit/v30/test_vlan.py @@ -35,13 +35,13 @@ def setUp(self): def test_interface_get_list(self): self.target.get_list() self.client.http.request.assert_called_with("GET", self.url_prefix, {}, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_interface_get(self): self.target.get(self.vlan_id) self.client.http.request.assert_called_with( "GET", '{0}/{1}'.format(self.url_prefix, self.vlan_id), {}, mock.ANY, - axapi_args=None, max_retries=None, timeout=None + axapi_args=None, max_retries=None, timeout=mock.ANY ) def test_vlan_create_shared(self): @@ -51,7 +51,7 @@ def test_vlan_create_shared(self): ep = self.expected_payload ep['vlan']['shared-vlan'] = True self.client.http.request.assert_called_with("POST", self.url_prefix, ep, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vlan_create_untagged_eths(self): untagged_eths = [{'untagged-ethernet-start': 2, 'untagged-ethernet-end': 2}] @@ -62,7 +62,7 @@ def test_vlan_create_untagged_eths(self): ep = self.expected_payload ep['vlan']['untagged-eth-list'] = untagged_eths self.client.http.request.assert_called_with("POST", self.url_prefix, ep, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vlan_create_untagged_trunks(self): untagged_trunks = [{'untagged-trunk-start': 2, 'untagged-trunk-end': 2}] @@ -74,7 +74,7 @@ def test_vlan_create_untagged_trunks(self): ep = self.expected_payload ep['vlan']['untagged-trunk-list'] = untagged_trunks self.client.http.request.assert_called_with("POST", self.url_prefix, ep, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vlan_create_tagged_eths(self): tagged_eths = [{'tagged-ethernet-start': 2, 'tagged-ethernet-end': 2}] @@ -85,7 +85,7 @@ def test_vlan_create_tagged_eths(self): ep = self.expected_payload ep['vlan']['tagged-eth-list'] = tagged_eths self.client.http.request.assert_called_with("POST", self.url_prefix, ep, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vlan_create_tagged_trunks(self): tagged_trunks = [{'tagged-trunk-start': 2, 'tagged-trunk-end': 2}] @@ -96,7 +96,7 @@ def test_vlan_create_tagged_trunks(self): ep = self.expected_payload ep['vlan']['tagged-trunk-list'] = tagged_trunks self.client.http.request.assert_called_with("POST", self.url_prefix, ep, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vlan_create_ve(self): self.target.create(self.vlan_id, shared_vlan=False, untagged_eths=[], untagged_trunks=[], @@ -105,7 +105,7 @@ def test_vlan_create_ve(self): ep = self.expected_payload ep['vlan']['ve'] = 1 self.client.http.request.assert_called_with("POST", self.url_prefix, ep, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vlan_create_lif(self): self.target.create(self.vlan_id, shared_vlan=False, untagged_eths=[], untagged_trunks=[], @@ -114,11 +114,11 @@ def test_vlan_create_lif(self): ep = self.expected_payload ep['vlan']['untagged-lif'] = 6 self.client.http.request.assert_called_with("POST", self.url_prefix, ep, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vlan_delete(self): self.target.delete(self.vlan_id) self.client.http.request.assert_called_with( "DELETE", '{0}/{1}'.format(self.url_prefix, self.vlan_id), mock.ANY, mock.ANY, - axapi_args=None, max_retries=None, timeout=None + axapi_args=None, max_retries=None, timeout=mock.ANY ) diff --git a/acos_client/tests/unit/v30/test_vrrpa.py b/acos_client/tests/unit/v30/test_vrrpa.py index 65266ef6..1e08e2d0 100644 --- a/acos_client/tests/unit/v30/test_vrrpa.py +++ b/acos_client/tests/unit/v30/test_vrrpa.py @@ -46,19 +46,19 @@ def expected_payload(self, vrid_val, threshold=1, disable=0, is_partition=None): def test_vrid_get(self): self.target.get(0) self.client.http.request.assert_called_with("GET", self.url_prefix + '0', {}, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vrid_create_threshold(self): self.target.create(4, threshold=2) self.client.http.request.assert_called_with( "POST", self.url_prefix, self.expected_payload(4, threshold=2), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vrid_create_disable(self): self.target.create(4, disable=1) self.client.http.request.assert_called_with( "POST", self.url_prefix, self.expected_payload(4, disable=1), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vrid_create_floating_ip(self): self.target.create(4, threshold=1, disable=0, floating_ips=['10.10.10.8']) @@ -66,19 +66,19 @@ def test_vrid_create_floating_ip(self): payload['vrid']['floating-ip'] = mock.ANY self.client.http.request.assert_called_with( "POST", self.url_prefix, payload, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vrid_update_threshold(self): self.target.update(4, threshold=2) self.client.http.request.assert_called_with( "PUT", self.url_prefix + '4', self.expected_payload(4, threshold=2), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vrid_update_disable(self): self.target.update(4, disable=1) self.client.http.request.assert_called_with( "PUT", self.url_prefix + '4', self.expected_payload(4, disable=1), mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_vrid_update_floating_ip(self): self.target.update(4, threshold=1, disable=0, floating_ips=['10.10.10.9']) @@ -86,7 +86,7 @@ def test_vrid_update_floating_ip(self): payload['vrid']['floating-ip'] = mock.ANY self.client.http.request.assert_called_with( "PUT", self.url_prefix + '4', payload, - mock.ANY, axapi_args=None, max_retries=None, timeout=None) + mock.ANY, axapi_args=None, max_retries=None, timeout=mock.ANY) def test_patition_vrid_create_floating_ip(self): self.target.create(4, threshold=1, disable=0, floating_ips=['10.10.10.8'], is_partition=True) @@ -94,7 +94,7 @@ def test_patition_vrid_create_floating_ip(self): payload['vrid']['floating-ip'] = mock.ANY self.client.http.request.assert_called_with( "POST", self.url_prefix, payload, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_partition_vrid_update_floating_ip(self): self.target.update(4, threshold=1, disable=0, floating_ips=['10.10.10.9'], is_partition=True) @@ -102,7 +102,7 @@ def test_partition_vrid_update_floating_ip(self): payload['vrid']['floating-ip'] = mock.ANY self.client.http.request.assert_called_with( "PUT", self.url_prefix + '4', payload, mock.ANY, - axapi_args=None, max_retries=None, timeout=None) + axapi_args=None, max_retries=None, timeout=mock.ANY) def test_build_params_multi_ip(self): floating_ips = ['11.11.11.11', '12.12.12.12', '13.13.13.13'] diff --git a/acos_client/v30/action.py b/acos_client/v30/action.py index 0c122e02..59627332 100644 --- a/acos_client/v30/action.py +++ b/acos_client/v30/action.py @@ -89,7 +89,7 @@ def set_vcs_device(self, device_id, priority): def set_vcs_para(self, floating_ip, floating_ip_mask): data = {"vcs-para": {"floating-ip-cfg": [{"floating-ip": floating_ip, - "floating-ip-mask": floating_ip_mask}]}} + "floating-ip-mask": floating_ip_mask}], "forever": 1}} url = "/vcs/vcs-para" self._post(url, data) @@ -119,3 +119,41 @@ def get_vcs_summary_oper(self): def get_thunder_up_time(self): url = "/miscellenious-alb/oper" return self._get(url) + + def probe_network_devices(self): + url = "/system/probe-network-devices" + self._post(url) + + def get_acos_version(self): + url = "/version/oper" + return self._get(url) + + def reload_reboot_for_interface_attachment(self, acos_version=None): + if not acos_version: + version_summary = self.get_acos_version() + acos_version = version_summary['version']['oper']['sw-version'].split(',')[0] + + major = acos_version.split('.')[0] + minor = acos_version.split('.')[1] + patch = acos_version.split('.')[2] + + if major >= 5 and minor >= 2 and patch >= 0: + self.probe_network_devices() + self.reload() + else: + self.reboot() + + def reload_reboot_for_interface_detachment(self, acos_version=None): + if not acos_version: + version_summary = self.get_acos_version() + acos_version = version_summary['version']['oper']['sw-version'].split(',')[0] + + major = acos_version.split('.')[0] + minor = acos_version.split('.')[1] + patch = acos_version.split('.')[2] + + if major >= 5 and minor >= 2 and patch >= 1: + self.probe_network_devices() + self.reload() + else: + self.reboot() diff --git a/acos_client/v30/axapi_http.py b/acos_client/v30/axapi_http.py index e59cd93e..cce61217 100644 --- a/acos_client/v30/axapi_http.py +++ b/acos_client/v30/axapi_http.py @@ -17,10 +17,14 @@ import json import logging +import time + from requests.adapters import HTTPAdapter +from requests import exceptions as req_exceptions from requests import Session import acos_client +from acos_client import errors as ae from acos_client import logutils from acos_client.v30 import responses as acos_responses @@ -32,12 +36,14 @@ class HttpClient(object): + AXAPI_DEFAULT_REQ_TIMEOUT = 300 HEADERS = { "Content-type": "application/json", "User-Agent": "ACOS-Client-AGENT-%s" % acos_client.VERSION, } - def __init__(self, host, port=None, protocol="https", max_retries=3, timeout=5): + def __init__(self, host, port=None, protocol="https", max_retries=3, + timeout=AXAPI_DEFAULT_REQ_TIMEOUT): if port is None: if protocol is 'http': self.port = 80 @@ -64,9 +70,9 @@ def dict_underscore_to_dash(self, my_dict): else: return my_dict - def request(self, method, api_url, params={}, headers=None, - file_name=None, file_content=None, axapi_args=None, - max_retries=None, timeout=None, **kwargs): + def request_impl(self, method, api_url, params={}, headers=None, + file_name=None, file_content=None, axapi_args=None, + max_retries=None, timeout=None, **kwargs): LOG.debug("axapi_http: full url = %s", self.url_base + api_url) LOG.debug("axapi_http: %s url = %s", method, api_url) LOG.debug("axapi_http: params = %s", json.dumps(logutils.clean(params), indent=4)) @@ -157,6 +163,30 @@ def request(self, method, api_url, params={}, headers=None, return json_response + def request(self, method, api_url, params={}, headers=None, + file_name=None, file_content=None, axapi_args=None, + max_retries=None, timeout=None, **kwargs): + attemps = 300 + if timeout and timeout > attemps: + attemps = timeout + + while attemps > 0: + try: + return self.request_impl(method, api_url, params, headers, + file_name=file_name, file_content=file_content, + max_retries=max_retries, + timeout=timeout, axapi_args=axapi_args, + **kwargs) + + except (ae.ACOSSystemIsBusy, ae.ACOSSystemNotReady, req_exceptions.ConnectionError) as e: + LOG.warning("ACOS device system is busy: %s", str(e)) + attemps = attemps - 2 + if attemps <= 0: + raise e + time.sleep(2) + except (Exception) as e: + raise e + def get(self, api_url, params={}, headers=None, max_retries=None, timeout=None, axapi_args=None, **kwargs): return self.request("GET", api_url, params, headers, max_retries=max_retries, timeout=timeout, axapi_args=axapi_args, **kwargs) diff --git a/acos_client/v30/responses.py b/acos_client/v30/responses.py index c9f4fca2..09b6351d 100644 --- a/acos_client/v30/responses.py +++ b/acos_client/v30/responses.py @@ -200,6 +200,16 @@ '*': ae.Exists } }, + 1023464192: { + '*': { + '*': ae.ACOSSystemNotReady + } + }, + 1023464193: { + '*': { + '*': ae.ACOSSystemIsBusy + } + }, 1023475727: { '*': { '*': ae.NotFound diff --git a/acos_client/v30/system.py b/acos_client/v30/system.py index fc6c3c37..a85960c9 100644 --- a/acos_client/v30/system.py +++ b/acos_client/v30/system.py @@ -31,3 +31,8 @@ def partition(self): def information(self): return self._get("/system") + + def stats(self, name='', max_retries=None, timeout=None, **kwargs): + return self._get("/system/" + name + '/stats', + max_retries=max_retries, timeout=timeout, + **kwargs) diff --git a/acos_client/version.py b/acos_client/version.py index 71936a03..c1745784 100644 --- a/acos_client/version.py +++ b/acos_client/version.py @@ -12,4 +12,4 @@ # License for the specific language governing permissions and limitations # under the License. -VERSION = '2.6.1' +VERSION = '2.7.0' diff --git a/requirements.txt b/requirements.txt index d7be1a21..3a7c54ab 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ requests>=2.3.0 six -uhashring +uhashring==1.2 ipaddress==1.0.22; python_version < '3.0' diff --git a/setup.py b/setup.py index 2679fd0e..da97c5e7 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name = "acos-client", - version = "2.6.1", + version = "2.7.0", packages = find_packages(), author = "A10 Networks",