示例#1
0
 def _build_iface_updown(self, iface_list, updown):
     """Stage commands to bring the interfaces up or down.
     """
     for iface_name in iface_list:
         iface = Interface(self.device, iface_name)
         if not iface.iface_exists:
             raise InterfaceAbsentError(iface.interface_name)
         iface.build(stage=True, admin=updown)
示例#2
0
 def _build_mad_exclude(self, iface_list):
     """Build the configuration for adding interfaces
     to the mad exclude list.
     """
     for iface_name in iface_list:
         iface = Interface(self.device, iface_name)
         if not iface.iface_exists:
             raise InterfaceAbsentError(iface.interface_name)
         if not self.device.stage_config(
                 'mad exclude interface {0}'.format(iface.interface_name),
                 'cli_config'):
             return False
     return True
示例#3
0
    def param_check(self, **params):
        """Checks given parameters against the interface for various errors.

        Args:
            **params: see Keyword Args

        Keyword Args:
            admin (str): The up/down state of the interface.
                'up' or 'down'.
            speed (str): The speed of the interface, in Mbps.
            duplex (str): The duplex of the interface.
                'full', 'half', or 'auto'.
            description (str): The textual description of the interface.
            type (str): Whether the interface is in layer 2 or layer 3 mode.
                'bridged' or 'routed'.

        Raises:
            InterfaceTypeError: if the given interface isn't a valid type.
            InterfaceAbsentError: if the given interface is of type is_ethernet
                and doesn't exist.
            InterfaceParamsError: if 'speed' or 'duplex' are supplied for a
                non ethernet interface.
            InterfaceVlanMustExist: if the interface is of type
                'Vlan-interface' and the the associated vlan doesn't exist.
        """
        if not self.iface_type:
            raise InterfaceTypeError(self.interface_name,
                                     list(self._iface_types))

        if not self.iface_exists:
            if self.iface_type in {
                    'FortyGigE', 'GigabitEthernet', 'TwentyGigE',
                    'Ten-GigabitEthernet', 'HundredGigE'
            }:
                raise InterfaceAbsentError(self.interface_name)

        if not self.is_ethernet:
            param_names = []
            if params.get('speed'):
                param_names.append('speed')
            if params.get('duplex'):
                param_names.append('duplex')
            if param_names:
                raise InterfaceParamsError(self.interface_name, param_names)

        if self.iface_type == 'Vlan-interface':
            number = self.interface_name.split('Vlan-interface')[1]
            vlan = Vlan(self.device, number)
            if not vlan.get_config():
                raise InterfaceVlanMustExist(self.interface_name, number)