/[Intel-AMT]/trunk/lib/Intel/AMT/SOAP.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/Intel/AMT/SOAP.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2 by dpavlin, Sat Aug 8 15:07:39 2009 UTC revision 23 by dpavlin, Mon Sep 14 14:15:08 2009 UTC
# Line 6  use strict; Line 6  use strict;
6  use warnings;  use warnings;
7  use SOAP::Lite;  use SOAP::Lite;
8  #use SOAP::Lite +trace => 'all';  #use SOAP::Lite +trace => 'all';
9    use Data::Dump qw/dump/;
10    
11    use lib 'lib';
12    
13    sub soap_url {
14            my $amt_host = $ENV{'AMT_HOST'};
15            my $amt_port = "16992";
16            "http://$amt_host:$amt_port";
17    }
18    
 my $amt_host = $ENV{'AMT_HOST'};  
 my $amt_port = "16992";  
 $main::amt_user = "admin";  
 $main::amt_pass = $ENV{'AMT_PASSWORD'};  
19  my $amt_debug = 0;  my $amt_debug = 0;
20  $amt_debug = $ENV{'AMT_DEBUG'} if defined($ENV{'AMT_DEBUG'});  $amt_debug = $ENV{'AMT_DEBUG'} if defined($ENV{'AMT_DEBUG'});
21    
22    my $timeout = $ENV{'AMT_TIMEOUT'} || 1;
23    
24  my $amt_version;  my $amt_version;
25    
26  #############################################################################  #############################################################################
27  # data  # data
28    
29  my @ps = ("S0", "S1", "S2", "S3", "S4", "S5 (soft-off)", "S4/S5", "Off");  my @ps = ("S0", "S1", "S2", "S3", "S4", "S5 (soft-off)", "S4/S5", "Off");
 my %rcc = (  
         "reset"      => "16",  
         "powerup"    => "17",  
         "powerdown"  => "18",  
         "powercycle" => "19",  
 );  
   
 my %rccs = (  
         "nop"        => "0",  
         "pxe"        => "1",  
         "hd"         => "2",  
         "hdsafe"     => "3",  
         "diag"       => "4",  
         "cd"         => "5",  
 );  
 my %rccs_oem = (  
         "bios"       => 0xc1,  
 );  
30    
31  # incomplete list  # incomplete list
32  my %pt_status = (  my %pt_status = (
# Line 91  my %pt_status = ( Line 80  my %pt_status = (
80  my ($nas, $sas, $rcs);  my ($nas, $sas, $rcs);
81    
82  sub SOAP::Transport::HTTP::Client::get_basic_credentials {  sub SOAP::Transport::HTTP::Client::get_basic_credentials {
83          return $main::amt_user => $main::amt_pass;          return 'admin' => $ENV{AMT_PASSWORD};
84  }  }
85    
86  sub soap_init() {  sub init() {
87          my $proxybase = "http://$amt_host:$amt_port";          my $proxybase = soap_url;
88          my $schemabase = "http://schemas.intel.com/platform/client";          my $schemabase = "http://schemas.intel.com/platform/client";
89    
90          $nas = SOAP::Lite->new(          $nas = SOAP::Lite->new(
# Line 112  sub soap_init() { Line 101  sub soap_init() {
101          $sas->autotype(0);          $sas->autotype(0);
102          $rcs->autotype(0);          $rcs->autotype(0);
103    
104            $nas->transport->timeout($timeout);
105            $sas->transport->timeout($timeout);
106            $rcs->transport->timeout($timeout);
107    
108            warn $proxybase;
109    
110          $amt_version = $sas->GetCoreVersion()->paramsout;          $amt_version = $sas->GetCoreVersion()->paramsout;
111  }  }
112    
113    sub _soap {
114            my $name = shift;
115    
116            my $proxybase = soap_url;
117            my $schemabase = "http://schemas.intel.com/platform/client";
118    
119            warn "call_soap $proxybase $name ",dump( @_ );
120    
121            my $soap = SOAP::Lite->new(
122                    proxy      => "$proxybase/${name}Service",
123                    default_ns => "$schemabase/$name/2004/01");
124    
125            $soap->autotype(0);
126            $soap->transport->timeout($timeout);
127    
128            if ( @_ ) {
129                    do_soap($soap, $name, @_)
130            } else {
131                    return $soap;
132            }
133    }
134    
135    
136  #############################################################################  #############################################################################
137  # functions  # functions
# Line 148  sub print_result($) { Line 165  sub print_result($) {
165    
166          if (!defined($rc)) {          if (!defined($rc)) {
167                  $msg = "soap failure";                  $msg = "soap failure";
168    warn dump( $ret->faultdetail );
169          } elsif (!defined($pt_status{$rc})) {          } elsif (!defined($pt_status{$rc})) {
170                  $msg = sprintf("unknown pt_status code: 0x%x", $rc);                  $msg = sprintf("unknown pt_status code: 0x%x", $rc);
171          } else {          } else {
# Line 224  sub check_amt_version { Line 242  sub check_amt_version {
242  }  }
243    
244  sub print_general_info() {  sub print_general_info() {
         printf "### AMT info on machine '%s' ###\n", $amt_host;  
245    
246          printf "AMT version:  %s\n", $amt_version;          printf "AMT version:  %s\n", $amt_version;
247                    
# Line 235  sub print_general_info() { Line 252  sub print_general_info() {
252          my $powerstate = $rcs->GetSystemPowerState()->paramsout;          my $powerstate = $rcs->GetSystemPowerState()->paramsout;
253          printf "Powerstate:   %s\n", $ps [ $powerstate & 0x0f ];          printf "Powerstate:   %s\n", $ps [ $powerstate & 0x0f ];
254  }  }
           
 sub print_remote_info() {  
         my @rccaps = $rcs->GetRemoteControlCapabilities()->paramsout;  
         printf "Remote Control Capabilities:\n";  
         printf "    IanaOemNumber                   %x\n", $rccaps[0];  
         printf "    OemDefinedCapabilities          %s%s%s%s%s\n",  
                 $rccaps[1] & 0x01 ? "IDER "        : "",  
                 $rccaps[1] & 0x02 ? "SOL "         : "",  
                 $rccaps[1] & 0x04 ? "BiosReflash " : "",  
                 $rccaps[1] & 0x08 ? "BiosSetup "   : "",  
                 $rccaps[1] & 0x10 ? "BiosPause "   : "";  
   
         printf "    SpecialCommandsSupported        %s%s%s%s%s\n",  
                 $rccaps[2] & 0x0100 ? "PXE-boot "         : "",  
                 $rccaps[2] & 0x0200 ? "HD-boot "          : "",  
                 $rccaps[2] & 0x0400 ? "HD-boot-safemode " : "",  
                 $rccaps[2] & 0x0800 ? "diag-boot "        : "",  
                 $rccaps[2] & 0x1000 ? "cd-boot "          : "";  
   
         printf "    SystemCapabilitiesSupported     %s%s%s%s\n",  
                 $rccaps[3] & 0x01 ? "powercycle " : "",  
                 $rccaps[3] & 0x02 ? "powerdown "  : "",  
                 $rccaps[3] & 0x03 ? "powerup "    : "",  
                 $rccaps[3] & 0x04 ? "reset "      : "";  
   
         printf "    SystemFirmwareCapabilities      %x\n", $rccaps[4];  
 }  
255    
256  sub print_network_info() {  sub print_network_info() {
257          my $ret;          my $ret;
# Line 278  sub print_network_info() { Line 268  sub print_network_info() {
268          }          }
269  }  }
270    
 sub remote_control($$) {  
         my $command = shift;  
         my $special = shift;  
         my @args;  
   
         my $hostname = $nas->GetHostName()->paramsout;  
         my $domainname = $nas->GetDomainName()->paramsout;  
         printf "host %s.%s, %s [y/N] ? ", $hostname, $domainname, $command;  
         my $reply = <>;  
         if ($reply =~ m/^(y|yes)$/i) {  
                 printf "execute: %s\n", $command;  
                 push (@args, SOAP::Data->name('Command' => $rcc{$command}));  
                 push (@args, SOAP::Data->name('IanaOemNumber' => 343));  
                 if (defined($special) && defined($rccs{$special})) {  
                         push (@args, SOAP::Data->name('SpecialCommand'  
                                                       => $rccs{$special} ));  
                 }  
                 if (defined($special) && defined($rccs_oem{$special})) {  
                         push (@args, SOAP::Data->name('OEMparameters' => 1 ));  
                         push (@args, SOAP::Data->name('SpecialCommand'  
                                                       => $rccs_oem{$special} ));  
                 }  
                 do_soap($rcs, "RemoteControl", @args);  
         } else {  
                 printf "canceled\n";  
         }  
 }  
   
271  sub ipv4_addr($$) {  sub ipv4_addr($$) {
272          my $name = shift;          my $name = shift;
273          my $ipv4 = shift;          my $ipv4 = shift;
# Line 373  sub configure_network { Line 335  sub configure_network {
335  sub command {  sub command {
336          my ($amt_command,$amt_arg) = @_;          my ($amt_command,$amt_arg) = @_;
337    
338          soap_init;          init;
339    
340          if ($amt_command eq "info") {          if ($amt_command eq "info") {
341                  print_general_info;                  print_general_info;
                 print_remote_info;  
342          } elsif ($amt_command eq "netinfo") {          } elsif ($amt_command eq "netinfo") {
343                  check_amt_version(2,5);                  check_amt_version(2,5);
344                  print_network_info;                  print_network_info;
345          } elsif ($amt_command eq "netconf") {          } elsif ($amt_command eq "netconf") {
346                  check_amt_version(2,5);                  check_amt_version(2,5);
347                  configure_network(@ARGV);                  configure_network(@_);
348          } elsif ($amt_command =~ m/^(reset|powerup|powerdown|powercycle)$/) {          } elsif ($amt_command =~ m/^(reset|powerup|powerdown|powercycle)$/) {
349                  remote_control($amt_command, $amt_arg);                  remote_control($amt_command, $amt_arg);
350          } else {          } else {

Legend:
Removed from v.2  
changed lines
  Added in v.23

  ViewVC Help
Powered by ViewVC 1.1.26