/[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

Contents of /lib/PXElator/amt.pm

Parent Directory Parent Directory | Revision Log Revision Log


Revision 376 - (show annotations)
Sun Aug 30 15:22:41 2009 UTC (10 years, 4 months ago) by dpavlin
File size: 1562 byte(s)
toggle power state using amt
1 package amt;
2
3 use warnings;
4 use strict;
5
6 use lib '/srv/Intel-AMT/lib/';
7 use Intel::AMT::RemoteControl;
8 use Intel::AMT::NetworkAdministration;
9 use Data::Dump qw/dump/;
10 use Regexp::Common qw/net/;
11
12 use html;
13 use ping;
14 use CouchDB;
15 use Carp qw/confess/;
16
17 sub ip {
18 my $client_ip = shift || confess "no ip";
19 my ( $passwd, $ip ) = split(/\s+/, client::conf( $client_ip => 'amt' ));
20 ( $ip, $passwd ) = ( $passwd, $ip ) if $passwd =~ m/$RE{net}{IPv4}/;
21
22 $ip ||= $client_ip;
23
24 if ( ! ping::host( $ip ) ) {
25 warn "W: ping $ip unreachable\n";
26 }
27
28 warn "amt $ip ", '*' x length($passwd), "\n";
29
30 $ENV{AMT_PASSWORD} = $passwd;
31 $ENV{AMT_HOST} = $ip;
32
33 }
34
35 sub power_on {
36 ip @_;
37 power_state() == 0;
38 }
39
40 sub power_state {
41 my $state = eval { Intel::AMT::RemoteControl::SystemPowerState };
42 CouchDB::audit('SystemPowerState', { ip => $ENV{AMT_HOST}, SystemPowerState => $state });
43 return $state;
44 }
45
46 sub info {
47 ip @_;
48
49 my $amt;
50 eval {
51 $amt = Intel::AMT::NetworkAdministration::network_settings;
52 $amt->{power_state} = Intel::AMT::RemoteControl::SystemPowerState;
53 CouchDB::audit('network', $amt );
54 };
55 warn "ERROR amt $@" if $@;
56
57 my $out;
58 my $ip = $ENV{AMT_HOST};
59
60 $out =
61 qq| <a href="http://$ip:16992/" target="$ip">amt</a>|
62 . qq| <a href="http://$ip:16992/ip.htm" target="$ip">ip</a>|
63 . qq|<br>|
64 . html::pre_dump( $amt )
65 ;
66
67 return $out;
68 }
69
70
71 sub RemoteControl {
72 ip shift;
73 my $command = shift;
74 eval { Intel::AMT::RemoteControl::run( $command ) };
75 CouchDB::audit( $command, { ip => $ENV{AMT_HOST}, error => $@ } );
76 warn "ERROR $@" if $@;
77 }
78
79 1;

  ViewVC Help
Powered by ViewVC 1.1.26