backend CHANGE update inventory schemas list after a device connect
Connecting a device may add some new schemas received from the device
into the searchpath location. So far, it was enough to update the
schemas list only when showing schemas inventory, but with linking
schemas (displaying in YANG Explorer) from the configuration data,
it is necessary to have the schemas list updated immediately after the
device is connected.
diff --git a/backend/connections.py b/backend/connections.py
index 4d2a2bb..e4d969e 100644
--- a/backend/connections.py
+++ b/backend/connections.py
@@ -19,6 +19,7 @@
from .inventory import INVENTORY
from .devices import devices_get, devices_replace
from .error import NetopeerException
+from .schemas import schemas_update
from .data import *
log = logging.getLogger(__name__)
@@ -157,6 +158,9 @@
sessions[user.username][key] = {}
sessions[user.username][key]['session'] = ncs
+ # update inventory's list of schemas
+ schemas_update(path)
+
return(json.dumps({'success': True, 'session-key': key}))
diff --git a/backend/schemas.py b/backend/schemas.py
index bf08f1b..7230aed 100644
--- a/backend/schemas.py
+++ b/backend/schemas.py
@@ -115,7 +115,7 @@
return schemas
-def __schemas_update(path):
+def schemas_update(path):
# get schemas database
schemas = __schemas_inv_load(path)
@@ -170,7 +170,7 @@
path = os.path.join(INVENTORY, user.username)
inventory_check(path)
- schemas = __schemas_update(path)
+ schemas = schemas_update(path)
result = []
for key in schemas:
@@ -231,8 +231,8 @@
'revision':schemas['schemas'][key]['revision']}, ensure_ascii = False))
else:
return(json.dumps({'success': True, 'data': data, 'name':schemas['schemas'][key]['name']}, ensure_ascii = False))
- except:
- pass;
+ except Exception as e:
+ return(json.dumps({'success': False, 'error-msg':str(e)}));
return(json.dumps({'success': False, 'error-msg':'Schema ' + key + ' not found.'}))