1
0
Fork 0
mirror of https://github.com/fog/fog-aws.git synced 2022-11-09 13:50:52 -05:00

Drop ipaddress dependency in favor of built in ipaddr

The ipaddr module is part of Ruby itself and can be used to check for
range inclusion.
This commit is contained in:
Ewoud Kohl van Wijngaarden 2022-02-04 14:08:22 +01:00
parent 2a3fe7ae0e
commit db8e8a706c
No known key found for this signature in database
GPG key ID: C6EC8F04A934BAB1
3 changed files with 10 additions and 8 deletions

View file

@ -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

View file

@ -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

View file

@ -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