Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨feat: Add cluster storage operations #155

Merged
merged 3 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion tests/mocks/pve7x/nodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -782,7 +782,7 @@ func nodes() {
"uptime": 2501631,
"kversion": "Linux 5.15.108-1-pve #1 SMP PVE 5.15.108-2 (2023-07-20T10:06Z)",
"cpuinfo": {
"mhz": "3400.000",
"mhz": 3400,
luthermonson marked this conversation as resolved.
Show resolved Hide resolved
"model": "Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz",
"sockets": 1,
"flags": "fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single pti tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm mpx rdseed adx smap clflushopt intel_pt xsaveopt xsavec xgetbv1 xsaves dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp",
Expand Down
17 changes: 17 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Loading