forked from joernott/go-proxmox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
storage.go
82 lines (70 loc) · 1.88 KB
/
storage.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package proxmox
import (
"fmt"
"net/url"
_ "github.com/davecgh/go-spew/spew"
)
type Storage struct {
StorageType string `json:"type"`
Active float64 `json:"active"`
Total float64 `json:"total"`
Content string `json:"content"`
Shared float64 `json:"shared"`
Storage string `json:"storage"`
Used float64 `json:"used"`
Avail float64 `json:"avail"`
Node Node
}
type StorageList map[string]Storage
func (storage Storage) CreateVolume(FileName string, DiskSize string, VmId string) (map[string]interface{}, error) {
var form url.Values
var err error
var data map[string]interface{}
var target string
//fmt.Println("!CreateVolume")
form = url.Values{
"filename": {FileName},
// "node": {storage.node.Node},
"size": {DiskSize},
"format": {"qcow2"},
"vmid": {VmId},
}
target = "nodes/" + storage.Node.Node + "/storage/" + storage.Storage + "/content"
data, err = storage.Node.Proxmox.PostForm(target, form)
if err != nil {
fmt.Println("Error!!!")
return nil, err
}
//fmt.Println("Storage created")
return data, err
}
func (storage Storage) Volumes() (VolumeList, error) {
var err error
var target string
var data map[string]interface{}
var list VolumeList
var volume Volume
var results []interface{}
//fmt.Println("!Volumes")
target = "nodes/" + storage.Node.Node + "/storage/" + storage.Storage + "/content"
data, err = storage.Node.Proxmox.Get(target)
if err != nil {
return nil, err
}
list = make(VolumeList)
results = data["data"].([]interface{})
for _, v0 := range results {
v := v0.(map[string]interface{})
volume = Volume{
Size: v["size"].(float64),
VolId: v["volid"].(string),
VmId: v["vmid"].(string),
Format: v["format"].(string),
Content: v["content"].(string),
Used: v["used"].(float64),
storage: storage,
}
list[volume.VolId] = volume
}
return list, nil
}