blib/lib/VM/EC2/REST/dhcp.pm untested

filter: Statementstmt 0.0% 0 / 43 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 14 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 6 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 73 CC 4 SCAR 18.3
CC
4
Cov
0%
create_dhcp_options
12.0
associate_dhcp_options
6.0
delete_dhcp_options
2.0
CRAP 6.2
1 package VM::EC2::REST::dhcp;
2  
3 use strict;
4 use VM::EC2 ''; # important not to import anything!
5 package VM::EC2; # add methods to VM::EC2
6  
7 VM::EC2::Dispatch->register(
8 DescribeDhcpOptions => 'fetch_items,dhcpOptionsSet,VM::EC2::VPC::DhcpOptions,nokey',
9 CreateDhcpOptions => 'fetch_one,dhcpOptions,VM::EC2::VPC::DhcpOptions,nokey',
10 DeleteDhcpOptions => 'boolean',
11 AssociateDhcpOptions => 'boolean',
12 );
13  
14 =head1 NAME VM::EC2::REST::dhcp
15  
16 =head1 SYNOPSIS
17  
18 use VM::EC2 qw(:vpn);
19  
20 =head1 METHODS
21  
22 These methods manage DHCP Option objects, which can then be applied to
23 a VPC to configure the DHCP options applied to running instances. You
24 get these methods when you import the tag ":vpn".
25  
26 Implemented:
27 AssociateDhcpOptions
28 CreateDhcpOptions
29 DeleteDhcpOptions
30 DescribeDhcpOptions
31  
32 Unimplemented;
33 (none)
34  
35 =head2 $options = $ec2->create_dhcp_options(\%configuration_list)
36  
37 This method creates a DhcpOption object, The single required argument is a
38 configuration list hash (which can be passed either as a hashref or a
39 flattened hash) with one or more of the following keys:
40  
41 -domain_name Domain name for instances running in this VPC.
42  
43 -domain_name_servers Scalar or arrayref containing up to 4 IP addresses of
44 domain name servers for this VPC.
45  
46 -ntp_servers Scalar or arrayref containing up to 4 IP addresses
47 of network time protocol servers
48  
49 -netbios_name_servers Scalar or arrayref containing up to 4 IP addresses for
50 NetBIOS name servers.
51  
52 -netbios_node_type The NetBios node type (1,2,4 or 8). Amazon recommends
53 using "2" at this time.
54  
55 On successful completion, a VM::EC2::VPC::DhcpOptions object will be
56 returned. This can be associated with a VPC using the VPC object's
57 set_dhcp_options() method:
58  
59 $vpc = $ec2->create_vpc(...);
60 $options = $ec2->create_dhcp_options(-domain_name=>'test.com',
61 -domain_name_servers=>['204.16.255.55','216.239.34.10']);
62 $vpc->set_dhcp_options($options);
63  
64 =cut
65  
66 # { 'domain-name-servers' => ['192.168.2.1','192.168.2.2'],'domain-name'=>'example.com'}
67 sub create_dhcp_options {
68 my $self = shift;
69 my %args;
70 if (@_ == 1 && ref $_[0] eq 'HASH') {
71 %args = %{$_[0]};
72 } else {
73 %args = @_;
74 }
75 my @parm;
76 my $count = 1;
77 for my $key (sort keys %args) {
78 my $value = $args{$key};
79 my @values = ref $value && ref $value eq 'ARRAY' ? @$value : $value;
80 $key =~ s/^-//;
81 $key =~ s/_/-/g;
82 my $item = 1;
83 push @parm,("DhcpConfiguration.$count.Key" => $key);
84 push @parm,("DhcpConfiguration.$count.Value.".$item++ => $_) foreach @values;
85 $count++;
86 }
87 return $self->call('CreateDhcpOptions',@parm);
88 }
89  
90 =head2 $success = $ec2->delete_dhcp_options($dhcp_id)
91  
92 Delete the indicated DHCPOptions, returning true if successful. You
93 may also use the named argument -dhcp_options_id..
94  
95 =cut
96  
97 sub delete_dhcp_options {
98 my $self = shift;
99 my %args = $self->args(-dhcp_options_id => @_);
100 my @param = $self->single_parm(DhcpOptionsId=>\%args);
101 return $self->call('DeleteDhcpOptions',@param);
102 }
103  
104 =head2 @options = $ec2->describe_dhcp_options(@option_ids)
105  
106 =head2 @options = $ec2->describe_dhcp_options(\%filters)
107  
108 =head2 @options = $ec2->describe_dhcp_options(-dhcp_options_id=>$id,
109 -filter => \%filters)
110  
111 This method returns a list of VM::EC2::VPC::DhcpOptions objects, which
112 describe a set of DHCP options that can be assigned to a VPC. Called
113 with no arguments, it returns all DhcpOptions. Pass a list of option
114 IDs or a filter hashref in order to restrict the search.
115  
116 Optional arguments:
117  
118 -dhcp_options_id Scalar or arrayref of DhcpOption IDs.
119 -filter Hashref of filters.
120  
121 Available filters are described at
122 http://docs.amazonwebservices.com/AWSEC2/latest/APIReference/ApiReference-query-DescribeDhcpOptions.html.
123  
124 =cut
125  
126 sub describe_dhcp_options {
127 my $self = shift;
128 my %args = $self->args(-dhcp_options_id => @_);
129 my @parm = $self->list_parm('DhcpOptionsId',\%args);
130 push @parm, $self->filter_parm(\%args);
131 return $self->call('DescribeDhcpOptions',@parm);
132 }
133  
134 =head2 $success = $ec2->associate_dhcp_options($vpc_id => $dhcp_id)
135  
136 =head2 $success = $ec2->associate_dhcp_options(-vpc_id => $vpc_id,-dhcp_options_id => $dhcp_id)
137  
138 Associate a VPC ID with a DHCP option set. Pass an ID of 'default' to
139 restore the default DHCP options for the VPC.
140  
141 =cut
142  
143 sub associate_dhcp_options {
144 my $self = shift;
145 my %args;
146 if ($_[0] !~ /^-/ && @_ == 2) {
147 @args{qw(-vpc_id -dhcp_options_id)} = @_;
148 } else {
149 %args = @_;
150 }
151 $args{-vpc_id} && $args{-dhcp_options_id}
152 or croak "-vpc_id and -dhcp_options_id must be specified";
153 my @param = $self->single_parm(DhcpOptionsId=> \%args);
154 push @param, $self->single_parm(VpcId => \%args);
155 return $self->call('AssociateDhcpOptions',@param);
156 }
157  
158 =head1 SEE ALSO
159  
160 L<VM::EC2>
161  
162 =head1 AUTHOR
163  
164 Lincoln Stein E<lt>lincoln.stein@gmail.comE<gt>.
165  
166 Copyright (c) 2011 Ontario Institute for Cancer Research
167  
168 This package and its accompanying libraries is free software; you can
169 redistribute it and/or modify it under the terms of the GPL (either
170 version 1, or at your option, any later version) or the Artistic
171 License 2.0. Refer to LICENSE for the full license text. In addition,
172 please see DISCLAIMER.txt for disclaimers of warranty.
173  
174 =cut
175  
176  
177 1;