line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Amazon::EC2::Metadata; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
23018
|
use vars qw/$VERSION/; $VERSION='0.10'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
63
|
|
4
|
1
|
|
|
1
|
|
570
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
36
|
|
5
|
1
|
|
|
1
|
|
4
|
use strict; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
32
|
|
6
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
103
|
|
7
|
|
|
|
|
|
|
|
8
|
1
|
|
|
1
|
|
836
|
use LWP::Simple; |
|
1
|
|
|
|
|
867710
|
|
|
1
|
|
|
|
|
11
|
|
9
|
|
|
|
|
|
|
# http://developer.amazonwebservices.com/connect/entry.jspa?externalID=1085&categoryID=100 |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
#Docs |
12
|
|
|
|
|
|
|
#http://docs.amazonwebservices.com/AWSEC2/2007-08-29/DeveloperGuide/AESDG-chapter-instancedata.html |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
### Metadata |
16
|
|
|
|
|
|
|
# ami-id The AMI ID used to launch the instance. 1.0 |
17
|
|
|
|
|
|
|
# ami-manifest-path The manifest path of the AMI with which the instance was launched. 1.0 |
18
|
|
|
|
|
|
|
# ami-launch-index The index of this instance in the reservation (per AMI). 1.0 |
19
|
|
|
|
|
|
|
# ancestor-ami-ids The AMI IDs of any instances that were rebundled to create this AMI. 2007-10-10 |
20
|
|
|
|
|
|
|
# instance-id The ID of this instance. 1.0 |
21
|
|
|
|
|
|
|
# instance-type The type of instance to launch. For more information, see Selecting Instance Types. 2007-08-29 |
22
|
|
|
|
|
|
|
# local-hostname The local hostname of the instance. 2007-01-19 |
23
|
|
|
|
|
|
|
# public-hostname The public hostname of the instance. 2007-01-19 |
24
|
|
|
|
|
|
|
# local-ipv4 Public IP address if launched with direct addressing; private IP address if launched with public addressing. 1.0 |
25
|
|
|
|
|
|
|
# public-ipv4 NATted public IP Address 2007-01-19 |
26
|
|
|
|
|
|
|
# public-keys/ Public keys. Only available if supplied at instance launch time 1.0 |
27
|
|
|
|
|
|
|
# reservation-id ID of the reservation. 1.0 |
28
|
|
|
|
|
|
|
# security-groups Names of the security groups the instance is launched in. Only available if supplied at instance launch time 1.0 |
29
|
|
|
|
|
|
|
# product-codes Product codes associated with this instance. 2007-03-01 |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $data = {}; |
35
|
|
|
|
|
|
|
my $baseurl='http://169.254.169.254/latest/'; |
36
|
|
|
|
|
|
|
my $metaurl=$baseurl."meta-data/"; |
37
|
|
|
|
|
|
|
my $userurl=$baseurl."user-data/"; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
my @data = qw(ami_id ami_manifest_path ami_launch_index |
40
|
|
|
|
|
|
|
ancestor_ami_ids instance_id instance_type |
41
|
|
|
|
|
|
|
local_hostname public_hostname |
42
|
|
|
|
|
|
|
local_ipv4 public_ipv4 |
43
|
|
|
|
|
|
|
reservation_id |
44
|
|
|
|
|
|
|
security_groups |
45
|
|
|
|
|
|
|
product_codes |
46
|
|
|
|
|
|
|
); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
for my $item (@data) { |
53
|
1
|
|
|
1
|
|
864
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
205
|
|
54
|
|
|
|
|
|
|
*{"$item"} = sub { |
55
|
0
|
0
|
|
0
|
|
|
return $data->{$item} if $data->{$item}; |
56
|
0
|
|
|
|
|
|
my $path = $item; |
57
|
0
|
|
|
|
|
|
$path =~ s/_/-/; |
58
|
0
|
|
|
|
|
|
$data->{$item} = get($metaurl.$path); |
59
|
0
|
|
|
|
|
|
return $data->{$item}; |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new{ |
65
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
66
|
0
|
|
|
|
|
|
return bless {}, $class; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# returns a hash of all the data |
72
|
|
|
|
|
|
|
# |
73
|
|
|
|
|
|
|
sub available_data{ |
74
|
0
|
|
|
0
|
1
|
|
return [@data, 'user_data', 'public_keys']; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub all_data{ |
78
|
0
|
|
|
0
|
1
|
|
my $data={}; |
79
|
0
|
|
|
|
|
|
for (@data, 'user_data', 'public_keys' ) { |
80
|
1
|
|
|
1
|
|
5
|
no strict 'refs'; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
289
|
|
81
|
0
|
|
|
|
|
|
$data->{$_}= $_->(); |
82
|
|
|
|
|
|
|
} |
83
|
0
|
|
|
|
|
|
return $data; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub public_keys{ |
89
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
90
|
0
|
|
|
|
|
|
my $key = shift; |
91
|
0
|
|
|
|
|
|
my $item = 'public_keys'; |
92
|
0
|
|
|
|
|
|
my $path = $item; |
93
|
0
|
|
|
|
|
|
$path =~ s/_/-/; |
94
|
0
|
0
|
|
|
|
|
if ($key) { |
95
|
0
|
|
|
|
|
|
$path .= "/$key"; |
96
|
0
|
|
|
|
|
|
$item .= "/$key"; |
97
|
|
|
|
|
|
|
} |
98
|
0
|
0
|
|
|
|
|
return $data->{$item} if $data->{$item} ; |
99
|
0
|
|
|
|
|
|
$data->{$item} = get($metaurl.$path); |
100
|
0
|
|
|
|
|
|
return $data->{$item}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub public_key{ |
104
|
0
|
|
|
0
|
1
|
|
public_keys(@_); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub user_data{ |
109
|
0
|
|
|
0
|
1
|
|
my $item = '__userdata'; |
110
|
0
|
0
|
|
|
|
|
return $data->{$item} if $data->{$item}; |
111
|
0
|
|
|
|
|
|
my $path = $item; |
112
|
0
|
|
|
|
|
|
$data->{$item} = get($userurl); |
113
|
0
|
|
|
|
|
|
return $data->{$item}; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
1; |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
# Magic true value required at end of module |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
__END__ |