2 Utility library for retrieving entity related data from ODL.
5 from logging import debug, warning
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" : {
47 debug("Data %s", data)
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"),
70 all_entities = get_entities(restconf_url)
78 "candidates": resp.json()["odl-entity-owners:output"]["candidate-nodes"],
79 "owner": resp.json()["odl-entity-owners:output"]["owner-node"],
85 def get_entity_owner(restconf_url, type, name):
88 "odl-entity-owners:input" : {
98 debug("Data %s", data)
101 url=restconf_url + """/operations/odl-entity-owners:get-entity-owner""",
103 "Content-Type": "application/json",
104 "Accept": "application/json",
105 "User-Agent": "csit agent",
108 auth=("admin", "admin"),
116 return resp.json()["odl-entity-owners:output"]["owner-node"]
120 if args[0] == "get-entities":
122 restconf_url="http://127.0.0.1:8181/rests",
125 elif args[0] == "get-entity":
127 restconf_url="http://127.0.0.1:8181/rests",
132 elif args[0] == "get-entity-owner":
133 json = get_entity_owner(
134 restconf_url="http://127.0.0.1:8181/rests",
140 raise Exception("Unhandled argument %s" % args[0])
143 if __name__ == "__main__":
144 # i.e. main does not depend on name of the binary