@@ -9,27 +9,20 @@ import (
99 "github.com/pkg/errors"
1010 "github.com/sp-yduck/proxmox-go/proxmox"
1111 "sigs.k8s.io/controller-runtime/pkg/log"
12-
13- infrav1 "github.com/sp-yduck/cluster-api-provider-proxmox/api/v1beta1"
14- "github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scope"
1512)
1613
1714// reconcileBootDevice
1815func (s * Service ) reconcileBootDevice (ctx context.Context , vm * proxmox.VirtualMachine ) error {
19- vmid := s .scope .GetVMID ()
20- storage := s .scope .GetStorage ()
21- image := s .scope .GetImage ()
22- hardware := s .scope .GetHardware ()
2316 log := log .FromContext (ctx )
24- log .Info (fmt . Sprintf ( "%v" , hardware ) )
17+ log .Info ("reconcile boot device" )
2518
2619 // os image
27- if err := setCloudImage (ctx , * vmid , storage , image , s . remote ); err != nil {
20+ if err := s . setCloudImage (ctx ); err != nil {
2821 return err
2922 }
3023
3124 // volume
32- if err := vm .ResizeVolume (ctx , "scsi0" , hardware .Disk ); err != nil {
25+ if err := vm .ResizeVolume (ctx , bootDvice , s . scope . GetHardware () .Disk ); err != nil {
3326 return err
3427 }
3528
@@ -38,18 +31,21 @@ func (s *Service) reconcileBootDevice(ctx context.Context, vm *proxmox.VirtualMa
3831
3932// setCloudImage downloads OS image into Proxmox node
4033// and then sets it to specified storage
41- func setCloudImage (ctx context.Context , vmid int , storage infrav1. Storage , image infrav1. Image , ssh scope. SSHClient ) error {
34+ func ( s * Service ) setCloudImage (ctx context.Context ) error {
4235 log := log .FromContext (ctx )
4336 log .Info ("setting cloud image" )
4437
38+ image := s .scope .GetImage ()
4539 url := image .URL
4640 fileName := path .Base (url )
4741 rawImageDirPath := fmt .Sprintf ("%s/images" , etcCAPPX )
4842 rawImageFilePath := fmt .Sprintf ("%s/%s" , rawImageDirPath , fileName )
4943
5044 // workaround
5145 // API does not support something equivalent of "qm importdisk"
52- out , err := ssh .RunCommand (fmt .Sprintf ("wget %s --directory-prefix %s -nc" , url , rawImageDirPath ))
46+ vnc , err := s .vncClient (s .scope .NodeName ())
47+ defer vnc .Close ()
48+ out , _ , err := vnc .Exec (ctx , fmt .Sprintf ("wget %s --directory-prefix %s -nc" , url , rawImageDirPath ))
5349 if err != nil {
5450 return errors .Errorf ("failed to download image: %s : %v" , out , err )
5551 }
@@ -60,16 +56,16 @@ func setCloudImage(ctx context.Context, vmid int, storage infrav1.Storage, image
6056 if err != nil {
6157 return err
6258 }
63- cmd := fmt .Sprintf ("%s --check -" , cscmd )
64- stdin := fmt .Sprintf ("%s %s" , image .Checksum , rawImageFilePath )
65- out , err = ssh .RunWithStdin (cmd , stdin )
59+ cmd := fmt .Sprintf ("echo '%s %s' | %s --check -" , image .Checksum , rawImageFilePath , cscmd )
60+ out , _ , err = vnc .Exec (context .TODO (), cmd )
6661 if err != nil {
6762 return errors .Errorf ("failed to confirm checksum: %s : %v" , out , err )
6863 }
6964 }
7065
71- destPath := fmt .Sprintf ("%s/images/%d/vm-%d-disk-0.raw" , storage .Path , vmid , vmid )
72- out , err = ssh .RunCommand (fmt .Sprintf ("/usr/bin/qemu-img convert -O raw %s %s" , rawImageFilePath , destPath ))
66+ vmid := s .scope .GetVMID ()
67+ destPath := fmt .Sprintf ("%s/images/%d/vm-%d-disk-0.raw" , s .scope .GetStorage ().Path , * vmid , * vmid )
68+ out , _ , err = vnc .Exec (context .TODO (), fmt .Sprintf ("/usr/bin/qemu-img convert -O raw %s %s" , rawImageFilePath , destPath ))
7369 if err != nil {
7470 return errors .Errorf ("failed to convert iamge : %s : %v" , out , err )
7571 }
0 commit comments