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
Branches
Tags
No related merge requests found
...@@ -7,7 +7,10 @@ from enum import Enum ...@@ -7,7 +7,10 @@ from enum import Enum
# Navigation Properties # 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 # http://149.210.162.190:81/ImsVersions/4.19.9/html/2d27d509-77cb-537d-3ffa-796de7e82af8.htm # noqa
NODE_PROPERTIES = { NODE_PROPERTIES = {
'equipment definition': 16, 'equipment definition': 16,
...@@ -84,6 +87,7 @@ class IMS(object): ...@@ -84,6 +87,7 @@ class IMS(object):
response.raise_for_status() response.raise_for_status()
cls.bearer_token_init_time = re_init_time cls.bearer_token_init_time = re_init_time
cls.bearer_token = response.json() cls.bearer_token = response.json()
print(f'New token issued: {cls.bearer_token}') # Remove after demo
def _get_entity( def _get_entity(
self, self,
...@@ -110,7 +114,7 @@ class IMS(object): ...@@ -110,7 +114,7 @@ class IMS(object):
return entity return entity
if not IMS.bearer_token: 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_): def _is_invalid_login_state(response_):
if response_.status_code == requests.codes.unauthorized: if response_.status_code == requests.codes.unauthorized:
...@@ -118,6 +122,10 @@ class IMS(object): ...@@ -118,6 +122,10 @@ class IMS(object):
if response_.status_code == requests.codes.ok: if response_.status_code == requests.codes.ok:
j = response_.json() 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 \ if j and isinstance(j, dict) and \
j.get('HasErrors', False) and 'guid expired' in \ j.get('HasErrors', False) and 'guid expired' in \
j['Errors'][0]['ErrorMessage'].lower(): j['Errors'][0]['ErrorMessage'].lower():
...@@ -203,10 +211,11 @@ if __name__ == '__main__': ...@@ -203,10 +211,11 @@ if __name__ == '__main__':
username = sys.argv[1] username = sys.argv[1]
password = sys.argv[2] password = sys.argv[2]
ims = IMS('http://83.97.94.128:81/api', username, password) ims = IMS('http://83.97.94.128:81/api', username, password)
i = ims.get_entity_by_name( i = ims.get_entity_by_id(
'Site', sys.argv[3],
'London', sys.argv[4],
SITE_PROPERTIES.values()) sys.argv[5] if len(sys.argv) > 5 else None
print(i) )
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.
Please register or to comment