| Line 67... |
Line 67... |
| 67 |
use Getopt::Long;
|
67 |
use Getopt::Long;
|
| 68 |
# allow -vvn (ie, --verbose --verbose --dryrun)
|
68 |
# allow -vvn (ie, --verbose --verbose --dryrun)
|
| 69 |
Getopt::Long::Configure ("bundling");
|
69 |
Getopt::Long::Configure ("bundling");
|
| 70 |
|
70 |
|
| 71 |
|
71 |
|
| 72 |
# global variables
|
72 |
our $config;
|
| 73 |
our $scriptDir = $FindBin::RealBin;
|
- |
|
| 74 |
my $scriptName = $FindBin::Script;
|
73 |
my $configFileName = $FindBin::RealBin . '/config.yaml';
|
| 75 |
my $dbDir = "$scriptDir/var";
|
- |
|
| 76 |
our $confDir = "$scriptDir/conf";
|
- |
|
| 77 |
our $statusDBName = "$dbDir/status.yaml";
|
- |
|
| 78 |
our $lastScanFileName = "$scriptDir/lastscan";
|
- |
|
| 79 |
our $minScanTimes = 5 * 60; # do not scan more than once every 5 minutes
|
- |
|
| 80 |
|
74 |
|
| 81 |
# Big hash that contains all information about system
|
75 |
# Big hash that contains all information about system
|
| 82 |
our $statusDB;
|
76 |
our $statusDB;
|
| 83 |
|
77 |
|
| 84 |
# options variables
|
- |
|
| 85 |
our $reportFormat = 'screen';
|
- |
|
| 86 |
our $force = 0;
|
- |
|
| 87 |
our $quiet = 0;
|
- |
|
| 88 |
our $targetNode = '';
|
- |
|
| 89 |
our $dryRun = 1;
|
- |
|
| 90 |
our $DEBUG = 0;
|
- |
|
| 91 |
my $help = 0;
|
- |
|
| 92 |
my $version = 0;
|
- |
|
| 93 |
|
- |
|
| 94 |
sub help {
|
78 |
sub help {
|
| 95 |
print "$0 command [argument]\n";
|
79 |
print "$0 command [argument]\n";
|
| 96 |
print "where command is one of\n";
|
80 |
print "where command is one of\n";
|
| 97 |
print "\tnode [help] # work with a node\n";
|
81 |
print "\tnode [help] # work with a node\n";
|
| 98 |
print "\tdomain [help] # work with individual domains\n";
|
82 |
print "\tdomain [help] # work with individual domains\n";
|
| Line 106... |
Line 90... |
| 106 |
print "\t--debug|d # increases verbosity, with -ddd, totally outragious\n";
|
90 |
print "\t--debug|d # increases verbosity, with -ddd, totally outragious\n";
|
| 107 |
print "\t--yes|y # force an action (like scan) even if it is not a good idea\n";
|
91 |
print "\t--yes|y # force an action (like scan) even if it is not a good idea\n";
|
| 108 |
print "\t--quiet|q # do not print anything except major errors\n";
|
92 |
print "\t--quiet|q # do not print anything except major errors\n";
|
| 109 |
}
|
93 |
}
|
| 110 |
|
94 |
|
| 111 |
|
- |
|
| - |
|
95 |
&makeConfig( $config,$configFileName ) unless -f $configFileName;
|
| - |
|
96 |
$config = readConfig( $configFileName );
|
| 112 |
|
97 |
|
| 113 |
# handle any command line parameters that may have been passed in
|
98 |
# handle any command line parameters that may have been passed in
|
| 114 |
|
99 |
|
| 115 |
GetOptions (
|
100 |
GetOptions (
|
| - |
|
101 |
$config->{'flags'},
|
| 116 |
'format|f=s' => \$reportFormat,
|
102 |
'format|f=s',
|
| 117 |
'target|t=s' => \$targetNode,
|
103 |
'target|t=s',
|
| 118 |
'dryrun|n!' => \$dryRun,
|
104 |
'dryrun|n!',
|
| 119 |
'debug|d+' => \$DEBUG,
|
105 |
'debug|d+',
|
| 120 |
'help|h' => \$help,
|
106 |
'help|h',
|
| 121 |
'yes|y' => \$force,
|
107 |
'yes|y',
|
| 122 |
'version|v' => \$version,
|
108 |
'version|v',
|
| 123 |
'quiet|q' => \$quiet
|
109 |
'quiet|q'
|
| 124 |
) or die "Error parsing command line\n";
|
110 |
) or die "Error parsing command line\n";
|
| 125 |
|
111 |
|
| - |
|
112 |
#die Dumper( $config );
|
| - |
|
113 |
|
| - |
|
114 |
#$config->{'flags'}->{'debug'} = 2;
|
| - |
|
115 |
#die Dumper( &getAvailableResources( 'dd-103' ) ) . "\n";
|
| - |
|
116 |
|
| 126 |
my $command = shift; # the first one is the actual subsection
|
117 |
my $command = shift; # the first one is the actual subsection
|
| 127 |
my $action = shift; # second is action to run
|
118 |
my $action = shift; # second is action to run
|
| 128 |
$action = 'help' unless $action;
|
119 |
$action = 'help' unless $action;
|
| 129 |
|
120 |
|
| 130 |
if ( $help || $command eq 'help' || ! $command ) { &help() ; exit; }
|
121 |
if ( $config->{'flags'}->{'help'} || $command eq 'help' || ! $command ) { &help() ; exit; }
|
| 131 |
if ( $version ) { use File::Basename; print basename($0) . " v$VERSION\n"; exit; }
|
122 |
if ( $config->{'flags'}->{'version'} ) { use File::Basename; print basename($0) . " v$VERSION\n"; exit; }
|
| 132 |
|
123 |
|
| 133 |
|
124 |
|
| 134 |
print "Parameters are\nreportFormat\t$reportFormat\ntargetNode\t$targetNode\ndryRun\t$dryRun\nDEBUG\t$DEBUG\n" if $DEBUG;
|
125 |
print "Parameters are " . Dumper( $config ) . "\n" if $config->{'flags'}->{'debug'};
|
| 135 |
print "Command = $command\nAction = $action\n" if $DEBUG;
|
126 |
print "Command = $command\nAction = $action\n" if $config->{'flags'}->{'debug'};
|
| 136 |
|
127 |
|
| 137 |
# we allow a three part command for some actions on a domain, ie start, shutdown, migrate and destroy
|
128 |
# we allow a three part command for some actions on a domain, ie start, shutdown, migrate and destroy
|
| 138 |
# for simplicity, if the command is one of the above, allow the user to enter like that, but we will
|
129 |
# for simplicity, if the command is one of the above, allow the user to enter like that, but we will
|
| 139 |
# restructure the command as if they had used the full, three part (ie, with domain as the command)
|
130 |
# restructure the command as if they had used the full, three part (ie, with domain as the command)
|
| 140 |
# so, the following are equivilent
|
131 |
# so, the following are equivilent
|
| Line 159... |
Line 150... |
| 159 |
|
150 |
|
| 160 |
|
151 |
|
| 161 |
# we have to concat here since the double colon causes some interpretation problems
|
152 |
# we have to concat here since the double colon causes some interpretation problems
|
| 162 |
my $execute = $command . '::' . $action;
|
153 |
my $execute = $command . '::' . $action;
|
| 163 |
# load the module, die if it doesn't exist.
|
154 |
# load the module, die if it doesn't exist.
|
| 164 |
if (-f $scriptDir . "/$command.pm" ) {
|
155 |
if (-f $config->{'script dir'} . "/$command.pm" ) {
|
| 165 |
require "$command.pm";
|
156 |
require "$command.pm";
|
| 166 |
Module->import( $command ); # for require, you must manually import
|
157 |
Module->import( $command ); # for require, you must manually import
|
| 167 |
} else {
|
158 |
} else {
|
| 168 |
die "Error, I don't know the command [$command]\n";
|
159 |
die "Error, I don't know the command [$command]\n";
|
| 169 |
}
|
160 |
}
|
| 170 |
|
161 |
|
| 171 |
if ( defined &{\&{$execute}} ) { # check if module::sub exists (ie, $command::action)
|
162 |
if ( defined &{\&{$execute}} ) { # check if module::sub exists (ie, $command::action)
|
| 172 |
my $message = &{\&{$execute}}(@ARGV); # yes, it exists, so call it with any remaining arguments
|
163 |
my $message = &{\&{$execute}}(@ARGV); # yes, it exists, so call it with any remaining arguments
|
| 173 |
print $message unless $quiet;
|
164 |
print $message unless $config->{'flags'}->{'quiet'};
|
| 174 |
} else { # method $action does not exist in module $command, so just a brief error message
|
165 |
} else { # method $action does not exist in module $command, so just a brief error message
|
| 175 |
die "Error, could not find action [$action] for module [$command]\n";
|
166 |
die "Error, could not find action [$action] for module [$command]\n";
|
| 176 |
}
|
167 |
}
|
| 177 |
|
168 |
|
| 178 |
|
- |
|
| 179 |
1;
|
169 |
1;
|