Skip to content

Commit

Permalink
clean up network interface and public ip on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
liu-samuel committed Sep 5, 2024
1 parent 6cc3d9c commit 9d9c3eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,5 +183,8 @@ def start_clone(clone_options)

File.join(azure.subscription_id, vm.resource_group.downcase, vm.type.downcase, vm.name)
end
rescue Azure::Armrest::BadRequestException
signal :clone_failure_cleanup
raise
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,23 @@ def customize_destination

signal :post_create_destination
end

def clone_failure_cleanup
return if phase_context[:clone_options].nil?
delete_instance(phase_context[:clone_options]) if phase_context[:clone_options]
signal_abort
rescue Azure::Armrest::BadRequestException
requeue_phase(3.minutes)
end

def delete_instance(instance_attrs)
source.with_provider_connection do |azure|
nis = ::Azure::Armrest::Network::NetworkInterfaceService.new(azure)
ips = ::Azure::Armrest::Network::IpAddressService.new(azure)
ni = nis.get(instance_attrs[:name], resource_group.name)
ip = ips.get("#{instance_attrs[:name]}-publicIp", resource_group.name)
nis.delete(instance_attrs[:name], resource_group.name) if ni
ips.delete("#{instance_attrs[:name]}-publicIp", resource_group.name) if ip
end
end
end

0 comments on commit 9d9c3eb

Please sign in to comment.