This file is indexed.

/usr/share/perl5/VM/EC2/NetworkInterface.pm is in libvm-ec2-perl 1.28-2build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
package VM::EC2::NetworkInterface;

=head1 NAME

VM::EC2::NetworkInterface - Object describing an Amazon Elastic Network Interface (ENI)

=head1 SYNOPSIS

  use VM::EC2;
  my $ec2 = VM::EC2->new(...);
  my $interface = $ec2->describe_network_interfaces('eni-12345');
  print $interface->subNetId,"\n",
        $interface->description,"\n",
        $interface->vpcId,"\n",
        $interface->status,"\n",
        $interface->privateIpAddress,"\n",
        $interface->macAddress,"\n";
  
=head1 DESCRIPTION

This object provides access to information about Amazon Elastic
Network Interface objects, which are used in conjunction with virtual
private cloud (VPC) instances to create multi-homed web servers,
routers, firewalls, and so forth.

Please see L<VM::EC2::Generic> for methods shared by all VM::EC2
objects.

=head1 METHODS

These object methods are supported:

 networkInterfaceId       -- The ID of this ENI
 subnetId                 -- The ID of the subnet this ENI belongs to
 vpcId                    -- The ID of the VPC this ENI belongs to
 ownerId                  -- Owner of the ENI
 status                   -- ENI status, one of "available" or "in-use"
 privateIpAddress         -- Primary private IP address of the ENI
 privateDnsName           -- Primary private DNS name of the ENI
                             as a set of VM::EC2::Group objects.
 attachment               -- Information about the attachment of this ENI to
                             an instance, as a VM::EC2::NetworkInterface::Attachment
                             object.
 association              -- Information about the association of this ENI with
                             an elastic public IP address.
 privateIpAddresses       -- List of private IP addresses assigned to this ENI,
                             as a list of VM::EC2::NetworkInterface::PrivateIpAddress
                             objects.
 availabilityZone         -- Availability zone for this ENI as a VM::EC2::AvailabilityZone
                             object.
 macAddress               -- MAC address for this interface.

In addition, this object supports the following convenience methods:

 resetAttributes()          -- Return attributes to their default states. Currently only
                               sets the SourceDestCheck value to true.

 description([$new_value])  -- Description of the ENI. Pass a single argument to set a new
                               description

 sourceDestCheck([$boolean])-- Boolean value. If true, prevent this ENI from
                               forwarding packets between subnets. Value can optionally
                               be set

 security_groups([@new_groups]) -- List of security groups this ENI belongs to. Pass a
                               list of new security groups to change this value.

 delete_on_termination([$boolean])
                            -- Whether the deleteOnTermination flag is set for the current
                               attachment. Pass a boolean value to change the value.

=head1 Attaching to an instance

The following methods allow the interface to be attached to, and
detached from, instances.

=head2 $attachment_id = $interface->attach($instance_id => $device)

=head2 $attachment_id = $interfacee->attach(-instance_id    => $id,
                                            -device_index   => $device)

This method attaches the network interface an instance using the the
indicated device index. You can provide either an instance ID, or a
VM::EC2::Instance object. You may use an integer for -device_index, or
use the strings "eth0", "eth1" etc.

Required arguments:

 -instance_id          ID of the instance to attach to.
 -device_index         Network device number to use (e.g. 0 for eth0).

On success, this method returns the attachmentId of the new attachment
(not a VM::EC2::NetworkInterface::Attachment object, due to an AWS API
inconsistency).

=head2 $boolean = $interface->detach([$force])

This method detaches the network interface from whatever instance it
is currently attached to. If a true argument is provided, then the
detachment will be forced, even if the interface is in use.

On success, this method returns a true value.

=head1 Adding IP addresses

=head2 $result = $interface->assign_private_ip_addresses(@addresses)

=head2 $result = $interface->assign_private_ip_addresses(%args)

Assign one or more secondary private IP addresses to the network
interface. You can either set the addresses explicitly, or provide a
count of secondary addresses, and let Amazon select them for you.

In the list argument form, pass a list of desired IP addresses, or a
count of the number of addresses to select for you:

 $interface->assign_private_ip_addresses(3);  # three automatic addresses
 $interface->assign_private_ip_addresses('192.168.0.10','192.168.0.11');

Required arguments:

 -private_ip_address      One or more secondary IP addresses, as a scalar string
 -private_ip_addresses    or array reference. (The two arguments are equivalent).

Optional arguments:

 -allow_reassignment      If true, allow assignment of an IP address is already in
                          use by another network interface or instance.

The following are valid arguments to -private_ip_address:

 -private_ip_address => '192.168.0.12'                    # single address
 -private_ip_address => ['192.168.0.12','192.168.0.13]    # multiple addresses
 -private_ip_address => 3                                 # autoselect three addresses

The mixed form of address, such as ['192.168.0.12','auto'] is not allowed in this call.

On success, this method returns true.

=head2 $result = $interface->unassign_private_ip_addresses(@addresses)

=head2 $result = $interface->unassign_private_ip_addresses(-private_ip_address => \@addresses)

Unassign one or more secondary private IP addresses from the network
interface.

In the list argument form, pass a list of desired IP addresses to unassign.

 $interface->assign_private_ip_addresses('192.168.0.10','192.168.0.11');

In the named argument form, use:

 -private_ip_address      One or more secondary IP addresses, as a scalar string
 -private_ip_addresses    or array reference. (The two arguments are equivalent).

The following are valid arguments to -private_ip_address:

 -private_ip_address => '192.168.0.12'                    # single address
 -private_ip_address => ['192.168.0.12','192.168.0.13]    # multiple addresses

On success, this method returns true.

=head1 STRING OVERLOADING

When used in a string context, this object will be interpolated as the
networkInterfaceId

=head1 SEE ALSO

L<VM::EC2>
L<VM::EC2::Generic>
L<VM::EC2::NetworkInterface>
L<VM::EC2::NetworkInterface::Attachment>
L<VM::EC2::NetworkInterface::Association>

=head1 AUTHOR

Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.

Copyright (c) 2012 Ontario Institute for Cancer Research

This package and its accompanying libraries is free software; you can
redistribute it and/or modify it under the terms of the GPL (either
version 1, or at your option, any later version) or the Artistic
License 2.0.  Refer to LICENSE for the full license text. In addition,
please see DISCLAIMER.txt for disclaimers of warranty.

=cut

use strict;
use base 'VM::EC2::Generic';
use Carp 'croak';
use VM::EC2::Group;
use VM::EC2::NetworkInterface::PrivateIpAddress;
use VM::EC2::NetworkInterface::Attachment;
use VM::EC2::NetworkInterface::Association;

sub valid_fields {
    my $self  = shift;
    return qw(networkInterfaceId subnetId vpcId description ownerId status privateIpAddress privateDnsName
              sourceDestCheck groupSet attachment association privateIpAddressesSet macAddress requesterManaged
              availabilityZone);
}

sub refresh {
    my $self = shift;
    my $i    = shift;
    local $self->aws->{raise_error} = 1;
    ($i) = $self->aws->describe_network_interfaces(-network_interface_id=>$self->networkInterfaceId) unless $i;
    %$self  = %$i if $i;
    return defined $i;
}

sub current_status {
    my $self = shift;
    $self->refresh;
    $self->status;
}

sub primary_id {shift->networkInterfaceId}

sub groups {
    my $self = shift;
    my $groupSet = $self->SUPER::groupSet;
    return map {VM::EC2::Group->new($_,$self->aws,$self->xmlns,$self->requestId)}
        @{$groupSet->{item}};
}

sub privateIpAddresses {
    my $self = shift;
    my $set  = $self->SUPER::privateIpAddressesSet;
    return map {VM::EC2::NetworkInterface::PrivateIpAddress->new($_,$self->aws)} @{$set->{item}};
}

sub attachment {
    my $self = shift;
    my $a    = $self->SUPER::attachment or return;
    return VM::EC2::NetworkInterface::Attachment->new($a,$self->aws);
}

sub association {
    my $self = shift;
    my $a    = $self->SUPER::association or return;
    return VM::EC2::NetworkInterface::Association->new($a,$self->aws);
}

sub vpc {
    my $self = shift;
    return $self->describe_vpcs($self->vpcId);
}

# get/set methods
sub description {
    my $self = shift;
    my $d    = $self->aws->describe_network_interface_attribute($self,'description');
    $self->aws->modify_network_interface_attribute($self,-description=>shift) if @_;
    return $d;
}

sub security_groups {
    my $self = shift;
    my @d    = $self->aws->describe_network_interface_attribute($self,'groupSet');
    $self->aws->modify_network_interface_attribute($self,-security_group_id=>\@_) if @_;
    return map {VM::EC2::Group->new($_,$self->aws)} @d;
}

sub source_dest_check {
    my $self = shift;
    my $d    = $self->aws->describe_network_interface_attribute($self,'sourceDestCheck');
    $self->aws->modify_network_interface_attribute($self,-source_dest_check=>(shift() ? 'true' : 'false')) if @_;    
    return $d eq 'true';
}

sub reset_attributes {
    my $self = shift;
    return $self->aws->reset_network_interface_attribute($self=>'sourceDestCheck');
}

sub delete_on_termination {
    my $self = shift;
    my $d    = $self->aws->describe_network_interface_attribute($self,'attachment') or return;
    my $att  = VM::EC2::NetworkInterface::Attachment->new($d,$self->aws);
    $self->aws->modify_network_interface_attribute($self,-delete_on_termination=>[$att=>shift]) if @_;
    return $att->delete_on_termination;
}

sub availabilityZone {
    my $self = shift;
    my $z    = $self->SUPER::availabilityZone or return;
    return $self->aws->describe_availability_zones($z);
}

sub attach { 
    my $self = shift;
    my %args;
    if (@_==2 && $_[0] !~ /^-/) {
	@args{qw(-instance_id -device_index)} = @_; 
    } else {
	%args = @_;
    }
    $args{-instance_id} && $args{-device_index}
       or croak "usage: \$interface->attach(\$instance_id,\$device_index)";
    $args{-network_interface_id} = $self->networkInterfaceId;
    my $result = $self->aws->attach_network_interface(%args);
    $self->refresh if $result;
    eval {$args{-instance_id}->refresh} if $result;
    return $result;
}

sub detach {
    my $self = shift;
    my $force = shift;
    my $attachment = $self->attachment;
    $attachment or croak "$self is not attached";
    my $result =  $self->aws->detach_network_interface($attachment,$force);
    $self->refresh if $result;
    return $result;
}

sub assign_private_ip_addresses {
    my $self = shift;
    my %args;
    if (@_ && $_[0] !~ /^-/) {
	%args = (-private_ip_address => @_==1 ? $_[0] : \@_);
    } else {
	%args = @_;
    }
    my $result = $self->aws->assign_private_ip_addresses(-network_interface_id=>$self,%args);
    $self->refresh if $result;
    return $result;
}

sub unassign_private_ip_addresses {
    my $self = shift;
    my %args;
    if (@_ && $_[0] !~ /^-/) {
	%args = (-private_ip_address => \@_);
    } else {
	%args = @_;
    }
    my $result = $self->aws->unassign_private_ip_addresses(-network_interface_id=>$self,%args);
    $self->refresh if $result;
    return $result;
}

1;