Skip to content

Commit

Permalink
Merge pull request #256 from agrare/delete_disks_if_instance_start_cl…
Browse files Browse the repository at this point in the history
…one_fails

Cleanup any created disks if start_clone fails
  • Loading branch information
kbrock authored Dec 12, 2023
2 parents 3f10f10 + 29c5aaa commit 54e2deb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,8 @@ def start_clone(clone_options)
instance = google.servers.create(clone_options)
return instance.id
end
rescue
cleanup_instance_disks
raise
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ def create_disk(disk_attrs)
create_disks([disk_attrs]).first
end

def delete_disk(disk_attrs)
source.with_provider_connection do |google|
disk = google.disks.get(disk_attrs[:name], disk_attrs[:zone_name])
disk&.destroy
end
end

def check_disks_ready(disks_attrs)
source.with_provider_connection do |google|
disks_attrs.each do |disk_attrs|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ def prepare_instance_disks
signal :poll_instance_disks_complete
end

def cleanup_instance_disks
return if phase_context[:boot_disk].nil?

delete_disk(phase_context[:boot_disk_attrs])
end

def poll_instance_disks_complete
boot_disk = phase_context[:boot_disk_attrs]

Expand Down

0 comments on commit 54e2deb

Please sign in to comment.