From 1ce446d07988aef94486087f44eb3c52db6b3630 Mon Sep 17 00:00:00 2001 From: Mohamed Chiheb Ben Jemaa Date: Wed, 20 Mar 2024 18:18:25 +0100 Subject: [PATCH] Refactor function --- virtual_machine.go | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/virtual_machine.go b/virtual_machine.go index 3d532ef..df95e15 100644 --- a/virtual_machine.go +++ b/virtual_machine.go @@ -645,18 +645,20 @@ func (v *VirtualMachine) ConvertToTemplate(ctx context.Context) (task *Task, err } func (v *VirtualMachine) UnmountCloudInitISO(ctx context.Context, device string) error { - if v.HasTag(MakeTag(TagCloudInit)) { - if ok, err := v.deleteCloudInitISO(ctx); err != nil || !ok { - return err - } - task, err := v.Config(ctx, VirtualMachineOption{ - Name: device, - Value: "none,media=cdrom", - }) - if err != nil { - return err - } - return task.WaitFor(ctx, 5) + if !v.HasTag(MakeTag(TagCloudInit)) { + return nil + } + + _, err := v.Config(ctx, VirtualMachineOption{ + Name: device, + Value: "none,media=cdrom", + }) + if err != nil { + return err + } + + if _, err = v.deleteCloudInitISO(ctx); err != nil { + return err } return nil }