Skip to content

Commit

Permalink
Merge pull request #186 from Tinyblargon/CLI-Overhaul
Browse files Browse the repository at this point in the history
Cli overhaul: storage
  • Loading branch information
mleone87 authored Aug 18, 2022
2 parents a98e03b + e9b47a2 commit 0129fa9
Show file tree
Hide file tree
Showing 55 changed files with 2,448 additions and 279 deletions.
33 changes: 33 additions & 0 deletions cli/command/create/create-storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package create

import (
"github.com/Telmate/proxmox-api-go/cli"
"github.com/Telmate/proxmox-api-go/proxmox"
"github.com/spf13/cobra"
)

var create_storageCmd = &cobra.Command{
Use: "storage STORAGEID",
Short: "Creates a new Storage Backend",
Long: `Creates a new Storage Backend.
The config can be set with the --file flag or piped from stdin.
For config examples see "example storage"`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
id := cli.ValidateIDset(args, 0, "StorageID")
config, err := proxmox.NewConfigStorageFromJson(cli.NewConfig())
if err != nil {
return
}
c := cli.NewClient()
err = config.CreateWithValidate(id, c)
if err != nil {
return
}
cli.PrintItemCreated(createCmd.OutOrStdout(), id, "Storage")
return
},
}

func init() {
createCmd.AddCommand(create_storageCmd)
}
17 changes: 17 additions & 0 deletions cli/command/delete/delete-storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package delete

import (
"github.com/spf13/cobra"
)

var delete_storageCmd = &cobra.Command{
Use: "storage STORAGEID",
Short: "Deletes the speciefied Storage",
RunE: func(cmd *cobra.Command, args []string) error {
return DeleteID(args, "Storage")
},
}

func init() {
deleteCmd.AddCommand(delete_storageCmd)
}
2 changes: 2 additions & 0 deletions cli/command/delete/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func DeleteID(args []string, IDtype string) (err error){
err = c.DeleteMetricServer(id)
case "Pool" :
err = c.DeletePool(id)
case "Storage" :
err = c.DeleteStorage(id)
case "User" :
err = c.DeleteUser(id)
}
Expand Down
17 changes: 17 additions & 0 deletions cli/command/get/get-storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package get

import (
"github.com/spf13/cobra"
)

var get_storageCmd = &cobra.Command{
Use: "storage",
Short: "Gets the configuration of the specified Storage backend",
RunE: func(cmd *cobra.Command, args []string) error {
return GetConfig(args, "Storage")
},
}

func init() {
getCmd.AddCommand(get_storageCmd)
}
2 changes: 2 additions & 0 deletions cli/command/get/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func GetConfig(args []string, IDtype string) (err error) {
switch IDtype {
case "MetricServer" :
config, err = proxmox.NewConfigMetricsFromApi(id, c)
case "Storage" :
config, err = proxmox.NewConfigStorageFromApi(id, c)
case "User" :
config, err = proxmox.NewConfigUserFromApi(id, c)
}
Expand Down
33 changes: 33 additions & 0 deletions cli/command/update/update-storage.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package update

import (
"github.com/Telmate/proxmox-api-go/cli"
"github.com/Telmate/proxmox-api-go/proxmox"
"github.com/spf13/cobra"
)

var update_storageCmd = &cobra.Command{
Use: "storage STORAGEID",
Short: "Updates the configuration of the speciefied Storage Backend.",
Long: `Updates the configuration of the speciefied Storage Backend.
The config can be set with the --file flag or piped from stdin.
For config examples see "example storage"`,
RunE: func(cmd *cobra.Command, args []string) (err error) {
id := cli.ValidateIDset(args, 0, "StorageID")
config, err := proxmox.NewConfigStorageFromJson(cli.NewConfig())
if err != nil {
return
}
c := cli.NewClient()
err = config.UpdateWithValidate(id, c)
if err != nil {
return
}
cli.PrintItemUpdated(updateCmd.OutOrStdout(), id, "Storage")
return
},
}

func init() {
updateCmd.AddCommand(update_storageCmd)
}
Loading

0 comments on commit 0129fa9

Please sign in to comment.