예제 #1
0
    def _delete_config(self, want, have):
        """ Commands to delete configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to delete the current configuration
                  of the provided objects
        """
        commands = []

        if not want and have:
            return ['no log']

        differ = DictDiffer(have, want)
        dict_intsec = differ.deepintersect()

        severity = dict_intsec.get('severity')
        if severity is not None:
            commands.append('no log severity')

        syslog = dict_intsec.get('syslog')
        if syslog is not None:
            for each in syslog:
                commands.append('no log syslog {0}'.format(each))

        return commands
    def _delete_config(self, want, have):
        """ Commands to delete configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to delete the current configuration
                  of the provided objects
        """
        commands = []

        if not want and have:
            return ['no link-aggregation']

        differ = DictDiffer(have, want, {'lag_id': [1], 'name': [3]})
        dict_intsec = differ.deepintersect()

        sys_prio = dict_intsec.get('sys_prio')
        if sys_prio is not None:
            commands.append('no link-aggregation system-priority')

        lag = dict_intsec.get('lag')
        if lag is not None:
            for each_lag in lag:
                commands.extend(self._delete_lag_commands(each_lag))

        return commands
    def _delete_config(self, want, have):
        """ Commands to delete configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to delete the current configuration
                  of the provided objects
        """
        commands = []

        if not want and have:
            return ['no switchport']

        differ = DictDiffer(have, want, {
            'interface_name': [1],
            'traffic': [3]
        })
        dict_intsec = differ.deepintersect()

        for diff in dict_intsec:
            interface_name = diff.get('interface_name')
            switchport_cmd = 'no switchport interface {0}'.format(
                interface_name)

            switchport_n_keys = diff.get('n_keys')
            if switchport_n_keys == 1:
                commands.append(switchport_cmd)
                continue

            native_vlan_id = diff.get('native_vlan_id')
            if native_vlan_id is not None:
                commands.append('{0} native-vlan'.format(switchport_cmd))

            qinq = diff.get('qinq')
            if qinq is not None:
                commands.append('{0} qinq'.format(switchport_cmd))

            storm_control = diff.get('storm_control')
            if storm_control is not None:
                for each in storm_control:
                    each = dict(each)
                    traffic = each.get('traffic')
                    storm_control_cmd = '{0} storm-control {1}'.format(
                        switchport_cmd, traffic)

                    commands.append(storm_control_cmd)

            tpid = diff.get('tpid')
            if tpid is not None:
                commands.append('{0} tpid'.format(switchport_cmd))

        return commands
    def _set_config(self, want, have):
        """ Commands to set configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to set the current configuration
                  of the provided objects
        """
        commands = []

        differ = DictDiffer(have, want, {
            'interface_name': [1],
            'traffic': [3]
        })

        dict_diff = differ.deepdiff()
        for diff in dict_diff:
            interface_name = diff.get('interface_name')
            switchport_cmd = 'switchport interface {0}'.format(interface_name)

            if len(diff) == 1:
                commands.append(switchport_cmd)
                continue

            native_vlan_id = diff.get('native_vlan_id')
            if native_vlan_id is not None:
                commands.append('{0} native-vlan vlan-id {1}'.format(
                    switchport_cmd, native_vlan_id))

            qinq = diff.get('qinq')
            if qinq is not None:
                commands.append('{0} {1} qinq'.format('' if qinq else 'no',
                                                      switchport_cmd).strip())

            storm_control = diff.get('storm_control')
            if storm_control is not None:
                for each in storm_control:
                    each = dict(each)
                    traffic = each.get('traffic')
                    percent = each.get('percent')
                    storm_control_cmd = '{0} storm-control {1} {2}'.format(
                        switchport_cmd, traffic, percent)

                    commands.append(storm_control_cmd)

            tpid = diff.get('tpid')
            if tpid is not None:
                commands.append('{0} tpid {1}'.format(switchport_cmd, tpid))

        return commands
예제 #5
0
    def _delete_config(self, want, have):
        """ Commands to delete configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to delete the current configuration
                  of the provided objects
        """
        commands = []

        if not want and have:
            return ['no dot1q']

        differ = DictDiffer(have, want, {'vlan_id': [1], 'name': [3]})
        dict_intsec = differ.deepintersect()

        for diff in dict_intsec:
            vlan_id = diff.get('vlan_id')
            vlan_cmd = 'no dot1q vlan {0}'.format(vlan_id)

            vlan_n_keys = diff.get('n_keys')
            if vlan_n_keys == 1:
                commands.append(vlan_cmd)
                continue

            name = diff.get('name')
            if name is not None:
                commands.append('{0} name'.format(vlan_cmd))

            interface = diff.get('interface')
            if interface is not None:
                for each in interface:
                    each = dict(each)
                    intf_name = each.get('name')
                    intf_cmd = '{0} interface {1}'.format(vlan_cmd, intf_name)

                    intf_n_keys = each.get('n_keys')
                    if intf_n_keys == 1:
                        commands.append(intf_cmd)
                        continue

                    tagged = each.get('tagged')
                    if tagged is not None:
                        intf_cmd += ' tagged' if tagged else ' untagged'
                    commands.append(intf_cmd)

        return commands
예제 #6
0
    def _set_config(self, want, have):
        """ Commands to set configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to set the current configuration
                  of the provided objects
        """
        commands = []

        differ = DictDiffer(have, want)
        dict_diff = differ.deepdiff()

        severity = dict_diff.get('severity')
        if severity is not None:
            commands.append('log severity {0}'.format(severity))

        syslog = dict_diff.get('syslog')
        if syslog is not None:
            for each in syslog:
                commands.append('log syslog {0}'.format(each))

        return commands
    def _set_config(self, want, have):
        """ Commands to set configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to set the current configuration
                  of the provided objects
        """
        commands = []

        differ = DictDiffer(have, want, {'lag_id': [1], 'name': [3]})
        dict_diff = differ.deepdiff()

        sys_prio = dict_diff.get('sys_prio')
        if sys_prio is not None:
            commands.append(
                'link-aggregation system-priority {0}'.format(sys_prio))

        lag = dict_diff.get('lag')
        if lag is not None:
            for each_lag in lag:
                commands.extend(self._get_lag_commands(each_lag))

        return commands
예제 #8
0
    def _set_config(self, want, have):
        """ Commands to set configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to set the current configuration
                  of the provided objects
        """
        commands = []

        differ = DictDiffer(have, want, {'vlan_id': [1], 'name': [3]})

        dict_diff = differ.deepdiff()
        for diff in dict_diff:
            vlan_id = diff.get('vlan_id')
            vlan_cmd = 'dot1q vlan {0}'.format(vlan_id)

            if len(diff) == 1:
                commands.append(vlan_cmd)
                continue

            name = diff.get('name')
            if name is not None:
                commands.append('{0} name "{1}"'.format(vlan_cmd, name))

            interface = diff.get('interface')
            if interface is not None:
                for each in interface:
                    each = dict(each)
                    intf_name = each.get('name')
                    intf_cmd = '{0} interface {1}'.format(vlan_cmd, intf_name)

                    tagged = each.get('tagged')
                    if tagged is not None:
                        intf_cmd += ' tagged' if tagged else ' untagged'
                    commands.append(intf_cmd)

        return commands
예제 #9
0
    def _delete_config(self, want, have):
        """ Commands to delete configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to delete the current configuration
                  of the provided objects
        """
        commands = []

        if not want and have:
            return ['no interface l3']

        differ = DictDiffer(have, want, {'name': [1], 'ip': [5]})
        dict_intsec = differ.deepintersect()

        for diff in dict_intsec:
            intf_name = diff.get('name')
            intf_cmd = 'no interface l3 {0}'.format(intf_name)

            intf_n_keys = diff.get('n_keys')
            if intf_n_keys == 1:
                commands.append(intf_cmd)
                continue

            description = diff.get('description')
            if description is not None:
                commands.append('{0} description'.format(intf_cmd))

            ip_mtu = diff.get('ip_mtu')
            if ip_mtu is not None:
                commands.append('{0} ip-mtu'.format(intf_cmd))

            lower_layer_if = diff.get('lower_layer_if')
            if lower_layer_if is not None:
                commands.append('{0} lower-layer-if vlan'.format(intf_cmd))

            # Ignoring vlan link detect deletion since its not possible, always returns error
            # vlan_link_detect = diff.get('vlan_link_detect')
            # if vlan_link_detect is not None:
            #     commands.append('{0} vlan-link-detect'.format(intf_cmd))

            vrf = diff.get('vrf')
            if vrf is not None:
                commands.append('{0} vrf'.format(intf_cmd))

            ipv4 = diff.get('ipv4')
            if ipv4 is not None:
                address = ipv4.get('address')
                if address is not None:
                    commands.append(
                        '{0} ipv4 address {1}'.format(intf_cmd, address))

                secondary = ipv4.get('secondary')
                if secondary is not None:
                    for each in secondary:
                        commands.append(
                            '{0} ipv4 address secondary {1}'.format(intf_cmd, each))

            ipv6 = diff.get('ipv6')
            if ipv6 is not None:
                address = ipv6.get('address')
                if address is not None:
                    for each in address:
                        commands.append(
                            '{0} ipv6 address {1}'.format(intf_cmd, each))

                nd_ra = ipv6.get('nd_ra')
                if nd_ra is not None:
                    nd_ra_cmd = '{0} ipv6 nd ra'.format(intf_cmd)

                    lifetime = nd_ra.get('lifetime')
                    if lifetime is not None:
                        commands.append('{0} lifetime'.format(nd_ra_cmd))

                    max_interval = nd_ra.get('max_interval')
                    if max_interval is not None:
                        commands.append('{0} max-interval'.format(nd_ra_cmd))

                    min_interval = nd_ra.get('min_interval')
                    if min_interval is not None:
                        commands.append('{0} min-interval'.format(nd_ra_cmd))

                    prefix = nd_ra.get('prefix')
                    if prefix is not None:
                        for each in prefix:
                            each = dict(each)
                            prefix_ip = each.get('ip')
                            prefix_cmd = '{0} prefix {1}'.format(
                                nd_ra_cmd, prefix_ip)

                            prefix_n_keys = each.get('n_keys')
                            if prefix_n_keys == 1:
                                commands.append(prefix_cmd)
                                continue

                            no_advertise = each.get('no_advertise')
                            if no_advertise is not None:
                                commands.append(
                                    '{0} no-advertise'.format(prefix_cmd))

                            no_autoconfig = each.get('no_autoconfig')
                            if no_autoconfig is not None:
                                commands.append(
                                    '{0} no-autoconfig'.format(prefix_cmd))

                            off_link = each.get('off_link')
                            if off_link is not None:
                                commands.append(
                                    '{0} off-link'.format(prefix_cmd))

                    suppress = nd_ra.get('suppress')
                    if suppress is not None:
                        commands.append('{0} suppress'.format(nd_ra_cmd))

                    mtu_suppress = nd_ra.get('mtu_suppress')
                    if mtu_suppress is not None:
                        commands.append('{0} mtu suppress'.format(nd_ra_cmd))

                enable = ipv6.get('enable')
                if enable is not None:
                    commands.append('{0} ipv6 enable'.format(intf_cmd))

        return commands
예제 #10
0
    def _set_config(self, want, have):
        """ Commands to set configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to set the current configuration
                  of the provided objects
        """
        commands = []

        differ = DictDiffer(have, want, {'name': [1], 'ip': [5]})

        dict_diff = differ.deepdiff()
        for diff in dict_diff:
            intf_name = diff.get('name')
            intf_cmd = 'interface l3 {0}'.format(intf_name)

            if len(diff) == 1:
                commands.append(intf_cmd)
                continue

            description = diff.get('description')
            if description is not None:
                commands.append('{0} description "{1}"'.format(
                    intf_cmd, description))

            ip_mtu = diff.get('ip_mtu')
            if ip_mtu is not None:
                commands.append('{0} ip-mtu {1}'.format(intf_cmd, ip_mtu))

            lower_layer_if = diff.get('lower_layer_if')
            if lower_layer_if is not None:
                commands.append(
                    '{0} lower-layer-if vlan {1}'.format(intf_cmd, lower_layer_if))

            vlan_link_detect = diff.get('vlan_link_detect')
            if vlan_link_detect is not None:
                commands.append('{0} vlan-link-detect {1}'.format(intf_cmd,
                                                                  'enabled' if vlan_link_detect else 'disabled'))

            vrf = diff.get('vrf')
            if vrf is not None:
                commands.append('{0} vrf {1}'.format(intf_cmd, vrf))

            ipv4 = diff.get('ipv4')
            if ipv4 is not None:
                address = ipv4.get('address')
                if address is not None:
                    commands.append(
                        '{0} ipv4 address {1}'.format(intf_cmd, address))

                secondary = ipv4.get('secondary')
                if secondary is not None:
                    for each in secondary:
                        commands.append(
                            '{0} ipv4 address secondary {1}'.format(intf_cmd, each))

            ipv6 = diff.get('ipv6')
            if ipv6 is not None:
                enable = ipv6.get('enable')
                if enable is not None:
                    commands.append('{0} {1} ipv6 enable'.format(
                        '' if enable else 'no', intf_cmd).strip())

                address = ipv6.get('address')
                if address is not None:
                    for each in address:
                        commands.append(
                            '{0} ipv6 address {1}'.format(intf_cmd, each))

                nd_ra = ipv6.get('nd_ra')
                if nd_ra is not None:
                    nd_ra_cmd = '{0} ipv6 nd ra'.format(intf_cmd)

                    lifetime = nd_ra.get('lifetime')
                    if lifetime is not None:
                        commands.append(
                            '{0} lifetime {1}'.format(nd_ra_cmd, lifetime))

                    max_interval = nd_ra.get('max_interval')
                    if max_interval is not None:
                        commands.append(
                            '{0} max-interval {1}'.format(nd_ra_cmd, max_interval))

                    min_interval = nd_ra.get('min_interval')
                    if min_interval is not None:
                        commands.append(
                            '{0} min-interval {1}'.format(nd_ra_cmd, min_interval))

                    prefix = nd_ra.get('prefix')
                    if prefix is not None:
                        for each in prefix:
                            each = dict(each)
                            prefix_ip = each.get('ip')
                            prefix_cmd = '{0} prefix {1}'.format(
                                nd_ra_cmd, prefix_ip)

                            if len(each) == 1:
                                commands.append(prefix_cmd)
                                continue

                            no_advertise = each.get('no_advertise')
                            if no_advertise is not None:
                                commands.append(
                                    '{0} {1} no-advertise'.format('' if no_advertise else 'no', prefix_cmd).strip())

                            no_autoconfig = each.get('no_autoconfig')
                            if no_autoconfig is not None:
                                commands.append(
                                    '{0} {1} no-autoconfig'.format('' if no_autoconfig else 'no', prefix_cmd).strip())

                            off_link = each.get('off_link')
                            if off_link is not None:
                                commands.append(
                                    '{0} {1} off-link'.format('' if off_link else 'no', prefix_cmd).strip())

                    suppress = nd_ra.get('suppress')
                    if suppress is not None:
                        commands.append('{0} {1} suppress'.format(
                            '' if suppress else 'no', nd_ra_cmd).strip())

                    mtu_suppress = nd_ra.get('mtu_suppress')
                    if mtu_suppress is not None:
                        commands.append('{0} {1} mtu suppress'.format(
                            '' if mtu_suppress else 'no', nd_ra_cmd).strip())

        return commands
    def _delete_config(self, want, have):
        """ Commands to delete configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to delete the current configuration
                  of the provided objects
        """
        commands = []

        if not want and have:
            return ['no oam twamp']

        differ = DictDiffer(have, want, {
            'address': [3],
            'network': [3],
            'id': [2, 4]
        })
        dict_intsec = differ.deepintersect()

        reflector = dict_intsec.get('reflector')
        if reflector is not None:
            reflector_cmd = 'no oam twamp reflector'

            admin_status = reflector.get('admin_status')
            if admin_status is not None:
                commands.append(
                    '{0} administrative-status'.format(reflector_cmd))

            ipv4 = reflector.get('ipv4')
            if ipv4 is not None:
                client_address = ipv4.get('client_address')
                if client_address is not None:
                    for each in client_address:
                        address = each.get('address')
                        client_address_cmd = '{0} ipv4 client-address {1}'.format(
                            reflector_cmd, address)

                        client_address_n_keys = each.get('n_keys')
                        if client_address_n_keys == 1:
                            commands.append(client_address_cmd)
                            continue

                        state = each.get('state')
                        if state is not None:
                            commands.append('{0} {1}'.format(
                                client_address_cmd, state))

                client_network = ipv4.get('client_network')
                if client_network is not None:
                    for each in client_network:
                        network = each.get('network')
                        client_network_cmd = '{0} ipv4 client-network {1}'.format(
                            reflector_cmd, network)

                        client_network_n_keys = each.get('n_keys')
                        if client_network_n_keys == 1:
                            commands.append(client_network_cmd)
                            continue

                        state = each.get('state')
                        if state is not None:
                            commands.append('{0} {1}'.format(
                                client_network_cmd, state))

            ipv6 = reflector.get('ipv6')
            if ipv6 is not None:
                client_address = ipv6.get('client_address')
                if client_address is not None:
                    for each in client_address:
                        address = each.get('address')
                        client_address_cmd = '{0} ipv6 client-address {1}'.format(
                            reflector_cmd, address)

                        client_address_n_keys = each.get('n_keys')
                        if client_address_n_keys == 1:
                            commands.append(client_address_cmd)
                            continue

                        state = each.get('state')
                        if state is not None:
                            commands.append('{0} {1}'.format(
                                client_address_cmd, state))

                client_network = ipv6.get('client_network')
                if client_network is not None:
                    for each in client_network:
                        network = each.get('network')
                        client_network_cmd = '{0} ipv6 client-network {1}'.format(
                            reflector_cmd, network)

                        client_network_n_keys = each.get('n_keys')
                        if client_network_n_keys == 1:
                            commands.append(client_network_cmd)
                            continue

                        state = each.get('state')
                        if state is not None:
                            commands.append('{0} {1}'.format(
                                client_network_cmd, state))

            port = reflector.get('port')
            if port is not None:
                commands.append('{0} port'.format(reflector_cmd))

        sender = dict_intsec.get('sender')
        if sender is not None:
            sender_cmd = 'no oam twamp sender'

            admin_status = sender.get('admin_status')
            if admin_status is not None:
                commands.append('{0} administrative-status'.format(sender_cmd))

            connection = sender.get('connection')
            if connection is not None:
                for each in connection:
                    conn_id = each.get('id')
                    conn_cmd = '{0} connection {1}'.format(sender_cmd, conn_id)

                    conn_n_keys = each.get('n_keys')
                    if conn_n_keys == 1:
                        commands.append(conn_cmd)
                        continue

                    admin_status = each.get('admin_status')
                    if admin_status is not None:
                        commands.append(
                            '{0} administrative-status'.format(conn_cmd))

                    ipv4 = each.get('ipv4')
                    if ipv4 is not None:
                        source_address = ipv4.get('source_address')
                        if source_address is not None:
                            commands.append(
                                '{0} ipv4 source-address'.format(conn_cmd))

                        target_address = ipv4.get('target_address')
                        if target_address is not None:
                            commands.append(
                                '{0} ipv4 target-address'.format(conn_cmd))

                    ipv6 = each.get('ipv6')
                    if ipv6 is not None:
                        source_address = ipv6.get('source_address')
                        if source_address is not None:
                            commands.append(
                                '{0} ipv6 source-address'.format(conn_cmd))

                        target_address = ipv6.get('target_address')
                        if target_address is not None:
                            commands.append(
                                '{0} ipv6 target-address'.format(conn_cmd))

                    number_of_packets = each.get('number_of_packets')
                    if number_of_packets is not None:
                        commands.append(
                            '{0} number-of-packets'.format(conn_cmd))

                    server_port = each.get('server_port')
                    if server_port is not None:
                        commands.append('{0} server-port'.format(conn_cmd))

                    test_interval = each.get('test_interval')
                    if test_interval is not None:
                        commands.append('{0} test-interval'.format(conn_cmd))

                    test_session = each.get('test_session')
                    if test_session is not None:
                        for each_test_session in test_session:
                            test_session_id = each_test_session.get('id')
                            test_session_cmd = '{0} test-session {1}'.format(
                                conn_cmd, test_session_id)

                            test_session_n_keys = each_test_session.get(
                                'n_keys')
                            if test_session_n_keys == 1:
                                commands.append(test_session_cmd)
                                continue

                            test_session_ipv4 = each_test_session.get('ipv4')
                            if test_session_ipv4 is not None:
                                source_address = test_session_ipv4.get(
                                    'source_address')
                                if source_address is not None:
                                    commands.append(
                                        '{0} ipv4 source-address'.format(
                                            test_session_cmd))

                                target_address = test_session_ipv4.get(
                                    'target_address')
                                if target_address is not None:
                                    commands.append(
                                        '{0} ipv4 target-address'.format(
                                            test_session_cmd))

                            test_session_ipv6 = each_test_session.get('ipv6')
                            if test_session_ipv6 is not None:
                                source_address = test_session_ipv6.get(
                                    'source_address')
                                if source_address is not None:
                                    commands.append(
                                        '{0} ipv6 source-address'.format(
                                            test_session_cmd))

                                target_address = test_session_ipv6.get(
                                    'target_address')
                                if target_address is not None:
                                    commands.append(
                                        '{0} ipv6 target-address'.format(
                                            test_session_cmd))

                            dscp = each_test_session.get('dscp')
                            if dscp is not None:
                                commands.append(
                                    '{0} dscp'.format(test_session_cmd))

                            max_port = each_test_session.get('max_port')
                            if max_port is not None:
                                commands.append(
                                    '{0} max-port'.format(test_session_cmd))

                            min_port = each_test_session.get('min_port')
                            if min_port is not None:
                                commands.append(
                                    '{0} min-port'.format(test_session_cmd))

                            packet_size = each_test_session.get('packet_size')
                            if packet_size is not None:
                                commands.append(
                                    '{0} packet-size'.format(test_session_cmd))

        return commands
예제 #12
0
    def _delete_config(self, want, have):
        """ Commands to delete configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to delete the current configuration
                  of the provided objects
        """
        commands = []

        if not want and have:
            return ['no lldp']

        differ = DictDiffer(have, want, {'name': [1]})
        dict_intsec = differ.deepintersect()

        interface = dict_intsec.get('interface')
        if interface is not None:
            for each in interface:
                each = dict(each)
                intf_name = each.get('name')
                intf_cmd = 'no lldp interface {0}'.format(intf_name)

                intf_n_keys = each.get('n_keys')
                if intf_n_keys == 1:
                    commands.append(intf_cmd)
                    continue

                admin_status = each.get('admin_status')
                if admin_status is not None:
                    commands.append('{0} admin-status'.format(intf_cmd))

                notification = each.get('notification')
                if notification is not None:
                    commands.append('{0} notification'.format(intf_cmd))

                tlv_port_description = each.get('tlv_port_description')
                if tlv_port_description is not None:
                    commands.append(
                        '{0} tlvs-tx port-description'.format(intf_cmd))

                tlv_system_capabilities = each.get('tlv_system_capabilities')
                if tlv_system_capabilities is not None:
                    commands.append(
                        '{0} tlvs-tx system-capabilities'.format(intf_cmd))

                tlv_system_description = each.get('tlv_system_description')
                if tlv_system_description is not None:
                    commands.append(
                        '{0} tlvs-tx system-description'.format(intf_cmd))

                tlv_system_name = each.get('tlv_system_name')
                if tlv_system_name is not None:
                    commands.append('{0} tlvs-tx system-name'.format(intf_cmd))

        msg_fast_tx = dict_intsec.get('msg_fast_tx')
        if msg_fast_tx is not None:
            commands.append('no lldp message-fast-tx')

        msg_tx_hold_multi = dict_intsec.get('msg_tx_hold_multi')
        if msg_tx_hold_multi is not None:
            commands.append('no lldp message-tx-hold-multiplier')

        msg_tx_interval = dict_intsec.get('msg_tx_interval')
        if msg_tx_interval is not None:
            commands.append('no lldp message-tx-interval')

        notification_interval = dict_intsec.get('notification_interval')
        if notification_interval is not None:
            commands.append('no lldp notification-interval')

        reinit_delay = dict_intsec.get('reinit_delay')
        if reinit_delay is not None:
            commands.append('no lldp reinit-delay')

        tx_credit_max = dict_intsec.get('tx_credit_max')
        if tx_credit_max is not None:
            commands.append('no lldp tx-credit-max')

        tx_fast_init = dict_intsec.get('tx_fast_init')
        if tx_fast_init is not None:
            commands.append('no lldp tx-fast-init')

        return commands
예제 #13
0
    def _set_config(self, want, have):
        """ Commands to set configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to set the current configuration
                  of the provided objects
        """
        commands = []

        differ = DictDiffer(have, want, {'name': [1]})
        dict_diff = differ.deepdiff()

        interface = dict_diff.get('interface')
        if interface is not None:
            for each in interface:
                each = dict(each)
                intf_name = each.get('name')
                intf_cmd = 'lldp interface {0}'.format(intf_name)

                if len(each) == 1:
                    commands.append(intf_cmd)
                    continue

                admin_status = each.get('admin_status')
                if admin_status is not None:
                    commands.append('{0} admin-status {1}'.format(
                        intf_cmd, admin_status))

                notification = each.get('notification')
                if notification is not None:
                    commands.append('{0} {1} notification'.format(
                        '' if notification else 'no', intf_cmd).strip())

                tlv_port_description = each.get('tlv_port_description')
                if tlv_port_description is not None:
                    commands.append('{0} {1} tlvs-tx port-description'.format(
                        '' if tlv_port_description else 'no',
                        intf_cmd).strip())

                tlv_system_capabilities = each.get('tlv_system_capabilities')
                if tlv_system_capabilities is not None:
                    commands.append(
                        '{0} {1} tlvs-tx system-capabilities'.format(
                            '' if tlv_system_capabilities else 'no',
                            intf_cmd).strip())

                tlv_system_description = each.get('tlv_system_description')
                if tlv_system_description is not None:
                    commands.append(
                        '{0} {1} tlvs-tx system-description'.format(
                            '' if tlv_system_description else 'no',
                            intf_cmd).strip())

                tlv_system_name = each.get('tlv_system_name')
                if tlv_system_name is not None:
                    commands.append('{0} {1} tlvs-tx system-name'.format(
                        '' if tlv_system_name else 'no', intf_cmd).strip())

        msg_fast_tx = dict_diff.get('msg_fast_tx')
        if msg_fast_tx is not None:
            commands.append('lldp message-fast-tx {0}'.format(msg_fast_tx))

        msg_tx_hold_multi = dict_diff.get('msg_tx_hold_multi')
        if msg_tx_hold_multi is not None:
            commands.append('lldp message-tx-hold-multiplier {0}'.format(
                msg_tx_hold_multi))

        msg_tx_interval = dict_diff.get('msg_tx_interval')
        if msg_tx_interval is not None:
            commands.append(
                'lldp message-tx-interval {0}'.format(msg_tx_interval))

        notification_interval = dict_diff.get('notification_interval')
        if notification_interval is not None:
            commands.append(
                'lldp notification-interval {0}'.format(notification_interval))

        reinit_delay = dict_diff.get('reinit_delay')
        if reinit_delay is not None:
            commands.append('lldp reinit-delay {0}'.format(reinit_delay))

        tx_credit_max = dict_diff.get('tx_credit_max')
        if tx_credit_max is not None:
            commands.append('lldp tx-credit-max  {0}'.format(tx_credit_max))

        tx_fast_init = dict_diff.get('tx_fast_init')
        if tx_fast_init is not None:
            commands.append('lldp tx-fast-init {0}'.format(tx_fast_init))

        return commands
예제 #14
0
    def _delete_config(self, want, have):
        """ Commands to delete configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to delete the current configuration
                  of the provided objects
        """
        commands = []

        if not want and have:
            return ['no sntp']

        differ = DictDiffer(have, want, {'id': [1], 'address': [1]})
        dict_intsec = differ.deepintersect()

        auth = dict_intsec.get('auth')
        if auth is not None:
            commands.append('no sntp authenticate')

        auth_key = dict_intsec.get('auth_key')
        if auth_key is not None:
            for each in auth_key:
                each = dict(each)
                id_value = each.get('id')
                auth_key_cmd = 'no sntp authentication-key {0}'.format(
                    id_value)

                auth_key_n_keys = each.get('n_keys')
                if auth_key_n_keys == 1:
                    commands.append(auth_key_cmd)
                    continue

        client = dict_intsec.get('client')
        if client is not None:
            commands.append('no sntp client')

        max_poll = dict_intsec.get('max_poll')
        if max_poll is not None:
            commands.append('no sntp max-poll')

        min_poll = dict_intsec.get('min_poll')
        if min_poll is not None:
            commands.append('no sntp min-poll')

        server = dict_intsec.get('server')
        if server is not None:
            for each in server:
                each = dict(each)
                address = each.get('address')
                server_cmd = 'no sntp server {0}'.format(address)

                server_n_keys = each.get('n_keys')
                if server_n_keys == 1:
                    commands.append(server_cmd)
                    continue

                key_id = each.get('key_id')
                if key_id is not None:
                    server_cmd += ' key'
                commands.append(server_cmd)

        source = dict_intsec.get('source')
        if source is not None:
            source = dict(source)
            ipv4 = source.get('ipv4')
            if ipv4 is not None:
                commands.append('no sntp source ipv4')
            ipv6 = source.get('ipv6')
            if ipv6 is not None:
                commands.append('no sntp source ipv6')

        return commands
예제 #15
0
    def _set_config(self, want, have):
        """ Commands to set configuration based on the want and have config

        :rtype: A list
        :returns: the commands necessary to set the current configuration
                  of the provided objects
        """
        commands = []

        differ = DictDiffer(have, want, {'id': [1], 'address': [1]})
        dict_diff = differ.deepdiff()

        auth = dict_diff.get('auth')
        if auth is not None:
            commands.append(
                '{0} sntp authenticate'.format('' if auth else 'no').strip())

        auth_key = dict_diff.get('auth_key')
        if auth_key is not None:
            for each in auth_key:
                each = dict(each)
                id_value = each.get('id')
                auth_key_cmd = 'sntp authentication-key {0}'.format(id_value)

                if len(each) == 1:
                    commands.append(auth_key_cmd)
                    continue

                pass_value = each.get('pass')
                if pass_value is not None:
                    auth_key_cmd += ' md5 {0}'.format(pass_value)
                commands.append(auth_key_cmd)

        client = dict_diff.get('client')
        if client is not None:
            commands.append(
                '{0} sntp client'.format('' if client else 'no').strip())

        max_poll = dict_diff.get('max_poll')
        if max_poll is not None:
            commands.append('sntp max-poll {0}'.format(max_poll))

        min_poll = dict_diff.get('min_poll')
        if min_poll is not None:
            commands.append('sntp min-poll {0}'.format(min_poll))

        server = dict_diff.get('server')
        if server is not None:
            for each in server:
                each = dict(each)
                address = each.get('address')
                server_cmd = 'sntp server {0}'.format(address)

                if len(each) == 1:
                    commands.append(server_cmd)
                    continue

                key_id = each.get('key_id')
                if key_id is not None:
                    server_cmd += ' key {0}'.format(key_id)
                commands.append(server_cmd)

        source = dict_diff.get('source')
        if source is not None:
            source = dict(source)
            ipv4 = source.get('ipv4')
            if ipv4 is not None:
                commands.append('sntp source ipv4 address {0}'.format(ipv4))
            ipv6 = source.get('ipv6')
            if ipv6 is not None:
                commands.append('sntp source ipv6 address {0}'.format(ipv6))

        return commands