Exemplo n.º 1
0
 def manage_update_vlan_exception(self, message, number):
     if "being used by" in message:
         raise VlanAlreadyExist(number)
     elif "not within range" in message:
         if message.startswith("Value"):
             raise BadVlanNumber()
     elif "Must be a string" in message:
         raise BadVlanName()
Exemplo n.º 2
0
    def add_vlan(self, number, name=None):
        result = self._show_vlan(number)
        if not result[0].startswith("Error"):
            raise VlanAlreadyExist(number)

        with self.config():
            result = self.shell.do('vlan {}{}'.format(number, " name {}".format(name) if name else ""))
            if len(result) > 0:
                if result[0].startswith("Error:"):
                    raise BadVlanNumber()
                else:
                    raise BadVlanName()
            else:
                self.shell.do('exit')
Exemplo n.º 3
0
    def add_vlan(self, number, name=None):
        if self._show_run_vlan(number):
            raise VlanAlreadyExist(number)

        with self.config():
            result = self.ssh.do('vlan {}'.format(number))
            if len(result) > 0:
                raise BadVlanNumber()
            else:
                if name:
                    result = self.ssh.do('name {}'.format(name))

                self.ssh.do('exit')

                if len(result) > 0:
                    raise BadVlanName()
Exemplo n.º 4
0
def is_vlan(data, **_):
    try:
        json_data = json.loads(data)
    except ValueError:
        raise BadRequest("Malformed content, should be a JSON object")

    if "number" not in json_data:
        raise BadVlanNumber()

    name = json_data["name"] if "name" in json_data and len(json_data["name"]) > 0 else None
    if name and " " in name:
        raise BadVlanName()

    return {
        'number': is_vlan_number(json_data["number"])['vlan_number'],
        'name': name
    }
Exemplo n.º 5
0
    def add_vlan(self, number, name=None):
        if not isvlan(number):
            raise BadVlanNumber()
        try:
            self.node.enable(["show vlan {}".format(number)], strict=True)
            raise VlanAlreadyExist(number)
        except CommandError:
            pass

        commands = ["vlan {}".format(number)]
        if name is not None:
            commands.append("name {}".format(name))

        try:
            self.node.config(commands)
        except CommandError:
            raise BadVlanName()
Exemplo n.º 6
0
    def add_vlan(self, number, name=None):
        result = self.shell.do("show vlan id {}".format(number))
        if regex.match(".*\^.*", result[0]):
            raise BadVlanNumber()
        elif regex.match("^VLAN", result[0]):
            raise VlanAlreadyExist(number)

        with self.config():
            result = self.shell.do('vlan {}'.format(number))
            if len(result) > 0:
                raise BadVlanNumber()
            else:
                if name:
                    result = self.shell.do('name {}'.format(name))

                self.shell.do('exit')

                if len(result) > 0:
                    raise BadVlanName()
Exemplo n.º 7
0
    def add_vlan(self, number, name=None):
        config = self.query(all_vlans)

        try:
            self.get_vlan_config(number, config)
            raise VlanAlreadyExist(number)
        except UnknownVlan:
            pass

        update = Update()
        update.add_vlan(vlan_update(number, name))

        try:
            self._push(update)
        except RPCError as e:
            if "being used by" in e.message:
                raise VlanAlreadyExist(number)
            elif "not within range" in e.message:
                if e.message.startswith("Value"):
                    raise BadVlanNumber()
                elif e.message.startswith("Length"):
                    raise BadVlanName()

            raise