From 8376bfab67ff0269d884ee234286864c4d30a642 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 11 Oct 2013 14:45:19 -0400 Subject: [PATCH 1/4] Attempt to set ip and netmask remotely --- xCAT-server/lib/perl/xCAT/IPMI.pm | 2 +- xCAT-server/lib/xcat/plugins/ipmi.pm | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/xCAT-server/lib/perl/xCAT/IPMI.pm b/xCAT-server/lib/perl/xCAT/IPMI.pm index 1e5c1f140..4c4140ea6 100644 --- a/xCAT-server/lib/perl/xCAT/IPMI.pm +++ b/xCAT-server/lib/perl/xCAT/IPMI.pm @@ -114,7 +114,7 @@ my %rmcp_codes = ( #human friendly translations of rmcp+ code numbers my $socket; #global socket for all sessions to share. Fun fun my $select = IO::Select->new(); -my %bmc_handlers; #hash from bmc address to a live session management object. +our %bmc_handlers; #hash from bmc address to a live session management object. #only one allowed at a time per bmc my %sessions_waiting; #track session objects that may want to retry a packet, value is timestamp to 'wake' object for retransmit diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm index 7a7389344..c52169589 100644 --- a/xCAT-server/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server/lib/xcat/plugins/ipmi.pm @@ -710,6 +710,24 @@ sub setnetinfo { $dstip = inet_ntoa(inet_aton($dstip)); my @dip = split /\./, $dstip; @cmd = (0x01,$channel_number,0x13,$1,0x00,0x00,$dip[0],$dip[1],$dip[2],$dip[3],0,0,0,0,0,0); + } elsif ($subcommand =~ m/netmask/) { + if ($argument =~ /\./) { + my @mask = split /\./, $argument; + foreach (0..3) { + $mask[$_] = $mask[$_] + 0; + } + @cmd = (0x01,$channel_number,0x6,@mask); + } + } elsif ($subcommand =~ m/ip/) { + if ($argument =~ /\./) { + my @mask = split /\./, $argument; + foreach (0..3) { + $mask[$_] = $mask[$_] + 0; + } + @cmd = (0x01,$channel_number,0x3,@mask); + $xCAT::IPMI::bmc_handlers{$argument} = $sessdata->{ipmisession}; + } + } #elsif($subcommand eq "alert" ) { # my $action=pop(@input); From 5bfcf116893f0ef28f350263d474b2c5548ea27b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 11 Oct 2013 14:57:26 -0400 Subject: [PATCH 2/4] Rework previous changeset somewhat and add gateway support --- xCAT-server/lib/xcat/plugins/ipmi.pm | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/ipmi.pm b/xCAT-server/lib/xcat/plugins/ipmi.pm index c52169589..1de465611 100644 --- a/xCAT-server/lib/xcat/plugins/ipmi.pm +++ b/xCAT-server/lib/xcat/plugins/ipmi.pm @@ -718,16 +718,20 @@ sub setnetinfo { } @cmd = (0x01,$channel_number,0x6,@mask); } - } elsif ($subcommand =~ m/ip/) { - if ($argument =~ /\./) { - my @mask = split /\./, $argument; - foreach (0..3) { - $mask[$_] = $mask[$_] + 0; - } - @cmd = (0x01,$channel_number,0x3,@mask); - $xCAT::IPMI::bmc_handlers{$argument} = $sessdata->{ipmisession}; + } elsif ($subcommand =~ m/gateway/) { + my $gw = inet_ntoa(inet_aton($argument)); + my @mask = split /\./, $gw; + foreach (0..3) { + $mask[$_] = $mask[$_] + 0; } - + @cmd = (0x01,$channel_number,12,@mask); + } elsif ($subcommand =~ m/ip/) { + my $mip = inet_ntoa(inet_aton($argument)); + my @mask = split /\./, $mip; + foreach (0..3) { + $mask[$_] = $mask[$_] + 0; + } + @cmd = (0x01,$channel_number,0x3,@mask); } #elsif($subcommand eq "alert" ) { # my $action=pop(@input); From 62b436be081588ca1836acfc68ed76bc93601e25 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 11 Oct 2013 15:57:29 -0400 Subject: [PATCH 3/4] Disable storable encoding for client Clever things can live in Storable payloads that can essentially be remote execution. Disable that for now. --- perl-xCAT/xCAT/Client.pm | 11 +++++++---- xCAT-server/sbin/xcatd | 20 +++++++++++--------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/perl-xCAT/xCAT/Client.pm b/perl-xCAT/xCAT/Client.pm index 5f2ac75bb..0599b5c3c 100644 --- a/perl-xCAT/xCAT/Client.pm +++ b/perl-xCAT/xCAT/Client.pm @@ -261,11 +261,14 @@ if (ref($request) eq 'HASH') { # the request is an array, not pure XML } my $msg; - my $encode = "storable"; - my $straightprint=0; - if ($ENV{XCATXMLTRACE} or $ENV{XCATXMLWARNING}) { $encode="xml"; } + my $encode = "xml"; + #storable encoding is unsafe, carry on with the unsafe xml scheme + #perhaps one day will support faster schemes + #my $encode = "storable"; + #my $straightprint=0; + #if ($ENV{XCATXMLTRACE} or $ENV{XCATXMLWARNING}) { $encode="xml"; } if (ref($request) eq 'HASH') { # the request is an array, not pure XML - print $client "xcatencoding: $encode\n"; + #print $client "xcatencoding: $encode\n"; my $encok=<$client>; send_request($request,$client,$encode); } else { #XML diff --git a/xCAT-server/sbin/xcatd b/xCAT-server/sbin/xcatd index fc491b881..fc5657c35 100755 --- a/xCAT-server/sbin/xcatd +++ b/xCAT-server/sbin/xcatd @@ -2055,15 +2055,17 @@ sub service_connection { while (1) { unless ($clientsel->can_read(15)) { last; } #don't let an unresponsive client hold us up my $line = <$sock>; # grab one line, check for mode... - if ($line and $line =~ /^xcatencoding: (.*)/) { - unless ($supported_encodes{$1}) { - print $sock "Unsupported encoding $1\n"; - last; - } - print $sock "Encoding accepted\n"; - $globalencode=$1; - $line = ""; - } + #Commenting out, could be a remote exceution path + #consider sereal one day + #if ($line and $line =~ /^xcatencoding: (.*)/) { + # unless ($supported_encodes{$1}) { + # print $sock "Unsupported encoding $1\n"; + # last; + # } + # print $sock "Encoding accepted\n"; + # $globalencode=$1; + # $line = ""; + #} $req = get_request($sock,$globalencode,$line); unless ($req) { last; } { #TODO: find closing brace.. From 1842cff1cff860a2f5aaf099d66a0791d41b4430 Mon Sep 17 00:00:00 2001 From: nott Date: Fri, 11 Oct 2013 16:40:44 -0400 Subject: [PATCH 4/4] add framework to -v and check for aix --- xCAT-server/lib/xcat/plugins/kit.pm | 160 +++++++++++++++++++++------- 1 file changed, 123 insertions(+), 37 deletions(-) diff --git a/xCAT-server/lib/xcat/plugins/kit.pm b/xCAT-server/lib/xcat/plugins/kit.pm index 8bacb467e..71a9e7072 100644 --- a/xCAT-server/lib/xcat/plugins/kit.pm +++ b/xCAT-server/lib/xcat/plugins/kit.pm @@ -89,7 +89,6 @@ sub process_request $::PID = $$; } - my $command = $request->{command}->[0]; my $rc; @@ -1059,14 +1058,20 @@ sub addkit my $xusage = sub { my %rsp; - push@{ $rsp{data} }, "addkit: add Kits into xCAT from a list of tarball file or directory which have the same structure with tarball file"; - push@{ $rsp{data} }, "Usage: "; + push@{ $rsp{data} }, "Usage: addkit - Adds product software Kits to an xCAT cluster environment."; push@{ $rsp{data} }, "\taddkit [-h|--help]"; + push@{ $rsp{data} }, "\taddkit [-v|--version]"; push@{ $rsp{data} }, "\taddkit [-i|--inspection] ]"; - push@{ $rsp{data} }, "\taddkit [-p|--path ] ] [-V]"; + push@{ $rsp{data} }, "\taddkit [-V|--verbose] [-p|--path ] ]"; xCAT::MsgUtils->message( "I", \%rsp, $callback ); }; + if ($^O ne 'linux') { + my $rsp = {}; + push @{ $rsp->{data}}, "The addkit command is only supported on Linux.\n"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + return 1; + } unless(defined($request->{arg})){ $xusage->(1); return; } @ARGV = @{$request->{arg}}; @@ -1075,10 +1080,10 @@ sub addkit return; } - GetOptions( 'h|help' => \$help, 'V|verbose' => \$::VERBOSE, + 'v|version' => \$vers, 'i|inspection' => \$::INSPECTION, 'p|path=s' => \$path, ); @@ -1088,6 +1093,12 @@ sub addkit return; } + # Option -v for version + if ( defined($vers) ) { + create_version_response('addkit'); + return 1; # no usage - just exit + } + my %tabs = (); my @tables = qw(kit kitrepo kitcomponent); foreach my $t ( @tables ) { @@ -1415,13 +1426,20 @@ sub rmkit my $xusage = sub { my %rsp; - push@{ $rsp{data} }, "rmkit: remove Kits from xCAT"; - push@{ $rsp{data} }, "Usage: "; + push@{ $rsp{data} }, "Usage: rmkit - Remove Kits from xCAT."; push@{ $rsp{data} }, "\trmkit [-h|--help]"; - push@{ $rsp{data} }, "\trmkit [-f|--force] ] [-V]"; + push@{ $rsp{data} }, "\trmkit [-v|--version]"; + push@{ $rsp{data} }, "\trmkit [-V|--verbose] [-f|--force] ] [-V]"; xCAT::MsgUtils->message( "I", \%rsp, $callback ); }; + if ($^O ne 'linux') { + my $rsp = {}; + push @{ $rsp->{data}}, "The rmkit command is only supported on Linux.\n"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + return 1; + } + unless(defined($request->{arg})){ $xusage->(1); return; } @ARGV = @{$request->{arg}}; if($#ARGV eq -1){ @@ -1433,9 +1451,16 @@ sub rmkit GetOptions( 'h|help' => \$help, 'V|verbose' => \$::VERBOSE, + 'v|version' => \$vers, 'f|force' => \$force ); + # Option -v for version + if ( defined($vers) ) { + create_version_response('rmkit'); + return 1; # no usage - just exit + } + if($help){ $xusage->(0); return; @@ -1765,13 +1790,20 @@ sub addkitcomp my $xusage = sub { my %rsp; - push@{ $rsp{data} }, "addkitcomp: assign kit component to osimage"; - push@{ $rsp{data} }, "Usage: "; + push@{ $rsp{data} }, "Usage: addkitcomp - Add a Kit component to an xCAT osimage."; push@{ $rsp{data} }, "\taddkitcomp [-h|--help]"; - push@{ $rsp{data} }, "\taddkitcomp [-a|--adddeps] [-f|--force] [-n|--noupgrade] [-V|--verbose] -i "; + push@{ $rsp{data} }, "\taddkitcomp [-v|--version]"; + push@{ $rsp{data} }, "\taddkitcomp [-V|--verbose] [-a|--adddeps] [-f|--force] \n\t\t[-n|--noupgrade] -i "; xCAT::MsgUtils->message( "I", \%rsp, $callback ); }; + if ($^O ne 'linux') { + my $rsp = {}; + push @{ $rsp->{data}}, "The addkitcomp command is only supported on Linux.\n"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + return 1; + } + unless(defined($request->{arg})){ $xusage->(1); return; } @ARGV = @{$request->{arg}}; if($#ARGV eq -1){ @@ -1779,10 +1811,10 @@ sub addkitcomp return; } - GetOptions( 'h|help' => \$help, 'V|verbose' => \$::VERBOSE, + 'v|version' => \$vers, 'a|adddeps' => \$adddeps, 'f|force' => \$force, 'n|noupgrade' => \$::noupgrade, @@ -1794,6 +1826,12 @@ sub addkitcomp return; } + # Option -v for version + if ( defined($vers) ) { + create_version_response('addkitcomp'); + return 1; # no usage - just exit + } + my %tabs = (); my @tables = qw(kit kitrepo kitcomponent osimage osdistro linuximage); foreach my $t ( @tables ) { @@ -2278,13 +2316,20 @@ sub rmkitcomp my $xusage = sub { my %rsp; - push@{ $rsp{data} }, "rmkitcomp: remove kit component from osimage"; - push@{ $rsp{data} }, "Usage: "; + push@{ $rsp{data} }, "Usage: rmkitcomp - Remove Kit components from an xCAT osimage."; push@{ $rsp{data} }, "\trmkitcomp [-h|--help]"; - push@{ $rsp{data} }, "\trmkitcomp [-u|--uninstall] [-f|--force] [-V|--verbose] -i "; + push@{ $rsp{data} }, "\trmkitcomp [-v|--version]"; + push@{ $rsp{data} }, "\trmkitcomp [-V|--verbose] [-u|--uninstall] [-f|--force] \n\t\t-i "; xCAT::MsgUtils->message( "I", \%rsp, $callback ); }; + if ($^O ne 'linux') { + my $rsp = {}; + push @{ $rsp->{data}}, "The rmkitcomp command is only supported on Linux.\n"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + return 1; + } + unless(defined($request->{arg})){ $xusage->(1); return; } @ARGV = @{$request->{arg}}; if($#ARGV eq -1){ @@ -2296,6 +2341,7 @@ sub rmkitcomp GetOptions( 'h|help' => \$help, 'V|verbose' => \$::VERBOSE, + 'v|version' => \$vers, 'u|uninstall' => \$uninstall, 'f|force' => \$force, 'i=s' => \$osimage @@ -2306,6 +2352,12 @@ sub rmkitcomp return; } + # Option -v for version + if ( defined($vers) ) { + create_version_response('rmkitcomp'); + return 1; # no usage - just exit + } + my %tabs = (); my @tables = qw(kit kitrepo kitcomponent osimage osdistro linuximage); foreach my $t ( @tables ) { @@ -3062,13 +3114,20 @@ sub chkkitcomp my $xusage = sub { my %rsp; - push@{ $rsp{data} }, "chkkitcomp: Check if kit component fits to osimage"; - push@{ $rsp{data} }, "Usage: "; + push@{ $rsp{data} }, "Usage: chkkitcomp - Check if a Kit component is compatible with an xCAT osimage."; push@{ $rsp{data} }, "\tchkkitcomp [-h|--help]"; + push@{ $rsp{data} }, "\tchkkitcomp [-v|--version]"; push@{ $rsp{data} }, "\tchkkitcomp [-V|--verbose] -i "; xCAT::MsgUtils->message( "I", \%rsp, $callback ); }; + if ($^O ne 'linux') { + my $rsp = {}; + push @{ $rsp->{data}}, "The chkkitcomp command is only supported on Linux.\n"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + return 1; + } + unless(defined($request->{arg})){ $xusage->(1); return; } @ARGV = @{$request->{arg}}; if($#ARGV eq -1){ @@ -3076,10 +3135,10 @@ sub chkkitcomp return; } - GetOptions( 'h|help' => \$help, 'V|verbose' => \$::VERBOSE, + 'v|version' => \$vers, 'i=s' => \$osimage ); @@ -3088,6 +3147,12 @@ sub chkkitcomp return; } + # Option -v for version + if ( defined($vers) ) { + create_version_response('chkkitcomp'); + return 1; # no usage - just exit + } + my %tabs = (); my @tables = qw(kit kitrepo kitcomponent osimage osdistro linuximage); foreach my $t ( @tables ) { @@ -3335,7 +3400,7 @@ sub chkkitcomp sub lskit_usage { my $rsp; push @{ $rsp->{data} }, - "\nUsage: lskit - List info for one or more kits.\n"; + "\nUsage: lskit - List infomation for one or more kits.\n"; push @{ $rsp->{data} }, " lskit [-V|--verbose] [-x|--xml|--XML] [-K|--kitattr kitattr_names] [-R|--repoattr repoattr_names] [-C|--compattr compattr_names] [kit_names]\n "; push @{ $rsp->{data} }, " lskit [-h|--help|-?] \n"; @@ -3358,12 +3423,10 @@ sub lskit_usage { sub lskitcomp_usage { my $rsp; push @{ $rsp->{data} }, - "\nUsage: lskitcomp - List info for one or more kit components.\n"; - push @{ $rsp->{data} }, - " lskitcomp [-V|--verbose] [-x|--xml|--XML] [-C|--compattr compattr_names] [-O|--osdistro os_distro] [-S|--serverrole server_role] [kitcomp_names]\n "; - push @{ $rsp->{data} }, " lskitcomp [-h|--help|-?] \n"; - push @{ $rsp->{data} }, - " lskitcomp [-v|--version] \n "; + "\nUsage: lskitcomp - List information for one or more Kit components."; + push @{ $rsp->{data} }, "\tlskitcomp [-h|--help|-?]"; + push @{ $rsp->{data} }, "\tlskitcomp [-v|--version]"; + push @{ $rsp->{data} }, "\tlskitcomp [-V|--verbose] [-x|--xml|--XML] \n\t\t[-C|--compattr compattr_names] [-O|--osdistro os_distro]\n\t\t[-S|--serverrole server_role] [kitcomp_names]\n "; xCAT::MsgUtils->message( "I", $rsp, $::CALLBACK ); return 0; } @@ -3380,18 +3443,14 @@ sub lskitcomp_usage { sub lskitdeployparam_usage { my $rsp; - push @{ $rsp->{data} }, - "\nUsage: lskitdeployparam - List the kit deployment parameters for either one or more kits, or one or more kit components.\n"; - push @{ $rsp->{data} }, - " lskitdeployparam [-V|--verbose] [-x|--xml|--XML] [-k|--kitname kit_names] [-c|--compname comp_names]\n "; - push @{ $rsp->{data} }, " lskitdeployparam [-h|--help|-?] \n"; - push @{ $rsp->{data} }, - " lskitdeployparam [-v|--version] \n "; + push @{ $rsp->{data} }, "\nUsage: lskitdeployparam - List the kit deployment parameters for full Kits or Kit components."; + push @{ $rsp->{data} }, "\tlskitdeployparam [-h|--help|-?]"; + push @{ $rsp->{data} }, "\tlskitdeployparam [-v|--version]"; + push @{ $rsp->{data} }, "\tlskitdeployparam [-V|--verbose] [-x|--xml|--XML] \n\t\t[-k|--kitname kit_names] [-c|--compname comp_names]\n"; xCAT::MsgUtils->message( "I", $rsp, $::CALLBACK ); return 0; } - #---------------------------------------------------------------------------- =head3 create_version_response @@ -3401,9 +3460,12 @@ sub lskitdeployparam_usage { #----------------------------------------------------------------------------- sub create_version_response { + my $command = shift; my $rsp; my $version = xCAT::Utils->Version(); - push @{ $rsp->{data} }, "$::command - $version\n"; + push @{ $rsp->{data} }, "$command - xCAT $version"; + push @{ $rsp->{data} }, "\tkitframework = $::KITFRAMEWORK"; + push @{ $rsp->{data} }, "\tcompatible_frameworks = $::COMPATIBLE_KITFRAMEWORKS\n"; xCAT::MsgUtils->message( "I", $rsp, $::CALLBACK ); } @@ -3468,7 +3530,7 @@ sub lskit_processargs { # Option -v for version if ( defined($::opt_v) ) { - create_version_response(); + create_version_response('lskit'); return 1; # no usage - just exit } @@ -3568,7 +3630,7 @@ sub lskitcomp_processargs { # Option -v for version if ( defined($::opt_v) ) { - create_version_response(); + create_version_response('lskitcomp'); return 1; # no usage - just exit } @@ -3660,7 +3722,7 @@ sub lskitdeployparam_processargs { # Option -v for version if ( defined($::opt_v) ) { - create_version_response(); + create_version_response('lskitdeployparam'); return 1; # no usage - just exit } @@ -3857,6 +3919,7 @@ sub lskit { # process the command line # 0=success, 1=version, 2=help, 3=error + $rc = lskit_processargs(@_); if ( $rc != 0 ) { if ( $rc != 1) { @@ -3865,6 +3928,13 @@ sub lskit { return ( $rc - 1 ); } + if ($^O ne 'linux') { + my $rsp = {}; + push @{ $rsp->{data}}, "The lskit command is only supported on Linux.\n"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + return 1; + } + # Prepare the hash tables to pass to the output routines my $kit_hash = get_kit_hash($::kitnames, $::kitattrs); my $kitrepo_hash = get_kitrepo_hash($::kitnames, $::kitrepoattrs); @@ -3910,6 +3980,14 @@ sub lskitcomp { # process the command line # 0=success, 1=version, 2=help, 3=error + + if ($^O ne 'linux') { + my $rsp = {}; + push @{ $rsp->{data}}, "The lskitcomp command is only supported on Linux.\n"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + return 1; + } + $rc = lskitcomp_processargs(@_); if ( $rc != 0 ) { if ( $rc != 1) { @@ -4003,6 +4081,14 @@ sub lskitdeployparam { # process the command line # 0=success, 1=version, 2=help, 3=error + + if ($^O ne 'linux') { + my $rsp = {}; + push @{ $rsp->{data}}, "The lskitdeployparam command is only supported on Linux.\n"; + xCAT::MsgUtils->message("E", $rsp, $::CALLBACK); + return 1; + } + $rc = lskitdeployparam_processargs(@_); if ( $rc != 0 ) { if ( $rc != 1) {