Subversion Repositories havirt

Rev

Rev 25 | Rev 27 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 25 Rev 26
Line 30... Line 30...
30
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
30
# NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
31
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
31
# THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
33
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
34
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35
 
35
#
-
 
36
# v1.2.0 20240826 RWR
-
 
37
# Modified the flag structure to conform to standard (ie, dryrun instead of yes)
-
 
38
# Added a lot of 'verbose' print lines, and modified for new flag structure
-
 
39
# Added a config file, which is auto-generated if it doesn't exist
36
 
40
 
37
#use experimental "switch";
41
#use experimental "switch";
38
 
42
 
39
# requires File::Slurp. 
43
# requires File::Slurp. 
40
# In Debian derivatives
44
# In Debian derivatives
Line 58... Line 62...
58
use YAML::Tiny;
62
use YAML::Tiny;
59
 
63
 
60
# define the version number
64
# define the version number
61
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
65
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
62
use version;
66
use version;
63
our $VERSION = version->declare("1.0.0");
67
our $VERSION = version->declare("1.2.0");
64
 
68
 
65
 
69
 
66
# see https://perldoc.perl.org/Getopt/Long.html
70
# see https://perldoc.perl.org/Getopt/Long.html
67
use Getopt::Long;
71
use Getopt::Long;
68
# allow -vvn (ie, --verbose --verbose --dryrun)
72
# allow -vvn (ie, --verbose --verbose --dryrun)
Line 82... Line 86...
82
   print "\tdomain [help] # work with individual domains\n";
86
   print "\tdomain [help] # work with individual domains\n";
83
   print "\tcluster [help] # report of memory and vcpu status on all nodes\n";
87
   print "\tcluster [help] # report of memory and vcpu status on all nodes\n";
84
   print "Some flags can be used where appropriate\n";
88
   print "Some flags can be used where appropriate\n";
85
   print "\t--help|-h # show this screen\n";
89
   print "\t--help|-h # show this screen\n";
86
   print "\t--version|-v # show version of program\n";
90
   print "\t--version|-v # show version of program\n";
87
   print "\t--format|-f screen|tsv # output of list commands is either padded for screen or Tab Delim\n";
91
   print "\t--format screen|tsv # output of list commands is either padded for screen or Tab Delim\n";
-
 
92
   print "\t--force|f force an action, even if not normally done\n";
88
   print "\t--target|-t NODE # the action use NODE for the target of actions\n";
93
   print "\t--target|-t NODE # the action use NODE for the target of actions\n";
89
   print "\t--dryrun|-n # does not perform the actions, simply shows what commands would be executed\n";
94
   print "\t--dryrun|-n # does not perform the actions, simply shows what commands would be executed\n";
90
   print "\t--debug|d # increases verbosity, with -ddd, totally outragious\n";
95
   print "\t--debug|d # increases verbosity, with -ddd, totally outragious\n";
91
   print "\t--yes|y # force an action (like scan) even if it is not a good idea\n";
-
 
92
   print "\t--quiet|q # do not print anything except major errors\n";
96
   print "\t--quiet|q # do not print anything except major errors\n";
93
}
97
}
94
 
98
 
95
&makeConfig( $config,$configFileName ) unless -f $configFileName;
99
&makeConfig( $config,$configFileName ) unless -f $configFileName;
96
$config = readConfig( $configFileName );
100
$config = readConfig( $configFileName );
97
 
101
 
98
# handle any command line parameters that may have been passed in
102
# handle any command line parameters that may have been passed in
99
 
103
 
100
GetOptions (
104
GetOptions (
101
   $config->{'flags'}, 
105
   $config->{'flags'}, 
-
 
106
      'debug|d+',  # integer, can be incremented like -ddd
-
 
107
      'dryrun|n!', # negatable with --nodryrun
102
      'format|f=s',
108
      'force|f',
-
 
109
      'format=s',  # must be --format (no short form)
-
 
110
      'help|h', 
-
 
111
      'quiet|q',
103
      'target|t=s',
112
      'target|t=s',
104
      'dryrun|n!',
-
 
105
      'debug|d+',
113
      'verbose|v+',# integer, can be incremented like -vv
106
      'help|h',
-
 
107
      'yes|y',
-
 
108
      'version|v',
114
      'version|V'  # note, the short form is a capital 'V'
109
      'quiet|q'
-
 
110
) or die "Error parsing command line\n";
115
) or die "Error parsing command line\n";
111
 
116
 
112
#die Dumper( $config );
117
die Dumper( $config );
113
 
118
 
114
#$config->{'flags'}->{'debug'} = 2;
119
#$config->{'flags'}->{'debug'} = 2;
115
#die Dumper( &getAvailableResources( 'dd-103' ) ) . "\n";
120
#die Dumper( &getAvailableResources( 'dd-103' ) ) . "\n";
116
 
121
 
117
my $command = shift; # the first one is the actual subsection
122
my $command = shift; # the first one is the actual subsection
Line 123... Line 128...
123
 
128
 
124
 
129
 
125
print "Parameters are " . Dumper( $config ) . "\n" if $config->{'flags'}->{'debug'};
130
print "Parameters are " . Dumper( $config ) . "\n" if $config->{'flags'}->{'debug'};
126
print "Command = $command\nAction = $action\n" if $config->{'flags'}->{'debug'};
131
print "Command = $command\nAction = $action\n" if $config->{'flags'}->{'debug'};
127
 
132
 
-
 
133
#die;
-
 
134
 
128
# we allow a three part command for some actions on a domain, ie start, shutdown, migrate and destroy
135
# we allow a three part command for some actions on a domain, ie start, shutdown, migrate and destroy
129
# for simplicity, if the command is one of the above, allow the user to enter like that, but we will
136
# for simplicity, if the command is one of the above, allow the user to enter like that, but we will
130
# restructure the command as if they had used the full, three part (ie, with domain as the command)
137
# restructure the command as if they had used the full, three part (ie, with domain as the command)
131
# so, the following are equivilent
138
# so, the following are equivilent
132
# havirt domain start nameofdomain
139
# havirt domain start nameofdomain
Line 159... Line 166...
159
   die "Error, I don't know the command [$command]\n";
166
   die "Error, I don't know the command [$command]\n";
160
}
167
}
161
 
168
 
162
if ( defined &{\&{$execute}} ) { # check if module::sub exists (ie, $command::action)
169
if ( defined &{\&{$execute}} ) { # check if module::sub exists (ie, $command::action)
163
  my $message =  &{\&{$execute}}(@ARGV); # yes, it exists, so call it with any remaining arguments
170
  my $message =  &{\&{$execute}}(@ARGV); # yes, it exists, so call it with any remaining arguments
164
  print $message unless $config->{'flags'}->{'quiet'};
171
  print $message unless $main::config->{'flags'}->{'quiet'};
165
} else { # method $action does not exist in module $command, so just a brief error message
172
} else { # method $action does not exist in module $command, so just a brief error message
166
  die "Error, could not find action [$action] for module [$command]\n";
173
  die "Error, could not find action [$action] for module [$command]\n";
167
} 
174
} 
168
 
175
 
169
1;
176
1;