예제 #1
0
    def getVlan(self, vlans):
        dict_requested = get_vlanSet(vlans)
        list_requested = sorted(dict_requested.keys())

        logger.debug("freed:green: %d, yellow: %d, used: %d, allowed: %d" %
                     (len(self.dict_freed_green), len(self.dict_freed_yellow),
                      len(self.dict_used), len(self.dict_allowed)))

        if len(self.dict_freed_green) == 0:
            if len(self.dict_freed_yellow) != 0:
                self.dict_freed_green = self.dict_freed_yellow.copy()
                self.dict_freed_yellow = {}

        for v in list_requested:
            if self.dict_freed_green.has_key(v):
                del self.dict_freed_green[v]
                self.dict_used[v] = int(v)
                return v

        for v in list_requested:
            if self.dict_freed_yellow.has_key(v):
                del self.dict_freed_yellow[v]
                self.dict_used[v] = int(v)
                return v

        raise tnex.ParamException("vlanManager:getVlan",
                                  "This vlan (%s) is not freed." % (vlans))
예제 #2
0
    def checkVlan(self, vlan):
        if self.dict_allowed.has_key(vlan):
            return True

        logger.info("checkVlans: False")
        raise tnex.ParamException("vlanManager:checkVlan",
                                  "This vlan (%s) is not allowed." % (vlan))
예제 #3
0
    def __init__(self, stp, vlans):
        self.stp = stp
        self.allowed_vlans = vlans
        self.dict_freed_green = {}
        self.dict_freed_yellow = {}
        self.dict_used = {}

        if vlans is None:
            vlans = "2-4094"

        self.dict_allowed = get_vlanSet(vlans)

        if stp is None:
            raise tnex.ParamException("vlanManager:init", "This stp is None.")
        if dict_vlanManagers.has_key(stp):
            raise tnex.ParamException("vlanManager:init",
                                      "This stp (%s) already exist." % (stp))

        dict_vlanManagers[stp] = self
        self.dict_freed_green = self.dict_allowed.copy()

        logger.debug("nsi stp: %s, vlans: %s" % (stp, vlans))
예제 #4
0
def get_vlanSet(vlans):
    dict_vlans = {}

    if vlans is not None:
        try:
            vv = vlans.split(",")
            for v in vv:
                vvv = v.split("-")
                if (len(vvv) == 2):
                    for i in range(int(vvv[0]), int(vvv[1]) + 1):
                        dict_vlans[str(i)] = i
                else:
                    s = v.strip()
                    dict_vlans[s] = int(s)

        except Exception as e:
            raise tnex.ParamException(
                "vlanManager:",
                "This vlan parameter (%s) is bad format." % (vlans))

    return dict_vlans
예제 #5
0
def get_vlanManager(stp):
    if dict_vlanManagers.has_key(stp):
        return dict_vlanManagers.has_key[stp]

    raise tnex.ParamException("vlanManagers:getVlanManager",
                              "This stp (%s) does not exist." % (stp))