| 1 | package VM::EC2::REST::dhcp; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use VM::EC2 ''; # important not to import anything! | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | package VM::EC2; # add methods to VM::EC2 | ||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 1 | 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 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
create_dhcp_options: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 69 | 0 | my %args; | |||||||||||||||||||||||||||
| 70 | 0 | ▶ | if (@_ == 1 && ref $_[0] eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ == 1 and ref $_[0] eq "HASH"
MC/DC0%0/2
@_ == 1 and ref $_[0] eq "HASH"
@_ == 1
ref $_[0] eq "HASH"
Truth table0%0/3
A and B
A= @_ == 1B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||
| 71 | 0 | %args = %{$_[0]}; | |||||||||||||||||||||||||||
| 72 | } else { | ||||||||||||||||||||||||||||
| 73 | 0 | %args = @_; | |||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | 0 | my @parm; | |||||||||||||||||||||||||||
| 76 | 0 | my $count = 1; | |||||||||||||||||||||||||||
| 77 | 0 | for my $key (sort keys %args) { | |||||||||||||||||||||||||||
| 78 | 0 | my $value = $args{$key}; | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | my @values = ref $value && ref $value eq 'ARRAY' ? @$value : $value; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
ref $value and ref $value eq "ARRAY"
MC/DC0%0/2
ref $value and ref $value eq "ARRAY"
ref $value
ref $value eq "ARRAY"
Truth table0%0/3
A and B
A= ref $valueB= ref $value eq "ARRAY"
| |||||||||||||||||||||||||||||
| 80 | 0 | $key =~ s/^-//; | |||||||||||||||||||||||||||
| 81 | 0 | $key =~ s/_/-/g; | |||||||||||||||||||||||||||
| 82 | 0 | my $item = 1; | |||||||||||||||||||||||||||
| 83 | 0 | push @parm,("DhcpConfiguration.$count.Key" => $key); | |||||||||||||||||||||||||||
| 84 | 0 | push @parm,("DhcpConfiguration.$count.Value.".$item++ => $_) foreach @values; | |||||||||||||||||||||||||||
| 85 | 0 | $count++; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | 0 | 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 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
delete_dhcp_options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 0 | my %args = $self->args(-dhcp_options_id => @_); | |||||||||||||||||||||||||||
| 100 | 0 | my @param = $self->single_parm(DhcpOptionsId=>\%args); | |||||||||||||||||||||||||||
| 101 | 0 | 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 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
describe_dhcp_options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 128 | 0 | my %args = $self->args(-dhcp_options_id => @_); | |||||||||||||||||||||||||||
| 129 | 0 | my @parm = $self->list_parm('DhcpOptionsId',\%args); | |||||||||||||||||||||||||||
| 130 | 0 | push @parm, $self->filter_parm(\%args); | |||||||||||||||||||||||||||
| 131 | 0 | 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 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
associate_dhcp_options: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 145 | 0 | my %args; | |||||||||||||||||||||||||||
| 146 | 0 | ▶ | if ($_[0] !~ /^-/ && @_ == 2) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $_[0] =~ /^-/ and @_ == 2
MC/DC0%0/2
not $_[0] =~ /^-/ and @_ == 2
not $_[0] =~ /^-/
@_ == 2
Truth table0%0/3
not(A) and B
A= not $_[0] =~ /^-/B= @_ == 2
| |||||||||||||||||||||||||||||
| 147 | 0 | @args{qw(-vpc_id -dhcp_options_id)} = @_; | |||||||||||||||||||||||||||
| 148 | } else { | ||||||||||||||||||||||||||||
| 149 | 0 | %args = @_; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | $args{-vpc_id} && $args{-dhcp_options_id} | ||||||||||||||||||||||||||||
| 152 | 0 | ▶ | or croak "-vpc_id and -dhcp_options_id must be specified"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$args{"-vpc_id"} and $args{"-dhcp_options_id"}
MC/DC0%0/2
$args{"-vpc_id"} and $args{"-dhcp_options_id"}
$args{"-vpc_id"}
$args{"-dhcp_options_id"}
Truth table0%0/3
A and B
A= $args{"-vpc_id"}B= $args{"-dhcp_options_id"}
| |||||||||||||||||||||||||||||
| 153 | 0 | my @param = $self->single_parm(DhcpOptionsId=> \%args); | |||||||||||||||||||||||||||
| 154 | 0 | push @param, $self->single_parm(VpcId => \%args); | |||||||||||||||||||||||||||
| 155 | 0 | 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 | 1; | |||||||||||||||||||||||||||