blib/lib/VM/EC2/VPC/DhcpOptions.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 2 Conditioncond 0.0% 0 / 10 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 71 CC 2 SCAR 10.0
CC
2
Cov
0%
option
6.0
valid_fields
2.0
primary_id
2.0
CRAP 2.7
1 package VM::EC2::VPC::DhcpOptions;
2  
3 =head1 NAME
4  
5 VM::EC2::VPC::DhcpOptions -- DHCP options set for an AWS Virtual Private Cloud
6  
7 =head1 SYNOPSIS
8  
9 use VM::EC2;
10 my $ec2 = VM::EC2->new(...);
11 my $vpc = $ec2->create_vpc('10.0.0.0/16');
12 my $options = $ec2->create_dhcp_options(-domain_name=>'test.com',
13 -domain_name_servers=>['204.16.255.55','216.239.34.10']);
14 $vpc->set_dhcp_options($options);
15  
16 =head1 DESCRIPTION
17  
18 Please see L<VM::EC2::Generic> for methods shared by all VM::EC2
19 objects.
20  
21 =head1 METHODS
22  
23 These object methods are supported:
24  
25 dhcpOptionsId -- ID of the dhcp options
26 dhcpConfigurationSet -- Hash of options
27  
28 In addition, this object supports the following convenience methods:
29  
30 options() -- return list of DHCP options contained in this set
31 option('option-name') -- return list of values for the named option. Note
32 that all options correspond to a list; calling in
33 a scalar context will return size of the list
34 associate_vpc($vpc_id) -- Associate these options with the given VPC.
35 associated_vpcs() -- Return list of VPCs associated with the DHCP option set.
36 as_string() -- returns a string concatenation of all options
37  
38 =head1 STRING OVERLOADING
39  
40 When used in a string context, this object will be interpolated as the
41 dhcp ID.
42  
43 =head1 SEE ALSO
44  
45 L<VM::EC2>
46 L<VM::EC2::Generic>
47  
48 =head1 AUTHOR
49  
50 Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
51  
52 Copyright (c) 2012 Ontario Institute for Cancer Research
53  
54 This package and its accompanying libraries is free software; you can
55 redistribute it and/or modify it under the terms of the GPL (either
56 version 1, or at your option, any later version) or the Artistic
57 License 2.0. Refer to LICENSE for the full license text. In addition,
58 please see DISCLAIMER.txt for disclaimers of warranty.
59  
60 =cut
61  
62 use strict;
63 use Carp 'croak';
64 use base 'VM::EC2::Generic';
65  
66 sub valid_fields {
67 my $self = shift;
68 return qw(dhcpOptionsId dhcpConfigurationSet);
69 }
70  
71 sub primary_id { shift->dhcpOptionsId }
72  
73 sub option {
74 my $self = shift;
75 my $key = shift;
76 my $hash = $self->dhcpConfigurationSet or return;
77 my @items = @{$hash->{item}} or return;
78 my @result;
79 foreach (@items) {
80 next unless $_->{key} eq $key;
81 push @result,map {$_->{value}} @{$_->{valueSet}{item}}
82 }
83 return @result;
84 }
85  
86 sub options {
87 my $self = shift;
88 my $hash = $self->dhcpConfigurationSet or return;
89 my @items = @{$hash->{item}} or return;
90 return map {$_->{key}} @items;
91 }
92  
93 sub associate_vpc {
94 my $self = shift;
95 my $vpc = shift or croak "Usage: associate_vpc(\$vpc_id)";
96 $self->aws->associate_dhcp_options($vpc => $self);
97 }
98  
99 sub associated_vpcs {
100 my $self = shift;
101 return $self->aws->describe_vpcs({'dhcp-options-id'=>$self});
102 }
103  
104 sub as_string {
105 my $self = shift;
106 my @options = $self->options;
107 my @results = map {"$_ = ".join(',',$self->option($_))} @options;
108 return join '; ',@results;
109 }
110  
111  
112  
113 1;
114