Skip to content

Commit

Permalink
Refactor function
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbenjemaa committed Mar 20, 2024
1 parent 55a167c commit 1ce446d
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions virtual_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 1ce446d

Please sign in to comment.