コード例 #1
0
    def _get_metrics(self, reservID, address, entry):
        #managers = copy.copy(crs_managers_view.CRSManagersView.managers)
        reservations = crs_reservations_view.CRSReservationsView.reservations

        if reservID not in reservations:
            raise Exception("cannot find reservation: " + reservID)

        resData = reservations[reservID]
        print "resData=", json.dumps(resData, indent=4)
        ret = {}
        for rd in resData:
            r = post({"ReservationID": rd['iRes']}, "checkReservation",
                     rd['port'], rd['addr'])
            if "result" not in r:
                raise Exception(
                    "error extracting address from reservationID: ", reservID)

            print "r['result'] =", json.dumps(r["result"], indent=4)
            instances = r["result"]["Instances"]

            for i in instances:
                status = instances[i]["Ready"]
                if type(status) is bool:
                    status = "TRUE"
                if status.upper() == "FALSE":
                    raise Exception("Reservation: " + i + " not ready!")

                for addr in instances[i]["Address"]:
                    if address == "" or addr == address:
                        print str({
                            "ReservationID": i,
                            "Address": addr,
                            "Entry": entry
                        })
                        r=post({ "ReservationID": i, "Address": addr, "Entry": entry }, "getMetrics",\
                               rd['port'], rd['addr'])
                        if "result" not in r:
                            raise Exception("Cannot get metrics: " + str(r))
                        ret[addr] = r["result"]["Metrics"]
        return {"Metrics": ret}

        raise Exception("Cannot find address for reservation: " + reservID)
コード例 #2
0
    def _get_metrics(self, reservID, address, entry):
        try:
            ret = post(
                {
                    "ReservationID": reservID,
                    "Address": address,
                    "Entry": entry
                }, "getResourceValueStore", 12000, self.config['ORCH_IP'])

            return {"Metrics": ret}
        except:
            raise Exception("Cannot connect monitoring agent!")
コード例 #3
0
def register_monitor(data, IP, IP_IB, rID):
    try:
        if 'DFECluster' not in data:
            return

        req_metrics = copy.deepcopy(data['DFECluster'])

        for metric in req_metrics:
            if metric == "DFE_UTILISATION":
                req_metrics[metric]['command'] = "maxtop -r %s^%s -v | grep \"FPGA usage\"" \
                                                 " | gawk '{ sub(\"%%\", \"\", $3); sum += $3; n++ } END" \
                                                 " { if (n > 0) print sum /n;}'" % (rID, IP_IB)
            elif metric == "DFE_POWER":
                req_metrics[metric]['command'] = "maxtop -r %s^%s -v | grep \"Power usage\"" \
                                                 " | gawk '{ sum += $3; n++ } END" \
                                                 " { if (n > 0) print sum /n;  }'" % (rID, IP_IB)
            elif metric == "DFE_TEMPERATURE":
                req_metrics[metric]['command'] = "maxtop -r %s^%s -v | grep \"Temperature\"" \
                                                 " | gawk '{ sub(\"C\", \"\", $3); sum += $3; n++ } END" \
                                                 " { if (n > 0) print sum/n; } ' " \
                                                 % (rID, IP_IB)
            elif metric != "PollTime":
                pass  # should probably give a warning
            req_metrics[metric]['type'] = "FLOAT"
            if 'PollTimeMultiplier' not in req_metrics[metric]:
                req_metrics[metric]['PollTimeMultiplier'] = 1

        if "PollTime" in req_metrics:
            polltime = req_metrics['PollTime']
            del req_metrics['PollTime']
        else:
            polltime = 1000

        ret = post(
            {
                "metrics": req_metrics,
                "instanceType": "generic",
                "PollTime": polltime,
                "uuid": rID
            }, "createAgent", 12000, IP)
    except Exception as e:
        print "[!] Monitoring agent not set up correctly!"
        pass
コード例 #4
0
def compute_capacity(managers, mgr_id, resource, request):
    if mgr_id not in managers:
        raise Exception("cannot find manager: " + mgr_id)

    addr = managers[mgr_id]['Address']
    port = managers[mgr_id]['Port']

    data = {
        'Resource': resource,
        "Allocation": [{
            "Attributes": request["Attributes"]
        }],
        "Release": []
    }
    ret = utils.post(data, 'calculateCapacity', port, addr)
    if "result" not in ret:
        raise Exception("cannot calculate capacity!")

    return ret["result"]
コード例 #5
0
 def _calculate_capacity(self, resource, allocation, release):
     net_managers_view.NETManagersView.expect_ready_manager()
     
     spec = self._get_alloc_spec()
     
     if resource["Type"] not in spec["Types"]:
        raise Exception("Type %s not supported!" % resource["Type"])
        
     if resource["Type"] == "Link": 
        ret = { "result": link_calc_capacity(resource, allocation, release) }
     else:
        manager = net_managers_view.NETManagersView.managers[NETResourcesView.ManagersTypes[resource["Type"]]]    
     
        ret = post({"Resource": resource, "Allocation": allocation, "Release": release}, \
                "calculateCapacity", manager["Port"], manager["Address"])
                
     if "result" not in ret:
        raise Exception("Error: %s", str(ret))           
              
     return ret["result"]                                                                              
コード例 #6
0
    def _calculate_capacity(self, resource, allocation, release):
        net_managers_view.NETManagersView.expect_ready_manager()

        spec = self._get_alloc_spec()

        if resource["Type"] not in spec["Types"]:
            raise Exception("Type %s not supported!" % resource["Type"])

        if resource["Type"] == "Link":
            ret = {"result": link_calc_capacity(resource, allocation, release)}
        else:
            manager = net_managers_view.NETManagersView.managers[
                NETResourcesView.ManagersTypes[resource["Type"]]]

            ret = post({"Resource": resource, "Allocation": allocation, "Release": release}, \
                    "calculateCapacity", manager["Port"], manager["Address"])

        if "result" not in ret:
            raise Exception("Error: %s", str(ret))

        return ret["result"]
コード例 #7
0
    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)] }          
コード例 #8
0
    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)]}