NODES_API = REST_API + "nodes/"
SLICES_API = REST_API + "slices/"
SLIVERS_API = REST_API + "slivers/"
+NETWORKSLIVERS_API = REST_API + "networkslivers/"
opencloud_auth=("demo@onlab.us", "demo")
return r.json()[0]["id"]
def get_node_id(host_name):
- r = requests.get(NODES_API + "?name=%s" % host_name, auth=opencloud_auth)
- return r.json()[0]["id"]
+ r = requests.get(NODES_API)
+ nodes = r.json()
+ for node in nodes:
+ if node["name"].lower() == host_name.lower():
+ return node["id"]
+ print >> sys.stderr, "Error: failed to find node %s" % host_name
+ sys.exit(-1)
def get_slivers(slice_id=None, node_id=None):
queries = []
# get (instance_name, ip) pairs for instances with names and ips
- slivers = [x for x in slivers if x["instance_name"] and x["ip"]]
+ slivers = [x for x in slivers if x["instance_name"]]
slivers = sorted(slivers, key = lambda sliver: sliver["instance_name"])
# return the last one in the list (i.e. the newest one)
- print slivers[-1]["ip"]
+ sliver_id = slivers[-1]["id"]
+
+ r = requests.get(NETWORKSLIVERS_API + "?sliver=%s" % sliver_id, auth=opencloud_auth)
+
+ networkSlivers = r.json()
+ ips = [x["ip"] for x in networkSlivers]
+
+ # XXX kinda hackish -- assumes private ips start with "10." and nat start with "172."
+
+ # print a public IP if there is one
+ for ip in ips:
+ if (not ip.startswith("10")) and (not ip.startswith("172")):
+ print ip
+ return
+
+ # otherwise print a privat ip
+ for ip in ips:
+ if (not ip.startswith("172")):
+ print ip
+ return
+
+ # otherwise just print the first one
+ print ips[0]
if __name__ == "__main__":
main()