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

        Args:
            lsp_name (str). Define lsp name
            lsp_primary_path (str). Define lsp primary 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 `lsp_name` and `lsp_primary_path` 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_primary_path(get=True,
            ...              lsp_name='test')
            ...     output = dev.mpls.mpls_lsp_primary_path(delete=True,
            ...              lsp_name='test')
            ...     output = dev.mpls.mpls_lsp_primary_path(
            ...              lsp_name='test_lsp',
            ...              lsp_primary_path='test')
        """

        lsp_name = kwargs.pop('lsp_name')
        lsp_primary_path = kwargs.pop('lsp_primary_path', 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_primary_path_delete'
            config = (method_name, mpls_args)
            return callback(config)
        if not get_config:
            mpls_args.update(lsp_primary_path=lsp_primary_path)
            method_name = 'router_mpls_lsp_primary_path_update'
            config = (method_name, mpls_args)
            return callback(config)
        elif get_config:
            method_name = 'router_mpls_lsp_primary_path_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, './/primary-path')
            else:
                result = None
        return result
Пример #2
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)
Пример #3
0
    def conversation_property(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.conversation_property(get=True)
        ...      print output
        """

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

        if not get_config:
            arp_aging_timeout = kwargs.pop('arp_aging_timeout', '300')
            mac_aging_timeout = kwargs.pop('mac_aging_timeout', '300')
            mac_legacy_aging_timeout = kwargs.pop('mac_legacy_aging_timeout', '1800')
            mac_move_limit = kwargs.pop('mac_move_limit', '5')
            t = Template(getattr(template, 'conversation_property_create'))
            config = t.render(arp_aging_timeout=arp_aging_timeout,
                              mac_aging_timeout=mac_aging_timeout,
                              mac_legacy_aging_timeout=mac_legacy_aging_timeout,
                              mac_move_limit=mac_move_limit)
            self._callback(config)

        if get_config:
            if get_config:
                config = getattr(template, 'mac_address_table_get').format()
                rest_root = self._callback(config, handler='get_config')
                util = Util(rest_root)
                conversational_mac = True if util.find(util.root,
                                                       './/learning-mode') is not None else False
                mac_aging_timeout = util.find(util.root, './/conversational-time-out')
                mac_legacy_aging_timeout = util.find(util.root, './/legacy-time-out')
                mac_move_limit = util.find(util.root, './/mac-move-limit')
                mac_move_enable = True if util.find(util.root,
                                                    './/mac-move-detect-enable') is not None else\
                    False

                config = getattr(template, 'host_table_get').format()
                rest_root = self._callback(config, handler='get_config')
                util = Util(rest_root)

                conversational_arp = True if util.find(util.root,
                                                       './/aging-mode') is not None else False
                arp_aging_timeout = util.find(util.root, './/conversational-time-out')

                return {"conversational_mac": conversational_mac,
                        "mac_aging_timeout": mac_aging_timeout,
                        'mac_legacy_aging_timeout': mac_legacy_aging_timeout,
                        'mac_move_limit': mac_move_limit,
                        'mac_move_enable': mac_move_enable,
                        "conversational_arp": conversational_arp,
                        "arp_aging_timeout": arp_aging_timeout,
                        }
Пример #4
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
Пример #5
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
Пример #6
0
    def evpn_instance(self, **kwargs):
        """
        >>> 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.evpn_instance(get=True)
        ...      print output
        ...      output = dev.interface.evpn_instance(evi_name='Leaf1', duplicate_mac_timer=10,

        ...      max_count = '5')
        ...      output = dev.interface.evpn_instance(get=True)
        ...      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')

            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)
            self._callback(config)

        if get_config:
            config = getattr(template, 'evpn_instance_get').format()
            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
            }
Пример #7
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)
Пример #8
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
Пример #9
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
Пример #10
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
Пример #11
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
Пример #12
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)
Пример #13
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
Пример #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 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
Пример #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 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
Пример #19
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)
Пример #20
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
Пример #21
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
Пример #22
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=False,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)
            rbridge_id = kwargs.pop('rbridge_id', None)
            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 rbridge_id:
                config = getattr(template, 'overlay_gateway_attach_rb').format(
                    gw_name=gw_name, gw_type=gw_type, rbridge_id=rbridge_id)
                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')
            rbridge_id = util.find(util.root, './/rb-add')
            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': rbridge_id,
                'activate': activate,
                'vni_auto': vni_auto,
            }
Пример #23
0
    def spanning_tree_state(self, **kwargs):
        """Set Spanning Tree state.

        Args:
            int_type (str): Type of interface. (gigabitethernet,
                tengigabitethernet, vlan, port_channel etc).
            name (str): Name of interface or VLAN id.
                (For interface: 1/0/5, 1/0/10 etc).
                (For VLANs 0, 1, 100 etc).
                (For Port Channels 1, 100 etc).
            enabled (bool): Is Spanning Tree enabled? (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 `enabled` is not passed.
            ValueError: if `int_type`, `name`, or `enabled` are invalid.

        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:
            ...         enabled = True
            ...         int_type = 'tengigabitethernet'
            ...         name = '225/0/37'
            ...         output = dev.interface.enable_switchport(int_type,
            ...         name)
            ...         output = dev.interface.spanning_tree_state(
            ...         int_type=int_type, name=name, enabled=enabled)
            ...         enabled = False
            ...         output = dev.interface.spanning_tree_state(
            ...         int_type=int_type, name=name, enabled=enabled)
            ...         int_type = 'vlan'
            ...         name = '102'
            ...         enabled = False
            ...         output = dev.interface.add_vlan_int(name)
            ...         output = dev.interface.enable_switchport(
            ...             int_type, name)
            ...         output = dev.interface.spanning_tree_state(
            ...         int_type=int_type, name=name, enabled=enabled)
            ...         enabled = False
            ...         output = dev.interface.spanning_tree_state(
            ...         int_type=int_type, name=name, enabled=enabled)
            ...         output = dev.interface.del_vlan_int(name)
            ...         int_type = 'port_channel'
            ...         name = '2'
            ...         enabled = False
            ...         output = dev.interface.channel_group(name='225/0/20',
            ...                              int_type='tengigabitethernet',
            ...                              port_int=name,
            ...                              channel_type='standard',
            ...                              mode='active')
            ...         output = dev.interface.enable_switchport(
            ...             int_type, name)
            ...         output = dev.interface.spanning_tree_state(
            ...         int_type=int_type, name=name, enabled=enabled)
            ...         enabled = False
            ...         output = dev.interface.spanning_tree_state(
            ...         int_type=int_type, name=name, enabled=enabled)
            ...         output = dev.interface.remove_port_channel(
            ...             port_int=name)
        """
        int_type = kwargs.pop('int_type').lower()
        name = kwargs.pop('name')
        get = kwargs.pop('get', False)

        callback = kwargs.pop('callback', self._callback)
        valid_int_types = self.valid_int_types
        valid_int_types.append('vlan')

        if int_type not in valid_int_types:
            raise ValueError('int_type must be one of: %s' %
                             repr(valid_int_types))
        state_args = dict()
        state_args[int_type] = name
        if get:
            method_name = 'interface_%s_get' % int_type
            if int_type == 'vlan':
                method_name = 'vlan_get'
            config = (method_name, state_args)
            x = callback(config, handler='get_config')
            util = Util(x.data)

            if util.find(util.root, './/spanning-tree//shutdown'):
                return False
            return True

        enabled = kwargs.pop('enabled')
        if not isinstance(enabled, bool):
            raise ValueError('%s must be `True` or `False`.' % repr(enabled))

        if int_type == 'vlan':
            if not pyswitch.utilities.valid_vlan_id(name):
                raise InvalidVlanId('%s must be between 0 to 8191.' % int_type)
            shutdown_name = 'stp_shutdown'
            method_name = 'interface_%s_spanning_tree_update' % int_type

        else:
            if not pyswitch.utilities.valid_interface(int_type, name):
                raise ValueError('`name` must be in the format of x/y/z for '
                                 'physical interfaces or x for port channel.')
            shutdown_name = 'shutdown'
            method_name = 'interface_%s_spanning_tree_update' % int_type

        if enabled:
            state_args[shutdown_name] = False
        else:
            state_args[shutdown_name] = True
        try:
            config = (method_name, state_args)
            return callback(config)
        # TODO: Catch existing 'no shut'
        # This is in place because if the interface spanning tree is already
        # up,`ncclient` will raise an error if you try to admin up the
        # interface again.
        # TODO: add logic to shutdown STP at protocol level too.
        except AttributeError:
            return None
Пример #24
0
    def ip_anycast_gateway(self, **kwargs):
        """
        Add anycast gateway under interface ve.

        Args:
            int_type: L3 interface type on which the anycast ip
               needs to be configured.
            name:L3 interface name on which the anycast ip
               needs to be configured.
            anycast_ip: Anycast ip which the L3 interface
               needs to be associated.
            enable (bool): If ip anycast gateway should be enabled
                or disabled.Default:``True``.
            get (bool) : Get config instead of editing config. (True, False)
            rbridge_id (str): rbridge-id for device. Only required when
            type is `ve`.
            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`, `anycast_ip` is not passed.
            ValueError: if `int_type`, `name`, `anycast_ip` is invalid.
        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.ip_anycast_gateway(
            ...         int_type='ve',
            ...         name='89',
            ...         anycast_ip='10.20.1.1/24',
            ...         rbridge_id='1')
            ...         output = dev.interface.ip_anycast_gateway(
            ...         get=True,int_type='ve',
            ...         name='89',
            ...         anycast_ip='10.20.1.1/24',
            ...         rbridge_id='1')
            ...         output = dev.interface.ip_anycast_gateway(
            ...         enable=False,int_type='ve',
            ...         name='89',
            ...         anycast_ip='10.20.1.1/24',
            ...         rbridge_id='1')
            ...         # doctest: +IGNORE_EXCEPTION_DETAIL
            Traceback (most recent call last):
            KeyError
         """

        int_type = kwargs.pop('int_type').lower()
        name = kwargs.pop('name')
        anycast_ip = kwargs.pop('anycast_ip', '')
        enable = kwargs.pop('enable', True)
        get = kwargs.pop('get', False)
        rbridge_id = kwargs.pop('rbridge_id', '1')
        callback = kwargs.pop('callback', self._callback)
        valid_int_types = ['ve']

        if get and anycast_ip == '':
            enable = None
            if int_type not in valid_int_types:
                raise ValueError('`int_type` must be one of: %s' %
                                 repr(valid_int_types))
            anycast_args = dict(ve=name)

            method_name1 = 'rbridge_id_interface_%s_ip_anycast_address_get'\
                           % int_type
            method_name2 = 'rbridge_id_interface_%s_ipv6_anycast_address_get'\
                           % int_type
            anycast_args['rbridge_id'] = rbridge_id
            if not pyswitch.utilities.valid_vlan_id(name):
                raise InvalidVlanId("`name` must be between `1` and `8191`")

            config1 = (method_name1, anycast_args)
            config2 = (method_name2, anycast_args)
            result = []
            op = callback(config1, handler='get_config')
            util = Util(op.data)
            result.append(util.find(util.root, './/ip-address'))
            op = callback(config2, handler='get_config')
            util = Util(op.data)
            result.append(util.find(util.root, './/ipv6-address'))

            return result

        ipaddress = ip_interface(unicode(anycast_ip))
        if int_type not in valid_int_types:
            raise ValueError('`int_type` must be one of: %s' %
                             repr(valid_int_types))
        if anycast_ip != '':
            ipaddress = ip_interface(unicode(anycast_ip))
            if ipaddress.version == 4:
                anycast_args = dict(ve=name,
                                    ip_anycast_address=(str(anycast_ip), ))
                method_name = 'rbridge_id_interface_%s_ip_anycast_address'\
                              % int_type
            elif ipaddress.version == 6:
                anycast_args = dict(ve=name,
                                    ipv6_anycast_address=(str(anycast_ip), ))
                method_name = 'rbridge_id_interface_%s_ipv6_anycast_address'\
                              % int_type

        anycast_args['rbridge_id'] = rbridge_id

        if not pyswitch.utilities.valid_vlan_id(name):
            raise InvalidVlanId("`name` must be between `1` and `8191`")
        create_method = "%s_create" % method_name
        config = (create_method, anycast_args)

        if not enable:
            delete_method = "%s_delete" % method_name
            config = (delete_method, anycast_args)
        return callback(config)
Пример #25
0
    def neighbors(self, **kwargs):
        """list[dict]: A list of dictionary items describing the operational
        state of LLDP.
        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.lldp.neighbors()
        """

        result = []
        has_more = ''
        last_ifindex = ''
        rbridge_id = None
        if 'rbridge_id' in kwargs:
            rbridge_id = kwargs.pop('rbridge_id')
        while (has_more == '') or (has_more == 'true'):
            request_lldp = self.get_lldp_neighbors_request(
                last_ifindex, rbridge_id)

            lldp_result = self._callback(request_lldp, handler='get')
            util = Util(lldp_result.data)

            has_more = util.find(util.root, './/has-more')

            for item in util.findlist(util.root, './/lldp-neighbor-detail'):

                local_int_name = util.findText(item, './/local-interface-name')
                local_int_mac = util.findText(item, './/local-interface-mac')
                last_ifindex = util.findText(item,
                                             './/local-interface-ifindex')
                remote_int_name = util.findText(item,
                                                './/remote-interface-name')
                remote_int_mac = util.findText(item, './/remote-interface-mac')
                remote_chas_id = util.findText(item, './/remote-chassis-id')

                remote_sys_name = util.findText(item, './/remote-system-name')

                remote_sys_desc = util.findText(
                    item, './/remote-system-description')

                remote_mgmt_addr = util.findText(
                    item, './/remote-management-address')

                if 'Fo ' in local_int_name:
                    local_int_name = local_int_name.replace(
                        'Fo ', 'FortyGigabitEthernet ')
                if 'Te ' in local_int_name:
                    local_int_name = local_int_name.replace(
                        'Te ', 'TenGigabitEthernet ')
                if 'Eth ' in local_int_name:
                    local_int_name = local_int_name.replace(
                        'Eth ', 'Ethernet ')

                item_results = {
                    'local-int-name': local_int_name,
                    'local-int-mac': local_int_mac,
                    'remote-int-name': remote_int_name,
                    'remote-int-mac': remote_int_mac,
                    'remote-chassis-id': remote_chas_id,
                    'remote-system-name': remote_sys_name,
                    'remote-system-description': remote_sys_desc,
                    'remote-management-address': remote_mgmt_addr
                }
                result.append(item_results)

        return result
Пример #26
0
    def mct_client_interface_create(self, **kwargs):
        """ Configure/get/delete mct client interface under the mct client

        Args:
            cluster_name (str): MCT Cluster Name.
            cluster_id (int): . MCT Cluster ID.
            client_name (str): MCT Client Name.
            client_id (int): . MCT Client ID. (Valid Values: 1-512)
            intf_type (str): Type of interface. ['Ethernet', 'Port_channel']
            intf_name (str): Intername name.
            client_deploy (bool): Deploy. (True, False)
            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`, `cluster_name`, `cluster_id`
                      `client_name`, `client_id` are  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:
            ...     dev.mct.mct_client_interface_create(client_deploy=True,
            ...              cluster_id=1, cluster_name='pod-cluster')
            ...              client_id=1, client_name='client1',
            ...              intf_type='Ethernet', intf_name='0/35')
            ...     output = dev.mct.mct_client_interface_create(get=True,
            ...              cluster_id=1, cluster_name='pod-cluster')
            ...              client_id=1, client_name='client1')
            ...    print output
            ...    dev.mct.mct_client_interface_create(delete=True,
            ...        cluster_id=1, cluster_name='pod-cluster')
            ...        client_id=1, client_name='client1')
        """
        cluster_name = kwargs.pop('cluster_name')
        cluster_id = kwargs.pop('cluster_id')
        client_name = kwargs.pop('client_name', None)
        client_id = kwargs.pop('client_id', None)

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

        if cluster_id not in xrange(1, 65536):
            raise ValueError("cluster_id %s must be in range `1-65535`" %
                             (cluster_id))
        if client_id is not None and not xrange(1, 513):
            raise ValueError("client_id %s must be in range `1-512`" %
                             (client_id))

        mct_args = dict(cluster=(cluster_name, str(cluster_id)))
        if delete:
            method_name = 'cluster_client_client_interface_delete'
            mct_args.update(client=(client_name, str(client_id)))
            config = (method_name, mct_args)
            return callback(config)
        if not get_config:
            intf_name = kwargs.pop('intf_name')
            intf_type = kwargs.pop('intf_type', 'Ethernet')
            if intf_type == 'ethernet':
                intf_type = 'Ethernet'
            if intf_type == 'port_channel':
                intf_type = 'Port-channel'
            if intf_type not in ['Ethernet', 'Port-channel']:
                raise ValueError('intf_type %s must be either'
                                 '`Ethernet or Port-channel`' % (intf_type))
            method_name = 'cluster_client_client_interface_update'
            mct_args.update(client=(client_name, str(client_id)),
                            if_type=intf_type,
                            if_value=intf_name)
            config = (method_name, mct_args)
            return callback(config)
        elif get_config:
            method_name = 'cluster_client_client_interface_get'
            mct_args.update(client=(client_name, str(client_id)))
            config = (method_name, mct_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            if output.data != '<output></output>':
                result = util.find(util.root, './/if-value')
            else:
                result = None

        return result
Пример #27
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
Пример #28
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)
Пример #29
0
    def vrrp(self, **kwargs):
        """Enable or Disable VRRP.

        Args:
            ip_version (str): The IP version ('4' or '6') for which VRRP should
                be enabled/disabled.  Default: `4`.
            enable (bool): If VRRP should be enabled or disabled.  Default:
                ``True``.
            rbridge_id (str): The rbridge ID of the device on which VRRP will
                be enabled/disabled.  Default: `1`.
            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
            >>> 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.vrrp(rbridge_id='231',enable=True)
            ...         output = dev.services.vrrp(rbridge_id='231',get=True)
            ...         output = dev.services.vrrp(rbridge_id='231',enable=False)
            ...         output = dev.services.vrrp(rbridge_id='231',get=True)
        """
        ip_version = kwargs.pop('ip_version', '4')
        get = kwargs.pop('get', False)
        enable = kwargs.pop('enable', True)
        rbridge_id = kwargs.pop('rbridge_id', '1')
        callback = kwargs.pop('callback', self._callback)
        if get:
            enable = None

        vrrp_args = dict(rbridge_id=rbridge_id)
        vrrp_method = 'rbridge_id_protocol_vrrp_update'
        if ip_version == '6':
            vrrp_method = 'rbridge_id_ipv6_protocol_vrrp_update'

        if get:
            config = ('rbridge_id_protocol_vrrp_get', vrrp_args)
            x = callback(config, handler='get_config')
            util = Util(x.data)

            ipv4_vrrp = util.find(util.root, './/vrrp')
            ipv4_vrrp = ipv4_vrrp if ipv4_vrrp else False

            config = ('rbridge_id_ipv6_protocol_vrrp_get', vrrp_args)
            x = callback(config, handler='get_config')
            util = Util(x.data)

            ipv6_vrrp = util.find(util.root, './/vrrp')
            ipv6_vrrp = ipv6_vrrp if ipv6_vrrp else False
            return {'ipv4_vrrp': ipv4_vrrp, 'ipv6_vrrp': ipv6_vrrp}

        if not enable:
            vrrp_args['vrrp'] = False
        else:
            vrrp_args['vrrp'] = True

        config = (vrrp_method, vrrp_args)
        return callback(config)
Пример #30
0
    def mct_cluster_create(self, **kwargs):
        """Configure Name of MCT cluster

        Args:
            cluster_name: Name of Overlay Gateway
            cluster_id: Name of Overlay Gateway
            get (bool): Get config instead of editing config. (True, False)
            delete (bool): True, delete the overlay gateway 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 `gw_name` is not passed.
            ValueError: if `gw_name` is invalid.

        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.mct.mct_cluster_create(
            ...              cluster_name='Leaf', cluster_id=10)
            ...     output = dev.mct.mct_cluster_create(get=True)
            ...     print output
            ...     dev.mct.mct_cluster_create(delete=True)
        """
        cluster_name = kwargs.pop('cluster_name', None)
        cluster_id = kwargs.pop('cluster_id', None)

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

        if cluster_id is not None and not xrange(1, 65536):
            raise ValueError("cluster_id %s must be in range `1-65535`" %
                             (cluster_id))

        if delete:
            mct_args = dict(cluster=(cluster_name, str(cluster_id)))
            method_name = 'cluster_delete'
            config = (method_name, mct_args)
            return callback(config)
        if not get_config:
            mct_args = dict(cluster=(cluster_name, str(cluster_id)))
            method_name = 'cluster_create'
            config = (method_name, mct_args)
            return callback(config)
        elif get_config:
            method_name = 'cluster_get'
            config = (method_name, mct_args)
            output = callback(config, handler='get_config')
            util = Util(output.data)
            result = util.find(util.root, './/cluster-name'),\
                util.find(util.root, './/cluster-id')

        return result