From 330bde966dd538fe0f9e05da501fc9dfbdf866d3 Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 17:03:48 +0100 Subject: [PATCH 1/4] Add option for targetDN in snapshot --- aciClient/aci.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aciClient/aci.py b/aciClient/aci.py index 48c9f06..135b8df 100644 --- a/aciClient/aci.py +++ b/aciClient/aci.py @@ -223,7 +223,7 @@ def deleteMo(self, dn) -> int: # ============================================================================== # snapshot # ============================================================================== - def snapshot(self, description="snapshot") -> bool: + def snapshot(self, description="snapshot", target_dn="") -> bool: self.__logger.debug(f'snapshot called {description}') json_payload = [ @@ -239,7 +239,7 @@ def snapshot(self, description="snapshot") -> bool: "name": "aciclient", "nameAlias": "", "snapshot": "yes", - "targetDn": "" + "targetDn": f"{target_dn}" } } } From 03284eed4ea0635dce48c0296f9cf2a83a26a7b5 Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 17:15:37 +0100 Subject: [PATCH 2/4] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 914d536..b5bf26f 100644 --- a/README.md +++ b/README.md @@ -41,9 +41,10 @@ try: aciclient.logout() except Exception as e: logger.exception("Stack Trace") - ``` -For automatic authentication token refresh you can set refresh to True + +For automatic authentication token refresh you can set variable ```refresh``` to True + ```python aciclient = aciClient.ACI(apic_hostname, apic_username, apic_password, refresh=True) ``` @@ -96,8 +97,9 @@ aciclient.deleteMo('uni/tn-XYZ') ``` ### create snapshot +You can specify a tenant in variable ```target_dn``` or not provide any to do a fabric-wide snapshot. ```python -aci.snapshot('test') +aci.snapshot(description='test', target_dn='/uni/tn-test') ``` ## Testing From 1a0dcc13a79246bb75eafa740435425216c52cb3 Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 17:20:14 +0100 Subject: [PATCH 3/4] Added snapshot per tenant test --- test/test_aci.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/test/test_aci.py b/test/test_aci.py index 80160e1..c1ae15e 100644 --- a/test/test_aci.py +++ b/test/test_aci.py @@ -255,3 +255,28 @@ def test_snapshot_nok(requests_mock): aci.login() resp = aci.snapshot(description='unit_test') assert not resp + +def test_snapshot_tenant_ok(requests_mock): + requests_mock.post(f'https://{__BASE_URL}/api/mo.json', json={"totalCount": "0", "imdata": []}) + requests_mock.post(f'https://{__BASE_URL}/api/aaaLogin.json', json={'imdata': [ + {'aaaLogin': {'attributes': {'token': 'tokenxyz'}}} + ]}) + + aci = ACI(apicIp=__BASE_URL, apicUser='admin', apicPasword='unkown') + aci.login() + resp = aci.snapshot(description='unit_test', target_dn='/uni/tn-test') + assert resp + + +def test_snapshot_tenant_nok(requests_mock): + requests_mock.post(f'https://{__BASE_URL}/api/mo.json', + json={"totalCount": "0", "imdata": [{"error": {"attributes": {"text": "Error UnitTest"}}}]}, + status_code=400) + requests_mock.post(f'https://{__BASE_URL}/api/aaaLogin.json', json={'imdata': [ + {'aaaLogin': {'attributes': {'token': 'tokenxyz'}}} + ]}) + + aci = ACI(apicIp=__BASE_URL, apicUser='admin', apicPasword='unkown') + aci.login() + resp = aci.snapshot(description='unit_test', target_dn='/uni/tn-test') + assert not resp From 9bc472dfcff7ed95bbfed0b5d965dd451e4b0a9c Mon Sep 17 00:00:00 2001 From: dka-li <57945737+dka-li@users.noreply.github.com> Date: Mon, 22 Nov 2021 17:20:53 +0100 Subject: [PATCH 4/4] Update setup.py --- setup.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/setup.py b/setup.py index 62f801c..a6402fd 100644 --- a/setup.py +++ b/setup.py @@ -7,14 +7,14 @@ long_description = f.read() setup(name='aciClient', - version='1.3', + version='1.4', description='aci communication helper class', url='http://www.netcloud.ch', author='mze', author_email='nc_dev@netcloud.ch', license='MIT', packages=['aciClient'], - install_requires=['requests>=2.25.0 , <3', 'pyOpenSSL>=19.1.0, <20'], + install_requires=['requests>=2.26.0 , <3', 'pyOpenSSL>=21.0.0, <22'], long_description=long_description, long_description_content_type='text/markdown', python_requires=">=3.6",