Line 268... |
Line 268... |
268 |
|
268 |
|
269 |
|
269 |
|
270 |
print "Parameters are\nreportFormat\t$reportFormat\ntargetNode\t$targetNode\ndryRun\t$dryRun\nDEBUG\t$DEBUG\n" if $DEBUG;
|
270 |
print "Parameters are\nreportFormat\t$reportFormat\ntargetNode\t$targetNode\ndryRun\t$dryRun\nDEBUG\t$DEBUG\n" if $DEBUG;
|
271 |
print "Command = $command\nAction = $action\n" if $DEBUG;
|
271 |
print "Command = $command\nAction = $action\n" if $DEBUG;
|
272 |
|
272 |
|
273 |
if ( $command eq 'node' ) {
|
273 |
# we allow a three part command for some actions on a domain, ie start, shutdown, migrate and destroy
|
274 |
require node;
|
274 |
# for simplicity, if the command is one of the above, allow the user to enter like that, but we will
|
275 |
Module->import( qw/node/ );
|
275 |
# restructure the command as if they had used the full, three part (ie, with domain as the command)
|
276 |
print &{\&{"node::$action"}}();
|
276 |
# so, the following are equivilent
|
277 |
} elsif ( $command eq 'domain' ) {
|
277 |
# havirt domain start nameofdomain
|
278 |
require domain;
|
278 |
# havirt start nameofdomain
|
- |
|
279 |
|
279 |
Module->import( qw/domain/ );
|
280 |
if ( $command eq 'start' || $command eq 'shutdown' || $command eq 'migrate' || $command eq 'destroy' ) { # shortcut for working with domains
|
280 |
print &{\&{"domain::$action"}}();
|
281 |
push @ARGV, $action; # this is the domain we are working with
|
281 |
} elsif ( $command eq 'cluster' ) {
|
282 |
$action = $command; # this is what we want to do (start, shutdown, etc...)
|
282 |
print &cluster( $action, @ARGV );
|
283 |
$command = 'domain'; # keywork domain, for correct module
|
283 |
} else {
|
- |
|
284 |
&help();
|
- |
|
285 |
}
|
284 |
}
|
286 |
|
285 |
|
- |
|
286 |
# ok, this is some serious weirdness. $command is actually the name of a module, and $action is a method
|
- |
|
287 |
# defined in the module.
|
- |
|
288 |
|
- |
|
289 |
# I use 'require' which loads at runtime, not compile time, so it will only load a module if needed.
|
- |
|
290 |
# then, I check to see if a method named in $action is defined within that module and, if so
|
- |
|
291 |
# execute it and return the result. If not, gives an error message.
|
- |
|
292 |
|
- |
|
293 |
# This means to add functionality, we simply add a method (sub) in a given module, or create a whole
|
- |
|
294 |
# new module.
|
- |
|
295 |
|
- |
|
296 |
|
- |
|
297 |
# we have to concat here since the double colon causes some interpretation problems
|
- |
|
298 |
my $execute = $command . '::' . $action;
|
- |
|
299 |
# load the module, die if it doesn't exist. Might make this an eval later
|
- |
|
300 |
require "$command.pm";
|
- |
|
301 |
Module->import( $command ); # for require, you must manually import
|
- |
|
302 |
|
- |
|
303 |
if ( defined &{\&{$execute}} ) { # check if module::sub exists (ie, $command::action)
|
- |
|
304 |
print &{\&{$execute}}(@ARGV); # yes, it exists, so call it with any remaining arguments
|
- |
|
305 |
} else { # method $action does not exist in module $command, so just a brief error message
|
- |
|
306 |
die "Error, could not find action $action for module $command\n";
|
- |
|
307 |
}
|
- |
|
308 |
|
287 |
|
309 |
|
288 |
1;
|
310 |
1;
|