@@ -20,10 +20,6 @@ import (
2020 "github.com/sp-yduck/cluster-api-provider-proxmox/cloud/scope"
2121)
2222
23- const (
24- vmStorage = "local-capi" // to do
25- )
26-
2723func (s * Service ) Reconcile (ctx context.Context ) error {
2824 log := log .FromContext (ctx )
2925 log .Info ("Reconciling instance resources" )
@@ -119,23 +115,23 @@ func (s *Service) CreateInstance(ctx context.Context, bootstrap string) (*vm.Vir
119115 }
120116
121117 // cloud init snippet // to do ssh key
122- if err := setCloudConfig (ctx , s .scope .Name (), bootstrap , s .remote ); err != nil {
118+ if err := setCloudConfig (ctx , s .scope .Name (), s . scope . GetStorage (). Name , bootstrap , s .remote ); err != nil {
123119 return nil , err
124120 }
125121
126122 // create vm
127- vmoption := generateVMOptions (s .scope .Name (), vmStorage )
123+ vmoption := generateVMOptions (s .scope .Name (), s . scope . GetStorage (). Name )
128124 vm , err := node .CreateVirtualMachine (vmid , vmoption )
129125 if err != nil {
130126 log .Error (err , "failed to create virtual machine" )
131127 return nil , err
132128 }
133129
134- if err := applyCICustom (vmid , s .scope .Name (), vmStorage , s .remote ); err != nil {
130+ if err := applyCICustom (vmid , s .scope .Name (), s . scope . GetStorage (). Name , s .remote ); err != nil {
135131 return nil , err
136132 }
137133
138- if err := setCloudImage (ctx , vmid , s .remote ); err != nil {
134+ if err := setCloudImage (ctx , vmid , s .scope . GetStorage (). Name , s . remote ); err != nil {
139135 return nil , err
140136 }
141137
@@ -188,7 +184,7 @@ func (s *Service) Delete(ctx context.Context) error {
188184 return instance .Delete ()
189185}
190186
191- func setCloudImage (ctx context.Context , vmid int , ssh scope.SSHClient ) error {
187+ func setCloudImage (ctx context.Context , vmid int , storageName string , ssh scope.SSHClient ) error {
192188 log := log .FromContext (ctx )
193189 log .Info ("setting cloud image" )
194190
@@ -199,7 +195,7 @@ func setCloudImage(ctx context.Context, vmid int, ssh scope.SSHClient) error {
199195 // return nil, errors.Errorf("failed to download image")
200196 // }
201197
202- destPath := fmt .Sprintf ("/var/lib/vz/%s/images/%d/vm-%d-disk-0.raw" , vmStorage , vmid , vmid )
198+ destPath := fmt .Sprintf ("/var/lib/vz/%s/images/%d/vm-%d-disk-0.raw" , storageName , vmid , vmid )
203199 out , err = ssh .RunCommand (fmt .Sprintf ("/usr/bin/qemu-img convert -O raw /root/jammy-server-cloudimg-amd64-disk-kvm.img %s" , destPath ))
204200 if err != nil {
205201 return err
@@ -209,7 +205,7 @@ func setCloudImage(ctx context.Context, vmid int, ssh scope.SSHClient) error {
209205 return nil
210206}
211207
212- func setCloudConfig (ctx context.Context , vmName , bootstrap string , ssh scope.SSHClient ) error {
208+ func setCloudConfig (ctx context.Context , vmName , storageName , bootstrap string , ssh scope.SSHClient ) error {
213209 log := log .FromContext (ctx )
214210 log .Info ("setting cloud config" )
215211
@@ -226,7 +222,7 @@ func setCloudConfig(ctx context.Context, vmName, bootstrap string, ssh scope.SSH
226222 log .Info (configYaml )
227223
228224 // to do: should be set via API
229- out , err := ssh .RunWithStdin (fmt .Sprintf ("tee /var/lib/vz/%s/snippets/%s.yml" , vmStorage , vmName ), configYaml )
225+ out , err := ssh .RunWithStdin (fmt .Sprintf ("tee /var/lib/vz/%s/snippets/%s.yml" , storageName , vmName ), configYaml )
230226 if err != nil {
231227 return errors .Errorf ("ssh command error : %s : %v" , out , err )
232228 }
0 commit comments