+ if resp.status_code == status_codes["bad_request"]:
+ info(
+ "Status code is '%s' - trying operational data instead.",
+ resp.status_code,
+ )
+ result = get_entity_owner_data(restconf_url, e_type, e_name)
+ else:
+ result = resp.json()["odl-entity-owners:output"]["owner-node"]
+
+ return result
+
+
+def get_entities_data(restconf_url):
+ """
+ Get the entity information from the datastore for Silicon
+ or earlier versions.
+ :param restconf_url: RESTCONF URL up to the RESTCONF root
+ """
+ resp = get(
+ url=restconf_url + "/data/entity-owners:entity-owners",
+ headers={
+ "Accept": "application/yang-data+json",
+ "User-Agent": "csit agent",
+ },
+ auth=("admin", "admin"),
+ timeout=10.0,
+ )
+
+ info(
+ "Response %s",
+ resp,
+ )
+ info(
+ "Response JSON %s",
+ resp.json(),
+ )
+
+ return resp.json()
+
+
+def get_entity_type_data(restconf_url, e_type):
+ """
+ Get the entity information for the given entity type from the datastore
+ for Silicon or earlier versions.
+ :param restconf_url: RESTCONF URL up to the RESTCONF root
+ :param e_type: entity type
+ :return: entity-type
+ """
+ resp = get(
+ url=restconf_url
+ + "/data/entity-owners:entity-owners"
+ + "/entity-type=%s" % e_type,
+ headers={
+ "Accept": "application/yang-data+json",
+ "User-Agent": "csit agent",
+ },
+ auth=("admin", "admin"),
+ timeout=10.0,
+ )
+
+ info(
+ "Response %s",
+ resp,
+ )
+ info(
+ "Response JSON %s",
+ resp.json(),
+ )
+
+ return resp.json()["entity-owners:entity-type"][0]
+
+
+def get_entity_data(restconf_url, e_type, e_name):
+ """
+ Get the entity owner & candidates for the given entity type
+ and entity name from the datastore for Silicon or earlier versions
+ :param restconf_url: RESTCONF URL up to the RESTCONF root
+ :param e_type: entity type
+ :param e_name: entity name
+ :return: entity owner & candidates
+ """
+ id_templates = {
+ "org.opendaylight.mdsal.ServiceEntityType": "/odl-general-entity:entity[name='%s']",
+ "org.opendaylight.mdsal.AsyncServiceCloseEntityType": "/odl-general-entity:entity[name='%s']",
+ "ovsdb": "/network-topology:network-topology/topology[topology-id='ovsdb:1']/node[node-id='%s']",
+ }
+ id_template = id_templates[e_type]
+
+ entity_type = get_entity_type_data(restconf_url, e_type)
+ entity = [e for e in entity_type["entity"] if e["id"] == id_template % e_name][0]
+
+ result = {
+ "candidates": [c["name"] for c in entity["candidate"]],
+ "owner": entity["owner"],
+ }
+
+ return result
+
+
+def get_entity_owner_data(restconf_url, e_type, e_name):
+ """
+ Get the entity owner for the given entity type and entity name
+ from the datastore for Silicon or earlier versions
+ :param restconf_url: RESTCONF URL up to the RESTCONF root
+ :param e_type: entity type
+ :param e_name: entity name
+ :return: entity owner
+ """
+ entity = get_entity_data(restconf_url, e_type, e_name)
+ return entity["owner"]