/[pxelator]/lib/PXElator/amt.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 /lib/PXElator/amt.pm

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

revision 330 by dpavlin, Fri Aug 28 22:29:08 2009 UTC revision 482 by dpavlin, Sat Jan 23 18:31:14 2010 UTC
# Line 6  use strict; Line 6  use strict;
6  use lib '/srv/Intel-AMT/lib/';  use lib '/srv/Intel-AMT/lib/';
7  use Intel::AMT::RemoteControl;  use Intel::AMT::RemoteControl;
8  use Intel::AMT::NetworkAdministration;  use Intel::AMT::NetworkAdministration;
9    use Intel::AMT::EventManager;
10  use Data::Dump qw/dump/;  use Data::Dump qw/dump/;
11  use Regexp::Common qw/net/;  use Regexp::Common qw/net/;
12    
13  use html;  use html;
14  use ping;  use ping;
15  use CouchDB;  use store;
16    use Carp qw/confess/;
17    
18  sub info {  sub ip {
19          my ( $amt, $client_ip ) = @_;          my ( $client_ip, $amt ) = @_;
20            return unless $client_ip;
21            $amt ||= client::conf( $client_ip => 'amt' );
22          my ( $passwd, $ip ) = split(/\s+/, $amt);          my ( $passwd, $ip ) = split(/\s+/, $amt);
23          ( $ip, $passwd ) = ( $passwd, $ip ) if $passwd =~ m/$RE{net}{IPv4}/;          ( $ip, $passwd ) = ( $passwd, $ip ) if $passwd =~ m/$RE{net}{IPv4}/;
24    
25          $ip ||= $client_ip;          $ip ||= $client_ip;
26    
27          if ( ! ping::host( $ip ) ) {          $ENV{AMT_PASSWORD} = $passwd;
28                  return "$ip unreachable";          $ENV{AMT_HOST} = $ip;
         }  
29    
30          warn "amt $ip ", '*' x length($passwd), "\n";          my $hostname = client::conf( $client_ip => 'hostname' ) || $client_ip;
31    
32          $ENV{AMT_HOST} = $ip;          client::conf( $ip => 'hostname', default => "amt-$hostname" );
         $ENV{AMT_PASSWORD} = $passwd;  
33    
34          my $amt = Intel::AMT::NetworkAdministration::network_settings;          return $ip;
35          $amt->{power_state} = Intel::AMT::RemoteControl::SystemPowerState;  }
36    
37          CouchDB::audit('network', $amt );  sub power_state {
38            my $state = eval { Intel::AMT::RemoteControl::SystemPowerState };
39            store::audit('SystemPowerState', { ip => $ENV{AMT_HOST}, SystemPowerState => $state });
40            return $state;
41    }
42    
43          my $out;  sub power_on {
44            ip @_;
45            my $state = power_state;
46            defined $state && ( $state & 0x0f ) == 0;
47    }
48    
49          $out =  sub network {
50                    qq| <a href="http://$ip:16992/" target="$ip">amt</a>|          ip @_;
51                  . qq| <a href="http://$ip:16992/ip.htm" target="$ip">ip</a>|  
52                  . qq|<br>|          my $amt = eval { Intel::AMT::NetworkAdministration::network_settings };
53                  . html::pre_dump( $amt )          if ( $@ ) {
54                  ;                  warn "ERROR $@";
55            } else {
56                    $amt->{ip} = $ENV{AMT_HOST};
57                    store::audit('log', $amt );
58            }
59            $amt;
60    }
61    
62    sub log {
63            ip @_;
64    
65            my $amt = eval { Intel::AMT::EventManager::ReadEventLogRecords };
66            if ( $@ ) {
67                    warn "ERROR $@";
68            } else {
69                    $amt->{ip} = $ENV{AMT_HOST};
70                    store::audit('log', $amt );
71            }
72            $amt;
73    }
74    
75          return $out;  sub RemoteControl {
76            ip shift;
77            my $command = shift;
78            eval { Intel::AMT::RemoteControl::run( $command ) };
79            store::audit( $command, { ip => $ENV{AMT_HOST}, error => $@ } );
80            warn "ERROR $@" if $@;
81  }  }
82    
83  1;  1;

Legend:
Removed from v.330  
changed lines
  Added in v.482

  ViewVC Help
Powered by ViewVC 1.1.26