Skip to content

Commit 7b6fd86

Browse files
committed
add storage.GetStatus()
1 parent 2dcccf7 commit 7b6fd86

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

proxmox/storage.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,18 @@ func (s *Storage) Delete(ctx context.Context) error {
3838
return s.restclient.DeleteStorage(ctx, s.Storage.Storage)
3939
}
4040

41+
func (s *Storage) GetStatus(ctx context.Context) ([]*api.Storage, error) {
42+
var status []*api.Storage
43+
if s.Node == "" {
44+
return nil, errors.New("Node must not be empty")
45+
}
46+
path := fmt.Sprintf("/nodes/%s/storage/%s/status", s.Node, s.Storage.Storage)
47+
if err := s.restclient.Get(ctx, path, &status); err != nil {
48+
return nil, err
49+
}
50+
return status, nil
51+
}
52+
4153
func (s *Storage) GetContents(ctx context.Context) ([]*api.StorageContent, error) {
4254
var contents []*api.StorageContent
4355
if s.Node == "" {

rest/node.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,25 @@ func (c *RESTClient) GetNodeVNCWebSocket(ctx context.Context, nodeName, port, vn
5555
}
5656
return websocket, nil
5757
}
58+
59+
func (c *RESTClient) GetNodeStorages(ctx context.Context, nodeName string) ([]*api.Storage, error) {
60+
path := fmt.Sprintf("/nodes/%s/storage", nodeName)
61+
var storages []*api.Storage
62+
if err := c.Get(ctx, path, &storages); err != nil {
63+
return nil, err
64+
}
65+
return storages, nil
66+
}
67+
68+
func (c *RESTClient) GetNodeStorage(ctx context.Context, nodeName, storageName string) (*api.Storage, error) {
69+
storages, err := c.GetNodeStorages(ctx, nodeName)
70+
if err != nil {
71+
return nil, err
72+
}
73+
for _, s := range storages {
74+
if s.Storage == storageName {
75+
return s, nil
76+
}
77+
}
78+
return nil, NotFoundErr
79+
}

0 commit comments

Comments
 (0)