except Exception as e: pass request_resources() #NETResourcesView.load_topology() NETManagersView.CRS_DISABLE=options.CRS_DISABLE NETManagersView.IGNORE_IRMS=options.IGNORE_IRMS NETManagersView.CRS_HOST = options.CRS_HOST NETManagersView.CRS_PORT = options.CRS_PORT NETManagersView.PORT = options.PORT log = logging.getLogger('werkzeug') log.setLevel(logging.ERROR) if not NETManagersView.CRS_DISABLE: NETManagersView.register_crs() print "running..." mgr.run(options.PORT)
def _create_reservation(self, scheduler, alloc_req, alloc_constraints, monitor): NETManagersView.expect_ready_manager() groups = {} #print "alloc_req=", json.dumps(alloc_req) #print "monitor=", monitor NETResourcesView()._get_alloc_spec() # first check that we can support all allocation requests for req in alloc_req: if req["Type"] not in NETReservationsView.SupportedTypes: raise Exception("Do not support allocation request type: %s!" % req["Type"]) # add original order, so that we do not lose it when we sort n = 1 for elem in alloc_req: elem['pos'] = n n = n + 1 # sort the allocation requests salloc_req = sorted(alloc_req, key=lambda x: NETReservationsView.SupportedTypes[x["Type"]]) #print "salloc_req=", json.dumps(salloc_req) reservations=[] rollback = False error_msg = "" try: for req in salloc_req: if req["Type"] in NETResourcesView.ManagersTypes: manager = NETManagersView.managers[NETResourcesView.ManagersTypes[req["Type"]]] else: manager = None if req["Type"] == "PublicIP" and "Attributes" in req and "VM" in req["Attributes"] and \ req["Attributes"]["VM"] in groups: req["Attributes"]["VM"] = groups[req["Attributes"]["VM"]]["resID"] if req["Type"] == "Link" and "Attributes" in req and "Source" in req["Attributes"] and \ req["Attributes"]["Source"] in groups: req["Attributes"]["Source"] = groups[req["Attributes"]["Source"]]["ID"] if req["Type"] == "Link" and "Attributes" in req and "Target" in req["Attributes"] and \ req["Attributes"]["Target"] in groups: req["Attributes"]["Target"] = groups[req["Attributes"]["Target"]]["ID"] if manager != None: ret = post({"Allocation": [req], "Monitor": monitor}, "createReservation", \ manager["Port"], manager["Address"]) elif req["Type"] == "Link": topology = NETResourcesView.Topology id = link_create_reservation(topology["links"], topology["paths"], topology["link_list"],\ NETReservationsView.LinkReservations, req) ret = { "result": { "ReservationID": [id] }} else: raise Exception("internal error: type %s not supported!" % req["Type"]) if "result" in ret and "ReservationID" in ret["result"]: rID = ret["result"]["ReservationID"] if len(rID) != 1: raise Exception("Wrong reservation ID (%s), expecting one element; manager info: %s" % (str(rID), str(manager))) if "Group" in req: groups[req["Group"]] = {"resID": rID[0] } # reservation ID if "ID" in req: groups[req["Group"]]["ID"] = req["ID"] # ID of the physical resource if manager: reservations.append({ "addr": manager["Address"], "port": manager["Port"], \ "name": manager["Name"], "ManagerID": manager["ManagerID"], \ "iRes": rID, "pos": req["pos"], "type": req["Type"] }) else: reservations.append({ "addr": None, "port": None, \ "name": "IRM-NET", "ManagerID": None, \ "iRes": rID, "pos": req["pos"], "type": req["Type"] }) else: raise Exception("internal error: %s" % str(ret)) except Exception as e: print "rolling back! " + str(e) error_msg = str(e) rollback = True if not rollback: resID = uuid.uuid1() ReservationsView.reservations[str(resID)] = reservations else: for iResID in reservations[::-1]: print "backtracking...%s" % str(iResID) data = {"ReservationID": iResID["iRes"]} try: hresman.utils.delete_(data, 'releaseReservation', iResID["port"], iResID["addr"]) except: pass raise Exception("cannot make reservation! (rollbacking): %s" % error_msg) return { "ReservationID" : [str(resID)] }
def _create_reservation(self, scheduler, alloc_req, alloc_constraints, monitor): NETManagersView.expect_ready_manager() groups = {} #print "alloc_req=", json.dumps(alloc_req) #print "monitor=", monitor NETResourcesView()._get_alloc_spec() # first check that we can support all allocation requests for req in alloc_req: if req["Type"] not in NETReservationsView.SupportedTypes: raise Exception("Do not support allocation request type: %s!" % req["Type"]) # add original order, so that we do not lose it when we sort n = 1 for elem in alloc_req: elem['pos'] = n n = n + 1 # sort the allocation requests salloc_req = sorted( alloc_req, key=lambda x: NETReservationsView.SupportedTypes[x["Type"]]) #print "salloc_req=", json.dumps(salloc_req) reservations = [] rollback = False error_msg = "" try: for req in salloc_req: if req["Type"] in NETResourcesView.ManagersTypes: manager = NETManagersView.managers[ NETResourcesView.ManagersTypes[req["Type"]]] else: manager = None if req["Type"] == "PublicIP" and "Attributes" in req and "VM" in req["Attributes"] and \ req["Attributes"]["VM"] in groups: req["Attributes"]["VM"] = groups[req["Attributes"] ["VM"]]["resID"] if req["Type"] == "Link" and "Attributes" in req and "Source" in req["Attributes"] and \ req["Attributes"]["Source"] in groups: req["Attributes"]["Source"] = groups[req["Attributes"] ["Source"]]["ID"] if req["Type"] == "Link" and "Attributes" in req and "Target" in req["Attributes"] and \ req["Attributes"]["Target"] in groups: req["Attributes"]["Target"] = groups[req["Attributes"] ["Target"]]["ID"] if manager != None: ret = post({"Allocation": [req], "Monitor": monitor}, "createReservation", \ manager["Port"], manager["Address"]) elif req["Type"] == "Link": topology = NETResourcesView.Topology id = link_create_reservation(topology["links"], topology["paths"], topology["link_list"],\ NETReservationsView.LinkReservations, req) ret = {"result": {"ReservationID": [id]}} else: raise Exception("internal error: type %s not supported!" % req["Type"]) if "result" in ret and "ReservationID" in ret["result"]: rID = ret["result"]["ReservationID"] if len(rID) != 1: raise Exception( "Wrong reservation ID (%s), expecting one element; manager info: %s" % (str(rID), str(manager))) if "Group" in req: groups[req["Group"]] = { "resID": rID[0] } # reservation ID if "ID" in req: groups[req["Group"]]["ID"] = req[ "ID"] # ID of the physical resource if manager: reservations.append({ "addr": manager["Address"], "port": manager["Port"], \ "name": manager["Name"], "ManagerID": manager["ManagerID"], \ "iRes": rID, "pos": req["pos"], "type": req["Type"] }) else: reservations.append({ "addr": None, "port": None, \ "name": "IRM-NET", "ManagerID": None, \ "iRes": rID, "pos": req["pos"], "type": req["Type"] }) else: raise Exception("internal error: %s" % str(ret)) except Exception as e: print "rolling back! " + str(e) error_msg = str(e) rollback = True if not rollback: resID = uuid.uuid1() ReservationsView.reservations[str(resID)] = reservations else: for iResID in reservations[::-1]: print "backtracking...%s" % str(iResID) data = {"ReservationID": iResID["iRes"]} try: hresman.utils.delete_(data, 'releaseReservation', iResID["port"], iResID["addr"]) except: pass raise Exception("cannot make reservation! (rollbacking): %s" % error_msg) return {"ReservationID": [str(resID)]}