#!/usr/bin/perl -w # vi:sm:ai:et:wm=0:ts=4:sw=4 # a CLI program used to use VirtdomInjector.pm to create a virtdom # designed to be flexible enough to create the domain fully and # then if necessary later go back and recover from any failures # that might have happened # # painfully capable and hard to understand, will need some documentation # that includes examples of how to use it # $Id: virt_injector,v 1.10 2000/06/30 19:39:10 cdent Exp $ # $Source: /usr2/sarc/cvsroot/mcvirtdom/client/virt_injector,v $ # Chris Dent # Kiva Networking, April 2000 # Same license as Perl # for testing #use lib '/home/cdent/src/mcvirtdom/lib'; use strict; use Getopt::Std; use VirtdomInjector; # get the options my %opt; getopts('uh?Ldtp:g:r:', \%opt); # if we are looking for help give it usage() if ($opt{'h'} || $opt{'u'} || $opt{'?'}); # if we want to do listings, do them and don't worry about # the arguments, both of these will exit of their own # accord tasks_list() if $opt{'L'}; # okay, if we've made it here, we must be wanting to some kind of # inject so let's get the arguments, create the object and # then see what we need to do send the tasks # get the arguments my $domain = shift; my $username = shift; my $organization = shift; usage('three arguments required') unless defined $organization; # create the object my $handle; eval { $handle = new VirtdomInjector('-debug' => $opt{'d'}, '-test' => $opt{'t'}, '-log' => 1, '-username' => $username, '-domain' => $domain, '-organization' => $organization, ); } || do { if ($@ =~ /^(username|domain|organization):/) { usage("$@"); } else { die "creation of VirtdomInjector object failed: $@"; } }; # do a full if we don't have args that say otherwise if (!$opt{'p'} && !$opt{'g'} && !$opt{'r'}) { eval { $handle->full_inject(); } || die "full_inject failed: $@"; exit; } # we must want to do a partial of some kind # -p -g and -r can all be used to together but don't # have to be, they create lists of tasks, we need to # resolve all those lists # the list where we keep the tasks my @tasks; # if we have opt g but not opt r that means we are trying # create a partial job based on the way the tasks are grouped if ($opt{'g'} && !$opt{'r'}) { # opt g should be a list of groups, comma separted push(@tasks, $handle->create_partial(split(',', $opt{'g'}))); } # if we have opt r we want to reverse resolve dependencies to find # out what things will have stalled out and not worked if the # given tasks failed if ($opt{'r'}) { # opt r is a list of groups comma separated that # describe comms that failed and we want to do those # things which didn't happen because of dependency relationships foreach (split(',', $opt{'r'})) { push(@tasks, $handle->reverse_dependencies($_, $opt{'g'})); } } # add the tasks that we name explicitly with -p if (defined($opt{'p'})) { push(@tasks, split(',', $opt{'p'})); } # it's possible to end up with no tasks, I suppose if (@tasks == 0) { die "no tasks available to inject\n"; } # do the partial inject eval { $handle->partial_inject(@tasks); } || die "partial_inject failed: $@"; # we are done exit; ########################################################################## # subs ########################################################################## # print the usage message sub usage { my $message = shift; $message ||= ''; print<<"EOF"; $0: $message virt_injector [-uh?LGdt] [-p ] [-g ] \\ [-r u|h|? this help L List the available tasks and Groups d turn on debugging output t run in test mode, this injects mcfeely test_comm instead of the real tasks p inject a partial job made up the listed tasks, implications will be resolved g inject a partial job made up the tasks associated with the listed groups r create a job based on resolving the dependencies of the failed tasks provided. Changes g. If r is used g can only be one group and the dependency resolution is limited to that one group. the domain being created the vhttp owner account for the domain the name of the organization associated with the domain EOF if ($message) { exit 1; } else { exit 0; } } # display the tasks that # are available for running sub tasks_list { my $arrayref = VirtdomInjector::tasks_list(); my $hashref = VirtdomInjector::task_groups(); my %groups; my $item; printf "%20s %-50s\n", 'TASK', 'GROUPS'; foreach $item (sort(@$arrayref)) { printf "%20s %-50s\n", $item, @{$$hashref{$item}}; foreach (@{$$hashref{$item}}) { $groups{$_}++; } } print "GROUPS: ", map {"$_ "} (keys(%groups)), "\n"; exit; }