Skip to content

Commit 3510c46

Browse files
Merge pull request #14 from dka-li/snapshot-teanant
Add option to specify tenant when creating snapshot
2 parents e9360f3 + 9bc472d commit 3510c46

4 files changed

Lines changed: 33 additions & 6 deletions

File tree

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ try:
4141
aciclient.logout()
4242
except Exception as e:
4343
logger.exception("Stack Trace")
44-
4544
```
46-
For automatic authentication token refresh you can set refresh to True
45+
46+
For automatic authentication token refresh you can set variable ```refresh``` to True
47+
4748
```python
4849
aciclient = aciClient.ACI(apic_hostname, apic_username, apic_password, refresh=True)
4950
```
@@ -96,8 +97,9 @@ aciclient.deleteMo('uni/tn-XYZ')
9697
```
9798

9899
### create snapshot
100+
You can specify a tenant in variable ```target_dn``` or not provide any to do a fabric-wide snapshot.
99101
```python
100-
aci.snapshot('test')
102+
aci.snapshot(description='test', target_dn='/uni/tn-test')
101103
```
102104

103105
## Testing

aciClient/aci.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def deleteMo(self, dn) -> int:
223223
# ==============================================================================
224224
# snapshot
225225
# ==============================================================================
226-
def snapshot(self, description="snapshot") -> bool:
226+
def snapshot(self, description="snapshot", target_dn="") -> bool:
227227
self.__logger.debug(f'snapshot called {description}')
228228

229229
json_payload = [
@@ -239,7 +239,7 @@ def snapshot(self, description="snapshot") -> bool:
239239
"name": "aciclient",
240240
"nameAlias": "",
241241
"snapshot": "yes",
242-
"targetDn": ""
242+
"targetDn": f"{target_dn}"
243243
}
244244
}
245245
}

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
long_description = f.read()
88

99
setup(name='aciClient',
10-
version='1.3',
10+
version='1.4',
1111
description='aci communication helper class',
1212
url='http://www.netcloud.ch',
1313
author='mze',

test/test_aci.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,3 +255,28 @@ def test_snapshot_nok(requests_mock):
255255
aci.login()
256256
resp = aci.snapshot(description='unit_test')
257257
assert not resp
258+
259+
def test_snapshot_tenant_ok(requests_mock):
260+
requests_mock.post(f'https://{__BASE_URL}/api/mo.json', json={"totalCount": "0", "imdata": []})
261+
requests_mock.post(f'https://{__BASE_URL}/api/aaaLogin.json', json={'imdata': [
262+
{'aaaLogin': {'attributes': {'token': 'tokenxyz'}}}
263+
]})
264+
265+
aci = ACI(apicIp=__BASE_URL, apicUser='admin', apicPasword='unkown')
266+
aci.login()
267+
resp = aci.snapshot(description='unit_test', target_dn='/uni/tn-test')
268+
assert resp
269+
270+
271+
def test_snapshot_tenant_nok(requests_mock):
272+
requests_mock.post(f'https://{__BASE_URL}/api/mo.json',
273+
json={"totalCount": "0", "imdata": [{"error": {"attributes": {"text": "Error UnitTest"}}}]},
274+
status_code=400)
275+
requests_mock.post(f'https://{__BASE_URL}/api/aaaLogin.json', json={'imdata': [
276+
{'aaaLogin': {'attributes': {'token': 'tokenxyz'}}}
277+
]})
278+
279+
aci = ACI(apicIp=__BASE_URL, apicUser='admin', apicPasword='unkown')
280+
aci.login()
281+
resp = aci.snapshot(description='unit_test', target_dn='/uni/tn-test')
282+
assert not resp

0 commit comments

Comments
 (0)