Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
```
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions aciClient/aci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand All @@ -239,7 +239,7 @@ def snapshot(self, description="snapshot") -> bool:
"name": "aciclient",
"nameAlias": "",
"snapshot": "yes",
"targetDn": ""
"targetDn": f"{target_dn}"
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pyOpenSSL>=19.1.0, <20
requests>=2.25.0 , <3
pyOpenSSL>=21.0.0, <22
requests>=2.26.0 , <3
requests-mock
pytest
flake8
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
25 changes: 25 additions & 0 deletions test/test_aci.py
Original file line number Diff line number Diff line change
Expand Up @@ -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