예제 #1
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,
            }
예제 #2
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)
예제 #3
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