Skip to content

Commit

Permalink
Add feature to interact with Storage Backends
Browse files Browse the repository at this point in the history
  • Loading branch information
Tinyblargon committed Apr 24, 2022
1 parent 768690d commit d5721c6
Show file tree
Hide file tree
Showing 6 changed files with 1,340 additions and 1 deletion.
44 changes: 44 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ export PM_OTP=otpcode (only if required)
./proxmox-api-go setMetricsServer metricsid < metricsServer.json

./proxmox-api-go deleteMetricsServer metricsid

./proxmox-api-go getStorageList

./proxmox-api-go getStorage storageid

./proxmox-api-go createStorage storageid < storage.json

./proxmox-api-go updateStorage storageid < storage.json

./proxmox-api-go deleteStorage
```
## Proxy server support
Expand Down Expand Up @@ -218,6 +228,40 @@ setMetricsServer JSON Sample:
}
```
createStorage JSON Sample:
```json
{
"enable": true,
"type": "smb",
"smb": {
"username": "b.wayne",
"share": "NetworkShare",
"preallocation": "metadata",
"domain": "organization.com",
"server": "10.20.1.1",
"version": "3.11",
"password": "Enter123!"
},
"content": {
"backup": true,
"iso": false,
"template": true,
"diskimage": true,
"container": true,
"snippets": false
},
"backupretention": {
"last": 10,
"hourly": 4,
"daily": 7,
"monthly": 3,
"weekly": 2,
"yearly": 1
}
}
```
### Cloud-init options
Cloud-init VMs must be cloned from a cloud-init ready template.
Expand Down
56 changes: 56 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,6 +588,62 @@ func main() {
failError(err)
fmt.Printf("Metrics Server %s removed\n", metricsid)

//Storage
case "getStorageList":
storage, err := c.GetStorageList()
if err != nil {
log.Printf("Error listing Storages %+v\n", err)
os.Exit(1)
}
storageList, err := json.Marshal(storage)
failError(err)
fmt.Println(string(storageList))

case "getStorage":
if len(flag.Args()) < 2 {
log.Printf("Error: Storage id required")
os.Exit(1)
}
var config interface{}
storageid := flag.Args()[1]
config, err := proxmox.NewConfigStorageFromApi(storageid, c)
failError(err)
cj, err := json.MarshalIndent(config, "", " ")
failError(err)
log.Println(string(cj))

case "createStorage":
if len(flag.Args()) < 2 {
log.Printf("Error: Storage id required")
os.Exit(1)
}
config, err := proxmox.NewConfigStorageFromJson(configSource)
failError(err)
storageid := flag.Args()[1]
failError(config.CreateWithValidate(storageid, c))
log.Printf("Storage %s has been created\n", storageid)

case "updateStorage":
if len(flag.Args()) < 2 {
log.Printf("Error: Storage id required")
os.Exit(1)
}
config, err := proxmox.NewConfigStorageFromJson(configSource)
failError(err)
storageid := flag.Args()[1]
failError(config.UpdateWithValidate(storageid, c))
log.Printf("Storage %s has been updated\n", storageid)

case "deleteStorage":
if len(flag.Args()) < 2 {
log.Printf("Error: Storage id required")
os.Exit(1)
}
storageid := flag.Args()[1]
err := c.DeleteStorage(storageid)
failError(err)
fmt.Printf("Storage %s removed\n", storageid)


default:
fmt.Printf("unknown action, try start|stop vmid\n")
Expand Down
34 changes: 34 additions & 0 deletions proxmox/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,40 @@ func (c *Client) DeleteMetricServer(id string) error {
return c.DeleteUrl("/cluster/metrics/server/" + id)
}

//storage
func (c *Client) EnableStorage(id string) error {
param := map[string]interface{}{
"disable": false,
}
return c.UpdateItem(param, "/storage/" + id)
}

func (c *Client) GetStorageList() (metricServers map[string]interface{}, err error){
return c.GetItemList("/storage")
}

func (c *Client) GetStorageConfig(id string) (config map[string]interface{}, err error) {
return c.GetItemConfigMapStringInterface("/storage/" + id, "storage")
}

func (c *Client) CreateStorage(id string, params map[string]interface{}) error {
return c.CreateItem(params, "/storage")
}

func (c *Client) CheckStorageExistance(id string) (existance bool, err error) {
list, err := c.GetStorageList()
existance = ItemInKeyOfArray(list["data"].([]interface{}), "storage", id)
return
}

func (c *Client) UpdateStorage(id string, params map[string]interface{}) error {
return c.UpdateItem(params, "/storage/" + id)
}

func (c *Client) DeleteStorage(id string) error {
return c.DeleteUrl("/storage/" + id)
}




Expand Down
Loading

0 comments on commit d5721c6

Please sign in to comment.