@@ -2,6 +2,8 @@ package proxmox
22
33import (
44 "context"
5+ "errors"
6+ "fmt"
57
68 "github.com/sp-yduck/proxmox-go/api"
79 "github.com/sp-yduck/proxmox-go/rest"
@@ -10,6 +12,7 @@ import (
1012type Storage struct {
1113 restclient * rest.RESTClient
1214 Storage * api.Storage
15+ Node string
1316}
1417
1518func (s * Service ) Storage (ctx context.Context , name string ) (* Storage , error ) {
@@ -29,3 +32,32 @@ func (s *Service) CreateStorage(ctx context.Context, name, storageType string, o
2932 }
3033 return & Storage {restclient : s .restclient , Storage : storage }, nil
3134}
35+
36+ func (s * Storage ) Delete (ctx context.Context ) error {
37+ return s .restclient .DeleteStorage (ctx , s .Storage .Storage )
38+ }
39+
40+ func (s * Storage ) GetContents (ctx context.Context ) ([]* api.StorageContent , error ) {
41+ var contents []* api.StorageContent
42+ if s .Node == "" {
43+ return nil , errors .New ("Node must not be empty" )
44+ }
45+ path := fmt .Sprintf ("/nodes/%s/storage/%s/content" , s .Node , s .Storage .Storage )
46+ if err := s .restclient .Get (ctx , path , & contents ); err != nil {
47+ return nil , err
48+ }
49+ return contents , nil
50+ }
51+
52+ func (s * Storage ) GetContent (ctx context.Context , volumeID string ) (* api.StorageContent , error ) {
53+ contents , err := s .GetContents (ctx )
54+ if err != nil {
55+ return nil , err
56+ }
57+ for _ , content := range contents {
58+ if content .VolID == volumeID {
59+ return content , nil
60+ }
61+ }
62+ return nil , rest .NotFoundErr
63+ }
0 commit comments