Пример #1
0
    def _get_acl_info_rest(self, rest_device, acl_name, get_seqs=False):
        """
        Return acl-type as dict
            {'type':'standard'/'extended;, 'protocol':'mac'/'ip'/'ipv6'}.
        """
        ret = None
        seq_ids = []

        config = ''
        for address_type in ['mac', 'ip', 'ipv6']:
            for acl_type in ['standard', 'extended']:

                method = address_type + '_access_list_' + acl_type
                config = (method + '_get', {})
                output = rest_device._callback(config, handler='get_config')
                util = Util(output.data)
                for rcvd_name in util.root.findall(".//name"):
                    if rcvd_name.text == acl_name:
                        ret = {'type': acl_type, 'protocol': address_type,
                               'seq_ids': None}

                        if get_seqs:
                            config = (method + '_seq_get',
                                      {acl_type: acl_name})
                            output = rest_device. \
                                _callback(config, handler='get_config')
                            util = Util(output.data)
                            for rcvd_seqs in util.root.findall(".//seq-id"):
                                seq_ids.append(int(rcvd_seqs.text))
                            ret['seq_ids'] = seq_ids
                        return ret

        raise ValueError('Failed to identify acl_type. '
                         'Check if the ACL {} exists'.format(acl_name))
Пример #2
0
    def chassis_name(self, **kwargs):
        """Get device's chassis name/Model.
        Args:
            rbridge_id (str): The rbridge ID of the device.
        Returns:
            Return value of `callback`.
        Raises:
            KeyError: if `rbridge_id` is not specified.
        Examples:
        >>> import pyswitch.device
        >>> switches = ['10.24.39.231']
        >>> auth = ('admin', 'password')
        >>> for switch in switches:
        ...     conn = (switch, '22')
        ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
        ...         output = dev.system.chassis_name(rbridge_id='1')
        """

        rbridge_id = kwargs.pop('rbridge_id')
        chname_args = dict(rbridge_id=rbridge_id, resource_depth=2)
        config = ('rbridge_id_get', chname_args)

        output = self._callback(config, handler='get_config')

        util = Util(output.data)

        chassis_name = util.find(util.root, './/chassis-name')

        return chassis_name
Пример #3
0
    def mpls_lsp_destination_address(self, **kwargs):
        """ Configure/get/delete router mpls lsp destination address

        Args:
            lsp_name (str). Define lsp name
            lsp_dest_address (str) : Define LSP destination address
            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 `lsp_name` and lsp_dest_address 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_lsp_destination_address(get=True,
            ...              lsp_name='test')
            ...     output = dev.mpls.mpls_lsp_destination_address(delete=True,
            ...              lsp_name='test')
            ...     output = dev.mpls.mpls_lsp_destination_address(
            ...              lsp_name='test_lsp',
            ...              lsp_dest_address='1.1.1.1')
        """

        lsp_name = kwargs.pop('lsp_name')
        lsp_dest_address = kwargs.pop('lsp_dest_address', None)

        mpls_args = {}

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

        mpls_args = dict(lsp=lsp_name)
        if delete:
            method_name = 'router_mpls_lsp_to_delete'
            config = (method_name, mpls_args)
            return callback(config)
        if not get_config:
            mpls_args.update(lsp_dest_address=lsp_dest_address)
            method_name = 'router_mpls_lsp_to_update'
            config = (method_name, mpls_args)
            return callback(config)
        elif get_config:
            method_name = 'router_mpls_lsp_to_get'
            config = (method_name, mpls_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            if output.data != '<output></output>':
                result = util.find(util.root, './/to')
            else:
                result = None
        return result
Пример #4
0
    def system_l2_mtu(self, **kwargs):
        """Set system mtu.

            Args:

                mtu (str): Value between 1522 and 9216
                version (int) : 4 or 6
                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 `int_type`, `name`, or `mtu` is not specified.
                ValueError: if `int_type`, `name`, or `mtu` is invalid.

            Examples:
                >>> import pyswitch.device
                >>> switches = ['10.24.39.231']
                >>> auth = ('admin', 'password')
                >>> for switch in switches:
                ...  conn = (switch, '22')
                ...  with pyswitch.device.Device(conn=conn, auth=auth) as dev:
                ...         output = dev.system.system_l2_mtu(mtu='1666')
                ...         output = dev.system.system_l2_mtu(get=True)
                ...         assert output == '1666'
                ...         output = dev.system.system_l2_mtu(mtu='1667',version=6)
                ...         output = dev.system.system_l2_mtu(get=True,version=6)
                ...         assert output == '1667'
            """

        callback = kwargs.pop('callback', self._callback)

        if kwargs.pop('get', False):
            method_name = 'mtu_get'
            config = (method_name, {})
            op = callback(config, handler='get_config')

            util = Util(op.data)
            return util.find(util.root, './/mtu')

        mtu = kwargs.pop('mtu')

        minimum_mtu = 1522
        maximum_mtu = 9216
        if int(mtu) < minimum_mtu or int(mtu) > maximum_mtu:
            raise ValueError("Incorrect mtu value, Valid Range %s-%s" %
                             (minimum_mtu, maximum_mtu))

        mtu_name = 'global_l2_mtu'
        mtu_args = {mtu_name: mtu}

        method_name = 'mtu_update'

        config = (method_name, mtu_args)
        return callback(config)
Пример #5
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
Пример #6
0
    def chassis_name(self, **kwargs):
        """Get device's chassis name/Model.
        """

        config = ('switch_attributes_get', {'resource_depth': 3})

        output = self._callback(config, handler='get_config')
        util = Util(output.data)
        chassis_name = util.find(util.root, './/chassis-name')
        return chassis_name
Пример #7
0
    def ospf_area(self, **kwargs):
        """ Configure/get/delete area under router ospf

        Args:
            ip_version (str): ('4' or '6') address family
                              Default: `4`.
            area (str): OSPF areas.
            vrf (str): Create a VRF. Default: `default-vrf`
            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:
            None

        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.ospf.ospf_area(get=True, vrf='111')
            ...     output = dev.ospf.ospf_area(delete=True, vrf='111')
            ...     output = dev.ospf.ospf_area(vrf='111', area='10')
        """
        ip_version = kwargs.pop('ip_version', '4')
        vrf = kwargs.pop('vrf', 'default-vrf')
        area = kwargs.pop('area', None)
        ospf_args = {}
        get_config = kwargs.pop('get', False)
        delete = kwargs.pop('delete', False)
        callback = kwargs.pop('callback', self._callback)

        ospf_args = dict(ospf=vrf, area=area)
        if delete:
            method_name = 'router_ospf_area_delete' if ip_version == '4' \
                else 'ipv6_router_ospf_area_delete'
            config = (method_name, ospf_args)
            return callback(config)
        if not get_config:
            method_name = 'router_ospf_area_create' if ip_version == '4' \
                else 'ipv6_router_ospf_area_create'
            config = (method_name, ospf_args)
            return callback(config)
        elif get_config:
            method_name = 'router_ospf_area_get' if ip_version == '4' \
                else 'ipv6_router_ospf_area_get'
            config = (method_name, ospf_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            result = util.find(util.root, './/area-id')
        return result
Пример #8
0
    def maintenance_mode(self, **kwargs):
        """Configures maintenance mode on the device
        Args:
            rbridge_id (str): The rbridge ID of the device on which
            Maintenance mode
                will be configured in a VCS fabric.
            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:
            KeyError: if `rbridge_id` is not specified.
        Examples:
            >>> import pyswitch.device
            >>> conn = ('10.24.39.202', '22')
            >>> auth = ('admin', 'password')
            >>> with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...     output = dev.system.maintenance_mode(rbridge_id='226')
            ...     output = dev.system.maintenance_mode(rbridge_id='226',
            ...     get=True)
            ...     assert output == True
            ...     output = dev.system.maintenance_mode(rbridge_id='226',
            ...     delete=True)
            ...     output = dev.system.maintenance_mode(rbridge_id='226',
            ...     get=True)
            ...     assert output == False
        """
        is_get_config = kwargs.pop('get', False)
        delete = kwargs.pop('delete', False)
        rbridge_id = kwargs.pop('rbridge_id')
        callback = kwargs.pop('callback', self._callback)
        rid_args = dict(rbridge_id=rbridge_id)

        if is_get_config:
            config = ('rbridge_id_get', rid_args)
            maint_mode = callback(config, handler='get_config')

            util = Util(maint_mode.data)

            system_mode = util.findNode(util.root, './/system-mode')
            maintenance = util.find(system_mode, './/maintenance')
            if maintenance:
                return True
            else:
                return False

        if delete:
            rid_args['maintenance'] = False
        else:
            rid_args['maintenance'] = True
        config = ('rbridge_id_system_mode_update', rid_args)
        return callback(config)
Пример #9
0
    def vfab_enable(self, **kwargs):
        """Config/get/delete vfab enable

        Args:
            vfab_enable (bool): Enable/Disable virtual fabric. (True, False)
            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:
            None.
        Examples:
            >>> import pyswitch.device
            >>> switches = ['10.24.39.231']
            >>> auth = ('admin', 'password')
            >>> for switch in switches:
            ...     conn = (switch, '22')
            ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...         output_all = dev.interface.vfab_enable(vfab_enable=True)
            ...         output_all = dev.interface.vfab_enable(get=True)
            ...         assert output_all == True
            ...         output_all = dev.interface.vfab_enable(delete=True)
            ...         output_all = dev.interface.vfab_enable(get=True)
            ...         assert output_all == False
        """

        vfab_enable = kwargs.pop('vfab_enable', False)

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

        if delete:
            method_name = 'vcs_virtual_fabric_enable_delete'
            config = (method_name, map_args)
            return callback(config)
        if not get_config:
            map_args = dict(vfab_enable=vfab_enable)
            method_name = 'vcs_virtual_fabric_enable_update'
            config = (method_name, map_args)
            return callback(config)
        elif get_config:
            method_name = 'vcs_virtual_fabric_enable_get'
            config = (method_name, map_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            if util.find(util.root, './/enable'):
                result = True
            else:
                result = False

        return result
Пример #10
0
    def net_address(self, **kwargs):
        """ Configure net NSAP Address

        Args:
            net (str): NSAP Address. <HH.HHHH.HHHH.HHHH.00>
            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 `net` 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.isis.net_address(get=True)
            ...     output = dev.isis.net_address(
            ...     net='49.0001.0100.1001.0006.00')
            ...     output = dev.isis.net_address(delete=True)
        """

        isis_args = {}

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

        if delete:
            method_name = 'router_isis_net_delete'
            config = (method_name, isis_args)
            return callback(config)
        if not get_config:
            net = kwargs.pop('net')
            isis_args['net'] = net
            method_name = 'router_isis_net_create'
            config = (method_name, isis_args)
            return callback(config)
        elif get_config:
            method_name = 'router_isis_net_get'
            config = (method_name, isis_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            result = util.find(util.root, './/net-cmd')
            return result
Пример #11
0
    def evpn_instance(self, **kwargs):
        """
        >>> import pyswitch.device
        >>> conn = ('10.37.18.136', '22')
        >>> auth = ('admin', 'password')
        >>> with pyswitch.device.Device(conn=conn, auth=auth,connection_type='NETCONF') as dev:
        ...      output = dev.interface.evpn_instance(get=True,rbridge_id='2')
        ...      print output
        ...      output = dev.interface.evpn_instance(evi_name='Leaf1', duplicate_mac_timer=10,

        ...      max_count = '5',rbridge_id=2)
        ...      output = dev.interface.evpn_instance(get=True,rbridge_id=2)
        ...      print output
        """

        get_config = kwargs.pop('get', False)

        if not get_config:
            evi_name = kwargs.pop('evi_name')
            duplicate_mac_timer = kwargs.pop('duplicate_mac_timer')
            max_count = kwargs.pop('max_count')
            rbridge_id = kwargs.pop('rbridge_id')

            t = Template(getattr(template, 'evpn_instance_create'))
            config = t.render(evi_name=evi_name,
                              duplicate_mac_timer=duplicate_mac_timer,
                              duplicate_mac_timer_max_count=max_count,
                              rbridge_id=rbridge_id)
            self._callback(config)

            t = Template(getattr(template, 'evpn_instance_router_target_auto'))
            config = t.render(evi_name=evi_name, rbridge_id=rbridge_id)
            self._callback(config)

        if get_config:
            rbridge_id = kwargs.pop('rbridge_id')
            config = getattr(template,
                             'evpn_instance_get').format(rbridge_id=rbridge_id)
            rest_root = self._callback(config, handler='get_config')
            util = Util(rest_root)
            evi_name = util.find(util.root, './/instance-name')
            duplicate_mac_timer = util.find(util.root,
                                            './/duplicate-mac-timer-value')
            max_count = util.find(util.root, './/max-count')

            return {
                "evi_name": evi_name,
                "duplicate_mac_timer": duplicate_mac_timer,
                'max_count': max_count
            }
Пример #12
0
    def _get_acl_rules(self, rest_device, address_type, acl_type, acl_name,
                       sequences):
        """
        Return list of rules configured for acl_name
        """
        rules_list = []
        method = address_type + '_access_list_' + acl_type + '_seq_get'
        config = (method, {acl_type: acl_name, 'resource_depth': 2})
        output = rest_device._callback(config, handler='get_config')
        util = Util(output.data)

        for rcvd_seq in util.root.findall(".//seq"):
            if rcvd_seq is not None:
                seq_id = int(rcvd_seq.find('seq-id').text)
                if seq_id in sequences:
                    sequences.remove(seq_id)
                    pd = parker.data(rcvd_seq)

                    new_pd = {}
                    # Replace "-" with "_"
                    for k, v in pd.iteritems():
                        nk = k.replace("-", "_")
                        new_pd[nk] = v

                    rules_list.append(new_pd)

        return rules_list
Пример #13
0
    def host_name(self, **kwargs):
        """Configures device's host name.
        Args:
            rbridge_id (str): The rbridge ID of the device on which BGP will be
                configured in a VCS fabric.
            host_name (str): The host name of the device.
            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:
            KeyError: if `rbridge_id` is not specified.
        Examples:
            >>> import pyswitch.device
            >>> conn = ('10.24.39.231', '22')
            >>> auth = ('admin', 'password')
            >>> with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...     output = dev.system.host_name(rbridge_id='231',
            ...     host_name='sw0_231')
            ...     output = dev.system.host_name(rbridge_id='231', get=True)
            ...     print output
        """
        is_get_config = kwargs.pop('get', False)
        rbridge_id = kwargs.pop('rbridge_id')
        if not is_get_config:
            host_name = kwargs.pop('host_name', 'sw0')
        else:
            host_name = ' '
        callback = kwargs.pop('callback', self._callback)
        rid_args = dict(rbridge_id=rbridge_id, host_name=host_name)

        config = ('rbridge_id_switch_attributes_update', rid_args)

        if is_get_config:
            config = ('rbridge_id_get', {
                'resource_depth': 2,
                'rbridge_id': rbridge_id
            })
            output = callback(config, handler='get_config')

            util = Util(output.data)

            return util.find(util.root, './/host-name')

        return callback(config)
Пример #14
0
    def log_adjacency(self, **kwargs):
        """ Configure log adjacency

        Args:
            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:
            None

        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.isis.log_adjacency(get=True)
            ...     output = dev.isis.log_adjacency()
            ...     output = dev.isis.log_adjacency(delete=True)
        """
        isis_args = {}
        get_config = kwargs.pop('get', False)
        delete = kwargs.pop('delete', False)
        callback = kwargs.pop('callback', self._callback)

        if delete:
            method_name = 'router_isis_log_adjacency_delete'
            config = (method_name, isis_args)
            return callback(config)
        if not get_config:
            isis_args['adjacency'] = True
            method_name = 'router_isis_log_adjacency_update'
            config = (method_name, isis_args)
            return callback(config)
        elif get_config:
            method_name = 'router_isis_log_adjacency_get'
            config = (method_name, isis_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            result = util.find(util.root, './/adjacency')
            return result
Пример #15
0
    def overlay_gateway(self, **kwargs):
        """

        Creates Overlay Gateway

        Examples:
        >>> import pyswitch.device
        >>> conn = ('10.26.8.210', '22')
        >>> auth = ('admin', 'password')
        >>> with pyswitch.device.Device(conn=conn, auth=auth,connection_type='NETCONF') as dev:
        ...      output = dev.interface.overlay_gateway(gw_name='Leaf1', loopback_id=2,

        ...      gw_type = 'layer2-extension',vni_auto=True,rbridge_id=None)
        ...      output = dev.interface.overlay_gateway(get=True)
        ...      print output
        """
        get_config = kwargs.pop('get', False)

        if not get_config:
            gw_name = kwargs.pop('gw_name')
            gw_type = kwargs.pop('gw_type', 'layer2-extension')
            vni_auto = kwargs.pop('vni_auto', True)
            loopback_id = kwargs.pop('loopback_id', None)
            vni_auto_data = ""
            if vni_auto:
                vni_auto_data = getattr(template,
                                        'overlay_gateway_vni_auto').format()

            config = getattr(template, 'overlay_gateway_create').format(
                gw_name=gw_name,
                gw_type=gw_type,
                loopback_id=loopback_id,
                vni_auto_data=vni_auto_data)

            self._callback(config)

        if get_config:
            config = getattr(template, 'overlay_gateway_get').format()
            rest_root = self._callback(config, handler='get_config')
            util = Util(rest_root)
            gw_name = util.find(util.root, './/name')
            gw_type = util.find(util.root, './/gw-type')
            loopback_id = util.find(util.root, './/loopback-id')
            activate = True if util.findNode(
                util.root, './/activate') is not None else False
            vni_auto = True if util.findNode(util.root,
                                             './/auto') is not None else False

            return {
                "gw_name": gw_name,
                "gw_type": gw_type,
                'loopback_id': loopback_id,
                'rbridge_id': 'None',
                'activate': activate,
                'vni_auto': vni_auto,
            }
Пример #16
0
    def mpls_lsp_get_details(self, **kwargs):
        """ get all router mpls lsp details

        Args:
            lsp_name (str). Define lsp name
            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 `lsp_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_lsp_get_details(
            ...              lsp_name='test')
        """

        lsp_name = kwargs.pop('lsp_name')

        mpls_args = {}
        callback = kwargs.pop('callback', self._callback)
        mpls_args = dict(lsp=lsp_name)
        method_name = 'router_mpls_lsp_get'
        config = (method_name, mpls_args)
        output = callback(config, handler='get_config')
        util = Util(output.data)
        if output.data != '<output></output>':
            lsp_name = util.find(util.root, './/lsp-name')
            lsp_destn_addr = util.find(util.root, './/to')
            lsp_primary_path = util.find(util.root, './/primary-path')
            lsp_secondary_path = util.find(util.root, './/secpath-name')
            lsp_cos = util.find(util.root, './/cos')
            lsp_enable = util.find(util.root, './/enable')
            result = {
                'lsp_name': lsp_name,
                'lsp_destn_addr': lsp_destn_addr,
                'lsp_primary_path': lsp_primary_path,
                'lsp_secondary_path': lsp_secondary_path,
                'lsp_cos': lsp_cos,
                'lsp_enable': lsp_enable
            }
        else:
            result = None
        return result
Пример #17
0
    def rbridge_id(self, **kwargs):
        """Configures device's rbridge ID. Setting this property will need
        a switch reboot
        Args:
            rbridge_id (str): The rbridge ID of the device on which BGP will be
                configured in a VCS fabric.
            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:
            KeyError: if `rbridge_id` 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.system.rbridge_id(rbridge_id='225')
            ...     output = dev.system.rbridge_id(rbridge_id='225', get=True)
        """
        callback = kwargs.pop('callback', self._callback)
        is_get_config = kwargs.pop('get', False)
        if not is_get_config:
            rbridge_id = kwargs.pop('rbridge_id')
        else:
            rbridge_id = ''

        if is_get_config:
            config = ('rbridge_id_get', {})
            op = callback(config, handler='get_config')

            util = Util(op.data)
            return util.find(util.root, 'rbridge-id')

        rid_args = dict(rbridge_id=rbridge_id)
        config = ('vcs_rbridge_config_rpc', rid_args)
        return callback(config)
Пример #18
0
    def mpls_policy(self, **kwargs):
        """ Configure/get/delete router mpls policy

        Args:
            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:
            None.

        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_policy(get=True)
            ...     output = dev.mpls.mpls_policy(delete=True)
            ...     output = dev.mpls.mpls_policy()
        """

        mpls_args = {}

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

        if delete:
            method_name = 'router_mpls_policy_delete'
            config = (method_name, mpls_args)
            return callback(config)
        if not get_config:
            method_name = 'router_mpls_policy_create'
            config = (method_name, mpls_args)
            return callback(config)
        elif get_config:
            method_name = 'router_mpls_policy_get'
            config = (method_name, mpls_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            if output.data != '<output></output>':
                ospf_area_decimal = util.find(util.root,
                                              './/ospf-area-as-decimal')
                ospf_area_ip = util.find(util.root,
                                         './/ospf-area-as-ip-address')
                ospf_area_all = util.find(util.root, './/all')
                isis = util.find(util.root, './/isis')
                result = dict(ospf_area_decimal=ospf_area_decimal,
                              ospf_area_ip=ospf_area_ip,
                              ospf_area_all=ospf_area_all,
                              isis=isis)
            else:
                result = None
        return result
Пример #19
0
    def uptime(self):
        """dict: device uptime
        Examples:
            >>> import pyswitch.device
            >>> switches = ['10.24.39.231']
            >>> auth = ('admin', 'password')
            >>> for switch in switches:
            ...     conn = (switch, '22')
            ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...         output = dev.system.uptime
        """

        get_system_uptime = ('get_system_uptime_rpc', {})

        results = self._callback(get_system_uptime, handler='get')

        util = Util(results.data)

        system_uptime = dict(days=util.find(util.root, './/days'),
                             hours=util.find(util.root, './/hours'),
                             minutes=util.find(util.root, './/minutes'),
                             seconds=util.find(util.root, './/seconds'))
        return system_uptime
Пример #20
0
    def mac_table(self):
        """list[dict]: the MAC table of the device.
         Examples:
            >>> import pyswitch.device
            >>> switches = ['10.24.39.231']
            >>> auth = ('admin', 'password')
            >>> for switch in switches:
            ...     conn = (switch, '22')
            ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...         output = dev.mac_table
        """
        table = []

        config = ('get_mac_address_table_rpc', {})
        rest_root = self._callback(config, handler='get')
        util = Util(rest_root.data)
        for entry in util.findlist(util.root, './/mac-address-table'):
            address = util.find(entry, './/mac-address')
            vlan = util.find(entry, './/vlanid')
            mac_type = util.find(entry, './/mac-type')
            state = util.find(entry, './/mac-state')
            interface = util.findNode(entry, './/forwarding-interface')
            interface_type = util.find(interface, './/interface-type')
            interface_name = util.find(interface, './/interface-name')
            interface = '%s%s' % (interface_type, interface_name)

            table.append(
                dict(mac_address=address,
                     interface_type=interface_type,
                     interface_name=interface_name,
                     interface=interface,
                     state=state,
                     vlan=vlan,
                     type=mac_type))

        return table
Пример #21
0
    def arp(self):
        """dict: arp details
        Examples:
        >>> import pyswitch.device
        >>> switches = ['10.24.39.231']
        >>> auth = ('admin', 'password')
        >>> for switch in switches:
        ...     conn = (switch, '22')
        ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
        ...         output = dev.services.arp
        """

        config = ('get_arp_rpc', {})
        results = self._callback(config, handler='get')
        util = Util(results.data)
        result = []

        for item in util.findlist(util.root, './/arp-entry'):
            ip_address = util.find(item, './/ip-address')
            mac_address = util.find(item, './/mac-address')
            interface_type = util.find(item, './/interface-type')
            interface_name = util.find(item, './/interface-name')
            is_resolved = util.find(item, './/is-resolved')
            age = util.find(item, './/age')
            entry_type = util.find(item, './/entry-type')
            item_results = {
                'ip-address': ip_address,
                'mac-address': mac_address,
                'interface-type': interface_type,
                'interface-name': interface_name,
                'is-resolved': is_resolved,
                'age': age,
                'entry-type': entry_type
            }
            result.append(item_results)
        return result
Пример #22
0
    def trill_links(self):
        """dict: trill link details
        Examples:
        >>> import pyswitch.device
        >>> switches = ['10.24.39.231']
        >>> auth = ('admin', 'password')
        >>> for switch in switches:
        ...     conn = (switch, '22')
        ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
        ...         output = dev.fabric_service.trill_links
        """

        get_links_info = ('show_linkinfo_rpc', {})

        results = self._callback(get_links_info, handler='get')
        util = Util(results.data)

        result = []

        for item in util.findlist(util.root, './/show-link-info'):
            src_rbridge_id = util.find(item, './/linkinfo-rbridgeid')
            src_switch_wwn = util.find(item, './/linkinfo-wwn')
            for link in util.findlist(item, './/linkinfo-isl'):
                dest_rbridge_id = util.find(link,
                                            './/linkinfo-isllink-destdomain')
                src_interface = util.find(
                    link, './/linkinfo-isllink-srcport-interface')
                dest_interface = util.find(
                    link, './/linkinfo-isllink-destport-interface')
                link_cost = util.find(link, './/linkinfo-isl-linkcost')
                link_cost_count = util.find(link,
                                            './/linkinfo-isllink-costcount')

                item_results = {
                    'source-rbridgeid': src_rbridge_id,
                    'source-switch-wwn': src_switch_wwn,
                    'dest-rbridgeid': dest_rbridge_id,
                    'source-interface': src_interface,
                    'dest-interface': dest_interface,
                    'link-cost': link_cost,
                    'link-costcount': link_cost_count
                }

                result.append(item_results)

        return result
Пример #23
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
Пример #24
0
    def bd_add(self, **kwargs):
        """Add VNIs to the EVPN Instance
        Args:
            rbridge_id (str): rbridge-id for device.
            evpn_instance (str): Name of the evpn instance.
            vni (str): vnis to the evpn instance
            get (bool): Get config instead of editing config. (True, False)
            delete (bool): True, delete the vni configuration
            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 `rbridge_id`,`evpn_instance`, 'vni' is not passed.
            ValueError: if `rbridge_id`, `evpn_instance`, 'vni' is 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.bd_add(
            ...         evpn_instance="evpn1", bd='10')
            ...         output = dev.bgp.bd_add(evpn_instance="evpn1",
            ...         get=True)
            ...         print output
            ...         output = dev.bgp.bd_add(evpn_instance="evpn1",bd='10',
            ...         delete=True)

        """
        get_config = kwargs.pop('get', False)
        delete = kwargs.pop('delete', False)
        callback = kwargs.pop('callback', self._callback)
        result = []
        if not get_config:
            evpn_instance = kwargs['evpn_instance']
            bd = kwargs.pop('bd', None)
            if not delete:
                method_name = [
                    self.method_prefix('evpn_evpn_instance_create'),
                    self.method_prefix(
                        'evpn_evpn_instance_bridge_domain_add_update')
                ]
            else:
                method_name = [
                    self.method_prefix(
                        'evpn_evpn_instance_bridge_domain_add_delete'),
                    self.method_prefix('evpn_evpn_instance_delete')
                ]
            for i in range(0, 2):
                method = method_name[i]
                bd_args = dict(evpn_instance=evpn_instance)
                if 'bridge_domain' in method and not delete:
                    bd_args['bd_range_add'] = bd
                config = (method, bd_args)
                result = callback(config)

        elif get_config:
            evpn_instance = kwargs.pop('evpn_instance', '')
            method_name = self.method_prefix(
                'evpn_evpn_instance_bridge_domain_add_get')
            bd_args = dict(evpn_instance=evpn_instance, resource_depth=2)
            config = (method_name, bd_args)
            out = callback(config, handler='get_config')
            bgp = Util(out.data)
            tmp = {
                'rbridge_id': None,
                'evpn_instance': evpn_instance,
                'bd': bgp.find(bgp.root, './/add')
            }
            result.append(tmp)
        return result
Пример #25
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)
Пример #26
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
Пример #27
0
    def vcs_vip(self, **kwargs):
        """Set VCS Virtual IP.

        Args:
            vip (str): IPv4/IPv6 Virtual IP Address.
            rbridge_id (str): rbridge-id for device. Only required when type is
                `ve`.
            delete (bool): Deletes the virtual ip 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:
            KeyError: if `vip` is not passed.
            ValueError: if `vip` is invalid.

        Examples:
            >>> import pyswitch.device
            >>> switches = ['10.24.39.231']
            >>> auth = ('admin', 'password')
            >>> for switch in switches:
            ...     conn = (switch, '22')
            ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
            ...         print dev.vcs.vcs_vip(get=True)
            ...         output = dev.vcs.vcs_vip(vip='10.24.39.239/26')
            ...         print dev.vcs.vcs_vip(get=True)
            ...         output = dev.vcs.vcs_vip(vip='10.24.39.239/26',delete=True)
            ...         print dev.vcs.vcs_vip(get=True)
        """
        get_config = kwargs.pop('get', False)
        delete = kwargs.pop('delete', False)
        callback = kwargs.pop('callback', self._callback)

        if not get_config:
            vip = str(kwargs.pop('vip'))
            ipaddress = ip_interface(unicode(vip))
            vcs_args = dict(address=vip)
            if ipaddress.version == 4:
                method_name = 'vcs_virtual_ip_address_'
            elif ipaddress.version == 6:
                method_name = 'vcs_virtual_ipv6_address_'

            if not delete:
                method_name = "%screate" % method_name
                config = (method_name, vcs_args)

            else:
                method_name = "%sdelete" % method_name
                config = (method_name, vcs_args)

        elif get_config:
            vip_info = {}

            method_name = 'vcs_virtual_ip_address_get'

            config = (method_name, {})
            op = callback(config, handler='get_config')
            util = Util(op.data)

            vip_info['ipv4_vip'] = util.find(util.root, './/address/address')

            method_name = 'vcs_virtual_ipv6_address_get'

            config = (method_name, {})

            op = callback(config, handler='get_config')
            util = Util(op.data)

            vip_info['ipv6_vip'] = util.find(util.root, './/address/address')
            return vip_info

        return callback(config)
Пример #28
0
    def vcs_nodes(self):
        """dict: vcs node details
        >>> import pyswitch.device
        >>> switches = ['10.24.39.231']
        >>> auth = ('admin', 'password')
        >>> for switch in switches:
        ...     conn = (switch, '22')
        ...     with pyswitch.device.Device(conn=conn, auth=auth) as dev:
        ...         output = dev.vcs.vcs_nodes
        """
        show_vcs = ('show_vcs_rpc', {})

        results = self._callback(show_vcs, handler='get')
        util = Util(results.data)
        result = []
        for nodes in util.findlist(util.root, './/vcs-nodes'):
            for item in util.findlist(nodes, './/vcs-node-info'):
                serial_number = util.find(item, './/node-serial-num')
                node_status = util.find(item, './/node-status')
                vcs_id = util.find(item, './/node-vcs-id')
                rbridge_id = util.find(item, './/node-rbridge-id')
                switch_mac = util.find(item, './/node-switch-mac')
                switch_wwn = util.find(item, './/node-switch-wwn')
                switch_name = util.find(item, './/node-switchname')
                node_is_principal = util.find(item, './/node-is-principal')
                switch_ip = ''
                for switch_ip_addr in util.findlist(
                        item, './/node-public-ip-addresses'):
                    switch_ip = util.find(switch_ip_addr,
                                          './/node-public-ip-address')
                    break
                item_results = {'node-serial-num': serial_number,
                                'node-status': node_status,
                                'node-vcs-id': vcs_id,
                                'node-rbridge-id': rbridge_id,
                                'node-switch-mac': switch_mac,
                                'node-switch-wwn': switch_wwn,
                                'node-switch-ip': switch_ip,
                                'node-switchname': switch_name,
                                'node-is-principal': node_is_principal}

                result.append(item_results)

        return result
Пример #29
0
    def fabric_isl(self, **kwargs):
        """Set fabric ISL state.

        Args:
            int_type (str): Type of interface. (gigabitethernet,
                tengigabitethernet, etc)
            name (str): Name of interface. (1/0/5, 1/0/10, etc)
            enabled (bool): Is fabric ISL state enabled? (True, False)
            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:
            KeyError: if `int_type`, `name`, or `state` is not specified.
            ValueError: if `int_type`, `name`, or `state` is not a valid value.

        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 = dev.interface.fabric_isl(
            ...         int_type='tengigabitethernet',
            ...         name='225/0/40',
            ...         enabled=False)
            ...         dev.interface.fabric_isl()
            ...         # doctest: +IGNORE_EXCEPTION_DETAIL
            Traceback (most recent call last):
            KeyError
        """
        int_type = str(kwargs.pop('int_type').lower())
        name = str(kwargs.pop('name'))
        enabled = kwargs.pop('enabled', True)
        callback = kwargs.pop('callback', self._callback)

        int_types = [
            'tengigabitethernet', 'fortygigabitethernet',
            'hundredgigabitethernet'
        ]

        if int_type not in int_types:
            raise ValueError("`int_type` must be one of: %s" % repr(int_types))

        if not isinstance(enabled, bool):
            raise ValueError('`enabled` must be `True` or `False`.')

        fabric_isl_args = dict()
        fabric_isl_args[int_type] = name

        if not pyswitch.utilities.valid_interface(int_type, name):
            raise ValueError("`name` must match `^[0-9]{1,3}/[0-9]{1,3}/[0-9]"
                             "{1,3}$`")
        if kwargs.pop('get', False):
            method_name = 'interface_%s_get' % int_type
            config = (method_name, fabric_isl_args)
            op = callback(config, handler='get_config')
            util = Util(op.data)

            if util.find(util.root, './/fabric//isl//enable'):
                return True
            return None

        method_name = 'interface_%s_fabric_isl_update' % int_type

        if not enabled:
            fabric_isl_args['fabric_isl_enable'] = False
        else:
            fabric_isl_args['fabric_isl_enable'] = True
        config = (method_name, fabric_isl_args)
        return callback(config)
Пример #30
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