From 0a31b09c4fdd6a42813053a7423a56a23c378b1d Mon Sep 17 00:00:00 2001 From: Mohamed Chiheb Ben Jemaa Date: Sat, 23 Mar 2024 00:53:17 +0100 Subject: [PATCH] Add function that Unmount Cloud ISO if not needed (#131) * Add function that Unmount Cloud ISO if not needed * Refactor function --- virtual_machine.go | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/virtual_machine.go b/virtual_machine.go index 3e379d8..df95e15 100644 --- a/virtual_machine.go +++ b/virtual_machine.go @@ -643,3 +643,22 @@ func (v *VirtualMachine) ConvertToTemplate(ctx context.Context) (task *Task, err } return NewTask(upid, v.client), nil } + +func (v *VirtualMachine) UnmountCloudInitISO(ctx context.Context, device string) error { + 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 +}