###
### Copyright 2000-2007 University of Illinois Board of Trustees
### All rights reserved.
###
### PSGConf::Action::svcs::addpg - setting svcs property group action type for psgconf
###
### Campus Information Technologies and Educational Services
### University of Illinois at Urbana-Champaign
###
package PSGConf::Action::svcs::addpg;
use strict;
use PSGConf::Action;
use PSGConf::Util;
our @ISA = qw(PSGConf::Action);
###############################################################################
### check method
###############################################################################
sub check
{
my ($self, $psgconf) = @_;
my ($cmd, $group, $type, $res);
$group = $self->{group};
$type = $self->{type};
$cmd = '/usr/sbin/svccfg';
$cmd .= ' -s ' . $self->{FMRI}
if ( $self->{FMRI} );
$cmd .= ' listpg ';
if ( ! open (SVCCFG, "$cmd 2>&1|" )) {
warn "\n\t!!! cannot run ($cmd): $!\n";
return -1
}
$res=1;
grep ( /${group}[\s]*${type}/ && ($res=0), <SVCCFG>);
close SVCCFG;
$self->{changed} = $res;
return $res;
}
###############################################################################
### diff method
###############################################################################
sub diff
{
my ($self) = @_;
my ($cmd);
$cmd = '/usr/sbin/svccfg';
$cmd .= ' -s ' . $self->{FMRI}
if ( $self->{FMRI} );
$cmd .= ' addpg ' . $self->{group};
$cmd .= ' ' . $self->{type};
print "###############################################################################\n";
print "### DIFF FOR $self->{name}\n";
print "###############################################################################\n";
print "+ addpg: ${cmd}\n";
print "\n";
}
###############################################################################
### do() method
###############################################################################
sub do
{
my ($self) = @_;
my ($cmd, $val, $res);
$cmd = '/usr/sbin/svccfg';
$cmd .= ' -s ' . $self->{FMRI}
if ( $self->{FMRI} );
$cmd .= ' addpg ' . $self->{group};
$cmd .= ' ' . $self->{type};
$res=!(&PSGConf::Util::RunCommand(${cmd}));
### If we failed, then return right away
return $res if ( ! $res );
if ($self->{refresh})
{
### Otherwise we need to refresh the service
$cmd = '/usr/sbin/svcadm refresh ' . $self->{FMRI};
return (!&PSGConf::Util::RunCommand(${cmd}));
}
return 1;
}
###############################################################################
### documentation
###############################################################################
1;
__END__
=head1 NAME
PSGConf::Action::svcs::addpg - setting svcs property action type for psgconf
=head1 SYNOPSIS
use PSGConf::Action::svcs::addpg;
$psgconf->register_actions(
PSGConf::Action::svcs::addpg->new(
'name' => 'message about property group being set',
'FMRI' => 'The FMRI to work on ...',
'group' => 'property group name ...',
'type' => 'the type the property group is ...',
'refresh' => 'true if the service should be refreshed'
),
...
);
=head1 DESCRIPTION
The B<PSGConf::Action::svcs::addpg> module provides a B<PSGConf> action
class for configuring the System Management Facility .
The B<PSGConf::Action::svcs::addpg> class is derived from the
B<PSGConf::Action> class, but it defines/overrides the
following methods:
=over 4
=item check()
Checks to see if the property I<group> is in the I<listpg> output.
If it is not, it sets the changed flag so that later on, the
C<svccfg addpg> and C<svcadm refresh> will get run.
=item diff()
Prints a message indicating that C<svccfg addpg> will be executed.
=item do()
Actually executes the C<svccfg addpg> and C<svcadm refresh> commands.
=back
In addition to the attributes supported by the B<PSGConf::Action>
class, the B<PSGConf::Action::svcs::addpg> class supports the following
attributes:
=over 4
=item I<FMRI>
The Fault Management Resource Identifier where the property group resides.
=item I<group>
The name of the property group to be defined.
=item I<type>
What type of property group we are going to create.
=item I<refresh>
true if the service should be refreshed via svcadm
=back
Note that the I<name> attribute will only be used to print the
"checking" message when the check() method is called.
=head1 SEE ALSO
C<CE<lt>smf(5)E<gt>>
C<CE<lt>svccfg(1m)E<gt>>
L<perl>
L<PSGConf>
L<PSGConf::Action>
=cut
syntax highlighted by Code2HTML, v. 0.9.1