Module: Aws::ENI
- Extended by:
- ENI
- Included in:
- ENI
- Defined in:
- lib/aws-eni.rb,
lib/aws-eni/meta.rb,
lib/aws-eni/client.rb,
lib/aws-eni/errors.rb,
lib/aws-eni/version.rb,
lib/aws-eni/interface.rb
Defined Under Namespace
Modules: Client, Errors, Meta Classes: Interface
Constant Summary collapse
- VERSION =
"0.6.0"
Instance Method Summary collapse
-
#allocate_elastic_ip ⇒ Object
allocate a new elastic ip address.
-
#assert_client_access ⇒ Object
throw exception if we do not have permissions to perform all needed EC2 operations with our given AWS credentials.
-
#assert_interface_access ⇒ Object
throw exception if we cannot modify our machine’s interface configuration.
-
#assign_secondary_ip(id, options = {}) ⇒ Object
add new private ip using the AWS api and add it to our local ip config.
-
#associate_elastic_ip(private_ip, options = {}) ⇒ Object
associate a private ip with an elastic ip through the AWS api.
-
#attach_interface(interface_id, options = {}) ⇒ Object
attach network interface.
-
#clean_interfaces(filter = nil, options = {}) ⇒ Object
delete unattached network interfaces.
-
#configure(filter = nil, options = {}) ⇒ Object
sync local machine’s network interface config with the EC2 meta-data pass dry_run option to check whether configuration is out of sync without modifying it.
-
#create_interface(options = {}) ⇒ Object
create network interface.
-
#deconfigure(filter = nil) ⇒ Object
clear local machine’s network interface config.
-
#detach_interface(selector, options = {}) ⇒ Object
detach network interface.
-
#disable(filter = nil) ⇒ Object
disable one or more network interfaces.
-
#dissociate_elastic_ip(address, options = {}) ⇒ Object
dissociate a public ip from a private ip through the AWS api and optionally release the public ip.
-
#enable(filter = nil) ⇒ Object
enable one or more network interfaces.
- #environment ⇒ Object
-
#has_client_access? ⇒ Boolean
test whether we have permission to perform all necessary EC2 operations within our given AWS access credentials.
-
#has_interface_access? ⇒ Boolean
test whether we have permission to modify our machine’s interface configuration.
-
#list(filter = nil) ⇒ Object
return our internal model of this instance’s network configuration on AWS.
- #owner_tag(new_owner = nil) ⇒ Object
-
#release_elastic_ip(ip) ⇒ Object
release the specified elastic ip address.
-
#test_association(address, options = {}) ⇒ Object
validate an internet connection on a secondary ip address with an associated elastic ip.
-
#test_secondary_ip(private_ip, options = {}) ⇒ Object
validate a local area connection on a secondary ip address.
- #timeout(new_default = nil) ⇒ Object
-
#unassign_secondary_ip(private_ip, options = {}) ⇒ Object
remove a private ip using the AWS api and remove it from local config.
- #verbose(set_verbose = nil) ⇒ Object
Instance Method Details
#allocate_elastic_ip ⇒ Object
allocate a new elastic ip address
568 569 570 571 572 573 574 575 576 577 578 |
# File 'lib/aws-eni.rb', line 568 def allocate_elastic_ip eip = Client.allocate_address(domain: 'vpc') wait_for 'new elastic ip to become available', rescue: Errors::UnknownAddress do # strangely this doesn't happen immediately in some cases Client.describe_address(eip[:allocation_id]) end { public_ip: eip[:public_ip], allocation_id: eip[:allocation_id] } end |
#assert_client_access ⇒ Object
throw exception if we do not have permissions to perform all needed EC2 operations with our given AWS credentials
611 612 613 |
# File 'lib/aws-eni.rb', line 611 def assert_client_access raise Errors::ClientPermissionError, 'Insufficient access to EC2 operations for network interface modification' unless has_client_access? end |
#assert_interface_access ⇒ Object
throw exception if we cannot modify our machine’s interface configuration
599 600 601 |
# File 'lib/aws-eni.rb', line 599 def assert_interface_access raise Errors::InterfacePermissionError, 'Insufficient user priveleges to configure network interfaces' unless has_interface_access? end |
#assign_secondary_ip(id, options = {}) ⇒ Object
add new private ip using the AWS api and add it to our local ip config
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
# File 'lib/aws-eni.rb', line 255 def assign_secondary_ip(id, = {}) device = Interface[id].assert( exists: true, device_name: [:device_name], interface_id: [:interface_id], device_number: [:device_number] ) interface_id = device.interface_id current_ips = Client.interface_private_ips(interface_id) do_config = [:configure] != false do_block = [:block] != false new_ip = [:private_ip] if current_ips.count >= interface_ip_limit raise Errors::LimitExceeded, "Unable to assign #{new_ip || 'new IP'} to #{interface_id} (assignment limit exceeded)" end if do_block && !device.enabled? raise Errors::InvalidInput, "Interface #{device.name} is not enabled (cannot test connection)" end if new_ip if current_ips.include?(new_ip) raise Errors::ClientOperationError, "IP #{new_ip} already assigned to #{device.name}" end Client.assign_private_ip_addresses( network_interface_id: interface_id, private_ip_addresses: [new_ip], allow_reassignment: false ) else Client.assign_private_ip_addresses( network_interface_id: interface_id, secondary_private_ip_address_count: 1, allow_reassignment: false ) wait_for 'new private IP address to be assigned' do client_ips = Client.interface_private_ips(interface_id) new_ip = (client_ips - current_ips).first || (device. - current_ips).first end end if do_config device.add_alias(new_ip) if do_block && !Interface.test(new_ip, target: device.gateway, timeout: timeout) raise Errors::TimeoutError, 'Timed out waiting for IP address to become active' end end if do_block # ensure new state has propagated to avoid race conditions wait_for 'new private IP address to appear in metadata' do device..include?(new_ip) end wait_for 'new private IP address to appear in EC2 resource' do Client.interface_private_ips(interface_id).include?(new_ip) end end { private_ip: new_ip, interface_id: interface_id, device_name: device.name, device_number: device.device_number, interface_ips: current_ips << new_ip } end |
#associate_elastic_ip(private_ip, options = {}) ⇒ Object
associate a private ip with an elastic ip through the AWS api
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 |
# File 'lib/aws-eni.rb', line 391 def associate_elastic_ip(private_ip, = {}) raise Errors::MissingInput, 'You must specify a private IP address' unless private_ip do_alloc = !![:new] do_block = [:block] != false find = [:device_name] || [:device_number] || [:interface_id] || private_ip device = Interface[find].assert( exists: true, private_ip: private_ip, device_name: [:device_name], interface_id: [:interface_id], device_number: [:device_number] ) [:public_ip] ||= [:allocation_id] if do_block && !device.enabled? raise Errors::InvalidInput, "Interface #{device.name} is not enabled (cannot block)" end if public_ip = device.public_ips[private_ip] raise Errors::ClientOperationError, "IP #{private_ip} already has an associated EIP (#{public_ip})" end if [:public_ip] eip = Client.describe_address([:public_ip]) if [:allocation_id] && eip[:allocation_id] != [:allocation_id] raise Errors::InvalidAddress, "EIP #{eip[:public_ip]} (#{eip[:allocation_id]}) does not match #{[:allocation_id]}" end elsif do_alloc || !eip = Client.available_addresses.first allocated = true eip = allocate_elastic_ip end resp = Client.associate_address( network_interface_id: device.interface_id, allocation_id: eip[:allocation_id], private_ip_address: private_ip, allow_reassociation: false ) if do_block # ensure new state has propagated to avoid race conditions wait_for 'public IP address to appear in metadata' do device.public_ips.has_value?(eip[:public_ip]) end if !Interface.test(private_ip, timeout: timeout) raise Errors::TimeoutError, 'Timed out waiting for IP address to become active' end end { private_ip: private_ip, device_name: device.name, interface_id: device.interface_id, allocated: !!allocated, public_ip: eip[:public_ip], allocation_id: eip[:allocation_id], association_id: resp[:association_id] } end |
#attach_interface(interface_id, options = {}) ⇒ Object
attach network interface
107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/aws-eni.rb', line 107 def attach_interface(interface_id, = {}) do_block = [:block] != false do_enable = [:enable] != false do_config = [:configure] != false assert_interface_access if do_config || do_enable device = Interface[[:device_number] || [:name]].assert(exists: false) if Interface.count >= interface_limit raise Errors::LimitExceeded, "Unable to attach #{interface_id} to #{device.name} (attachment limit exceeded)" end response = Client.attach_network_interface( network_interface_id: interface_id, instance_id: environment[:instance_id], device_index: device.device_number ) if do_block || do_config || do_enable wait_for 'the interface to attach', rescue: Errors::InvalidInterface do device.exists? && Client.interface_attached(device.interface_id) end end device.configure if do_config device.enable if do_enable { interface_id: interface_id, device_name: device.name, device_number: device.device_number, enabled: do_enable, configured: do_config, api_response: response } end |
#clean_interfaces(filter = nil, options = {}) ⇒ Object
delete unattached network interfaces
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/aws-eni.rb', line 199 def clean_interfaces(filter = nil, = {}) public_ips = [] do_release = !![:release] safe_mode = [:safe_mode] != false filters = [ { name: 'vpc-id', values: [environment[:vpc_id]] }, { name: 'status', values: ['available'] } ] if filter case filter when /^eni-/ filters << { name: 'network-interface-id', values: [filter] } when /^subnet-/ filters << { name: 'subnet-id', values: [filter] } when /^#{environment[:region]}[a-z]$/ filters << { name: 'availability-zone', values: [filter] } else raise Errors::InvalidInput, "Unknown interface attribute: #{filter}" end end if safe_mode filters << { name: 'tag:created by', values: [owner_tag] } end descriptions = Client.describe_network_interfaces(filters: filters) interfaces = descriptions[:network_interfaces].select do |interface| created_recently = interface.tag_set.any? do |tag| begin tag.key == 'created on' && Time.now - Time.parse(tag.value) < 60 rescue ArgumentError end end unless safe_mode && created_recently interface[:private_ip_addresses].each do |addr| if assoc = addr[:association] public_ips << { public_ip: assoc[:public_ip], allocation_id: assoc[:allocation_id] } dissociate_elastic_ip(assoc[:allocation_id], release: true) if do_release end end Client.delete_network_interface(network_interface_id: interface[:network_interface_id]) true end end { interfaces: interfaces.map { |eni| eni[:network_interface_id] }, public_ips: public_ips, released: do_release, api_response: interfaces } end |
#configure(filter = nil, options = {}) ⇒ Object
sync local machine’s network interface config with the EC2 meta-data pass dry_run option to check whether configuration is out of sync without modifying it
61 62 63 |
# File 'lib/aws-eni.rb', line 61 def configure(filter = nil, = {}) Interface.configure(filter, ) if environment end |
#create_interface(options = {}) ⇒ Object
create network interface
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/aws-eni.rb', line 81 def create_interface( = {}) = Time.now.xmlschema params = {} params[:subnet_id] = [:subnet_id] || Interface.first.subnet_id params[:private_ip_address] = [:primary_ip] if [:primary_ip] params[:groups] = [*[:security_groups]] if [:security_groups] params[:description] = "generated by #{owner_tag} from #{environment[:instance_id]} on #{}" interface = Client.create_network_interface(params)[:network_interface] wait_for 'the interface to be created', rescue: Errors::UnknownInterface do if Client.describe_interface(interface[:network_interface_id]) Client.(resources: [interface[:network_interface_id]], tags: [ { key: 'created by', value: owner_tag }, { key: 'created on', value: }, { key: 'created from', value: environment[:instance_id] } ]) end end { interface_id: interface[:network_interface_id], subnet_id: interface[:subnet_id], api_response: interface } end |
#deconfigure(filter = nil) ⇒ Object
clear local machine’s network interface config
66 67 68 |
# File 'lib/aws-eni.rb', line 66 def deconfigure(filter = nil) Interface.deconfigure(filter) if environment end |
#detach_interface(selector, options = {}) ⇒ Object
detach network interface
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/aws-eni.rb', line 142 def detach_interface(selector, = {}) device = Interface[selector].assert( exists: true, device_name: [:device_name], interface_id: [:interface_id], device_number: [:device_number] ) interface = Client.describe_interface(device.interface_id) do_release = !![:release] created_by_us = interface.tag_set.any? { |tag| tag.key == 'created by' && tag.value == owner_tag } do_delete = [:delete] != false && created_by_us do_block = [:block] != false if device.name == 'eth0' raise Errors::InvalidInterface, 'For safety, interface eth0 cannot be detached.' end unless interface[:attachment] && interface[:attachment][:instance_id] == environment[:instance_id] raise Errors::InvalidInterface, "Interface #{interface_id} is not attached to this machine" end public_ips = [] interface[:private_ip_addresses].each do |addr| if assoc = addr[:association] public_ips << { public_ip: assoc[:public_ip], allocation_id: assoc[:allocation_id] } dissociate_elastic_ip(assoc[:allocation_id], release: true) if do_release end end device.disable device.deconfigure Client.detach_network_interface( attachment_id: interface[:attachment][:attachment_id], force: true ) if do_block || do_delete wait_for 'the interface to detach', interval: 0.3 do !device.exists? && !Client.interface_attached(interface[:network_interface_id]) end end Client.delete_network_interface(network_interface_id: interface[:network_interface_id]) if do_delete { interface_id: interface[:network_interface_id], device_name: device.name, device_number: device.device_number, created_by_us: created_by_us, deleted: do_delete, released: do_release, public_ips: public_ips, api_response: interface } end |
#disable(filter = nil) ⇒ Object
disable one or more network interfaces
76 77 78 |
# File 'lib/aws-eni.rb', line 76 def disable(filter = nil) Interface.filter(filter).select{ |dev| dev.enabled? && dev.name != 'eth0' }.each(&:disable).count end |
#dissociate_elastic_ip(address, options = {}) ⇒ Object
dissociate a public ip from a private ip through the AWS api and optionally release the public ip
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
# File 'lib/aws-eni.rb', line 452 def dissociate_elastic_ip(address, = {}) do_release = !![:release] do_block = [:block] != false # assert device attributes if we've specified a device if find = [:device_name] || [:device_number] device = Interface[find].assert( device_name: [:device_name], device_number: [:device_number], interface_id: [:interface_id], private_ip: [:private_ip], public_ip: [:public_ip] ) end # get our address info eip = Client.describe_address(address) device ||= Interface.find { |dev| dev.interface_id == eip[:network_interface_id] } # assert eip attributes if options provided if [:private_ip] && eip[:private_ip_address] != [:private_ip] raise Errors::InvalidAddress, "#{address} is not associated with IP #{[:private_ip]}" end if [:public_ip] && eip[:public_ip] != [:public_ip] raise Errors::InvalidAddress, "#{address} is not associated with public IP #{[:public_ip]}" end if [:allocation_id] && eip[:allocation_id] != [:allocation_id] raise Errors::InvalidAddress, "#{address} is not associated with allocation ID #{[:allocation_id]}" end if [:association_id] && eip[:association_id] != [:association_id] raise Errors::InvalidAddress, "#{address} is not associated with association ID #{[:association_id]}" end if [:interface_id] && eip[:network_interface_id] != [:interface_id] raise Errors::InvalidAddress, "#{address} is not associated with interface ID #{[:interface_id]}" end if device if device.name == 'eth0' && device.local_ips.first == eip[:private_ip_address] raise Errors::ClientOperationError, 'For safety, a public address cannot be dissociated from the primary IP on eth0' end elsif Client.interface_attached(eip[:network_interface_id]) raise Errors::ClientOperationError, "#{address} is associated with an interface attached to another machine" end Client.disassociate_address(association_id: eip[:association_id]) Client.release_address(allocation_id: eip[:allocation_id]) if do_release if device && do_block # ensure new state has propagated to avoid race conditions wait_for 'public IP address to be removed from metadata' do !device.public_ips.has_value?(eip[:public_ip]) end end { private_ip: eip[:private_ip_address], device_name: device && device.name, interface_id: eip[:network_interface_id], public_ip: eip[:public_ip], allocation_id: eip[:allocation_id], association_id: eip[:association_id], released: do_release } end |
#enable(filter = nil) ⇒ Object
enable one or more network interfaces
71 72 73 |
# File 'lib/aws-eni.rb', line 71 def enable(filter = nil) Interface.filter(filter).select{ |dev| !dev.enabled? }.each(&:enable).count end |
#environment ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/aws-eni.rb', line 15 def environment @lock.synchronize do @environment ||= Meta.connection do hwaddr = Meta.instance('network/interfaces/macs/').lines.first.strip.chomp('/') { instance_id: Meta.instance('instance-id'), instance_type: Meta.instance('instance-type'), availability_zone: Meta.instance('placement/availability-zone'), region: Meta.instance('placement/availability-zone').sub(/^(.*)[a-z]$/,'\1'), vpc_id: Meta.interface(hwaddr, 'vpc-id'), vpc_cidr: Meta.interface(hwaddr, 'vpc-ipv4-cidr-block') }.freeze end end rescue Errors::MetaNotFound raise Errors::EnvironmentError, 'Unable to detect VPC, library incompatible with EC2-Classic' rescue Errors::MetaConnectionFailed raise Errors::EnvironmentError, 'Unable to load EC2 meta-data' end |
#has_client_access? ⇒ Boolean
test whether we have permission to perform all necessary EC2 operations within our given AWS access credentials
605 606 607 |
# File 'lib/aws-eni.rb', line 605 def has_client_access? Client.has_access? end |
#has_interface_access? ⇒ Boolean
test whether we have permission to modify our machine’s interface configuration
594 595 596 |
# File 'lib/aws-eni.rb', line 594 def has_interface_access? Interface.mutable? end |
#list(filter = nil) ⇒ Object
return our internal model of this instance’s network configuration on AWS
54 55 56 |
# File 'lib/aws-eni.rb', line 54 def list(filter = nil) Interface.filter(filter).map(&:to_h) if environment end |
#owner_tag(new_owner = nil) ⇒ Object
35 36 37 38 |
# File 'lib/aws-eni.rb', line 35 def owner_tag(new_owner = nil) @owner_tag = new_owner.to_s if new_owner @owner_tag ||= 'aws-eni script' end |
#release_elastic_ip(ip) ⇒ Object
release the specified elastic ip address
581 582 583 584 585 586 587 588 589 590 591 |
# File 'lib/aws-eni.rb', line 581 def release_elastic_ip(ip) eip = Client.describe_address(ip) if eip[:association_id] raise Errors::ClientOperationError, "Elastic IP #{eip[:public_ip]} (#{eip[:allocation_id]}) is currently in use" end Client.release_address(allocation_id: eip[:allocation_id]) { public_ip: eip[:public_ip], allocation_id: eip[:allocation_id] } end |
#test_association(address, options = {}) ⇒ Object
validate an internet connection on a secondary ip address with an associated elastic ip
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 |
# File 'lib/aws-eni.rb', line 518 def test_association(address, = {}) timeout = [:timeout] || self.timeout # assert device attributes if we've specified a device if find = [:device_name] || [:device_number] device = Interface[find].assert( device_name: [:device_name], device_number: [:device_number], interface_id: [:interface_id], private_ip: [:private_ip], public_ip: [:public_ip] ) end # get our address info eip = Client.describe_address(address) device ||= Interface.find { |dev| dev.interface_id == eip[:network_interface_id] } # assert eip attributes if options provided if [:private_ip] && eip[:private_ip_address] != [:private_ip] raise Errors::InvalidAddress, "#{address} is not associated with IP #{[:private_ip]}" end if [:public_ip] && eip[:public_ip] != [:public_ip] raise Errors::InvalidAddress, "#{address} is not associated with public IP #{[:public_ip]}" end if [:allocation_id] && eip[:allocation_id] != [:allocation_id] raise Errors::InvalidAddress, "#{address} is not associated with allocation ID #{[:allocation_id]}" end if [:association_id] && eip[:association_id] != [:association_id] raise Errors::InvalidAddress, "#{address} is not associated with association ID #{[:association_id]}" end if [:interface_id] && eip[:network_interface_id] != [:interface_id] raise Errors::InvalidAddress, "#{address} is not associated with interface ID #{[:interface_id]}" end # assert that this eip attached to an enabled, configured interface on this machine unless device raise Errors::InvalidAddress, "#{address} is not associated with an interface on this machine" end unless device.enabled? raise Errors::InvalidAddress, "#{address} cannot be tested while #{device.name} is disabled" end unless device.local_ips.include?(eip[:private_ip_address]) raise Errors::InvalidAddress, "#{address} cannot be tested until #{device.name} is configured" end Interface.test(eip[:private_ip_address], timeout: timeout) end |
#test_secondary_ip(private_ip, options = {}) ⇒ Object
validate a local area connection on a secondary ip address
375 376 377 378 379 380 381 382 383 384 385 386 387 388 |
# File 'lib/aws-eni.rb', line 375 def test_secondary_ip(private_ip, = {}) timeout = [:timeout] || self.timeout find = [:device_name] || [:device_number] || [:interface_id] || private_ip device = Interface[find].assert( exists: true, enabled: true, device_name: [:device_name], interface_id: [:interface_id], device_number: [:device_number], private_ip: private_ip ) Interface.test(private_ip, target: device.gateway, timeout: timeout) end |
#timeout(new_default = nil) ⇒ Object
40 41 42 43 |
# File 'lib/aws-eni.rb', line 40 def timeout(new_default = nil) @timeout = new_default.to_i if new_default @timeout ||= 120 end |
#unassign_secondary_ip(private_ip, options = {}) ⇒ Object
remove a private ip using the AWS api and remove it from local config
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 |
# File 'lib/aws-eni.rb', line 323 def unassign_secondary_ip(private_ip, = {}) do_release = !![:release] do_block = [:block] != false find = [:device_name] || [:device_number] || [:interface_id] || private_ip device = Interface[find].assert( exists: true, device_name: [:device_name], interface_id: [:interface_id], device_number: [:device_number] ) interface = Client.describe_interface(device.interface_id) unless addr_info = interface[:private_ip_addresses].find { |addr| addr[:private_ip_address] == private_ip } raise Errors::ClientOperationError, "IP #{private_ip} not found on #{device.name}" end if addr_info[:primary] raise Errors::ClientOperationError, 'The primary IP address of an interface cannot be unassigned' end if assoc = addr_info[:association] dissociate_elastic_ip(assoc[:allocation_id], release: do_release) end device.remove_alias(private_ip) Client.unassign_private_ip_addresses( network_interface_id: interface[:network_interface_id], private_ip_addresses: [private_ip] ) if do_block # ensure new state has propagated to avoid race conditions wait_for 'private IP address to be removed from metadata' do !device..include?(private_ip) end wait_for 'private IP address to be removed from EC2 resource' do !Client.interface_private_ips(device.interface_id).include?(private_ip) end end { private_ip: private_ip, device_name: device.name, interface_id: device.interface_id, public_ip: assoc && assoc[:public_ip], allocation_id: assoc && assoc[:allocation_id], association_id: assoc && assoc[:association_id], released: assoc && do_release } end |