###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### NFS_Client.pm - NFS client configuration module for psgconf
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Control::NFS_Client;
use strict;
use PSGConf::Action::GenerateFile::Literal;
use PSGConf::Action::GenerateFile::auto_direct;
use PSGConf::Action::RunCommand;
use PSGConf::Data::Boolean;
use PSGConf::Data::Hash;
use PSGConf::Data::List;
use PSGConf::Data::String;
use PSGConf::Control::Packages qw(_add_pkgs);
###############################################################################
### decide() method
###############################################################################
sub decide
{
my ($self, $psgconf) = @_;
return
if ($psgconf->data_obj('nfs_client_enable')->equals('false'));
if ($psgconf->data_obj('platform')->match('solaris|aix'))
{
$psgconf->register_actions(
PSGConf::Action::GenerateFile::Literal->new(
name => '/etc/auto_master',
description => 'automounter master map',
content => "/-\t/etc/auto_direct\n" .
$psgconf->data_obj('auto_master_literal')->get()
),
PSGConf::Action::GenerateFile::auto_direct->new(
name => '/etc/auto_direct',
description => 'automounter direct map',
mounts => $psgconf->data_obj('nfs_mounts')->get()
),
PSGConf::Action::RunCommand->new(
name => 'automounter maps',
command => 'automount',
check_func => \&_check_automount_maps
)
);
}
# elsif ($psgconf->data_obj('platform')->match('freebsd'))
# {
# FIXME: need to add code to write out amd.map files
# and process the amd_flags in $psgconf->data_obj('rc_vars')->insert()
# }
}
###############################################################################
### plugin function for PSGConf::Action::RunCommand
###############################################################################
sub _check_automount_maps
{
my ($self, $psgconf) = @_;
my ($action_auto_master, $action_auto_direct);
return
if ($psgconf->data_obj('nfs_client_enable')->equals('false'));
$action_auto_master = $psgconf->get_action('/etc/auto_master');
$action_auto_direct = $psgconf->get_action('/etc/auto_direct');
return 1
if ((defined($action_auto_master)
&& $action_auto_master->changed())
|| (defined($action_auto_direct)
&& $action_auto_direct->changed()));
return 0;
}
###############################################################################
### policy methods
###############################################################################
sub _policy_add_crontab
{
my ($self, $psgconf) = @_;
return
if ($psgconf->data_obj('nfs_client_enable')->equals('false'));
map {
$psgconf->data_obj('crontabs')->insert(
{ $_ => %{$psgconf->data_obj('nfs_client_crontabs')->find($_)} }
)
} keys %{$psgconf->data_obj('nfs_client_crontabs')->get()};
}
sub _policy_enable_rc_scripts
{
my ($self, $psgconf) = @_;
my ($script);
# Note: the RPC portmapper may be needed elsewhere, so
# we enable it here if we need it, but we don't explicitly
# disable it if we don't need it
if ($psgconf->data_obj('platform')->match('aix')) {
if ( $psgconf->data_obj('nfs_client_enable')->equals('true') ) {
$psgconf->data_obj('inittab')->replace_row_cells(
{ 0 => 'rcnfs' },
{ 2 => 'wait' }
);
}
}
foreach $script (@{$psgconf->data_obj('nfs_client_daemons')->get()}) {
if ( $psgconf->data_obj('nfs_client_enable')->equals('true') ) {
$psgconf->data_obj('rc_scripts')->insert(
{ $script => { 'state' => 'enable' }}
);
}
}
}
###############################################################################
### constructor
###############################################################################
sub new
{
my ($class, $psgconf) = @_;
my ($self);
$self = {};
bless($self, $class);
### So that _add_pkgs knows which directives to look at
$self->{name} = 'nfs_client';
$self->{enable} = $self->{name} . '_enable';
$self->{packages} = $self->{name} . '_packages';
$psgconf->register_data(
nfs_client_enable => PSGConf::Data::Boolean->new(
value => 'false'
),
nfs_client_daemons => PSGConf::Data::List->new(),
nfs_client_packages => PSGConf::Data::List->new(),
auto_master_literal => PSGConf::Data::String->new(),
nfs_client_crontabs => PSGConf::Data::Hash->new(
value_type => 'ARRAY'
),
nfs_mounts => PSGConf::Data::Hash->new(
value_type => 'HASH',
key_abspath => 1
)
);
$psgconf->register_policy($self,
nfs_client_add_packages => '_add_pkgs',
nfs_client_enable_rc_scripts => '_policy_enable_rc_scripts',
);
return $self;
}
###############################################################################
### documentation
###############################################################################
1;
__END__
=head1 NAME
PSGConf::Control::NFS_Client - psgconf control class for NFS client
=head1 SYNOPSIS
In F<psgconf_modules>:
Control PSGConf::Control::NFS_Client
=head1 DESCRIPTION
The B<PSGConf::Control::NFS_Client> module provides a B<psgconf> control
object for configuring NFS clients. It supports the following methods:
=over 4
=item new()
The constructor. Its parameter is a reference to the B<PSGConf>
object. It registers the following data objects:
=over 4
=item I<nfs_client_enable>
A B<PSGConf::Data::Boolean> object indicating whether the NFS client
should be configured.
=item I<nfs_client_packages>
A B<PSGConf::Data::List> object containing the packages to install.
=item I<nfs_client_daemons>
A B<PSGConf::Data::List> object containing the list of I<rc_scripts>
to enable for this service to work.
=item I<nfs_mounts>
A B<PSGConf::Data::Hash> object containing the list of filesystems to
mount via NFS. The key is the absolute path of the mount point, and
the value is an anonymous hash containing the options and location to
be mounted at that mount point.
=back
The constructor also registers the following policy methods:
=over 4
=item I<nfs_client_enable_rc_scripts>
Enables or disables (depending on whether I<nfs_client_enabled>
is set) the NFS client RC scripts using the I<rc_scripts> and
I<inittab> data objects (provided by B<PSGConf::Control::InitScripts>
and B<PSGConf::Control::Inittab>).
If I<nfs_client_enabled> is set, also enables the RPC portmapper RC
script using the I<rc_scripts> data object (provided by
B<PSGConf::Control::InitScripts>).
=back
=item decide()
If I<nfs_client_enable> is not set, does nothing.
Otherwise, registers a B<PSGConf::Action::GenerateFile::Literal>
object to create F</etc/auto_master> and a
B<PSGConf::Action::GenerateFile::auto_direct> object to create
F</etc/auto_direct>. Also registers a B<PSGConf::Action::RunCommand>
action object to run C<automount> if the automounter configuration
has changed.
=back
=head1 BUGS
This module always sets up the NFS mounts using the automounter. This
should really be configurable; in some situations, a standard mount
might be preferred.
The automounter setup uses direct maps, so it will only work on
platforms like AIX and Solaris. The Linux automounter does not support
direct maps.
=head1 SEE ALSO
L<perl>
L<PSGConf>
L<PSGConf::Action::GenerateFile::Literal>
L<PSGConf::Action::GenerateFile::auto_direct>
L<PSGConf::Action::RunCommand>
L<PSGConf::Control::InitScripts>
L<PSGConf::Control::Packages>
L<PSGConf::Data::Boolean>
L<PSGConf::Data::List>
L<PSGConf::Data::Hash>
L<PSGConf::Data::String>
L<psgconf-intro>
=cut
syntax highlighted by Code2HTML, v. 0.9.1