2 Utility library for retrieving entity related data from ODL.
5 from logging import info
6 from requests import post
10 def get_entities(restconf_url):
12 url=restconf_url + """/operations/odl-entity-owners:get-entities""",
14 "Content-Type": "application/json",
15 "Accept": "application/json",
16 "User-Agent": "csit agent",
18 auth=("admin", "admin"),
29 def get_entity(restconf_url, type, name):
30 """Calls the get-entity rpc on the controller and returns the result in a
31 dictionary that contains the parsed response in two keys:
32 "candidates" and "owner"
37 "odl-entity-owners:input" : {
50 url=restconf_url + """/operations/odl-entity-owners:get-entity""",
52 "Content-Type": "application/json",
53 "Accept": "application/json",
54 "User-Agent": "csit agent",
57 auth=("admin", "admin"),
66 "candidates": resp.json()["odl-entity-owners:output"]["candidate-nodes"],
67 "owner": resp.json()["odl-entity-owners:output"]["owner-node"],
73 def get_entity_owner(restconf_url, type, name):
76 "odl-entity-owners:input" : {
89 url=restconf_url + """/operations/odl-entity-owners:get-entity-owner""",
91 "Content-Type": "application/json",
92 "Accept": "application/json",
93 "User-Agent": "csit agent",
96 auth=("admin", "admin"),
104 return resp.json()["odl-entity-owners:output"]["owner-node"]
108 if args[0] == "get-entities":
110 restconf_url="http://127.0.0.1:8181/rests",
113 elif args[0] == "get-entity":
115 restconf_url="http://127.0.0.1:8181/rests",
120 elif args[0] == "get-entity-owner":
121 json = get_entity_owner(
122 restconf_url="http://127.0.0.1:8181/rests",
128 raise Exception("Unhandled argument %s" % args[0])
131 if __name__ == "__main__":
132 # i.e. main does not depend on name of the binary