Пример #1
0
    def mpls_path_create(self, **kwargs):
        """ Configure/get/delete router mpls path

        Args:
            path_name (str). Define path name.
            get (bool): Get config instead of editing config. (True, False)
            delete (bool): Delete config. (True, False)
            callback (function): A function executed upon completion of the
                method.  The only parameter passed to `callback` will be the
                ``ElementTree`` `config`.
        Returns:
            Return value of `callback`.

        Raises:
            KeyError: if `path_name` is not specified.

        Examples:
            >>> import pyswitch.device
            >>> conn = ('10.24.39.211', '22')
            >>> auth = ('admin', 'password')
            >>> with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...     output = dev.mpls.mpls_path_create(get=True,
            ...                                        path_name='test')
            ...     output = dev.mpls.mpls_path_create(delete=True,
            ...                                        path_name='test')
            ...     output = dev.mpls.mpls_path_create(path_name='test')
        """

        path_name = kwargs.pop('path_name', None)

        mpls_args = {}

        get_config = kwargs.pop('get', False)
        delete = kwargs.pop('delete', False)
        callback = kwargs.pop('callback', self._callback)

        if delete:
            mpls_args = dict(path=path_name)
            method_name = 'router_mpls_path_delete'
            config = (method_name, mpls_args)
            return callback(config)
        if not get_config:
            mpls_args = dict(path=path_name)
            method_name = 'router_mpls_path_create'
            config = (method_name, mpls_args)
            return callback(config)
        elif get_config:
            if path_name is not None:
                mpls_args = dict(path=path_name)
            method_name = 'router_mpls_path_get'
            config = (method_name, mpls_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            if path_name is not None:
                result = util.find(util.root, './/path-name')
            else:
                result = util.findall(util.root, './/path-name')
        return result
Пример #2
0
    def evpn_afi_peergroup_encapsulation(self, **kwargs):
        """BGP evpn afi peer-group encapsulation.
        Args:
            peer_group (bool): Name of the peer group
            callback (function): A function executed upon completion of the
                method.  The only parameter passed to `callback` will be the
                ``ElementTree`` `config`.
            delete (bool): Deletes the peer group encapsulation
                if `delete` is ``True``.
            encapsulation_type: Valid vlaues 'vxlan','mpls','nxh'

            get (bool): Get config instead of editing config. (True, False)
        Returns:
            Return value of `callback`.
        Raises:
            ValueError: if `enabled` are invalid.
        Examples:
            >>> import pyswitch.device
            >>> switches = ['10.26.8.210']
            >>> auth = ('admin', 'password')
            >>> for switch in switches:
            ...     conn = (switch, '22')
            ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...         output = dev.bgp.local_asn(local_as='64101')
            ...         output = dev.bgp.neighbor_peer_group(peer_group='test')
            ...
            ...         output = dev.bgp.evpn_afi()
            ...         output = dev.bgp.evpn_afi_peergroup_activate(peer_group='test')
            ...         output = dev.bgp.evpn_afi_peergroup_nexthop(
            ...         peer_group='test')
            ...         output = dev.bgp.evpn_afi_peergroup_encapsulation(
            ...         peer_group='test', encapsulation_type='vxlan')
            ...         output = dev.bgp.evpn_afi_peergroup_encapsulation(
            ...         peer_group='test', get=True)
            ...         output
            ...         output = dev.bgp.evpn_afi_peergroup_encapsulation(
            ...         peer_group='test', delete=True)
            ...         output = dev.bgp.evpn_afi_peergroup_encapsulation(
            ...         peer_group='test', get=True)
            ...         output = dev.bgp.neighbor_peer_group(peer_group='test',delete=True)
            ['vxlan']
        """
        get_config = kwargs.pop('get', False)
        delete = kwargs.pop('delete', False)
        peer_group = kwargs.pop('peer_group')

        callback = kwargs.pop('callback', self._callback)
        result = []
        if not get_config:
            args = dict(evpn_peer_group=peer_group)

            if not delete:
                method_name = [
                    self.method_prefix(
                        'router_bgp_address_family_l2vpn_evpn_neighbor_'
                        'evpn_peer_group_update')
                ]
                encapsulation_type = kwargs.pop('encapsulation_type')
                args['encapsulation'] = encapsulation_type

            else:
                method_name = [
                    self.method_prefix(
                        'router_bgp_address_family_l2vpn_evpn_neighbor_'
                        'evpn_peer_group_encapsulation_delete')
                ]

            method = method_name[0]
            config = (method, args)
            result = callback(config)

        elif get_config:
            method_name = self.method_prefix(
                'router_bgp_address_family_l2vpn_evpn_neighbor_'
                'evpn_peer_group_encapsulation_get')
            args = dict(resource_depth=2, evpn_peer_group=peer_group)
            config = (method_name, args)
            out = callback(config, handler='get_config')
            bgp = Util(out.data)
            for peer in bgp.findall(bgp.root, './/encapsulation'):
                result.append(peer)
        return result
Пример #3
0
    def evpn_encapsulation(self, **kwargs):
        """Configure evpn_encapsulation for an EVPN neighbor.


        Args:
            ip_addr (str): IP Address of BGP neighbor.

            encapsulation_type: Valid vlaues 'vxlan','mpls','nxh'
            delete (bool): Deletes the peer  encapsulation if `delete` is ``True``.
            get (bool): Get config instead of editing config. (True, False)
            callback (function): A function executed upon completion of the
                method.  The only parameter passed to `callback` will be the
                ``ElementTree`` `config`.

        Returns:
            Return value of `callback`.

        Raises:
            None

        Examples:
            >>> import pyswitch.device
            >>> conn = ('10.24.86.60', '22')
            >>> auth = ('admin', 'password')
            >>> with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...     output = dev.bgp.local_asn(local_as='64101')
            ...     output = dev.bgp.neighbor(ip_addr='10.10.10.10',
            ...     remote_as='65535')
            ...     output= dev.bgp.neighbor(ip_addr='20.20.20.20',
            ...     remote_as='65555')
            ...     output = dev.bgp.evpn_afi_peer_activate(peer_ip='10.10.10.10')
            ...     output = dev.bgp.evpn_afi_peer_activate(peer_ip='20.20.20.20')
            ...     output = dev.bgp.evpn_encapsulation(
            ...     ip_addr='10.10.10.10',encapsulation_type='vxlan')
            ...     output = dev.bgp.evpn_encapsulation(
            ...     ip_addr='20.20.20.20',encapsulation_type='nsh')
            ...     output = dev.bgp.evpn_encapsulation(
            ...     ip_addr='10.10.10.10', get=True)
            ...     output = dev.bgp.evpn_encapsulation(
            ...     ip_addr='20.20.20.20', get=True)
            ...     output = dev.bgp.evpn_encapsulation(
            ...     ip_addr='10.10.10.10', delete=True)
        """
        callback = kwargs.pop('callback', self._callback)
        ip_addr = kwargs.pop('ip_addr')
        feature = '_neighbor_evpn_neighbor_ipv4_encapsulation'
        afi = 'l2vpn'
        if kwargs.pop('delete', False):
            args = dict()
            config = util.get_bgp_api(feature=feature,
                                      afi=afi,
                                      op='_delete',
                                      evpn_n_addr=ip_addr,
                                      args=args,
                                      os=self.os)
            return callback(config)
        if kwargs.pop('get', False):
            config = util.get_bgp_api(feature=feature,
                                      evpn_n_addr=ip_addr,
                                      afi=afi,
                                      op='_get',
                                      os=self.os)
            out = callback(config, handler='get_config')
            bgp = Util(out.data)
            result = []
            for peer in bgp.findall(bgp.root, './/encapsulation'):
                result.append(peer)
            return result
        encapsulation_type = kwargs.pop('encapsulation_type')
        args = dict(encapsulation=encapsulation_type)
        config = util.get_bgp_api(feature=feature,
                                  afi=afi,
                                  op='_update',
                                  evpn_n_addr=ip_addr,
                                  args=args,
                                  os=self.os)
        return callback(config)
Пример #4
0
    def switchport_access_mac_create(self, **kwargs):
        """Config/get/delete switchport access with the mac

        Args:
            intf_type (str): Interface Type.('ethernet',
                             'port_channel', gigabitethernet,
                              tengigabitethernet etc).
            intf_name (str): Interface Name
            access_vlan_id (int): Access vlan id.
                                 <1-4090/8191 when VFAB disabled/enabled>
            mac_address (str): Mac address. HHHH.HHHH.HHHH format
            get (bool): Get config instead of editing config. (True, False)
            delete (bool): True, delete the service policy on the interface.
        Returns:
            Return value of `callback`.
        Raises:
            KeyError: if `mac_address`, `access_vlan_id` and intf_name
                      are not specified.
        Examples:
            >>> import pyswitch.device
            >>> switches = ['10.24.39.211', '10.24.39.203']
            >>> auth = ('admin', 'password')
            >>> for switch in switches:
            ...     conn = (switch, '22')
            ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...         output_all = dev.interface.
            ...             switchport_access_mac_create
            ...             get=True, intf_type='tengigabitethernet',
            ...             intf_name='235/0/35')
            ...         dev.interface.switchport_access_mac_create
            ...             delete=True, intf_type='tengigabitethernet',
            ...             intf_name='235/0/35',  access_vlan_id='100',
            ...             mac_address='0011.2233.4455')
            ...         dev.interface.switchport_access_mac_create
            ...             intf_type='tengigabitethernet',
            ...             intf_name='235/0/35',
            ...             access_vlan_id='100', mac_address='0011.2233.4455')
        """

        intf_type = kwargs.pop('intf_type', 'ethernet')
        intf_name = kwargs.pop('intf_name')
        mac_address = kwargs.pop('mac_address', None)
        access_vlan_id = kwargs.pop('access_vlan_id', None)

        valid_int_types = self.valid_int_types + ['ethernet']
        if intf_type not in valid_int_types:
            raise ValueError('intf_type must be one of: %s' %
                             repr(valid_int_types))

        get_config = kwargs.pop('get', False)
        delete = kwargs.pop('delete', False)
        callback = kwargs.pop('callback', self._callback)

        if intf_type == 'ethernet':
            map_args = dict(ethernet=intf_name)
        elif intf_type == 'gigabitethernet':
            map_args = dict(gigabitethernet=intf_name)
        elif intf_type == 'tengigabitethernet':
            map_args = dict(tengigabitethernet=intf_name)
        elif intf_type == 'fortygigabitethernet':
            map_args = dict(fortygigabitethernet=intf_name)
        else:
            map_args = dict(port_channel=intf_name)

        if delete:
            if access_vlan_id is not None and mac_address is not None:
                map_args.update(vlan=(access_vlan_id, mac_address))
            method_name = 'interface_%s_switchport_access_vlan_access_mac_vlan_' \
                          'classification_delete' % intf_type
            config = (method_name, map_args)
            return callback(config)
        if not get_config:
            map_args.update(vlan=(access_vlan_id, mac_address))
            if not pyswitch.utilities.valid_vlan_id(access_vlan_id):
                raise InvalidVlanId("`name` must be between `1` and `8191`")

            method_name = 'interface_%s_switchport_access_vlan_access_mac_vlan_' \
                          'classification_create' % intf_type
            config = (method_name, map_args)
            return callback(config)
        elif get_config:
            if access_vlan_id is not None and mac_address is not None:
                map_args.update(vlan=(access_vlan_id, mac_address))

            method_name = 'interface_%s_switchport_access_vlan_access_mac_vlan_' \
                          'classification_get' % intf_type
            config = (method_name, map_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            result = []
            if output.data != '<output></output>':
                if mac_address is None and access_vlan_id is None:
                    vlans = util.findall(util.root, './/access-vlan-id')
                    macs = util.findall(util.root, './/mac')
                    for each_vlan, each_mac in zip(vlans, macs):
                        result.append((each_vlan, each_mac))
                else:
                    result = util.find(util.root, './/mac')
        return result
Пример #5
0
    def mac_group_mac_create(self, **kwargs):
        """Config/get/delete mac-group entry mac-addresses

        Args:
            mac_group_id(int): Mac Group Id. Valid Range [1,500]
            mac_address (str): Entry Mac Address. HHHH.HHHH.HHHH format
            get (bool): Get config instead of editing config. (True, False)
            delete (bool): True, delete the service policy on the interface.
        Returns:
            Return value of `callback`.
        Raises:
            KeyError: if `mac_group_id` and mac_address are not specified.
        Examples:
            >>> import pyswitch.device
            >>> switches = ['10.24.39.211', '10.24.39.203']
            >>> auth = ('admin', 'password')
            >>> for switch in switches:
            ...     conn = (switch, '22')
            ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...         output_all = dev.interface.mac_group_mac_create(
            ...         get=True, mac_group_id=10)
            ...         output_all = dev.interface.mac_group_mac_create(
            ...         delete=True, mac_group_id=10)
            ...         output_all = dev.interface.mac_group_mac_create(
            ...         mac_group_id=10, mac_address='0011.1111.0a23')
        """

        mac_group_id = kwargs.pop('mac_group_id')
        mac_group_entry = kwargs.pop('mac_address', None)

        if int(mac_group_id) not in range(1, 501):
            raise ValueError('`mac_group_id` not in range[1,500]')

        get_config = kwargs.pop('get', False)
        delete = kwargs.pop('delete', False)
        callback = kwargs.pop('callback', self._callback)

        map_args = dict(mac_group=mac_group_id)
        if delete:
            if mac_group_entry is None:
                map_args.update(mac_group_entry=(mac_group_entry, ))
            method_name = 'mac_group_mac_delete'
            config = (method_name, map_args)
            return callback(config)
        if not get_config:
            map_args.update(mac_group_entry=(mac_group_entry, ))
            method_name = 'mac_group_mac_create'
            config = (method_name, map_args)
            return callback(config)
        elif get_config:
            if mac_group_entry is not None:
                map_args.update(mac_group_entry=(mac_group_entry, ))
            method_name = 'mac_group_mac_get'
            config = (method_name, map_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            if output.data != '<output></output>':
                if mac_group_entry is None:
                    result = util.findall(util.root, './/entry-address')
                else:
                    result = util.find(util.root, './/entry-address')
            else:
                result = None
        return result
Пример #6
0
    def mpls_interface(self, **kwargs):
        """ Configure/get/delete router mpls interface

        Args:
            intf_type (str): Type of interface.['ethernet', 've']
            intf_name (str): Intername name.
            get (bool): Get config instead of editing config. (True, False)
            delete (bool): Delete config. (True, False)
            callback (function): A function executed upon completion of the
                method.  The only parameter passed to `callback` will be the
                ``ElementTree`` `config`.
        Returns:
            Return value of `callback`.

        Raises:
            KeyError: if `intf_name` is not specified.
            ValueError: if `intf_type` is not valid.

        Examples:
            >>> import pyswitch.device
            >>> conn = ('10.24.39.211', '22')
            >>> auth = ('admin', 'password')
            >>> with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...     output = dev.mpls.mpls_interface(get=True)
            ...     output = dev.mpls.mpls_interface(get=True, intf_name='111',
            ...                                      intf_type='ve')
            ...     output = dev.mpls.mpls_interface(intf_name='111',
            ...                                      intf_type='ve')
            ...     output = dev.mpls.mpls_interface(delete=True,
            ...                                      intf_name='111',
            ...                                      intf_type='ve')
        """

        intf_type = kwargs.pop('intf_type', 'ethernet')
        intf_name = kwargs.pop('intf_name', None)

        if intf_type not in self.valid_int_types:
            raise ValueError('intf_type must be one of: %s' %
                             repr(self.valid_int_types))

        mpls_args = {}

        get_config = kwargs.pop('get', False)
        delete = kwargs.pop('delete', False)
        callback = kwargs.pop('callback', self._callback)

        mpls_args = dict(mpls_interface=(intf_type, intf_name))
        if delete:
            method_name = 'router_mpls_mpls_interface_delete'
            config = (method_name, mpls_args)
            return callback(config)
        if not get_config:
            method_name = 'router_mpls_mpls_interface_create'
            config = (method_name, mpls_args)
            return callback(config)
        elif get_config:
            if intf_name is None:
                mpls_args = {}
            method_name = 'router_mpls_mpls_interface_get'
            config = (method_name, mpls_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            if output.data == '<output></output>':
                result = None
            else:
                if intf_name is None:
                    result = util.findall(util.root, './/interface-name')
                else:
                    result = util.find(util.root, './/interface-name')
        return result