Skip to content
Snippets Groups Projects
Commit 388155eb authored by Robert Latta's avatar Robert Latta
Browse files

additional logn check; added circuit navigation properties

parent 54888ff2
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,10 @@ from enum import Enum
# Navigation Properties
# http://149.210.162.190:81/ImsVersions/4.19.9/html/86d07a57-fa45-835e-d4a2-a789c4acbc96.htm # noqa
CIRCUIT_PROPERTIES = {
'InternalPorts': 1024
}
# http://149.210.162.190:81/ImsVersions/4.19.9/html/2d27d509-77cb-537d-3ffa-796de7e82af8.htm # noqa
NODE_PROPERTIES = {
'equipment definition': 16,
......@@ -84,6 +87,7 @@ class IMS(object):
response.raise_for_status()
cls.bearer_token_init_time = re_init_time
cls.bearer_token = response.json()
print(f'New token issued: {cls.bearer_token}') # Remove after demo
def _get_entity(
self,
......@@ -110,7 +114,7 @@ class IMS(object):
return entity
if not IMS.bearer_token:
self._init_bearer_token(self.username, self.password)
IMS._init_bearer_token(self.username, self.password)
def _is_invalid_login_state(response_):
if response_.status_code == requests.codes.unauthorized:
......@@ -118,6 +122,10 @@ class IMS(object):
if response_.status_code == requests.codes.ok:
j = response_.json()
if j is None:
# Sometime the API returns a 200 response but with no
# body when the token has expired e.g. on a filtered query
return True
if j and isinstance(j, dict) and \
j.get('HasErrors', False) and 'guid expired' in \
j['Errors'][0]['ErrorMessage'].lower():
......@@ -203,10 +211,11 @@ if __name__ == '__main__':
username = sys.argv[1]
password = sys.argv[2]
ims = IMS('http://83.97.94.128:81/api', username, password)
i = ims.get_entity_by_name(
'Site',
'London',
SITE_PROPERTIES.values())
print(i)
i = ims.get_entity_by_id(
sys.argv[3],
sys.argv[4],
sys.argv[5] if len(sys.argv) > 5 else None
)
print(json.dumps(i, indent=4, sort_keys=True))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment