Config-Model-Backend-Augeas

 view release on metacpan or  search on metacpan

lib/Config/Model/Backend/Augeas.pm  view on Meta::CPAN

C<read_config> parameters:

=over

=item backend

Use C<augeas> (or C<Augeas>)in this case.

=item save

Either C<backup> or C<newfile>. See L<Config::Augeas/Constructor> for
details.

=item file

Name of the configuration file.

=item sequential_lens

This one is tricky. Set to one when new Augeas list or hash node must
be created for each new list or hash element. See L</Sequential lens>
for details.

=back

For instance:

   read_config  => {
       backend => 'augeas' ,
       save   => 'backup',
       file => '/etc/ssh/sshd_config',
       # declare "seq" Augeas elements
       sequential_lens => [/AcceptEnv AllowGroups/],
    },

=head2 Sequential lens

Some configuration files feature data that must be written as list or
as hash. Depending on the syntax, Augeas list or hash lenses can be
written so that new "container" nodes are required for each new element.

lib/Config/Model/models/Itself/ConfigReadWrite.d/augeas-backend.pl  view on Meta::CPAN

            'backend' => {
                choice       => [qw/Augeas/],
                help => {
                    augeas => "Experimental backend with RedHat's Augeas library. See http://augeas.net for details",
                }
            },

            'save' => {
                type       => 'leaf',
                value_type => 'enum',
                choice     => [qw/backup newfile/],
                level      => 'hidden',
                description =>
'Specify how to save the configuration file. Either create a newfile (with extension .augnew, and do not overwrite the original file) or move the original file into a backup file (.augsave extension). Configuration files are overwritten by default',
                warp => {
                    follow => '- backend',
                    rules  => [ Augeas => { level => 'normal', } ],
                }
            },

            'set_in' => {
                type       => 'leaf',
                value_type => 'reference',
                refer_to   => '- - element',

t/augeas_backend.t  view on Meta::CPAN

               record:3 canonical=goner   ipaddr=192.168.0.111") ;

$dump = $i_root->dump_tree ;
print $dump if $trace ;

$i_hosts->write_back ;
ok(1,"/etc/hosts write back done") ;

my $aug_file      = $wr_root->child('etc/hosts');
my $aug_save_file = $aug_file->parent->child('hosts.augsave') ;
ok($aug_save_file->is_file, "check that backup config file $aug_save_file was written");

my @expect = (
    "192.168.0.1 buildbot\n",
    "192.168.0.10\tkomarr\n",
    "192.168.0.11\trepoman\n",
    "192.168.0.111\tgoner\n"
);

is_deeply([$aug_file->lines],\@expect,"check content of $aug_file") ;

t/augeas_backend.t  view on Meta::CPAN

    # augeas is broken somehow when reloading CIphers, let's delete this field
    $sshd_root->fetch_element("Ciphers")->clear ;

    $dump = $sshd_root->dump_tree ;
    print $dump if $trace ;

    $i_sshd->write_back ;

    my $aug_save_sshd_file = $sshd_config->parent->child('sshd_config.augsave') ;
    ok($aug_save_sshd_file -> is_file,
       "check that backup config file $aug_save_sshd_file was written");

    my @mod = @sshd_orig;
    $mod[2] = "HostbasedAuthentication yes\n";
    splice @mod, 8,0,"Protocol 1,2\n";

    $mod[15] = "Subsystem            ddftp /home/dd/bin/ddftp\n";
    splice @mod,24,1 ; # remove Ciphers check because Augeas looks broken

    eq_or_diff([$sshd_config->lines],\@mod,"check content of $sshd_config") ;

t/lib/LoadTest.pm  view on Meta::CPAN



    $model->create_config_class (
        name => 'Hosts',

        rw_config  =>  {
            backend => 'augeas',
            config_dir => '/etc/',
            file => 'hosts',
            set_in => 'record',
            save   => 'backup',
            #sequential_lens => ['record'],
        },

        element => [
            record => {
                type => 'list',
                cargo => {
                    type => 'node',
                    config_class_name => 'Host',
                } ,

t/lib/LoadTest.pm  view on Meta::CPAN

        ]
    );

    $model->create_config_class (
        name => 'Sshd',

        'rw_config' => {
            backend => 'augeas',
            config_dir => '/etc/ssh/',
            file => 'sshd_config',
            save   => 'backup',
            sequential_lens => [qw/HostKey Subsystem Match/],
        },

        element => [
            'AcceptEnv', {
                'cargo' => {
                    'value_type' => 'uniline',
                    'type' => 'leaf'
                },
                'type' => 'list',

t/test_model.pl  view on Meta::CPAN

);

$model->create_config_class (
   name => 'Hosts',

   rw_config  =>  {
       backend => 'augeas',
       config_dir => '/etc/',
       file => 'hosts',
       set_in => 'record',
       save   => 'backup',
       #sequential_lens => ['record'],
   },

   element => [
       record => {
           type => 'list',
           cargo => {
               type => 'node',
               config_class_name => 'Host',
           } ,

t/test_model.pl  view on Meta::CPAN

   ]
);

$model->create_config_class (
   name => 'Sshd',

   rw_config => {
       backend => 'augeas',
       config_dir => '/etc/ssh/',
       file => 'sshd_config',
       save   => 'backup',
       sequential_lens => [qw/HostKey Subsystem Match/],
   },

   element => [
       'AcceptEnv' => {
           'type' => 'list',
           'cargo' => {
               'value_type' => 'uniline',
               'type' => 'leaf'
           },



( run in 0.993 second using v1.01-cache-2.11-cpan-49f99fa48dc )