diff --git a/fog-aws.gemspec b/fog-aws.gemspec index efd3aa7c5..72510bc3b 100644 --- a/fog-aws.gemspec +++ b/fog-aws.gemspec @@ -31,5 +31,4 @@ Gem::Specification.new do |spec| spec.add_dependency 'fog-core', '~> 2.1' spec.add_dependency 'fog-json', '~> 1.1' spec.add_dependency 'fog-xml', '~> 0.1' - spec.add_dependency 'ipaddress', '~> 0.8' end diff --git a/lib/fog/aws/requests/compute/create_network_interface.rb b/lib/fog/aws/requests/compute/create_network_interface.rb index 33e3225eb..ab7bcd9ac 100644 --- a/lib/fog/aws/requests/compute/create_network_interface.rb +++ b/lib/fog/aws/requests/compute/create_network_interface.rb @@ -2,6 +2,7 @@ module Fog module AWS class Compute class Real + require 'ipaddr' require 'fog/aws/parsers/compute/create_network_interface' # Creates a network interface @@ -68,7 +69,7 @@ module Fog raise Fog::AWS::Compute::Error.new("Unknown subnet '#{subnetId}' specified") else id = Fog::AWS::Mock.network_interface_id - cidr_block = IPAddress.parse(subnet['cidrBlock']) + cidr_block = IPAddr.new(subnet['cidrBlock']) groups = {} if options['GroupSet'] @@ -82,12 +83,14 @@ module Fog end if options['PrivateIpAddress'].nil? + range = cidr_block.to_range # Here we try to act like a DHCP server and pick the first # available IP (not including the first in the cidr block, # which is typically reserved for the gateway). - cidr_block.each_host do |p_ip| - unless self.data[:network_interfaces].map{ |ni, ni_conf| ni_conf['privateIpAddress'] }.include?p_ip.to_s || - cidr_block.first == p_ip + range = range.drop(2)[0..-2] if cidr_block.ipv4? + + range.each do |p_ip| + unless self.data[:network_interfaces].map{ |ni, ni_conf| ni_conf['privateIpAddress'] }.include?p_ip.to_s options['PrivateIpAddress'] = p_ip.to_s break end diff --git a/lib/fog/aws/requests/compute/create_subnet.rb b/lib/fog/aws/requests/compute/create_subnet.rb index d9302ba5e..074e68e72 100644 --- a/lib/fog/aws/requests/compute/create_subnet.rb +++ b/lib/fog/aws/requests/compute/create_subnet.rb @@ -2,7 +2,7 @@ module Fog module AWS class Compute class Real - require 'ipaddress' + require 'ipaddr' require 'fog/aws/parsers/compute/create_subnet' # Creates a Subnet with the CIDR block you specify. @@ -50,11 +50,11 @@ module Fog if vpc.nil? raise Fog::AWS::Compute::NotFound.new("The vpc ID '#{vpcId}' does not exist") end - if ! ::IPAddress.parse(vpc['cidrBlock']).include?(::IPAddress.parse(cidrBlock)) + if ! ::IPAddr.new(vpc['cidrBlock']).include?(::IPAddr.new(cidrBlock)) raise Fog::AWS::Compute::Error.new("Range => The CIDR '#{cidrBlock}' is invalid.") end self.data[:subnets].select{ |s| s['vpcId'] == vpcId }.each do |subnet| - if ::IPAddress.parse(subnet['cidrBlock']).include?(::IPAddress.parse(cidrBlock)) + if ::IPAddr.new(subnet['cidrBlock']).include?(::IPAddr.new(cidrBlock)) raise Fog::AWS::Compute::Error.new("Conflict => The CIDR '#{cidrBlock}' conflicts with another subnet") end end