Line 39... |
Line 39... |
39 |
# Added a config file, which is auto-generated if it doesn't exist
|
39 |
# Added a config file, which is auto-generated if it doesn't exist
|
40 |
#
|
40 |
#
|
41 |
# v1.2.1 20250511 RWR
|
41 |
# v1.2.1 20250511 RWR
|
42 |
# changed so even if quiet set, if dryrun is set, will print what is returned from the called script
|
42 |
# changed so even if quiet set, if dryrun is set, will print what is returned from the called script
|
43 |
# Also, incorporates v1.3.0 on cluster.pm and v1.2.1 on havirt.pm
|
43 |
# Also, incorporates v1.3.0 on cluster.pm and v1.2.1 on havirt.pm
|
- |
|
44 |
#
|
- |
|
45 |
# v1.2.2 20250511 RWR
|
- |
|
46 |
# Added variance flag (--variance), and fixed the version flag (--version or -V)
|
44 |
|
47 |
|
45 |
#use experimental "switch";
|
48 |
#use experimental "switch";
|
46 |
|
49 |
|
47 |
# requires File::Slurp.
|
50 |
# requires File::Slurp.
|
48 |
# In Debian derivatives
|
51 |
# In Debian derivatives
|
Line 66... |
Line 69... |
66 |
use YAML::Tiny;
|
69 |
use YAML::Tiny;
|
67 |
|
70 |
|
68 |
# define the version number
|
71 |
# define the version number
|
69 |
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
|
72 |
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
|
70 |
use version;
|
73 |
use version;
|
71 |
our $VERSION = version->declare("1.2.1");
|
74 |
our $VERSION = version->declare("1.2.2");
|
72 |
|
75 |
|
73 |
|
76 |
|
74 |
# see https://perldoc.perl.org/Getopt/Long.html
|
77 |
# see https://perldoc.perl.org/Getopt/Long.html
|
75 |
use Getopt::Long;
|
78 |
use Getopt::Long;
|
76 |
# allow -vvn (ie, --verbose --verbose --dryrun)
|
79 |
# allow -vvn (ie, --verbose --verbose --dryrun)
|
Line 97... |
Line 100... |
97 |
print "\t--target|-t NODE # the action use NODE for the target of actions\n";
|
100 |
print "\t--target|-t NODE # the action use NODE for the target of actions\n";
|
98 |
print "\t--dryrun|-n # does not perform the actions, simply shows what commands would be executed\n";
|
101 |
print "\t--dryrun|-n # does not perform the actions, simply shows what commands would be executed\n";
|
99 |
print "\t--debug|d # increases verbosity, with -ddd, totally outragious\n";
|
102 |
print "\t--debug|d # increases verbosity, with -ddd, totally outragious\n";
|
100 |
print "\t--quiet|q # do not print anything except major errors\n";
|
103 |
print "\t--quiet|q # do not print anything except major errors\n";
|
101 |
print "\t--verbose|v # increase verbosity of program. May be used multiple times\n";
|
104 |
print "\t--verbose|v # increase verbosity of program. May be used multiple times\n";
|
- |
|
105 |
print "\t--variance int # Real time adjust variance for cluster balance\n";
|
102 |
}
|
106 |
}
|
103 |
|
107 |
|
104 |
&makeConfig( $config,$configFileName ) unless -f $configFileName;
|
108 |
&makeConfig( $config,$configFileName ) unless -f $configFileName;
|
105 |
$config = readConfig( $configFileName );
|
109 |
$config = readConfig( $configFileName );
|
106 |
|
110 |
|
Line 115... |
Line 119... |
115 |
'help|h',
|
119 |
'help|h',
|
116 |
'quiet|q',
|
120 |
'quiet|q',
|
117 |
'target|t=s',
|
121 |
'target|t=s',
|
118 |
'testing',
|
122 |
'testing',
|
119 |
'verbose|v+',# integer, can be incremented like -vv
|
123 |
'verbose|v+',# integer, can be incremented like -vv
|
120 |
'version|V' # note, the short form is a capital 'V'
|
124 |
'version|V', # note, the short form is a capital 'V'
|
- |
|
125 |
'variance=f' # adjust variance for cluster balance
|
121 |
) or die "Error parsing command line\n";
|
126 |
) or die "Error parsing command line\n";
|
122 |
|
127 |
|
123 |
# if they pass the testing flag, turn verbose on, dry run on, and append
|
128 |
# if they pass the testing flag, turn verbose on, dry run on, and append
|
124 |
# .testing to the status db filename
|
129 |
# .testing to the status db filename
|
125 |
if ( $config->{'flags'}->{'testing'} ) {
|
130 |
if ( $config->{'flags'}->{'testing'} ) {
|
Line 129... |
Line 134... |
129 |
}
|
134 |
}
|
130 |
|
135 |
|
131 |
print "Parameters are " . Dumper( $config ) . "\n" if $config->{'flags'}->{'debug'};
|
136 |
print "Parameters are " . Dumper( $config ) . "\n" if $config->{'flags'}->{'debug'};
|
132 |
die if $config->{'flags'}->{'debug'} > 3;
|
137 |
die if $config->{'flags'}->{'debug'} > 3;
|
133 |
|
138 |
|
- |
|
139 |
if ( $config->{'flags'}->{'version'} ) { use File::Basename; print basename($0) . " v$VERSION\n"; exit; }
|
- |
|
140 |
|
- |
|
141 |
# adjust variance if they passed in the flag
|
- |
|
142 |
$config->{'balance_max_variance'} = $config->{'flags'}->{'variance'} if $config->{'flags'}->{'variance'};
|
- |
|
143 |
|
134 |
my $command = shift; # the first one is the actual subsection
|
144 |
my $command = shift; # the first one is the actual subsection
|
135 |
my $action = shift; # second is action to run
|
145 |
my $action = shift; # second is action to run
|
136 |
$action = 'help' unless $action;
|
146 |
$action = 'help' unless $action;
|
137 |
|
- |
|
138 |
if ( $config->{'flags'}->{'help'} || $command eq 'help' || ! $command ) { &help() ; exit; }
|
- |
|
139 |
if ( $config->{'flags'}->{'version'} ) { use File::Basename; print basename($0) . " v$VERSION\n"; exit; }
|
- |
|
140 |
|
147 |
|
- |
|
148 |
if ( $config->{'flags'}->{'help'} || $command eq 'help' || ! $command ) { &help() ; exit; }
|
141 |
|
149 |
|
- |
|
150 |
|
142 |
print "Command = $command\nAction = $action\n" if $config->{'flags'}->{'debug'};
|
151 |
print "Command = $command\nAction = $action\n" if $config->{'flags'}->{'debug'};
|
143 |
|
152 |
|
144 |
|
153 |
|
145 |
# we allow a three part command for some actions on a domain, ie start, shutdown, migrate and destroy
|
154 |
# we allow a three part command for some actions on a domain, ie start, shutdown, migrate and destroy
|
146 |
# for simplicity, if the command is one of the above, allow the user to enter like that, but we will
|
155 |
# for simplicity, if the command is one of the above, allow the user to enter like that, but we will
|
Line 177... |
Line 186... |
177 |
die "Error, I don't know the command [$command]\n";
|
186 |
die "Error, I don't know the command [$command]\n";
|
178 |
}
|
187 |
}
|
179 |
|
188 |
|
180 |
if ( defined &{\&{$execute}} ) { # check if module::sub exists (ie, $command::action)
|
189 |
if ( defined &{\&{$execute}} ) { # check if module::sub exists (ie, $command::action)
|
181 |
my $message = &{\&{$execute}}(@ARGV); # yes, it exists, so call it with any remaining arguments
|
190 |
my $message = &{\&{$execute}}(@ARGV); # yes, it exists, so call it with any remaining arguments
|
182 |
print $message unless $main::config->{'flags'}->{'quiet'} && !$main::config->{'flags'}->{'dryrun'};
|
191 |
print $message unless !$message || $main::config->{'flags'}->{'quiet'} && !$main::config->{'flags'}->{'dryrun'};
|
183 |
} else { # method $action does not exist in module $command, so just a brief error message
|
192 |
} else { # method $action does not exist in module $command, so just a brief error message
|
184 |
die "Error, could not find action [$action] for module [$command]\n";
|
193 |
die "Error, could not find action [$action] for module [$command]\n";
|
185 |
}
|
194 |
}
|
186 |
|
195 |
|
187 |
1;
|
196 |
1;
|