Subversion Repositories havirt

Rev

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

Rev 3 Rev 4
Line 53... Line 53...
53
use havirt; # Load all our shared stuff
53
use havirt; # Load all our shared stuff
54
 
54
 
55
use Data::Dumper;
55
use Data::Dumper;
56
use YAML::Tiny;
56
use YAML::Tiny;
57
 
57
 
-
 
58
# define the version number
-
 
59
# see https://metacpan.org/pod/release/JPEACOCK/version-0.97/lib/version.pod
-
 
60
use version;
-
 
61
our $VERSION = version->declare("0.0.1");
-
 
62
 
-
 
63
 
-
 
64
# see https://perldoc.perl.org/Getopt/Long.html
-
 
65
use Getopt::Long;
-
 
66
# allow -vvn (ie, --verbose --verbose --dryrun)
-
 
67
Getopt::Long::Configure ("bundling");
-
 
68
 
-
 
69
 
58
# global variables
70
# global variables
59
my $scriptDir = $FindBin::RealBin;
71
my $scriptDir = $FindBin::RealBin;
60
my $scriptName = $FindBin::Script;
72
my $scriptName = $FindBin::Script;
61
my $confDir = "$scriptDir/conf";
73
my $confDir = "$scriptDir/conf";
62
my $dbDir = "$scriptDir/var";
74
my $dbDir = "$scriptDir/var";
63
our $nodeDBName = "$dbDir/node.yaml";
75
our $nodeDBName = "$dbDir/node.yaml";
64
my $domainDBName = "$dbDir/domains.yaml";
76
our $domainDBName = "$dbDir/domains.yaml";
65
our $nodePopulationDBName = "$dbDir/node_population.yaml";
77
our $nodePopulationDBName = "$dbDir/node_population.yaml";
66
 
78
 
67
# these contain the values from the databases
79
# these contain the values from the databases
68
# loaded on demand
80
# loaded on demand
69
our $nodeDB;
81
our $nodeDB;
70
our $virtDB;
82
our $virtDB;
71
our $nodePopulations;
83
our $nodePopulations;
72
 
84
 
73
 
-
 
-
 
85
# options variables
-
 
86
our $reportFormat = 'screen';
-
 
87
our $targetNode = '';
74
my $dryRun = 1;
88
our $dryRun = 1;
75
my $DEBUG = 0;
89
our $DEBUG = 0;
-
 
90
my $help = 0;
-
 
91
my $version = 0;
76
 
92
 
77
sub help {
93
sub help {
78
   print "$0 command [argument]\n";
94
   print "$0 command [argument]\n";
79
   print "where command is one of\n";
95
   print "where command is one of\n";
80
   print "\tnode update [node] [node]... # update a given node (or ALL)\n";
96
   print "\tnode update [-t NODE] # update a given node (defaults to all)\n";
81
   print "\tnode list # display tab delimited list of node specs\n";
97
   print "\tnode list # display tab delimited list of node specs\n";
82
   print "\tnode scan # find domains on all nodes\n ";
98
   print "\tnode scan [-t NODE] # update list of domains on node (defaults to all)\n ";
83
   print "\tdomain update ALL|RUNNING|[domain] [domain]... # update domains\n";
99
   print "\tdomain update ALL|RUNNING|[domain] [domain]... # update domains\n";
84
   print "\tdomain list ALL|RUNNING|[domain] [domain]... # display tab delimited list of domain specs\n";
100
   print "\tdomain list ALL|RUNNING|[domain] [domain]... # display tab delimited list of domain specs\n";
85
   print "\tcluster status # report of memory and vcpu status on all nodes\n";
101
   print "\tcluster status # report of memory and vcpu status on all nodes\n";
-
 
102
   print "Some flags can be used where appropriate\n";
-
 
103
   print "\t--help|-h # show this screen\n";
-
 
104
   print "\t--version|-v # show version of program\n";
-
 
105
   print "\t--format|-f screen|tsv # output of list commands is either padded for screen or Tab Delim\n";
-
 
106
   print "\t--target|-t NODE # the action use NODE for the target of actions\n";
-
 
107
   print "\t--dryrun|-n # does not perform the actions, simply shows what commands would be executed\n";
-
 
108
   print "\t--debug|d # increases verbosity, does not actually perform actions (--dry-run assumed)\n";
86
}
109
}
87
 
110
 
88
sub loadVirtDB {
111
sub loadVirtDB {
89
   return if $virtDB;
112
   return if $virtDB;
90
   $virtDB = &readDB( $domainDBName );
113
   $virtDB = &readDB( $domainDBName );
91
}
114
}
92
 
115
 
93
sub loadNodePopulations {
-
 
94
   return if $nodePopulations;
-
 
95
   $nodePopulations = &readDB( $nodePopulationDBName );
-
 
96
}
-
 
97
 
-
 
98
sub domain {
116
sub domain {
99
   my $action = lc shift;
117
   my $action = lc shift;
100
   my $return = '';
118
   my $return = '';
101
   &loadVirtDB();
119
   &loadVirtDB();
102
   &loadNodePopulations();
120
   &loadNodePopulations();
Line 222... Line 240...
222
      $return .= "Total\t$availcpu\t$availmem\t$totalDomains\t$usedcpu\t$usedmem\n";
240
      $return .= "Total\t$availcpu\t$availmem\t$totalDomains\t$usedcpu\t$usedmem\n";
223
   }
241
   }
224
   return $return;
242
   return $return;
225
}
243
}
226
 
244
 
-
 
245
 
-
 
246
# handle any command line parameters that may have been passed in
-
 
247
 
-
 
248
GetOptions (
-
 
249
   'format|f=s' => \$reportFormat,
-
 
250
   'target|t=s' => \$targetNode,
-
 
251
   'dryrun|n!' => \$dryRun,
-
 
252
   'debug|d+' => \$DEBUG,
-
 
253
   'help|h' => \$help,
-
 
254
   'version|v' => \$version
-
 
255
) or die "Error parsing command line\n";
-
 
256
 
227
      
257
                  
228
#my $config = &readConf( $confFile );
258
if ( $help ) { &help() ; exit; }
-
 
259
if ( $version ) { use File::Basename; print basename($0) . " v$VERSION\n"; exit; }
229
 
260
 
230
my $command = shift; # the first one is the actual subsection
261
my $command = shift; # the first one is the actual subsection
231
my $action = shift; # second is action to run
262
my $action = shift; # second is action to run
232
 
263
 
-
 
264
#print "Parameters are\nreportFormat\t$reportFormat\ntargetNode\t$targetNode\ndryRun\t$dryRun\nDEBUG\t$DEBUG\n";
-
 
265
#print "Command = $command\nAction = $action\n";
-
 
266
#die;
-
 
267
 
233
if ( $command eq 'node' ) {
268
if ( $command eq 'node' ) {
234
   require node;
269
   require node;
235
   Module->import( qw/node/ );
270
   Module->import( qw/node/ );
236
   print &node::node( $action, @ARGV );
271
#   print &node::list( $action, @ARGV );
-
 
272
   print &{\&{"node::$action"}}();
237
} elsif ( $command eq 'domain' ) {
273
} elsif ( $command eq 'domain' ) {
238
   print &domain( $action, @ARGV );
274
   print &domain( $action, @ARGV );
239
} elsif ( $command eq 'cluster' ) {
275
} elsif ( $command eq 'cluster' ) {
240
   print &cluster( $action, @ARGV );
276
   print &cluster( $action, @ARGV );
241
} else {
277
} else {