@@ -31,50 +31,49 @@ func (s *Service) Delete(ctx context.Context) error {
3131func (s * Service ) createOrGetStorage (ctx context.Context ) error {
3232 log := log .FromContext (ctx )
3333 log .Info ("Reconciling vm storage" )
34- if err := s .getStorage (); err != nil {
34+
35+ opts := generateVMStorageOptions (s .scope )
36+ if err := s .getStorage (opts .Storage ); err != nil {
3537 if api .IsNotFound (err ) {
36- if err := s .createStorage (); err != nil {
38+ if err := s .createStorage (opts ); err != nil {
3739 return err
3840 }
3941 }
4042 return err
4143 }
44+
45+ s .scope .SetStorage (infrav1.Storage {Name : opts .Storage , Path : opts .Path })
4246 return nil
4347}
4448
45- func (s * Service ) getStorage () error {
46- storageSpec := s .scope .Storage ()
47- if _ , err := s .client .Storage (storageSpec .Name ); err != nil {
49+ func (s * Service ) getStorage (name string ) error {
50+ if _ , err := s .client .Storage (name ); err != nil {
4851 return err
4952 }
5053 return nil
5154}
5255
53- func (s * Service ) createStorage () error {
54- storageSpec := s .scope .Storage ()
55- opts := storage.StorageCreateOptions {
56- Content : "images,snippets" ,
57- Mkdir : true ,
58- Path : generateStoragePath (storageSpec ),
59- }
60- if _ , err := s .client .CreateStorage (storageSpec .Name , "dif" , opts ); err != nil {
56+ func (s * Service ) createStorage (options storage.StorageCreateOptions ) error {
57+ if _ , err := s .client .CreateStorage (options .Storage , options .StorageType , options ); err != nil {
6158 return err
6259 }
6360 return nil
6461}
6562
66- func generateStoragePath (storage infrav1.Storage ) string {
67- if storage .Path == "" {
68- return fmt .Sprintf ("%s/%s" , defaultBasePath , storage .Name )
69- }
70- return storage .Path
71- }
72-
73- func defaultVMStorageOptions (name string ) storage.StorageCreateOptions {
63+ func generateVMStorageOptions (scope Scope ) storage.StorageCreateOptions {
64+ storageSpec := scope .Storage ()
7465 options := storage.StorageCreateOptions {
75- Content : "images,snippets" ,
76- Mkdir : true ,
77- Path : defaultBasePath + "/" + name ,
66+ Storage : storageSpec .Name ,
67+ StorageType : "dir" ,
68+ Content : "images,snippets" ,
69+ Mkdir : true ,
70+ Path : storageSpec .Path ,
71+ }
72+ if options .Storage == "" {
73+ options .Storage = fmt .Sprintf ("local-dir-%s" , scope .Name ())
74+ }
75+ if options .Path == "" {
76+ options .Path = fmt .Sprintf ("%s/%s" , defaultBasePath , options .Storage )
7877 }
7978 return options
8079}
0 commit comments