Exemple #1
0
    def _logical_iface(self, remove=False, stage=False):
        """Stage or execute the configuration to create
        or remove a logical interface.

        Args:
            remove (bool): If ``True``, the logical
                interface is removed. If ``False``,
                the logical interface is created.

            stage (bool): whether to stage the commands or execute
                immediately

        Returns:
            True if stage=True and staging is successful
            etree.Element XML response if immediate execution
        """
        logic_type_map = {
            'LoopBack': '16',
            'Vlan-interface': '41',
            'Bridge-Aggregation': '56',
            'Route-Aggregation': '67'
        }

        if self.iface_type not in logic_type_map:
            raise InterfaceCreateError(self.interface_name)

        iface_number = self.interface_name.split(self.iface_type)[1]

        E = action_element_maker()
        top = E.top(
            E.Ifmgr(
                E.LogicInterfaces(
                    E.Interface(E.IfTypeExt(logic_type_map[self.iface_type]),
                                E.Number(iface_number)))))

        if remove:
            find_in_action('Interface', top).append(E.Remove())

        if stage:
            return self.device.stage_config(top, 'action')
        else:
            return self.device.action(top)
Exemple #2
0
    def update(self):
        """Update ``self.iface_index`` and ``self.iface_exists``.

        Usually called after a logical interface is created.

        Raises:
            InterfaceCreateError: if the interface hasn't yet
                been successfully created.

        Note:
            It is the responsibility of the caller to call ``update()`
            after staging (``create_logical()``) *and* executing
            (``execute()`` on this class's ``device`` object) of
            commands to create an interface.
         """
        if_index = self._get_iface_index()
        if not if_index:
            raise InterfaceCreateError(self.interface_name)
        self.iface_index = if_index
        self.iface_exists = True