4747
4848// Check if the given builder configuration maps to an existing VM template on the Proxmox cluster.
4949// Returns an empty *proxmox.VmRef when no matching ID or name is found.
50- func getExistingTemplate (c * Config , client vmStarter ) (* proxmox.VmRef , string , error ) {
50+ func getExistingTemplate (c * Config , client vmStarter ) (* proxmox.VmRef , error ) {
5151 vmRef := & proxmox.VmRef {}
5252 if c .VMID > 0 {
5353 log .Printf ("looking up VM with ID %d" , c .VMID )
@@ -59,9 +59,9 @@ func getExistingTemplate(c *Config, client vmStarter) (*proxmox.VmRef, string, e
5959 notFoundError := fmt .Sprintf ("vm '%d' not found" , c .VMID )
6060 if err .Error () == notFoundError {
6161 log .Println (err .Error ())
62- return & proxmox.VmRef {}, "" , nil
62+ return & proxmox.VmRef {}, nil
6363 }
64- return & proxmox.VmRef {}, "" , err
64+ return & proxmox.VmRef {}, err
6565 }
6666 log .Printf ("found VM with ID %d" , vmRef .VmId ())
6767 } else {
@@ -73,33 +73,33 @@ func getExistingTemplate(c *Config, client vmStarter) (*proxmox.VmRef, string, e
7373 notFoundError := fmt .Sprintf ("vm '%s' not found" , c .TemplateName )
7474 if err .Error () == notFoundError {
7575 log .Println (err .Error ())
76- return & proxmox.VmRef {}, "" , nil
76+ return & proxmox.VmRef {}, nil
7777 }
78- return & proxmox.VmRef {}, "" , err
78+ return & proxmox.VmRef {}, err
7979 }
8080 if len (vmRefs ) > 1 {
8181 vmIDs := []int {}
8282 for _ , vmr := range vmRefs {
8383 vmIDs = append (vmIDs , vmr .VmId ())
8484 }
85- return & proxmox.VmRef {}, "" , fmt .Errorf ("found multiple VMs with name '%s', IDs: %v" , c .TemplateName , vmIDs )
85+ return & proxmox.VmRef {}, fmt .Errorf ("found multiple VMs with name '%s', IDs: %v" , c .TemplateName , vmIDs )
8686 }
8787 vmRef = vmRefs [0 ]
8888 log .Printf ("found VM with name '%s' (ID: %d)" , c .TemplateName , vmRef .VmId ())
8989 }
9090 if c .SkipConvertToTemplate {
91- return vmRef , "VM" , nil
91+ return vmRef , nil
9292 }
9393 log .Printf ("check if VM %d is a template" , vmRef .VmId ())
9494 vmConfig , err := client .GetVmConfig (vmRef )
9595 if err != nil {
96- return & proxmox.VmRef {}, "" , err
96+ return & proxmox.VmRef {}, err
9797 }
9898 log .Printf ("VM %d template: %d" , vmRef .VmId (), vmConfig ["template" ])
9999 if vmConfig ["template" ] == nil {
100- return & proxmox.VmRef {}, "" , fmt .Errorf ("found matching VM (ID: %d, name: %s), but it is not a template" , vmRef .VmId (), vmConfig ["name" ])
100+ return & proxmox.VmRef {}, fmt .Errorf ("found matching VM (ID: %d, name: %s), but it is not a template" , vmRef .VmId (), vmConfig ["name" ])
101101 }
102- return vmRef , "VM template" , nil
102+ return vmRef , nil
103103}
104104
105105func (s * stepStartVM ) Run (ctx context.Context , state multistep.StateBag ) multistep.StepAction {
@@ -167,14 +167,14 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist
167167
168168 if c .PackerForce {
169169 ui .Say ("Force set, checking for existing artifact on PVE cluster" )
170- vmRef , vmType , err := getExistingTemplate (c , client )
170+ vmRef , err := getExistingTemplate (c , client )
171171 if err != nil {
172172 state .Put ("error" , err )
173173 ui .Error (err .Error ())
174174 return multistep .ActionHalt
175175 }
176176 if vmRef .VmId () != 0 {
177- ui .Say (fmt .Sprintf ("found existing %s with ID %d on PVE node %s, deleting it" , vmType , vmRef .VmId (), vmRef .Node ()))
177+ ui .Say (fmt .Sprintf ("found existing resource with ID %d on PVE node %s, deleting it" , vmRef .VmId (), vmRef .Node ()))
178178 // If building a VM artifact and c.PackerForce is true,
179179 // running VMs can't be deleted. Stop before deleting.
180180 vmState , err := client .GetVmState (vmRef )
@@ -188,17 +188,17 @@ func (s *stepStartVM) Run(ctx context.Context, state multistep.StateBag) multist
188188 _ , err = client .StopVm (vmRef )
189189 if err != nil {
190190 state .Put ("error" , err )
191- ui .Error (fmt .Sprintf ("error stopping %s : %s" , vmType , err .Error ()))
191+ ui .Error (fmt .Sprintf ("error stopping resource : %s" , err .Error ()))
192192 return multistep .ActionHalt
193193 }
194194 }
195195 _ , err = client .DeleteVm (vmRef )
196196 if err != nil {
197197 state .Put ("error" , err )
198- ui .Error (fmt .Sprintf ("error deleting %s : %s" , vmType , err .Error ()))
198+ ui .Error (fmt .Sprintf ("error deleting resource : %s" , err .Error ()))
199199 return multistep .ActionHalt
200200 }
201- ui .Say (fmt .Sprintf ("Successfully deleted %s %d" , vmType , vmRef .VmId ()))
201+ ui .Say (fmt .Sprintf ("Successfully deleted %d" , vmRef .VmId ()))
202202 } else {
203203 ui .Say ("No existing artifact found" )
204204 }
0 commit comments