diff --git a/storage.go b/storage.go index 3a72619..e040aea 100644 --- a/storage.go +++ b/storage.go @@ -12,6 +12,65 @@ var validContent = map[string]struct{}{ "vztmpl": {}, } +func (c *Client) ClusterStorages(ctx context.Context) (storages ClusterStorages, err error) { + err = c.Get(ctx, "/storage", &storages) + if err != nil { + return + } + + for _, s := range storages { + s.client = c + } + return +} + +func (c *Client) ClusterStorage(ctx context.Context, name string) (storage *ClusterStorage, err error) { + err = c.Get(ctx, fmt.Sprintf("/storage/%s", name), &storage) + if err != nil { + return + } + + storage.client = c + return +} + +func (c *Client) DeleteClusterStorage(ctx context.Context, name string) (*Task, error) { + var upid UPID + err := c.Delete(ctx, fmt.Sprintf("/storage/%s", name), &upid) + if err != nil { + return nil, err + } + return NewTask(upid, c), nil +} + +func (c *Client) NewClusterStorage(ctx context.Context, options ...ClusterStorageOptions) (*Task, error) { + var upid UPID + + data := make(map[string]interface{}) + for _, option := range options { + data[option.Name] = option.Value + } + err := c.Post(ctx, "/storage", data, &upid) + + if err != nil { + return nil, err + } + return NewTask(upid, c), nil +} + +func (c *Client) UpdateClusterStorage(ctx context.Context, name string, options ...ClusterStorageOptions) (*Task, error) { + var upid UPID + data := make(map[string]interface{}) + for _, option := range options { + data[option.Name] = option.Value + } + err := c.Put(ctx, fmt.Sprintf("/storage/%s", name), data, &upid) + if err != nil { + return nil, err + } + return NewTask(upid, c), nil +} + func (s *Storage) Upload(content, file string) (*Task, error) { return s.upload(content, file, nil) } diff --git a/types.go b/types.go index 69fc945..2e78fb1 100644 --- a/types.go +++ b/types.go @@ -248,7 +248,7 @@ type RootFS struct { type CPUInfo struct { UserHz int `json:"user_hz"` - MHZ int + MHZ StringOrInt Mode string Cores int Sockets int @@ -731,6 +731,23 @@ type Storage struct { Storage string } +type ClusterStorages []*ClusterStorage + +type ClusterStorage struct { + client *Client + Content string + Digest string + Storage string + Type string + Thinpool string `json:",omitempty"` + Path string `json:",omitempty"` + VgName string `json:",omitempty"` +} + +type ClusterStorageOptions struct { + Name string + Value string +} type Volume interface { Delete() error }