diff --git a/cli/command/create/create-storage.go b/cli/command/create/create-storage.go new file mode 100644 index 00000000..c1590f09 --- /dev/null +++ b/cli/command/create/create-storage.go @@ -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) +} diff --git a/cli/command/delete/delete-storage.go b/cli/command/delete/delete-storage.go new file mode 100644 index 00000000..106d28d9 --- /dev/null +++ b/cli/command/delete/delete-storage.go @@ -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) +} diff --git a/cli/command/delete/delete.go b/cli/command/delete/delete.go index 87bb3674..0f5af319 100644 --- a/cli/command/delete/delete.go +++ b/cli/command/delete/delete.go @@ -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) } diff --git a/cli/command/get/get-storage.go b/cli/command/get/get-storage.go new file mode 100644 index 00000000..49ae9174 --- /dev/null +++ b/cli/command/get/get-storage.go @@ -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) +} diff --git a/cli/command/get/get.go b/cli/command/get/get.go index 238bd23a..e910f904 100644 --- a/cli/command/get/get.go +++ b/cli/command/get/get.go @@ -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) } diff --git a/cli/command/update/update-storage.go b/cli/command/update/update-storage.go new file mode 100644 index 00000000..ec7179c4 --- /dev/null +++ b/cli/command/update/update-storage.go @@ -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) +} diff --git a/proxmox/config_storage.go b/proxmox/config_storage.go index 1f4fc7e1..3faadce5 100644 --- a/proxmox/config_storage.go +++ b/proxmox/config_storage.go @@ -9,50 +9,60 @@ import ( ) // matrix of storage types and which content types they support. -var strorageContentTypesAPI = []string{"backup","rootdir" ,"images" ,"iso","snippets","vztmpl" } -var strorageContentTypesStruct = []string{"backup","container","diskimage","iso","snippets","template"} +var strorageContentTypesAPI = []string{"backup", "rootdir", "images", "iso", "snippets", "vztmpl"} +var strorageContentTypesStruct = []string{"backup", "container", "diskimage", "iso", "snippets", "template"} var storageContentTypes = map[string]interface{}{ - "directory": []bool{true ,true ,true ,true ,true ,true }, - "lvm": []bool{false ,true ,true ,false,false ,false}, - "lvm-thin": []bool{false ,true ,true ,false,false ,false}, - "nfs": []bool{true ,true ,true ,true ,true ,true }, - "smb": []bool{true ,true ,true ,true ,true ,true }, - "glusterfs": []bool{true ,false ,true ,true ,true ,true }, - "iscsi": []bool{false ,false ,true ,false,false ,false}, - "cephfs": []bool{true ,false ,false ,true ,true ,true }, - "rbd": []bool{false ,true ,true ,false,false ,false}, - "zfs-over-iscsi": []bool{false ,false ,true ,false,false ,false}, - "zfs": []bool{false ,true ,true ,false,false ,false}, - "pbs": []bool{true ,false ,false ,false,false ,false}, + "directory": []bool{true, true, true, true, true, true}, + "lvm": []bool{false, true, true, false, false, false}, + "lvm-thin": []bool{false, true, true, false, false, false}, + "nfs": []bool{true, true, true, true, true, true}, + "smb": []bool{true, true, true, true, true, true}, + "glusterfs": []bool{true, false, true, true, true, true}, + "iscsi": []bool{false, false, true, false, false, false}, + "cephfs": []bool{true, false, false, true, true, true}, + "rbd": []bool{false, true, true, false, false, false}, + "zfs-over-iscsi": []bool{false, false, true, false, false, false}, + "zfs": []bool{false, true, true, false, false, false}, + "pbs": []bool{true, false, false, false, false, false}, } type ConfigStorageContent struct { - Backup *bool `json:"backup,omitempty"` //backup - Iso *bool `json:"iso,omitempty"` //iso - Template *bool `json:"template,omitempty"` //vztmpl - DiskImage *bool `json:"diskimage,omitempty"`//images - Container *bool `json:"container,omitempty"`//rootdir - Snippets *bool `json:"snippets,omitempty"` //snippets + Backup *bool `json:"backup,omitempty"` //backup + Iso *bool `json:"iso,omitempty"` //iso + Template *bool `json:"template,omitempty"` //vztmpl + DiskImage *bool `json:"diskimage,omitempty"` //images + Container *bool `json:"container,omitempty"` //rootdir + Snippets *bool `json:"snippets,omitempty"` //snippets } func (c *ConfigStorageContent) MapStorageContent(array []bool) (list string) { - for i, e := range []interface{}{c.Backup,c.Container,c.DiskImage,c.Iso,c.Snippets,c.Template}{ - if e.(*bool) != nil { - if *e.(*bool) && array[i]{ - list = AddToList(list, strorageContentTypesAPI[i]) + if c != nil { + for i, e := range []interface{}{c.Backup, c.Container, c.DiskImage, c.Iso, c.Snippets, c.Template} { + if e.(*bool) != nil { + if *e.(*bool) && array[i] { + list = AddToList(list, strorageContentTypesAPI[i]) + } } } } + if list == "" { + return "none" + } return } -func (c *ConfigStorageContent) Validate(array []bool) error { +func (c *ConfigStorageContent) Validate(storageType string) error { + // iscsi is the only storage type which can have "none" as content. + if storageType == "iscsi" { + return nil + } + array := storageContentTypes[storageType].([]bool) contentList := c.MapStorageContent(array) - if contentList != ""{ + if contentList != "" { return nil } var list string - for i, e := range array{ + for i, e := range array { if e { list = AddToList(list, strorageContentTypesStruct[i]) } @@ -70,42 +80,39 @@ type ConfigStorageBackupRetention struct { } func (b *ConfigStorageBackupRetention) MapStorageBackupRetention() string { - if !b.AllNil(){ - return "keep-daily=" + strconv.Itoa(*b.Daily) + - ",keep-hourly=" + strconv.Itoa(*b.Hourly) + - ",keep-last=" + strconv.Itoa(*b.Last) + - ",keep-monthly=" + strconv.Itoa(*b.Monthly) + - ",keep-weekly=" + strconv.Itoa(*b.Weekly) + - ",keep-yearly=" + strconv.Itoa(*b.Yearly) + if !b.AllNil() { + return "keep-daily=" + strconv.Itoa(*b.Daily) + + ",keep-hourly=" + strconv.Itoa(*b.Hourly) + + ",keep-last=" + strconv.Itoa(*b.Last) + + ",keep-monthly=" + strconv.Itoa(*b.Monthly) + + ",keep-weekly=" + strconv.Itoa(*b.Weekly) + + ",keep-yearly=" + strconv.Itoa(*b.Yearly) } return "keep-all=1" } func (b *ConfigStorageBackupRetention) Validate() (err error) { - if b == nil{ - return nil + if b == nil { + return nil } - - if !b.AllNil(){ - text := []string{"last","hourly","daily","weekly","monthly","yearly"} - for i, e := range []*int{b.Last,b.Hourly,b.Daily,b.Weekly,b.Monthly,b.Yearly}{ + if !b.AllNil() { + text := []string{"last", "hourly", "daily", "weekly", "monthly", "yearly"} + for i, e := range []*int{b.Last, b.Hourly, b.Daily, b.Weekly, b.Monthly, b.Yearly} { if e == nil { - return ErrorKeyNotSet("backupretention:{ "+ text[i] +" }") + return ErrorKeyNotSet("backupretention:{ " + text[i] + " }") } - err = ValidateIntGreater(0, *e, "backupretention:{ "+ text[i] +" }") - if err != nil{ + err = ValidateIntGreater(0, *e, "backupretention:{ "+text[i]+" }") + if err != nil { return } } } - - return nil } func (b *ConfigStorageBackupRetention) AllNil() bool { check := true - for _, e := range []*int{b.Last,b.Hourly,b.Daily,b.Weekly,b.Monthly,b.Yearly}{ + for _, e := range []*int{b.Last, b.Hourly, b.Daily, b.Weekly, b.Monthly, b.Yearly} { if e != nil { check = false } @@ -115,13 +122,13 @@ func (b *ConfigStorageBackupRetention) AllNil() bool { // Storage Types type ConfigStorageDirectory struct { - Path string `json:"Path"` + Path string `json:"path"` Preallocation *string `json:"preallocation,omitempty"` - Shared bool `json:"shared,omitempty"` + Shared bool `json:"shared"` } -func (directory *ConfigStorageDirectory) SetDefaults(){ - if directory.Preallocation == nil{ +func (directory *ConfigStorageDirectory) SetDefaults() { + if directory.Preallocation == nil { directory.Preallocation = PointerString("metadata") } } @@ -143,8 +150,8 @@ type ConfigStorageNFS struct { Version *string `json:"version,omitempty"` } -func (nfs *ConfigStorageNFS) SetDefaults(){ - if nfs.Preallocation == nil{ +func (nfs *ConfigStorageNFS) SetDefaults() { + if nfs.Preallocation == nil { nfs.Preallocation = PointerString("metadata") } } @@ -159,8 +166,8 @@ type ConfigStorageSMB struct { Version *string `json:"version,omitempty"` } -func (smb *ConfigStorageSMB) SetDefaults(){ - if smb.Preallocation == nil{ +func (smb *ConfigStorageSMB) SetDefaults() { + if smb.Preallocation == nil { smb.Preallocation = PointerString("metadata") } } @@ -172,8 +179,8 @@ type ConfigStorageGlusterFS struct { Volume string `json:"volume"` } -func (glusterfs *ConfigStorageGlusterFS) SetDefaults(){ - if glusterfs.Preallocation == nil{ +func (glusterfs *ConfigStorageGlusterFS) SetDefaults() { + if glusterfs.Preallocation == nil { glusterfs.Preallocation = PointerString("metadata") } } @@ -185,7 +192,7 @@ type ConfigStorageISCSI struct { type ConfigStorageCephFS struct { Monitors []string `json:"monitors"` - SecretKey *string `json:"secret-key,omitempty"` + SecretKey *string `json:"secret-key,omitempty"` Username string `json:"username"` FSname string `json:"fs-name"` } @@ -194,37 +201,37 @@ type ConfigStorageRBD struct { Pool string `json:"pool"` Monitors []string `json:"monitors"` Username string `json:"username"` - Keyring *string `json:"keyring,omitempty"` + Keyring *string `json:"keyring,omitempty"` Namespace string `json:"namespace"` KRBD bool `json:"krbd"` } type ConfigStorageZFSoverISCSI struct { - Portal string `json:"portal"` - Pool string `json:"pool"` - Blocksize *string `json:"blocksize"` - Target string `json:"target"` - ISCSIprovider string `json:"iscsiprovider"` - Thinprovision bool `json:"thinprovision"` - Comstar *ConfigStorageZFSoverISCSI_Comstar `json:"comstar,omitempty"` - Istgt *ConfigStorageZFSoverISCSI_istgt `json:"istgt,omitempty"` - LIO *ConfigStorageZFSoverISCSI_LIO `json:"lio,omitempty"` + Portal string `json:"portal"` + Pool string `json:"pool"` + Blocksize *string `json:"blocksize"` + Target string `json:"target"` + ISCSIprovider string `json:"iscsiprovider"` + Thinprovision bool `json:"thinprovision"` + Comstar *ConfigStorageZFSoverISCSI_Comstar `json:"comstar,omitempty"` + Istgt *ConfigStorageZFSoverISCSI_istgt `json:"istgt,omitempty"` + LIO *ConfigStorageZFSoverISCSI_LIO `json:"lio,omitempty"` } -func (zfsoveriscsi *ConfigStorageZFSoverISCSI) SetDefaults(){ - if zfsoveriscsi.Blocksize == nil{ +func (zfsoveriscsi *ConfigStorageZFSoverISCSI) SetDefaults() { + if zfsoveriscsi.Blocksize == nil { zfsoveriscsi.Blocksize = PointerString("4k") } } -func (zfsoveriscsi *ConfigStorageZFSoverISCSI) RemapToAPI(){ - if zfsoveriscsi.ISCSIprovider == "lio"{ +func (zfsoveriscsi *ConfigStorageZFSoverISCSI) RemapToAPI() { + if zfsoveriscsi.ISCSIprovider == "lio" { zfsoveriscsi.ISCSIprovider = "LIO" } } -func (zfsoveriscsi *ConfigStorageZFSoverISCSI) RemapFromAPI(){ - if zfsoveriscsi.ISCSIprovider == "LIO"{ +func (zfsoveriscsi *ConfigStorageZFSoverISCSI) RemapFromAPI() { + if zfsoveriscsi.ISCSIprovider == "LIO" { zfsoveriscsi.ISCSIprovider = "lio" } } @@ -247,8 +254,8 @@ type ConfigStorageZFS struct { Thinprovision bool `json:"thinprovision,omitempty"` } -func (zfs *ConfigStorageZFS) SetDefaults(){ - if zfs.Blocksize == nil{ +func (zfs *ConfigStorageZFS) SetDefaults() { + if zfs.Blocksize == nil { zfs.Blocksize = PointerString("8k") } } @@ -260,38 +267,63 @@ type ConfigStoragePBS struct { Password *string `json:"password,omitempty"` Fingerprint string `json:"fingerprint,omitempty"` Port *int `json:"port,omitempty"` + Namespace string `json:"namespace,omitempty"` } -func (pbs *ConfigStoragePBS) SetDefaults(){ - if pbs.Port == nil{ +func (pbs *ConfigStoragePBS) SetDefaults() { + if pbs.Port == nil { pbs.Port = PointerInt(8007) } } // Storage options for the Proxmox API type ConfigStorage struct { - ID string `json:"id"` - Enable bool `json:"enable"` - Nodes []string `json:"nodes,omitempty"` - Type string `json:"type,omitempty"` - Directory *ConfigStorageDirectory `json:"directory,omitempty"` - LVM *ConfigStorageLVM `json:"lvm,omitempty"` - LVMThin *ConfigStorageLVMThin `json:"lvm-thin,omitempty"` - NFS *ConfigStorageNFS `json:"nfs,omitempty"` - SMB *ConfigStorageSMB `json:"smb,omitempty"` - GlusterFS *ConfigStorageGlusterFS `json:"glusterfs,omitempty"` - ISCSI *ConfigStorageISCSI `json:"iscsi,omitempty"` - CephFS *ConfigStorageCephFS `json:"cephfs,omitempty"` - RBD *ConfigStorageRBD `json:"rbd,omitempty"` - ZFSoverISCSI *ConfigStorageZFSoverISCSI `json:"zfs-over-iscsi,omitempty"` - ZFS *ConfigStorageZFS `json:"zfs,omitempty"` - PBS *ConfigStoragePBS `json:"pbs,omitempty"` + ID string `json:"id"` + Enable bool `json:"enable"` + Nodes []string `json:"nodes,omitempty"` + Type string `json:"type"` + Directory *ConfigStorageDirectory `json:"directory,omitempty"` + LVM *ConfigStorageLVM `json:"lvm,omitempty"` + LVMThin *ConfigStorageLVMThin `json:"lvm-thin,omitempty"` + NFS *ConfigStorageNFS `json:"nfs,omitempty"` + SMB *ConfigStorageSMB `json:"smb,omitempty"` + GlusterFS *ConfigStorageGlusterFS `json:"glusterfs,omitempty"` + ISCSI *ConfigStorageISCSI `json:"iscsi,omitempty"` + CephFS *ConfigStorageCephFS `json:"cephfs,omitempty"` + RBD *ConfigStorageRBD `json:"rbd,omitempty"` + ZFSoverISCSI *ConfigStorageZFSoverISCSI `json:"zfs-over-iscsi,omitempty"` + ZFS *ConfigStorageZFS `json:"zfs,omitempty"` + PBS *ConfigStoragePBS `json:"pbs,omitempty"` Content *ConfigStorageContent `json:"content,omitempty"` BackupRetention *ConfigStorageBackupRetention `json:"backupretention,omitempty"` } -func (config *ConfigStorage) RemapToAPI(){ - switch config.Type{ +func (config *ConfigStorage) SetDefaults() { + if config.Directory != nil { + config.Directory.SetDefaults() + } + if config.NFS != nil { + config.NFS.SetDefaults() + } + if config.SMB != nil { + config.SMB.SetDefaults() + } + if config.GlusterFS != nil { + config.GlusterFS.SetDefaults() + } + if config.ZFSoverISCSI != nil { + config.ZFSoverISCSI.SetDefaults() + } + if config.ZFS != nil { + config.ZFS.SetDefaults() + } + if config.PBS != nil { + config.PBS.SetDefaults() + } +} + +func (config *ConfigStorage) RemapToAPI() { + switch config.Type { case "directory": config.Type = "dir" case "lvm-thin": @@ -305,8 +337,8 @@ func (config *ConfigStorage) RemapToAPI(){ } } -func (config *ConfigStorage) RemapFromAPI(){ - switch config.Type{ +func (config *ConfigStorage) RemapFromAPI() { + switch config.Type { case "dir": config.Type = "directory" case "lvmthin": @@ -322,7 +354,7 @@ func (config *ConfigStorage) RemapFromAPI(){ func (newConfig *ConfigStorage) Validate(id string, create bool, client *Client) (err error) { exists, err := client.CheckStorageExistance(id) - if err != nil{ + if err != nil { return } @@ -333,28 +365,28 @@ func (newConfig *ConfigStorage) Validate(id string, create bool, client *Client) return ErrorItemNotExists(id, "storage") } - err = ValidateStringInArray([]string{"directory", "lvm","lvm-thin","nfs","smb","glusterfs","iscsi","cephfs","rbd","zfs-over-iscsi","zfs","pbs"}, newConfig.Type, "type") - if err != nil{ + err = ValidateStringInArray([]string{"directory", "lvm", "lvm-thin", "nfs", "smb", "glusterfs", "iscsi", "cephfs", "rbd", "zfs-over-iscsi", "zfs", "pbs"}, newConfig.Type, "type") + if err != nil { return } var currentConfig *ConfigStorage if exists { currentConfig, err = NewConfigStorageFromApi(id, client) - if err != nil{ + if err != nil { return } err = ValidateStringsEqual(newConfig.Type, currentConfig.Type, "type") - if err != nil{ + if err != nil { return } } switch newConfig.Type { case "directory": - if exists && newConfig.Directory != nil{ + if exists && newConfig.Directory != nil { err = ValidateStringsEqual(newConfig.Directory.Path, currentConfig.Directory.Path, "path") - if err != nil{ + if err != nil { return } } else if !exists { @@ -362,15 +394,15 @@ func (newConfig *ConfigStorage) Validate(id string, create bool, client *Client) return ErrorKeyEmpty("directory") } else { err = ValidateFilePath(newConfig.Directory.Path, "path") - if err != nil{ + if err != nil { return } } } case "lvm": - if exists && newConfig.LVM != nil{ + if exists && newConfig.LVM != nil { err = ValidateStringsEqual(newConfig.LVM.VGname, currentConfig.LVM.VGname, "lvm:{ vgname }") - if err != nil{ + if err != nil { return } } else if !exists { @@ -383,13 +415,13 @@ func (newConfig *ConfigStorage) Validate(id string, create bool, client *Client) } } case "lvm-thin": - if exists && newConfig.LVMThin != nil{ + if exists && newConfig.LVMThin != nil { err = ValidateStringsEqual(newConfig.LVMThin.VGname, currentConfig.LVMThin.VGname, "lvm-thin:{ vgname }") - if err != nil{ + if err != nil { return } err = ValidateStringsEqual(newConfig.LVMThin.Thinpool, currentConfig.LVMThin.Thinpool, "lvm-thin:{ thinpool }") - if err != nil{ + if err != nil { return } } else if !exists { @@ -405,213 +437,213 @@ func (newConfig *ConfigStorage) Validate(id string, create bool, client *Client) } } case "nfs": - if exists && newConfig.NFS != nil{ + if exists && newConfig.NFS != nil { err = ValidateStringsEqual(newConfig.NFS.Export, currentConfig.NFS.Export, "nfs:{ export }") - if err != nil{ + if err != nil { return } err = ValidateStringsEqual(newConfig.NFS.Server, currentConfig.NFS.Server, "nfs:{ server }") - if err != nil{ + if err != nil { return } } else if !exists { - if newConfig.NFS == nil{ + if newConfig.NFS == nil { return ErrorKeyEmpty("nfs") } else { err = ValidateStringNotEmpty(newConfig.NFS.Server, "nfs:{ server }") - if err != nil{ + if err != nil { return } err = ValidateFilePath(newConfig.NFS.Export, "nfs:{ export }") - if err != nil{ + if err != nil { return - } + } } } if newConfig.NFS != nil { if newConfig.NFS.Version != nil { - err = ValidateStringInArray([]string{"3", "4","4.1","4.2"}, *newConfig.NFS.Version, "nfs:{ version }") - if err != nil{ + err = ValidateStringInArray([]string{"3", "4", "4.1", "4.2"}, *newConfig.NFS.Version, "nfs:{ version }") + if err != nil { return } } if newConfig.NFS.Preallocation != nil { err = ValidateStringNotEmpty(*newConfig.NFS.Preallocation, "nfs:{ preallocation }") - if err != nil{ + if err != nil { return } } } case "smb": - if exists && newConfig.SMB != nil{ + if exists && newConfig.SMB != nil { err = ValidateStringsEqual(newConfig.SMB.Server, currentConfig.SMB.Server, "smb:{ server }") - if err != nil{ + if err != nil { return } err = ValidateStringsEqual(newConfig.SMB.Share, currentConfig.SMB.Share, "smb:{ share }") - if err != nil{ + if err != nil { return } } else if !exists { - if newConfig.SMB == nil{ + if newConfig.SMB == nil { return ErrorKeyEmpty("smb") } else { err = ValidateStringNotEmpty(newConfig.SMB.Server, "smb:{ server }") - if err != nil{ + if err != nil { return } err = ValidateStringNotEmpty(newConfig.SMB.Share, "smb:{ share }") - if err != nil{ + if err != nil { return } } } if newConfig.SMB != nil { if newConfig.SMB.Version != nil { - err = ValidateStringInArray([]string{"2.0","2.1","3","3.0","3.11"}, *newConfig.SMB.Version, "smb:{ version }") - if err != nil{ + err = ValidateStringInArray([]string{"2.0", "2.1", "3", "3.0", "3.11"}, *newConfig.SMB.Version, "smb:{ version }") + if err != nil { return } } if newConfig.SMB.Preallocation != nil { err = ValidateStringNotEmpty(*newConfig.SMB.Preallocation, "smb:{ preallocation }") - if err != nil{ + if err != nil { return } } } case "glusterfs": - if exists && newConfig.GlusterFS != nil{ + if exists && newConfig.GlusterFS != nil { err = ValidateStringsEqual(newConfig.GlusterFS.Volume, currentConfig.GlusterFS.Volume, "glusterfs:{ volume }") - if err != nil{ + if err != nil { return } } else if !exists { - if newConfig.GlusterFS == nil{ + if newConfig.GlusterFS == nil { return ErrorKeyEmpty("glusterfs") } else { err = ValidateStringNotEmpty(newConfig.GlusterFS.Server1, "glusterfs:{ server1 }") - if err != nil{ + if err != nil { return } err = ValidateStringNotEmpty(newConfig.GlusterFS.Volume, "glusterfs:{ volume }") - if err != nil{ + if err != nil { return } } } if newConfig.GlusterFS != nil { err = ValidateStringNotEmpty(newConfig.GlusterFS.Server1, "glusterfs:{ server1 }") - if err != nil{ + if err != nil { return } if newConfig.GlusterFS.Preallocation != nil { err = ValidateStringNotEmpty(*newConfig.GlusterFS.Preallocation, "glusterfs:{ preallocation }") - if err != nil{ + if err != nil { return } } } case "iscsi": - if exists && newConfig.ISCSI != nil{ + if exists && newConfig.ISCSI != nil { err = ValidateStringsEqual(newConfig.ISCSI.Portal, currentConfig.ISCSI.Portal, "iscsi:{ portal }") - if err != nil{ + if err != nil { return } err = ValidateStringsEqual(newConfig.ISCSI.Target, currentConfig.ISCSI.Target, "iscsi:{ target }") - if err != nil{ + if err != nil { return } } else if !exists { - if newConfig.ISCSI == nil{ + if newConfig.ISCSI == nil { return ErrorKeyEmpty("iscsi") } else { err = ValidateStringNotEmpty(newConfig.ISCSI.Portal, "iscsi:{ portal }") - if err != nil{ + if err != nil { return } err = ValidateStringNotEmpty(newConfig.ISCSI.Target, "iscsi:{ target }") - if err != nil{ + if err != nil { return } } } case "cephfs": - if !exists && newConfig.CephFS == nil{ + if !exists && newConfig.CephFS == nil { return ErrorKeyEmpty("cephfs") } if newConfig.CephFS != nil { err = ValidateArrayNotEmpty(newConfig.CephFS.Monitors, "cephfs:{ monitors }") - if err != nil{ + if err != nil { return } } case "rbd": - if !exists && newConfig.RBD == nil{ + if !exists && newConfig.RBD == nil { return ErrorKeyEmpty("rbd") } if newConfig.RBD != nil { err = ValidateArrayNotEmpty(newConfig.RBD.Monitors, "rbd:{ monitors }") - if err != nil{ + if err != nil { return } } case "zfs-over-iscsi": - if exists && newConfig.ZFSoverISCSI != nil{ + if exists && newConfig.ZFSoverISCSI != nil { err = ValidateStringsEqual(newConfig.ZFSoverISCSI.ISCSIprovider, currentConfig.ZFSoverISCSI.ISCSIprovider, "zfs-over-iscsi:{ iscsiprovider }") - if err != nil{ + if err != nil { return } err = ValidateStringsEqual(newConfig.ZFSoverISCSI.Portal, currentConfig.ZFSoverISCSI.Portal, "zfs-over-iscsi:{ portal }") - if err != nil{ + if err != nil { return } err = ValidateStringsEqual(newConfig.ZFSoverISCSI.Target, currentConfig.ZFSoverISCSI.Target, "zfs-over-iscsi:{ target }") - if err != nil{ + if err != nil { return } err = ValidateStringsEqual(newConfig.ZFSoverISCSI.Pool, currentConfig.ZFSoverISCSI.Pool, "zfs-over-iscsi:{ pool }") - if err != nil{ + if err != nil { return } - err = ValidateStringsEqual(*newConfig.ZFSoverISCSI.Blocksize, *currentConfig.ZFSoverISCSI.Blocksize, "zfs-over-iscsi:{ blocksize }") - if err != nil{ + // err = ValidateStringsEqual(*newConfig.ZFSoverISCSI.Blocksize, *currentConfig.ZFSoverISCSI.Blocksize, "zfs-over-iscsi:{ blocksize }") + if err != nil { return } } else if !exists { - if newConfig.ZFSoverISCSI == nil{ + if newConfig.ZFSoverISCSI == nil { return ErrorKeyEmpty("zfs-over-iscsi") } else { - err = ValidateStringInArray([]string{"comstar","istgt","lio","iet"}, newConfig.ZFSoverISCSI.ISCSIprovider, "zfs-over-iscsi:{ iscsiprovider }") - if err != nil{ + err = ValidateStringInArray([]string{"comstar", "istgt", "lio", "iet"}, newConfig.ZFSoverISCSI.ISCSIprovider, "zfs-over-iscsi:{ iscsiprovider }") + if err != nil { return } err = ValidateStringNotEmpty(newConfig.ZFSoverISCSI.Portal, "zfs-over-iscsi:{ portal }") - if err != nil{ + if err != nil { return } err = ValidateStringNotEmpty(newConfig.ZFSoverISCSI.Pool, "zfs-over-iscsi:{ pool }") - if err != nil{ + if err != nil { return } err = ValidateStringNotEmpty(newConfig.ZFSoverISCSI.Target, "zfs-over-iscsi:{ target }") - if err != nil{ + if err != nil { return } } } - switch newConfig.ZFSoverISCSI.ISCSIprovider{ + switch newConfig.ZFSoverISCSI.ISCSIprovider { case "comstar": - if exists && newConfig.ZFSoverISCSI.Comstar != nil{ + if exists && newConfig.ZFSoverISCSI.Comstar != nil { err = ValidateStringsEqual(newConfig.ZFSoverISCSI.Comstar.HostGroup, currentConfig.ZFSoverISCSI.Comstar.HostGroup, "zfs-over-iscsi:{ comstar:{ host-group } }") - if err != nil{ + if err != nil { return } err = ValidateStringsEqual(newConfig.ZFSoverISCSI.Comstar.TargetGroup, currentConfig.ZFSoverISCSI.Comstar.TargetGroup, "zfs-over-iscsi:{ comstar:{ target-group } }") - if err != nil{ + if err != nil { return } - } else if !exists && newConfig.ZFSoverISCSI.Comstar == nil{ + } else if !exists && newConfig.ZFSoverISCSI.Comstar == nil { return ErrorKeyEmpty("zfs-over-iscsi:{ comstar }") } case "istgt": @@ -623,55 +655,55 @@ func (newConfig *ConfigStorage) Validate(id string, create bool, client *Client) return ErrorKeyEmpty("zfs-over-iscsi:{ lio }") } else { err = ValidateStringNotEmpty(newConfig.ZFSoverISCSI.LIO.TargetPortalGroup, "zfs-over-iscsi:{ lio:{ targetportal-group } }") - if err != nil{ + if err != nil { return } } } case "zfs": - if exists && newConfig.ZFS != nil{ + if exists && newConfig.ZFS != nil { err = ValidateStringsEqual(newConfig.ZFS.Pool, currentConfig.ZFS.Pool, "zfs:{ pool }") - if err != nil{ + if err != nil { return } } else if !exists { - if newConfig.ZFS == nil{ + if newConfig.ZFS == nil { return ErrorKeyEmpty("zfs") } else { err = ValidateStringNotEmpty(newConfig.ZFS.Pool, "zfs:{ pool }") - if err != nil{ + if err != nil { return } } } if newConfig.ZFS != nil { - if newConfig.ZFS.Blocksize != nil{ + if newConfig.ZFS.Blocksize != nil { err = ValidateStringNotEmpty(*newConfig.ZFS.Blocksize, "zfs:{ blocksize }") - if err != nil{ + if err != nil { return } } } case "pbs": - if exists && newConfig.PBS != nil{ + if exists && newConfig.PBS != nil { err = ValidateStringsEqual(newConfig.PBS.Server, currentConfig.PBS.Server, "pbs:{ server }") - if err != nil{ + if err != nil { return } err = ValidateStringsEqual(newConfig.PBS.Datastore, currentConfig.PBS.Datastore, "pbs:{ datastore }") - if err != nil{ + if err != nil { return } } else if !exists { - if newConfig.PBS == nil{ + if newConfig.PBS == nil { return ErrorKeyEmpty("pbs") } else { err = ValidateStringNotEmpty(newConfig.PBS.Server, "pbs:{ server }") - if err != nil{ + if err != nil { return } err = ValidateStringNotEmpty(newConfig.PBS.Datastore, "pbs:{ datastore }") - if err != nil{ + if err != nil { return } if newConfig.PBS.Password == nil { @@ -682,34 +714,36 @@ func (newConfig *ConfigStorage) Validate(id string, create bool, client *Client) if newConfig.PBS != nil { if newConfig.PBS.Port != nil { err = ValidateIntInRange(1, 65536, *newConfig.PBS.Port, "pbs:{ port }") - if err != nil{ + if err != nil { return } } err = ValidateStringNotEmpty(newConfig.PBS.Username, "pbs:{ username }") - if err != nil{ + if err != nil { return } } } - - if exists && newConfig.Content != nil{ - err = newConfig.Content.Validate(storageContentTypes[newConfig.Type].([]bool)) - if err != nil { - return - } - } else if !exists { - if newConfig.Content == nil { - return ErrorKeyEmpty("content") - } else { - err = newConfig.Content.Validate(storageContentTypes[newConfig.Type].([]bool)) + if !inArray([]string{"pbs", "zfs-over-iscsi"}, newConfig.Type) { + // pbs has a hardcoded content type, of type backup. + // zfs-over-iscsi has a hardcoded content type, of type diskimage. + if exists && newConfig.Content != nil { + err = newConfig.Content.Validate(newConfig.Type) if err != nil { return } + } else if !exists { + if newConfig.Content == nil { + return ErrorKeyEmpty("content") + } else { + err = newConfig.Content.Validate(newConfig.Type) + if err != nil { + return + } + } } } - err = newConfig.BackupRetention.Validate() - return + return newConfig.BackupRetention.Validate() } func (config *ConfigStorage) MapToApiValues(create bool) (params map[string]interface{}) { @@ -717,10 +751,9 @@ func (config *ConfigStorage) MapToApiValues(create bool) (params map[string]inte params = map[string]interface{}{ "storage": config.ID, "disable": BoolInvert(config.Enable), + "nodes": ArrayToCSV(config.Nodes), } - params["content"] = config.Content.MapStorageContent(storageContentTypes[config.Type].([]bool)) - switch config.Type { case "directory": if config.Directory != nil { @@ -739,7 +772,7 @@ func (config *ConfigStorage) MapToApiValues(create bool) (params map[string]inte } } case "lvm-thin": - if config.LVMThin != nil{ + if config.LVMThin != nil { if create { params["thinpool"] = config.LVMThin.Thinpool params["vgname"] = config.LVMThin.VGname @@ -768,7 +801,7 @@ func (config *ConfigStorage) MapToApiValues(create bool) (params map[string]inte params["share"] = config.SMB.Share params["server"] = config.SMB.Server } - if config.SMB.Password != nil{ + if config.SMB.Password != nil { params["password"] = *config.SMB.Password } if config.SMB.Version != nil { @@ -779,9 +812,9 @@ func (config *ConfigStorage) MapToApiValues(create bool) (params map[string]inte params["preallocation"] = *config.SMB.Preallocation } case "glusterfs": - if config.GlusterFS != nil{ + if config.GlusterFS != nil { config.GlusterFS.SetDefaults() - params["server"] = config.GlusterFS.Server1 + params["server"] = config.GlusterFS.Server1 if config.GlusterFS.Server2 != "" { params["server2"] = config.GlusterFS.Server2 } else if !create { @@ -797,17 +830,12 @@ func (config *ConfigStorage) MapToApiValues(create bool) (params map[string]inte params["portal"] = config.ISCSI.Portal params["target"] = config.ISCSI.Target } - content := config.Content.MapStorageContent(storageContentTypes[config.Type].([]bool)) - if content == "" { - content = "none" - } - params["content"] = content case "cephfs": if config.CephFS != nil { params["monhost"] = ArrayToCSV(config.CephFS.Monitors) params["fs-name"] = config.CephFS.FSname params["username"] = config.CephFS.Username - if config.CephFS.SecretKey != nil{ + if config.CephFS.SecretKey != nil { // not sure if this is the right api parameter params["keyring"] = *config.CephFS.SecretKey } @@ -854,7 +882,9 @@ func (config *ConfigStorage) MapToApiValues(create bool) (params map[string]inte params["blocksize"] = *config.ZFSoverISCSI.Blocksize } } - params["content"] = "images" + config.Content = &ConfigStorageContent{ + DiskImage: PointerBool(true), + } case "zfs": if config.ZFS != nil { config.ZFS.SetDefaults() @@ -868,8 +898,14 @@ func (config *ConfigStorage) MapToApiValues(create bool) (params map[string]inte if config.PBS != nil { config.PBS.SetDefaults() params["username"] = config.PBS.Username - params["fingerprint"] = config.PBS.Fingerprint - params["port"] = *config.PBS.Port + if config.PBS.Fingerprint != "" { + params["fingerprint"] = config.PBS.Fingerprint + } else { + deletions = AddToList(deletions, "fingerprint") + } + if config.PBS.Port != nil { + params["port"] = *config.PBS.Port + } if create { params["server"] = config.PBS.Server params["datastore"] = config.PBS.Datastore @@ -877,10 +913,17 @@ func (config *ConfigStorage) MapToApiValues(create bool) (params map[string]inte if config.PBS.Password != nil { params["password"] = *config.PBS.Password } + if config.PBS.Namespace != "" { + params["namespace"] = strings.TrimLeft(config.PBS.Namespace, "/") + } + } + config.Content = &ConfigStorageContent{ + Backup: PointerBool(true), } - params["content"] = "backup" } + params["content"] = config.Content.MapStorageContent(storageContentTypes[config.Type].([]bool)) + if config.BackupRetention != nil { if storageContentTypes[config.Type].([]bool)[0] { params["prune-backups"] = config.BackupRetention.MapStorageBackupRetention() @@ -898,7 +941,7 @@ func (config *ConfigStorage) MapToApiValues(create bool) (params map[string]inte func (config *ConfigStorage) CreateWithValidate(id string, client *Client) (err error) { err = config.Validate(id, true, client) - if err != nil{ + if err != nil { return } return config.Create(id, true, client) @@ -906,7 +949,7 @@ func (config *ConfigStorage) CreateWithValidate(id string, client *Client) (err func (config *ConfigStorage) Create(id string, errorSupression bool, client *Client) (err error) { var enableStorage bool - if errorSupression && config.Enable{ + if errorSupression && config.Enable { config.Enable = false enableStorage = true } @@ -915,18 +958,18 @@ func (config *ConfigStorage) Create(id string, errorSupression bool, client *Cli err = client.CreateStorage(id, params) if err != nil { params, _ := json.Marshal(¶ms) - return fmt.Errorf("error creating Metrics Server: %v, (params: %v)", err, string(params)) + return fmt.Errorf("error creating Storage Backend: %v, (params: %v)", err, string(params)) } // if it gets enabled after it has been configured proxmox wont give the error that it can't connect to the storage backend if enableStorage { err = client.EnableStorage(id) - } + } return } func (config *ConfigStorage) UpdateWithValidate(id string, client *Client) (err error) { err = config.Validate(id, false, client) - if err != nil{ + if err != nil { return } return config.Update(id, client) @@ -938,7 +981,7 @@ func (config *ConfigStorage) Update(id string, client *Client) (err error) { err = client.UpdateStorage(id, params) if err != nil { params, _ := json.Marshal(¶ms) - return fmt.Errorf("error creating Metrics Server: %v, (params: %v)", err, string(params)) + return fmt.Errorf("error creating Storage Backend: %v, (params: %v)", err, string(params)) } return } @@ -956,6 +999,10 @@ func NewConfigStorageFromApi(storageid string, client *Client) (config *ConfigSt config.ID = storageid config.Type = rawConfig["type"].(string) + if _, isSet := rawConfig["nodes"]; isSet { + config.Nodes = CSVtoArray(rawConfig["nodes"].(string)) + } + config.RemapFromAPI() if _, isSet := rawConfig["disable"]; isSet { @@ -969,13 +1016,14 @@ func NewConfigStorageFromApi(storageid string, client *Client) (config *ConfigSt config.Directory = new(ConfigStorageDirectory) config.Directory.Path = rawConfig["path"].(string) config.Directory.Shared = Itob(int(rawConfig["shared"].(float64))) - if _, isSet := rawConfig["preallocation"]; isSet {config.Directory.Preallocation = PointerString(rawConfig["preallocation"].(string))} - config.Directory.SetDefaults() + if _, isSet := rawConfig["preallocation"]; isSet { + config.Directory.Preallocation = PointerString(rawConfig["preallocation"].(string)) + } case "lvm": config.LVM = new(ConfigStorageLVM) config.LVM.VGname = rawConfig["vgname"].(string) config.LVM.Shared = Itob(int(rawConfig["shared"].(float64))) - case "lvmt-hin": + case "lvm-thin": config.LVMThin = new(ConfigStorageLVMThin) config.LVMThin.Thinpool = rawConfig["thinpool"].(string) config.LVMThin.VGname = rawConfig["vgname"].(string) @@ -987,8 +1035,9 @@ func NewConfigStorageFromApi(storageid string, client *Client) (config *ConfigSt version := strings.Split(rawConfig["options"].(string), "=") config.NFS.Version = PointerString(version[1]) } - if _, isSet := rawConfig["preallocation"]; isSet {config.NFS.Preallocation = PointerString(rawConfig["preallocation"].(string))} - config.NFS.SetDefaults() + if _, isSet := rawConfig["preallocation"]; isSet { + config.NFS.Preallocation = PointerString(rawConfig["preallocation"].(string)) + } case "smb": config.SMB = new(ConfigStorageSMB) config.SMB.Server = rawConfig["server"].(string) @@ -1001,17 +1050,25 @@ func NewConfigStorageFromApi(storageid string, client *Client) (config *ConfigSt config.SMB.Version = PointerString(smbVersion) } } - if _, isSet := rawConfig["domain"]; isSet {config.SMB.Domain = rawConfig["domain"].(string)} - if _, isSet := rawConfig["username"]; isSet {config.SMB.Username = rawConfig["username"].(string)} - if _, isSet := rawConfig["preallocation"]; isSet {config.SMB.Preallocation = PointerString(rawConfig["preallocation"].(string))} - config.SMB.SetDefaults() + if _, isSet := rawConfig["domain"]; isSet { + config.SMB.Domain = rawConfig["domain"].(string) + } + if _, isSet := rawConfig["username"]; isSet { + config.SMB.Username = rawConfig["username"].(string) + } + if _, isSet := rawConfig["preallocation"]; isSet { + config.SMB.Preallocation = PointerString(rawConfig["preallocation"].(string)) + } case "glusterfs": config.GlusterFS = new(ConfigStorageGlusterFS) config.GlusterFS.Server1 = rawConfig["server"].(string) config.GlusterFS.Volume = rawConfig["volume"].(string) - if _, isSet := rawConfig["server2"]; isSet {config.GlusterFS.Server2 = rawConfig["server2"].(string)} - if _, isSet := rawConfig["preallocation"]; isSet {config.GlusterFS.Preallocation = PointerString(rawConfig["preallocation"].(string))} - config.GlusterFS.SetDefaults() + if _, isSet := rawConfig["server2"]; isSet { + config.GlusterFS.Server2 = rawConfig["server2"].(string) + } + if _, isSet := rawConfig["preallocation"]; isSet { + config.GlusterFS.Preallocation = PointerString(rawConfig["preallocation"].(string)) + } case "iscsi": config.ISCSI = new(ConfigStorageISCSI) config.ISCSI.Portal = rawConfig["portal"].(string) @@ -1019,87 +1076,112 @@ func NewConfigStorageFromApi(storageid string, client *Client) (config *ConfigSt case "cephfs": config.CephFS = new(ConfigStorageCephFS) config.CephFS.Monitors = CSVtoArray(rawConfig["monhost"].(string)) - if _, isSet := rawConfig["fs-name"]; isSet {config.CephFS.FSname = rawConfig["fs-name"].(string)} - if _, isSet := rawConfig["username"]; isSet {config.CephFS.Username = rawConfig["username"].(string)} + if _, isSet := rawConfig["fs-name"]; isSet { + config.CephFS.FSname = rawConfig["fs-name"].(string) + } + if _, isSet := rawConfig["username"]; isSet { + config.CephFS.Username = rawConfig["username"].(string) + } case "rbd": config.RBD = new(ConfigStorageRBD) config.RBD.KRBD = Itob(int(rawConfig["krbd"].(float64))) config.RBD.Monitors = CSVtoArray(rawConfig["monhost"].(string)) config.RBD.Pool = rawConfig["pool"].(string) - if _, isSet := rawConfig["namespace"]; isSet {config.RBD.Namespace = rawConfig["namespace"].(string)} - if _, isSet := rawConfig["username"]; isSet {config.RBD.Username = rawConfig["username"].(string)} + if _, isSet := rawConfig["namespace"]; isSet { + config.RBD.Namespace = rawConfig["namespace"].(string) + } + if _, isSet := rawConfig["username"]; isSet { + config.RBD.Username = rawConfig["username"].(string) + } case "zfs-over-iscsi": config.ZFSoverISCSI = new(ConfigStorageZFSoverISCSI) config.ZFSoverISCSI.Blocksize = PointerString(rawConfig["blocksize"].(string)) config.ZFSoverISCSI.ISCSIprovider = rawConfig["iscsiprovider"].(string) config.ZFSoverISCSI.RemapFromAPI() - switch config.ZFSoverISCSI.ISCSIprovider{ - case "comstar": - config.ZFSoverISCSI.Comstar = new(ConfigStorageZFSoverISCSI_Comstar) - if _, isSet := rawConfig["comstar_hg"]; isSet { - config.ZFSoverISCSI.Comstar.Writecache = BoolInvert(Itob(int(rawConfig["nowritecache"].(float64)))) - } else { - config.ZFSoverISCSI.Comstar.Writecache = true - } - if _, isSet := rawConfig["comstar_hg"]; isSet {config.ZFSoverISCSI.Comstar.HostGroup = rawConfig["comstar_hg"].(string)} - if _, isSet := rawConfig["comstar_tg"]; isSet {config.ZFSoverISCSI.Comstar.TargetGroup = rawConfig["comstar_tg"].(string)} - case "istgt": - config.ZFSoverISCSI.Istgt = new(ConfigStorageZFSoverISCSI_istgt) - config.ZFSoverISCSI.Istgt.Writecache = BoolInvert(Itob(int(rawConfig["nowritecache"].(float64)))) - case "lio": - config.ZFSoverISCSI.LIO = new(ConfigStorageZFSoverISCSI_LIO) - config.ZFSoverISCSI.LIO.TargetPortalGroup = rawConfig["lio_tpg"].(string) + switch config.ZFSoverISCSI.ISCSIprovider { + case "comstar": + config.ZFSoverISCSI.Comstar = new(ConfigStorageZFSoverISCSI_Comstar) + if _, isSet := rawConfig["comstar_hg"]; isSet { + config.ZFSoverISCSI.Comstar.Writecache = BoolInvert(Itob(int(rawConfig["nowritecache"].(float64)))) + } else { + config.ZFSoverISCSI.Comstar.Writecache = true + } + if _, isSet := rawConfig["comstar_hg"]; isSet { + config.ZFSoverISCSI.Comstar.HostGroup = rawConfig["comstar_hg"].(string) + } + if _, isSet := rawConfig["comstar_tg"]; isSet { + config.ZFSoverISCSI.Comstar.TargetGroup = rawConfig["comstar_tg"].(string) + } + case "istgt": + config.ZFSoverISCSI.Istgt = new(ConfigStorageZFSoverISCSI_istgt) + config.ZFSoverISCSI.Istgt.Writecache = BoolInvert(Itob(int(rawConfig["nowritecache"].(float64)))) + case "lio": + config.ZFSoverISCSI.LIO = new(ConfigStorageZFSoverISCSI_LIO) + config.ZFSoverISCSI.LIO.TargetPortalGroup = rawConfig["lio_tpg"].(string) } config.ZFSoverISCSI.Pool = rawConfig["pool"].(string) config.ZFSoverISCSI.Portal = rawConfig["portal"].(string) config.ZFSoverISCSI.Target = rawConfig["target"].(string) config.ZFSoverISCSI.Thinprovision = Itob(int(rawConfig["sparse"].(float64))) - config.ZFSoverISCSI.SetDefaults() case "zfs": config.ZFS = new(ConfigStorageZFS) config.ZFS.Pool = rawConfig["pool"].(string) config.ZFS.Thinprovision = Itob(int(rawConfig["sparse"].(float64))) - if _, isSet := rawConfig["blocksize"]; isSet {config.ZFS.Blocksize = PointerString(rawConfig["blocksize"].(string))} - config.ZFS.SetDefaults() + if _, isSet := rawConfig["blocksize"]; isSet { + config.ZFS.Blocksize = PointerString(rawConfig["blocksize"].(string)) + } case "pbs": config.PBS = new(ConfigStoragePBS) config.PBS.Datastore = rawConfig["datastore"].(string) config.PBS.Server = rawConfig["server"].(string) config.PBS.Username = rawConfig["username"].(string) - if _, isSet := rawConfig["port"]; isSet {config.PBS.Port = PointerInt(int(rawConfig["port"].(float64)))} - if _, isSet := rawConfig["fingerprint"]; isSet {config.PBS.Fingerprint = rawConfig["fingerprint"].(string)} - config.PBS.SetDefaults() + if _, isSet := rawConfig["port"]; isSet { + config.PBS.Port = PointerInt(int(rawConfig["port"].(float64))) + } + if _, isSet := rawConfig["fingerprint"]; isSet { + config.PBS.Fingerprint = rawConfig["fingerprint"].(string) + } + if _, isSet := rawConfig["namespace"]; isSet { + config.PBS.Namespace = rawConfig["namespace"].(string) + } } + config.SetDefaults() if _, isSet := rawConfig["content"]; isSet { content := rawConfig["content"].(string) - if content != "none"{ + if content != "none" { contentArray := CSVtoArray(content) config.Content = new(ConfigStorageContent) - if storageContentTypes[config.Type].([]bool)[0]{ + if storageContentTypes[config.Type].([]bool)[0] { config.Content.Backup = PointerBool(inArray(contentArray, strorageContentTypesAPI[0])) } - if storageContentTypes[config.Type].([]bool)[1]{ + if storageContentTypes[config.Type].([]bool)[1] { config.Content.Container = PointerBool(inArray(contentArray, strorageContentTypesAPI[1])) } - if storageContentTypes[config.Type].([]bool)[2]{ + if storageContentTypes[config.Type].([]bool)[2] { config.Content.DiskImage = PointerBool(inArray(contentArray, strorageContentTypesAPI[2])) } - if storageContentTypes[config.Type].([]bool)[3]{ + if storageContentTypes[config.Type].([]bool)[3] { config.Content.Iso = PointerBool(inArray(contentArray, strorageContentTypesAPI[3])) } - if storageContentTypes[config.Type].([]bool)[4]{ + if storageContentTypes[config.Type].([]bool)[4] { config.Content.Snippets = PointerBool(inArray(contentArray, strorageContentTypesAPI[4])) } - if storageContentTypes[config.Type].([]bool)[5]{ + if storageContentTypes[config.Type].([]bool)[5] { config.Content.Template = PointerBool(inArray(contentArray, strorageContentTypesAPI[5])) } + } else { + // Edge cases + if config.Type == "iscsi" { + config.Content = new(ConfigStorageContent) + config.Content.DiskImage = PointerBool(false) + } } } if _, isSet := rawConfig["prune-backups"]; isSet { prune := CSVtoArray(rawConfig["prune-backups"].(string)) - if !inArray(prune, "keep-all=1"){ + if !inArray(prune, "keep-all=1") { retentionSettings := make(map[string]int) - for _, e := range prune{ + for _, e := range prune { a := strings.Split(e, "=") retentionSettings[a[0]], _ = strconv.Atoi(a[1]) } @@ -1112,7 +1194,6 @@ func NewConfigStorageFromApi(storageid string, client *Client) (config *ConfigSt config.BackupRetention.Yearly = PointerInt(retentionSettings["keep-yearly"]) } } - return } @@ -1122,5 +1203,6 @@ func NewConfigStorageFromJson(input []byte) (config *ConfigStorage, err error) { if err != nil { log.Fatal(err) } + config.SetDefaults() return -} \ No newline at end of file +} diff --git a/proxmox/validate.go b/proxmox/validate.go index 2360b975..ed8b363f 100644 --- a/proxmox/validate.go +++ b/proxmox/validate.go @@ -5,47 +5,48 @@ import ( "path/filepath" ) -func ValidateIntInRange(min, max, value int, text string) error{ - if value >= min && value <= max{ +func ValidateIntInRange(min, max, value int, text string) error { + if value >= min && value <= max { return nil } return fmt.Errorf("error the value of key (%s) must be between %d and %d", text, min, max) } -func ValidateIntGreaterOrEquals(min, value int, text string) error{ +func ValidateIntGreaterOrEquals(min, value int, text string) error { if value >= min { return nil } return fmt.Errorf("error the value of key (%s) must be greater or equal to %d", text, min) } -func ValidateIntGreater(min, value int, text string) error{ +func ValidateIntGreater(min, value int, text string) error { if value > min { return nil } return fmt.Errorf("error the value of key (%s) must be greater than %d", text, min) } -func ValidateStringInArray(array []string, value, text string) error{ +func ValidateStringInArray(array []string, value, text string) error { err := ValidateStringNotEmpty(value, text) if err != nil { return err } - if inArray(array, value){ + if inArray(array, value) { return nil } return fmt.Errorf("error the value of key (%s) must be one of %s", text, ArrayToCSV(array)) } -func ValidateStringNotEmpty(value, text string) error{ - if value != ""{ +func ValidateStringNotEmpty(value, text string) error { + if value != "" { return nil } return ErrorKeyEmpty(text) } -func ValidateStringsEqual(value1, value2, text string) error{ - if value1 == value2{ +// check if a key is allowd to be changed after creation. +func ValidateStringsEqual(value1, value2, text string) error { + if value1 == value2 { return nil } return fmt.Errorf("error the value of key (%s) may not be changed during update", text) @@ -56,7 +57,7 @@ func ValidateFilePath(path, text string) error { if err != nil { return err } - if filepath.IsAbs(path){ + if filepath.IsAbs(path) { return nil } return fmt.Errorf("error the value of key (%s) is not a valid file absolute path", text) @@ -69,18 +70,18 @@ func ValidateArrayNotEmpty(array interface{}, text string) error { return ErrorKeyEmpty(text) } -func ErrorKeyEmpty(text string) error { +func ErrorKeyEmpty(text string) error { return fmt.Errorf("error the value of key (%s) may not be empty", text) } -func ErrorKeyNotSet(text string) error { +func ErrorKeyNotSet(text string) error { return fmt.Errorf("error the key (%s) must be set", text) } -func ErrorItemExists(item ,text string) error { +func ErrorItemExists(item, text string) error { return fmt.Errorf("error %s with id ( %s ) already exists", text, item) } -func ErrorItemNotExists(item ,text string) error { +func ErrorItemNotExists(item, text string) error { return fmt.Errorf("error %s with id ( %s ) does not exist", text, item) -} \ No newline at end of file +} diff --git a/test/cli/Storage/Storage_CephFS_0_test.go b/test/cli/Storage/Storage_CephFS_0_test.go new file mode 100644 index 00000000..19700445 --- /dev/null +++ b/test/cli/Storage/Storage_CephFS_0_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_CephFS_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("cephfs-test-0", t) +} + +func Test_Storage_CephFS_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.CephfsFull) + storagesubtests.Create(s, "cephfs-test-0", t) +} + +func Test_Storage_CephFS_0_Get_Full(t *testing.T) { + storagesubtests.CephfsGetFull("cephfs-test-0", t) +} + +func Test_Storage_CephFS_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.CephfsEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Update(s, "cephfs-test-0", t) +} + +func Test_Storage_CephFS_0_Get_Empty(t *testing.T) { + storagesubtests.CephfsGetEmpty("cephfs-test-0", t) +} + +func Test_Storage_CephFS_0_Delete(t *testing.T) { + storagesubtests.Delete("cephfs-test-0", t) +} diff --git a/test/cli/Storage/Storage_CephFS_1_test.go b/test/cli/Storage/Storage_CephFS_1_test.go new file mode 100644 index 00000000..141ddb92 --- /dev/null +++ b/test/cli/Storage/Storage_CephFS_1_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_CephFS_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("cephfs-test-1", t) +} + +func Test_Storage_CephFS_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.CephfsEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Create(s, "cephfs-test-1", t) +} + +func Test_Storage_CephFS_1_Get_Empty(t *testing.T) { + storagesubtests.CephfsGetEmpty("cephfs-test-1", t) +} + +func Test_Storage_CephFS_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.CephfsFull) + storagesubtests.Update(s, "cephfs-test-1", t) +} + +func Test_Storage_CephFS_1_Get_Full(t *testing.T) { + storagesubtests.CephfsGetFull("cephfs-test-1", t) +} + +func Test_Storage_CephFS_1_Delete(t *testing.T) { + storagesubtests.Delete("cephfs-test-1", t) +} diff --git a/test/cli/Storage/Storage_Directory_0_test.go b/test/cli/Storage/Storage_Directory_0_test.go new file mode 100644 index 00000000..d31ca081 --- /dev/null +++ b/test/cli/Storage/Storage_Directory_0_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_Directory_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("directory-test-0", t) +} + +func Test_Storage_Directory_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.DirectoryFull) + storagesubtests.Create(s, "directory-test-0", t) +} + +func Test_Storage_Directory_0_Get_Full(t *testing.T) { + storagesubtests.DirectoryGetFull("directory-test-0", t) +} + +func Test_Storage_Directory_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.DirectoryEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Update(s, "directory-test-0", t) +} + +func Test_Storage_Directory_0_Get_Empty(t *testing.T) { + storagesubtests.DirectoryGetEmpty("directory-test-0", t) +} + +func Test_Storage_Directory_0_Delete(t *testing.T) { + storagesubtests.Delete("directory-test-0", t) +} diff --git a/test/cli/Storage/Storage_Directory_1_test.go b/test/cli/Storage/Storage_Directory_1_test.go new file mode 100644 index 00000000..4ce439e3 --- /dev/null +++ b/test/cli/Storage/Storage_Directory_1_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_Directory_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("directory-test-1", t) +} + +func Test_Storage_Directory_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.DirectoryEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Create(s, "directory-test-1", t) +} + +func Test_Storage_Directory_1_Get_Empty(t *testing.T) { + storagesubtests.DirectoryGetEmpty("directory-test-1", t) +} + +func Test_Storage_Directory_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.DirectoryFull) + storagesubtests.Update(s, "directory-test-1", t) +} + +func Test_Storage_Directory_1_Get_Full(t *testing.T) { + storagesubtests.DirectoryGetFull("directory-test-1", t) +} + +func Test_Storage_Directory_1_Delete(t *testing.T) { + storagesubtests.Delete("directory-test-1", t) +} diff --git a/test/cli/Storage/Storage_GlusterFS_0_test.go b/test/cli/Storage/Storage_GlusterFS_0_test.go new file mode 100644 index 00000000..7e50e320 --- /dev/null +++ b/test/cli/Storage/Storage_GlusterFS_0_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_GlusterFS_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("glusterfs-test-0", t) +} + +func Test_Storage_GlusterFS_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.GlusterfsFull) + storagesubtests.Create(s, "glusterfs-test-0", t) +} + +func Test_Storage_GlusterFS_0_Get_Full(t *testing.T) { + storagesubtests.GlusterfsGetFull("glusterfs-test-0", t) +} + +func Test_Storage_GlusterFS_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.GlusterfsEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Update(s, "glusterfs-test-0", t) +} + +func Test_Storage_GlusterFS_0_Get_Empty(t *testing.T) { + storagesubtests.GlusterfsGetEmpty("glusterfs-test-0", t) +} + +func Test_Storage_GlusterFS_0_Delete(t *testing.T) { + storagesubtests.Delete("glusterfs-test-0", t) +} diff --git a/test/cli/Storage/Storage_GlusterFS_1_test.go b/test/cli/Storage/Storage_GlusterFS_1_test.go new file mode 100644 index 00000000..a928756a --- /dev/null +++ b/test/cli/Storage/Storage_GlusterFS_1_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_GlusterFS_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("glusterfs-test-1", t) +} + +func Test_Storage_GlusterFS_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.GlusterfsEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Create(s, "glusterfs-test-1", t) +} + +func Test_Storage_GlusterFS_1_Get_Empty(t *testing.T) { + storagesubtests.GlusterfsGetEmpty("glusterfs-test-1", t) +} + +func Test_Storage_GlusterFS_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.GlusterfsFull) + storagesubtests.Update(s, "glusterfs-test-1", t) +} + +func Test_Storage_GlusterFS_1_Get_Full(t *testing.T) { + storagesubtests.GlusterfsGetFull("glusterfs-test-1", t) +} + +func Test_Storage_GlusterFS_1_Delete(t *testing.T) { + storagesubtests.Delete("glusterfs-test-1", t) +} diff --git a/test/cli/Storage/Storage_ISCSI_0_test.go b/test/cli/Storage/Storage_ISCSI_0_test.go new file mode 100644 index 00000000..46848c89 --- /dev/null +++ b/test/cli/Storage/Storage_ISCSI_0_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ISCSI_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("iscsi-test-0", t) +} + +func Test_Storage_ISCSI_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.IscsiFull) + storagesubtests.Create(s, "iscsi-test-0", t) +} + +func Test_Storage_ISCSI_0_Get_Full(t *testing.T) { + storagesubtests.IscsiGetFull("iscsi-test-0", t) +} + +func Test_Storage_ISCSI_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.IscsiEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Update(s, "iscsi-test-0", t) +} + +func Test_Storage_ISCSI_0_Get_Empty(t *testing.T) { + storagesubtests.IscsiGetEmpty("iscsi-test-0", t) +} + +func Test_Storage_ISCSI_0_Delete(t *testing.T) { + storagesubtests.Delete("iscsi-test-0", t) +} diff --git a/test/cli/Storage/Storage_ISCSI_1_test.go b/test/cli/Storage/Storage_ISCSI_1_test.go new file mode 100644 index 00000000..37381a9d --- /dev/null +++ b/test/cli/Storage/Storage_ISCSI_1_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ISCSI_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("iscsi-test-1", t) +} + +func Test_Storage_ISCSI_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.IscsiEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Create(s, "iscsi-test-1", t) +} + +func Test_Storage_ISCSI_1_Get_Empty(t *testing.T) { + storagesubtests.IscsiGetEmpty("iscsi-test-1", t) +} + +func Test_Storage_ISCSI_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.IscsiFull) + storagesubtests.Update(s, "iscsi-test-1", t) +} + +func Test_Storage_ISCSI_1_Get_Full(t *testing.T) { + storagesubtests.IscsiGetFull("iscsi-test-1", t) +} + +func Test_Storage_ISCSI_1_Delete(t *testing.T) { + storagesubtests.Delete("iscsi-test-1", t) +} diff --git a/test/cli/Storage/Storage_LVM-Thin_0_test.go b/test/cli/Storage/Storage_LVM-Thin_0_test.go new file mode 100644 index 00000000..1475d495 --- /dev/null +++ b/test/cli/Storage/Storage_LVM-Thin_0_test.go @@ -0,0 +1,34 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_LVMThin_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("lvm-thin-test-0", t) +} + +func Test_Storage_LVMThin_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.LVMThinFull) + storagesubtests.Create(s, "lvm-thin-test-0", t) +} + +func Test_Storage_LVMThin_0_Get_Full(t *testing.T) { + storagesubtests.LVMThinGetFull("lvm-thin-test-0", t) +} + +func Test_Storage_LVMThin_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.LVMThinEmpty) + storagesubtests.Update(s, "lvm-thin-test-0", t) +} + +func Test_Storage_LVMThin_0_Get_Empty(t *testing.T) { + storagesubtests.LVMThinGetEmpty("lvm-thin-test-0", t) +} + +func Test_Storage_LVMThin_0_Delete(t *testing.T) { + storagesubtests.Delete("lvm-thin-test-0", t) +} diff --git a/test/cli/Storage/Storage_LVM-Thin_1_test.go b/test/cli/Storage/Storage_LVM-Thin_1_test.go new file mode 100644 index 00000000..bf0a48cc --- /dev/null +++ b/test/cli/Storage/Storage_LVM-Thin_1_test.go @@ -0,0 +1,34 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_LVMThin_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("lvm-thin-test-1", t) +} + +func Test_Storage_LVMThin_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.LVMThinEmpty) + storagesubtests.Create(s, "lvm-thin-test-1", t) +} + +func Test_Storage_LVMThin_1_Get_Empty(t *testing.T) { + storagesubtests.LVMThinGetEmpty("lvm-thin-test-1", t) +} + +func Test_Storage_LVMThin_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.LVMThinFull) + storagesubtests.Update(s, "lvm-thin-test-1", t) +} + +func Test_Storage_LVMThin_1_Get_Full(t *testing.T) { + storagesubtests.LVMThinGetFull("lvm-thin-test-1", t) +} + +func Test_Storage_LVMThin_1_Delete(t *testing.T) { + storagesubtests.Delete("lvm-thin-test-1", t) +} diff --git a/test/cli/Storage/Storage_LVM_0_test.go b/test/cli/Storage/Storage_LVM_0_test.go new file mode 100644 index 00000000..f463c9dd --- /dev/null +++ b/test/cli/Storage/Storage_LVM_0_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_LVM_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("lvm-test-0", t) +} + +func Test_Storage_LVM_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.LVMFull) + storagesubtests.Create(s, "lvm-test-0", t) +} + +func Test_Storage_LVM_0_Get_Full(t *testing.T) { + storagesubtests.LVMGetFull("lvm-test-0", t) +} + +func Test_Storage_LVM_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.LVMEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Update(s, "lvm-test-0", t) +} + +func Test_Storage_LVM_0_Get_Empty(t *testing.T) { + storagesubtests.LVMGetEmpty("lvm-test-0", t) +} + +func Test_Storage_LVM_0_Delete(t *testing.T) { + storagesubtests.Delete("lvm-test-0", t) +} diff --git a/test/cli/Storage/Storage_LVM_1_test.go b/test/cli/Storage/Storage_LVM_1_test.go new file mode 100644 index 00000000..7af38dfb --- /dev/null +++ b/test/cli/Storage/Storage_LVM_1_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_LVM_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("lvm-test-1", t) +} + +func Test_Storage_LVM_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.LVMEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Create(s, "lvm-test-1", t) +} + +func Test_Storage_LVM_1_Get_Empty(t *testing.T) { + storagesubtests.LVMGetEmpty("lvm-test-1", t) +} + +func Test_Storage_LVM_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.LVMFull) + storagesubtests.Update(s, "lvm-test-1", t) +} + +func Test_Storage_LVM_1_Get_Full(t *testing.T) { + storagesubtests.LVMGetFull("lvm-test-1", t) +} + +func Test_Storage_LVM_1_Delete(t *testing.T) { + storagesubtests.Delete("lvm-test-1", t) +} diff --git a/test/cli/Storage/Storage_NFS_0_test.go b/test/cli/Storage/Storage_NFS_0_test.go new file mode 100644 index 00000000..4ce23c43 --- /dev/null +++ b/test/cli/Storage/Storage_NFS_0_test.go @@ -0,0 +1,38 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + cliTest "github.com/Telmate/proxmox-api-go/test/cli" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_NFS_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("nfs-test-0", t) +} + +func Test_Storage_NFS_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.NFSFull) + storagesubtests.Create(s, "nfs-test-0", t) +} + +func Test_Storage_NFS_0_Get_Full(t *testing.T) { + storagesubtests.NFSGetFull("nfs-test-0", t) +} + +func Test_Storage_NFS_0_Update_Empty(t *testing.T) { + cliTest.SetEnvironmentVariables() + s := storagesubtests.CloneJson(storagesubtests.NFSEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Update(s, "nfs-test-0", t) +} + +func Test_Storage_NFS_0_Get_Empty(t *testing.T) { + storagesubtests.NFSGetEmpty("nfs-test-0", t) +} + +func Test_Storage_NFS_0_Delete(t *testing.T) { + storagesubtests.Delete("nfs-test-0", t) +} diff --git a/test/cli/Storage/Storage_NFS_1_test.go b/test/cli/Storage/Storage_NFS_1_test.go new file mode 100644 index 00000000..d277e7f2 --- /dev/null +++ b/test/cli/Storage/Storage_NFS_1_test.go @@ -0,0 +1,38 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + cliTest "github.com/Telmate/proxmox-api-go/test/cli" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_NFS_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("nfs-test-1", t) +} + +func Test_Storage_NFS_1_Create_Empty(t *testing.T) { + cliTest.SetEnvironmentVariables() + s := storagesubtests.CloneJson(storagesubtests.NFSEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Create(s, "nfs-test-1", t) +} + +func Test_Storage_NFS_1_Get_Empty(t *testing.T) { + storagesubtests.NFSGetEmpty("nfs-test-1", t) +} + +func Test_Storage_NFS_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.NFSFull) + storagesubtests.Update(s, "nfs-test-1", t) +} + +func Test_Storage_NFS_1_Get_Full(t *testing.T) { + storagesubtests.NFSGetFull("nfs-test-1", t) +} + +func Test_Storage_NFS_1_Delete(t *testing.T) { + storagesubtests.Delete("nfs-test-1", t) +} diff --git a/test/cli/Storage/Storage_PBS_0_test.go b/test/cli/Storage/Storage_PBS_0_test.go new file mode 100644 index 00000000..ad760447 --- /dev/null +++ b/test/cli/Storage/Storage_PBS_0_test.go @@ -0,0 +1,49 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_PBS_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("pbs-test-0", t) +} + +func Test_Storage_PBS_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.PBSFull) + s.PBS.Password = proxmox.PointerString("Enter123!") + s.PBS.Namespace = "test" + storagesubtests.Create(s, "pbs-test-0", t) +} + +func Test_Storage_PBS_0_Get_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.PBSFull) + s.ID = "pbs-test-0" + s.PBS.Namespace = "test" + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_PBS_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.PBSEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + s.PBS.Namespace = "/test" + storagesubtests.Update(s, "pbs-test-0", t) +} + +func Test_Storage_PBS_0_Get_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.PBSEmpty) + s.ID = "pbs-test-0" + s.PBS.Port = proxmox.PointerInt(8007) + s.PBS.Namespace = "test" + s.Content = &proxmox.ConfigStorageContent{ + Backup: proxmox.PointerBool(true), + } + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_PBS_0_Delete(t *testing.T) { + storagesubtests.Delete("pbs-test-0", t) +} diff --git a/test/cli/Storage/Storage_PBS_1_test.go b/test/cli/Storage/Storage_PBS_1_test.go new file mode 100644 index 00000000..57751e61 --- /dev/null +++ b/test/cli/Storage/Storage_PBS_1_test.go @@ -0,0 +1,45 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_PBS_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("pbs-test-1", t) +} + +func Test_Storage_PBS_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.PBSEmpty) + s.PBS.Password = proxmox.PointerString("Enter123!") + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Create(s, "pbs-test-1", t) +} + +func Test_Storage_PBS_1_Get_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.PBSEmpty) + s.ID = "pbs-test-1" + s.PBS.Port = proxmox.PointerInt(8007) + s.Content = &proxmox.ConfigStorageContent{ + Backup: proxmox.PointerBool(true), + } + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_PBS_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.PBSFull) + storagesubtests.Update(s, "pbs-test-1", t) +} + +func Test_Storage_PBS_1_Get_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.PBSFull) + s.ID = "pbs-test-1" + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_PBS_1_Delete(t *testing.T) { + storagesubtests.Delete("pbs-test-1", t) +} diff --git a/test/cli/Storage/Storage_RBD_0_test.go b/test/cli/Storage/Storage_RBD_0_test.go new file mode 100644 index 00000000..c32328a1 --- /dev/null +++ b/test/cli/Storage/Storage_RBD_0_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_RBD_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("rbd-test-0", t) +} + +func Test_Storage_RBD_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.RBDFull) + s.RBD.Keyring = proxmox.PointerString("keyringplaceholder") + storagesubtests.Create(s, "rbd-test-0", t) +} + +func Test_Storage_RBD_0_Get_Full(t *testing.T) { + storagesubtests.RBDGetFull("rbd-test-0", t) +} + +func Test_Storage_RBD_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.RBDEmpty) + storagesubtests.Update(s, "rbd-test-0", t) +} + +func Test_Storage_RBD_0_Get_Empty(t *testing.T) { + storagesubtests.RBDGetEmpty("rbd-test-0", t) +} + +func Test_Storage_RBD_0_Delete(t *testing.T) { + storagesubtests.Delete("rbd-test-0", t) +} diff --git a/test/cli/Storage/Storage_RBD_1_test.go b/test/cli/Storage/Storage_RBD_1_test.go new file mode 100644 index 00000000..36da8ea8 --- /dev/null +++ b/test/cli/Storage/Storage_RBD_1_test.go @@ -0,0 +1,36 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_RBD_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("rbd-test-1", t) +} + +func Test_Storage_RBD_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.RBDEmpty) + s.RBD.Keyring = proxmox.PointerString("keyringplaceholder") + storagesubtests.Create(s, "rbd-test-1", t) +} + +func Test_Storage_RBD_1_Get_Empty(t *testing.T) { + storagesubtests.RBDGetEmpty("rbd-test-1", t) +} + +func Test_Storage_RBD_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.RBDFull) + storagesubtests.Update(s, "rbd-test-1", t) +} + +func Test_Storage_RBD_1_Get_Full(t *testing.T) { + storagesubtests.RBDGetFull("rbd-test-1", t) +} + +func Test_Storage_RBD_1_Delete(t *testing.T) { + storagesubtests.Delete("rbd-test-1", t) +} diff --git a/test/cli/Storage/Storage_SMB_0_test.go b/test/cli/Storage/Storage_SMB_0_test.go new file mode 100644 index 00000000..4d0aa74f --- /dev/null +++ b/test/cli/Storage/Storage_SMB_0_test.go @@ -0,0 +1,39 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + cliTest "github.com/Telmate/proxmox-api-go/test/cli" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_SMB_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("smb-test-0", t) +} + +func Test_Storage_SMB_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.SMBFull) + s.SMB.Password = proxmox.PointerString("Enter123!") + storagesubtests.Create(s, "smb-test-0", t) +} + +func Test_Storage_SMB_0_Get_Full(t *testing.T) { + storagesubtests.SMBGetFull("smb-test-0", t) +} + +func Test_Storage_SMB_0_Update_Empty(t *testing.T) { + cliTest.SetEnvironmentVariables() + s := storagesubtests.CloneJson(storagesubtests.SMBEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Update(s, "smb-test-0", t) +} + +func Test_Storage_SMB_0_Get_Empty(t *testing.T) { + storagesubtests.SMBGetEmpty("smb-test-0", t) +} + +func Test_Storage_SMB_0_Delete(t *testing.T) { + storagesubtests.Delete("smb-test-0", t) +} diff --git a/test/cli/Storage/Storage_SMB_1_test.go b/test/cli/Storage/Storage_SMB_1_test.go new file mode 100644 index 00000000..0f870af4 --- /dev/null +++ b/test/cli/Storage/Storage_SMB_1_test.go @@ -0,0 +1,37 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_SMB_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("smb-test-1", t) +} + +func Test_Storage_SMB_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.SMBEmpty) + s.BackupRetention = &proxmox.ConfigStorageBackupRetention{} + storagesubtests.Create(s, "smb-test-1", t) +} + +func Test_Storage_SMB_1_Get_Empty(t *testing.T) { + storagesubtests.SMBGetEmpty("smb-test-1", t) +} + +func Test_Storage_SMB_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.SMBFull) + s.SMB.Password = proxmox.PointerString("Enter123!") + storagesubtests.Update(s, "smb-test-1", t) +} + +func Test_Storage_SMB_1_Get_Full(t *testing.T) { + storagesubtests.SMBGetFull("smb-test-1", t) +} + +func Test_Storage_SMB_1_Delete(t *testing.T) { + storagesubtests.Delete("smb-test-1", t) +} diff --git a/test/cli/Storage/Storage_ZFS-over-ISCSI_0_test.go b/test/cli/Storage/Storage_ZFS-over-ISCSI_0_test.go new file mode 100644 index 00000000..552f94ee --- /dev/null +++ b/test/cli/Storage/Storage_ZFS-over-ISCSI_0_test.go @@ -0,0 +1,44 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ZFSoverISCSI_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("zfs-over-iscsi-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSIFull) + storagesubtests.Create(s, "zfs-over-iscsi-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_0_Get_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSIFull) + s.ID = "zfs-over-iscsi-test-0" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("8k") + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSIEmpty) + storagesubtests.Update(s, "zfs-over-iscsi-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_0_Get_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSIEmpty) + s.ID = "zfs-over-iscsi-test-0" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("8k") + s.Content = &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + } + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_0_Delete(t *testing.T) { + storagesubtests.Delete("zfs-over-iscsi-test-0", t) +} diff --git a/test/cli/Storage/Storage_ZFS-over-ISCSI_1_test.go b/test/cli/Storage/Storage_ZFS-over-ISCSI_1_test.go new file mode 100644 index 00000000..16879abf --- /dev/null +++ b/test/cli/Storage/Storage_ZFS-over-ISCSI_1_test.go @@ -0,0 +1,44 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ZFSoverISCSI_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("zfs-over-iscsi-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSIEmpty) + storagesubtests.Create(s, "zfs-over-iscsi-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_1_Get_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSIEmpty) + s.ID = "zfs-over-iscsi-test-1" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("4k") + s.Content = &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + } + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSIFull) + storagesubtests.Update(s, "zfs-over-iscsi-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_1_Get_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSIFull) + s.ID = "zfs-over-iscsi-test-1" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("4k") + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_1_Delete(t *testing.T) { + storagesubtests.Delete("zfs-over-iscsi-test-1", t) +} diff --git a/test/cli/Storage/Storage_ZFS-over-ISCSI_Comstar_0_test.go b/test/cli/Storage/Storage_ZFS-over-ISCSI_Comstar_0_test.go new file mode 100644 index 00000000..a5dc3b6a --- /dev/null +++ b/test/cli/Storage/Storage_ZFS-over-ISCSI_Comstar_0_test.go @@ -0,0 +1,50 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ZFSoverISCSI_Comstar_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("zfs-over-iscsi_comstar-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_Comstar_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_ComstarFull) + storagesubtests.Create(s, "zfs-over-iscsi_comstar-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_Comstar_0_Get_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_ComstarFull) + s.ID = "zfs-over-iscsi_comstar-test-0" + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Comstar_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_ComstarEmpty) + s.ZFSoverISCSI.Comstar.HostGroup = "h-group" + s.ZFSoverISCSI.Comstar.TargetGroup = "t-group" + storagesubtests.Update(s, "zfs-over-iscsi_comstar-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_Comstar_0_Get_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_ComstarEmpty) + s.ID = "zfs-over-iscsi_comstar-test-0" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("8k") + s.ZFSoverISCSI.Comstar = &proxmox.ConfigStorageZFSoverISCSI_Comstar{ + TargetGroup: "t-group", + HostGroup: "h-group", + Writecache: false, + } + s.Content = &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + } + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Comstar_0_Delete(t *testing.T) { + storagesubtests.Delete("zfs-over-iscsi_comstar-test-0", t) +} diff --git a/test/cli/Storage/Storage_ZFS-over-ISCSI_Comstar_1_test.go b/test/cli/Storage/Storage_ZFS-over-ISCSI_Comstar_1_test.go new file mode 100644 index 00000000..3048e1c1 --- /dev/null +++ b/test/cli/Storage/Storage_ZFS-over-ISCSI_Comstar_1_test.go @@ -0,0 +1,54 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ZFSoverISCSI_Comstar_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("zfs-over-iscsi_comstar-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_Comstar_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_ComstarEmpty) + s.ZFSoverISCSI.Comstar = &proxmox.ConfigStorageZFSoverISCSI_Comstar{} + storagesubtests.Create(s, "zfs-over-iscsi_comstar-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_Comstar_1_Get_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_ComstarEmpty) + s.ID = "zfs-over-iscsi_comstar-test-1" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("4k") + s.ZFSoverISCSI.Comstar = &proxmox.ConfigStorageZFSoverISCSI_Comstar{ + TargetGroup: "", + HostGroup: "", + Writecache: true, + } + s.Content = &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + } + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Comstar_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_ComstarFull) + s.ZFSoverISCSI.Comstar.HostGroup = "" + s.ZFSoverISCSI.Comstar.TargetGroup = "" + storagesubtests.Update(s, "zfs-over-iscsi_comstar-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_Comstar_1_Get_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_ComstarFull) + s.ID = "zfs-over-iscsi_comstar-test-1" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("4k") + s.ZFSoverISCSI.Comstar.HostGroup = "" + s.ZFSoverISCSI.Comstar.TargetGroup = "" + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Comstar_1_Delete(t *testing.T) { + storagesubtests.Delete("zfs-over-iscsi_comstar-test-1", t) +} diff --git a/test/cli/Storage/Storage_ZFS-over-ISCSI_Istgt_0_test.go b/test/cli/Storage/Storage_ZFS-over-ISCSI_Istgt_0_test.go new file mode 100644 index 00000000..e8f3970e --- /dev/null +++ b/test/cli/Storage/Storage_ZFS-over-ISCSI_Istgt_0_test.go @@ -0,0 +1,43 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ZFSoverISCSI_Istgt_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("zfs-over-iscsi_istgt-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_Istgt_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_IstgtFull) + storagesubtests.Create(s, "zfs-over-iscsi_istgt-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_Istgt_0_Get_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_IstgtFull) + s.ID = "zfs-over-iscsi_istgt-test-0" + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Istgt_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_IstgtEmpty) + storagesubtests.Update(s, "zfs-over-iscsi_istgt-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_Istgt_0_Get_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_IstgtEmpty) + s.ID = "zfs-over-iscsi_istgt-test-0" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("8k") + s.Content = &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + } + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Istgt_0_Delete(t *testing.T) { + storagesubtests.Delete("zfs-over-iscsi_istgt-test-0", t) +} diff --git a/test/cli/Storage/Storage_ZFS-over-ISCSI_Istgt_1_test.go b/test/cli/Storage/Storage_ZFS-over-ISCSI_Istgt_1_test.go new file mode 100644 index 00000000..c5a301a4 --- /dev/null +++ b/test/cli/Storage/Storage_ZFS-over-ISCSI_Istgt_1_test.go @@ -0,0 +1,45 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ZFSoverISCSI_Istgt_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("zfs-over-iscsi_istgt-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_Istgt_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_IstgtEmpty) + s.ZFSoverISCSI.Comstar = &proxmox.ConfigStorageZFSoverISCSI_Comstar{} + storagesubtests.Create(s, "zfs-over-iscsi_istgt-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_Istgt_1_Get_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_IstgtEmpty) + s.ID = "zfs-over-iscsi_istgt-test-1" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("4k") + s.Content = &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + } + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Istgt_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_IstgtFull) + storagesubtests.Update(s, "zfs-over-iscsi_istgt-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_Istgt_1_Get_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_IstgtFull) + s.ID = "zfs-over-iscsi_istgt-test-1" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("4k") + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Istgt_1_Delete(t *testing.T) { + storagesubtests.Delete("zfs-over-iscsi_istgt-test-1", t) +} diff --git a/test/cli/Storage/Storage_ZFS-over-ISCSI_LIO_0_test.go b/test/cli/Storage/Storage_ZFS-over-ISCSI_LIO_0_test.go new file mode 100644 index 00000000..01c8548a --- /dev/null +++ b/test/cli/Storage/Storage_ZFS-over-ISCSI_LIO_0_test.go @@ -0,0 +1,43 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ZFSoverISCSI_Lio_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("zfs-over-iscsi_lio-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_Lio_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_LioFull) + storagesubtests.Create(s, "zfs-over-iscsi_lio-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_Lio_0_Get_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_LioFull) + s.ID = "zfs-over-iscsi_lio-test-0" + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Lio_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_LioEmpty) + storagesubtests.Update(s, "zfs-over-iscsi_lio-test-0", t) +} + +func Test_Storage_ZFSoverISCSI_Lio_0_Get_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_LioEmpty) + s.ID = "zfs-over-iscsi_lio-test-0" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("8k") + s.Content = &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + } + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Lio_0_Delete(t *testing.T) { + storagesubtests.Delete("zfs-over-iscsi_lio-test-0", t) +} diff --git a/test/cli/Storage/Storage_ZFS-over-ISCSI_LIO_1_test.go b/test/cli/Storage/Storage_ZFS-over-ISCSI_LIO_1_test.go new file mode 100644 index 00000000..576763c0 --- /dev/null +++ b/test/cli/Storage/Storage_ZFS-over-ISCSI_LIO_1_test.go @@ -0,0 +1,45 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ZFSoverISCSI_Lio_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("zfs-over-iscsi_lio-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_Lio_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_LioEmpty) + s.ZFSoverISCSI.Comstar = &proxmox.ConfigStorageZFSoverISCSI_Comstar{} + storagesubtests.Create(s, "zfs-over-iscsi_lio-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_Lio_1_Get_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_LioEmpty) + s.ID = "zfs-over-iscsi_lio-test-1" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("4k") + s.Content = &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + } + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Lio_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_LioFull) + storagesubtests.Update(s, "zfs-over-iscsi_lio-test-1", t) +} + +func Test_Storage_ZFSoverISCSI_Lio_1_Get_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSoverISCSI_LioFull) + s.ID = "zfs-over-iscsi_lio-test-1" + s.ZFSoverISCSI.Blocksize = proxmox.PointerString("4k") + storagesubtests.Get(s, s.ID, t) +} + +func Test_Storage_ZFSoverISCSI_Lio_1_Delete(t *testing.T) { + storagesubtests.Delete("zfs-over-iscsi_lio-test-1", t) +} diff --git a/test/cli/Storage/Storage_ZFS_0_test.go b/test/cli/Storage/Storage_ZFS_0_test.go new file mode 100644 index 00000000..e08405b6 --- /dev/null +++ b/test/cli/Storage/Storage_ZFS_0_test.go @@ -0,0 +1,34 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ZFS_0_Cleanup(t *testing.T) { + storagesubtests.Cleanup("zfs-test-0", t) +} + +func Test_Storage_ZFS_0_Create_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSFull) + storagesubtests.Create(s, "zfs-test-0", t) +} + +func Test_Storage_ZFS_0_Get_Full(t *testing.T) { + storagesubtests.ZFSGetFull("zfs-test-0", t) +} + +func Test_Storage_ZFS_0_Update_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSEmpty) + storagesubtests.Update(s, "zfs-test-0", t) +} + +func Test_Storage_ZFS_0_Get_Empty(t *testing.T) { + storagesubtests.ZFSGetEmpty("zfs-test-0", t) +} + +func Test_Storage_ZFS_0_Delete(t *testing.T) { + storagesubtests.Delete("zfs-test-0", t) +} diff --git a/test/cli/Storage/Storage_ZFS_1_test.go b/test/cli/Storage/Storage_ZFS_1_test.go new file mode 100644 index 00000000..b1855123 --- /dev/null +++ b/test/cli/Storage/Storage_ZFS_1_test.go @@ -0,0 +1,34 @@ +package cli_storage_test + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + storagesubtests "github.com/Telmate/proxmox-api-go/test/cli/Storage/storage-sub-tests" +) + +func Test_Storage_ZFS_1_Cleanup(t *testing.T) { + storagesubtests.Cleanup("zfs-test-1", t) +} + +func Test_Storage_ZFS_1_Create_Empty(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSEmpty) + storagesubtests.Create(s, "zfs-test-1", t) +} + +func Test_Storage_ZFS_1_Get_Empty(t *testing.T) { + storagesubtests.ZFSGetEmpty("zfs-test-1", t) +} + +func Test_Storage_ZFS_1_Update_Full(t *testing.T) { + s := storagesubtests.CloneJson(storagesubtests.ZFSFull) + storagesubtests.Update(s, "zfs-test-1", t) +} + +func Test_Storage_ZFS_1_Get_Full(t *testing.T) { + storagesubtests.ZFSGetFull("zfs-test-1", t) +} + +func Test_Storage_ZFS_1_Delete(t *testing.T) { + storagesubtests.Delete("zfs-test-1", t) +} diff --git a/test/cli/Storage/storage-sub-tests/cephfs.go b/test/cli/Storage/storage-sub-tests/cephfs.go new file mode 100644 index 00000000..fd839393 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/cephfs.go @@ -0,0 +1,59 @@ +package storagesubtests + +import ( + "testing" + + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var CephfsFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "cephfs", + CephFS: &proxmox.ConfigStorageCephFS{ + Monitors: []string{"10.20.1.1", "10.20.1.2"}, + Username: "test-ceph-user", + FSname: "test-fs-name", + }, + Content: &proxmox.ConfigStorageContent{ + Backup: proxmox.PointerBool(true), + Iso: proxmox.PointerBool(true), + Snippets: proxmox.PointerBool(true), + Template: proxmox.PointerBool(true), + }, + BackupRetention: &proxmox.ConfigStorageBackupRetention{ + Last: proxmox.PointerInt(6), + Hourly: proxmox.PointerInt(5), + Daily: proxmox.PointerInt(4), + Monthly: proxmox.PointerInt(3), + Weekly: proxmox.PointerInt(2), + Yearly: proxmox.PointerInt(1), + }, +} + +var CephfsEmpty = proxmox.ConfigStorage{ + Type: "cephfs", + CephFS: &proxmox.ConfigStorageCephFS{ + Monitors: []string{"10.20.1.1"}, + Username: "test-ceph-user", + FSname: "test-fs-name", + }, + Content: &proxmox.ConfigStorageContent{ + Iso: proxmox.PointerBool(true), + }, +} + +func CephfsGetFull(name string, t *testing.T) { + s := CloneJson(CephfsFull) + s.ID = name + Get(s, name, t) +} + +func CephfsGetEmpty(name string, t *testing.T) { + s := CloneJson(CephfsEmpty) + s.ID = name + s.Content.Backup = proxmox.PointerBool(false) + s.Content.Snippets = proxmox.PointerBool(false) + s.Content.Template = proxmox.PointerBool(false) + Get(s, name, t) +} diff --git a/test/cli/Storage/storage-sub-tests/directory.go b/test/cli/Storage/storage-sub-tests/directory.go new file mode 100644 index 00000000..45d509e6 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/directory.go @@ -0,0 +1,62 @@ +package storagesubtests + +import ( + "testing" + + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var DirectoryFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "directory", + Directory: &proxmox.ConfigStorageDirectory{ + Path: "/test", + Preallocation: proxmox.PointerString("full"), + Shared: true, + }, + Content: &proxmox.ConfigStorageContent{ + Backup: proxmox.PointerBool(true), + Container: proxmox.PointerBool(true), + DiskImage: proxmox.PointerBool(true), + Iso: proxmox.PointerBool(true), + Snippets: proxmox.PointerBool(true), + Template: proxmox.PointerBool(true), + }, + BackupRetention: &proxmox.ConfigStorageBackupRetention{ + Last: proxmox.PointerInt(6), + Hourly: proxmox.PointerInt(5), + Daily: proxmox.PointerInt(4), + Monthly: proxmox.PointerInt(3), + Weekly: proxmox.PointerInt(2), + Yearly: proxmox.PointerInt(1), + }, +} + +var DirectoryEmpty = proxmox.ConfigStorage{ + Type: "directory", + Directory: &proxmox.ConfigStorageDirectory{ + Path: "/test", + }, + Content: &proxmox.ConfigStorageContent{ + Iso: proxmox.PointerBool(true), + }, +} + +func DirectoryGetFull(name string, t *testing.T) { + s := CloneJson(DirectoryFull) + s.ID = name + Get(s, name, t) +} + +func DirectoryGetEmpty(name string, t *testing.T) { + s := CloneJson(DirectoryEmpty) + s.ID = name + s.Directory.Preallocation = proxmox.PointerString("metadata") + s.Content.Backup = proxmox.PointerBool(false) + s.Content.Container = proxmox.PointerBool(false) + s.Content.DiskImage = proxmox.PointerBool(false) + s.Content.Snippets = proxmox.PointerBool(false) + s.Content.Template = proxmox.PointerBool(false) + Get(s, name, t) +} diff --git a/test/cli/Storage/storage-sub-tests/glusterfs.go b/test/cli/Storage/storage-sub-tests/glusterfs.go new file mode 100644 index 00000000..f860c1f1 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/glusterfs.go @@ -0,0 +1,62 @@ +package storagesubtests + +import ( + "testing" + + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var GlusterfsFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "glusterfs", + GlusterFS: &proxmox.ConfigStorageGlusterFS{ + Server1: "10.20.1.1", + Server2: "10.20.1.2", + Preallocation: proxmox.PointerString("full"), + Volume: "test", + }, + Content: &proxmox.ConfigStorageContent{ + Backup: proxmox.PointerBool(true), + DiskImage: proxmox.PointerBool(true), + Iso: proxmox.PointerBool(true), + Snippets: proxmox.PointerBool(true), + Template: proxmox.PointerBool(true), + }, + BackupRetention: &proxmox.ConfigStorageBackupRetention{ + Last: proxmox.PointerInt(6), + Hourly: proxmox.PointerInt(5), + Daily: proxmox.PointerInt(4), + Monthly: proxmox.PointerInt(3), + Weekly: proxmox.PointerInt(2), + Yearly: proxmox.PointerInt(1), + }, +} + +var GlusterfsEmpty = proxmox.ConfigStorage{ + Type: "glusterfs", + GlusterFS: &proxmox.ConfigStorageGlusterFS{ + Server1: "10.20.1.3", + Volume: "test", + }, + Content: &proxmox.ConfigStorageContent{ + Iso: proxmox.PointerBool(true), + }, +} + +func GlusterfsGetFull(name string, t *testing.T) { + s := CloneJson(GlusterfsFull) + s.ID = name + Get(s, name, t) +} + +func GlusterfsGetEmpty(name string, t *testing.T) { + s := CloneJson(GlusterfsEmpty) + s.ID = name + s.GlusterFS.Preallocation = proxmox.PointerString("metadata") + s.Content.Backup = proxmox.PointerBool(false) + s.Content.DiskImage = proxmox.PointerBool(false) + s.Content.Snippets = proxmox.PointerBool(false) + s.Content.Template = proxmox.PointerBool(false) + Get(s, name, t) +} diff --git a/test/cli/Storage/storage-sub-tests/iscsi.go b/test/cli/Storage/storage-sub-tests/iscsi.go new file mode 100644 index 00000000..500067dc --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/iscsi.go @@ -0,0 +1,42 @@ +package storagesubtests + +import ( + "testing" + + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var IscsiFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "iscsi", + ISCSI: &proxmox.ConfigStorageISCSI{ + Portal: "10.20.1.1", + Target: "target-volume", + }, + Content: &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + }, +} + +var IscsiEmpty = proxmox.ConfigStorage{ + Type: "iscsi", + ISCSI: &proxmox.ConfigStorageISCSI{ + Portal: "10.20.1.1", + Target: "target-volume", + }, + Content: &proxmox.ConfigStorageContent{}, +} + +func IscsiGetFull(name string, t *testing.T) { + s := CloneJson(IscsiFull) + s.ID = name + Get(s, name, t) +} + +func IscsiGetEmpty(name string, t *testing.T) { + s := CloneJson(IscsiEmpty) + s.ID = name + s.Content.DiskImage = proxmox.PointerBool(false) + Get(s, name, t) +} diff --git a/test/cli/Storage/storage-sub-tests/json.go b/test/cli/Storage/storage-sub-tests/json.go new file mode 100644 index 00000000..a4153a56 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/json.go @@ -0,0 +1,20 @@ +package storagesubtests + +import ( + "encoding/json" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" +) + +func CloneJson(jsonStruct proxmox.ConfigStorage) *proxmox.ConfigStorage { + s := &proxmox.ConfigStorage{} + ori, _ := json.Marshal(jsonStruct) + json.Unmarshal(ori, s) + return s +} + +func InlineMarshal(jsonStruct *proxmox.ConfigStorage) string { + j, _ := json.Marshal(jsonStruct) + return string(j) +} diff --git a/test/cli/Storage/storage-sub-tests/lvm-thin.go b/test/cli/Storage/storage-sub-tests/lvm-thin.go new file mode 100644 index 00000000..3092612e --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/lvm-thin.go @@ -0,0 +1,45 @@ +package storagesubtests + +import ( + "testing" + + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var LVMThinFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "lvm-thin", + LVMThin: &proxmox.ConfigStorageLVMThin{ + VGname: "pve", + Thinpool: "data", + }, + Content: &proxmox.ConfigStorageContent{ + Container: proxmox.PointerBool(true), + DiskImage: proxmox.PointerBool(true), + }, +} + +var LVMThinEmpty = proxmox.ConfigStorage{ + Type: "lvm-thin", + LVMThin: &proxmox.ConfigStorageLVMThin{ + VGname: "pve", + Thinpool: "data", + }, + Content: &proxmox.ConfigStorageContent{ + Container: proxmox.PointerBool(true), + }, +} + +func LVMThinGetFull(name string, t *testing.T) { + s := CloneJson(LVMThinFull) + s.ID = name + Get(s, name, t) +} + +func LVMThinGetEmpty(name string, t *testing.T) { + s := CloneJson(LVMThinEmpty) + s.ID = name + s.Content.DiskImage = proxmox.PointerBool(false) + Get(s, name, t) +} diff --git a/test/cli/Storage/storage-sub-tests/lvm.go b/test/cli/Storage/storage-sub-tests/lvm.go new file mode 100644 index 00000000..1076ba22 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/lvm.go @@ -0,0 +1,44 @@ +package storagesubtests + +import ( + "testing" + + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var LVMFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "lvm", + LVM: &proxmox.ConfigStorageLVM{ + VGname: "TestVolumeGroup", + Shared: true, + }, + Content: &proxmox.ConfigStorageContent{ + Container: proxmox.PointerBool(true), + DiskImage: proxmox.PointerBool(true), + }, +} + +var LVMEmpty = proxmox.ConfigStorage{ + Type: "lvm", + LVM: &proxmox.ConfigStorageLVM{ + VGname: "TestVolumeGroup", + }, + Content: &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + }, +} + +func LVMGetFull(name string, t *testing.T) { + s := CloneJson(LVMFull) + s.ID = name + Get(s, name, t) +} + +func LVMGetEmpty(name string, t *testing.T) { + s := CloneJson(LVMEmpty) + s.ID = name + s.Content.Container = proxmox.PointerBool(false) + Get(s, name, t) +} diff --git a/test/cli/Storage/storage-sub-tests/nfs.go b/test/cli/Storage/storage-sub-tests/nfs.go new file mode 100644 index 00000000..1b032301 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/nfs.go @@ -0,0 +1,64 @@ +package storagesubtests + +import ( + "testing" + + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var NFSFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "nfs", + NFS: &proxmox.ConfigStorageNFS{ + Server: "10.20.1.1", + Export: "/exports", + Preallocation: proxmox.PointerString("full"), + Version: proxmox.PointerString("4"), + }, + Content: &proxmox.ConfigStorageContent{ + Backup: proxmox.PointerBool(true), + Container: proxmox.PointerBool(true), + DiskImage: proxmox.PointerBool(true), + Iso: proxmox.PointerBool(true), + Snippets: proxmox.PointerBool(true), + Template: proxmox.PointerBool(true), + }, + BackupRetention: &proxmox.ConfigStorageBackupRetention{ + Last: proxmox.PointerInt(6), + Hourly: proxmox.PointerInt(5), + Daily: proxmox.PointerInt(4), + Monthly: proxmox.PointerInt(3), + Weekly: proxmox.PointerInt(2), + Yearly: proxmox.PointerInt(1), + }, +} + +var NFSEmpty = proxmox.ConfigStorage{ + Type: "nfs", + NFS: &proxmox.ConfigStorageNFS{ + Server: "10.20.1.1", + Export: "/exports", + }, + Content: &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + }, +} + +func NFSGetFull(name string, t *testing.T) { + s := CloneJson(NFSFull) + s.ID = name + Get(s, name, t) +} + +func NFSGetEmpty(name string, t *testing.T) { + s := CloneJson(NFSEmpty) + s.ID = name + s.NFS.Preallocation = proxmox.PointerString("metadata") + s.Content.Backup = proxmox.PointerBool(false) + s.Content.Container = proxmox.PointerBool(false) + s.Content.Snippets = proxmox.PointerBool(false) + s.Content.Iso = proxmox.PointerBool(false) + s.Content.Template = proxmox.PointerBool(false) + Get(s, name, t) +} diff --git a/test/cli/Storage/storage-sub-tests/pbs.go b/test/cli/Storage/storage-sub-tests/pbs.go new file mode 100644 index 00000000..80a320bb --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/pbs.go @@ -0,0 +1,38 @@ +package storagesubtests + +import ( + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var PBSFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "pbs", + PBS: &proxmox.ConfigStoragePBS{ + Server: "10.20.1.1", + Datastore: "proxmox", + Username: "root@pam", + Fingerprint: "B7:BC:55:10:CC:1C:63:7B:5E:5F:B7:85:81:6A:77:3D:BB:39:4B:68:33:7B:1B:11:7C:A5:AB:43:CC:F7:78:CF", + Port: proxmox.PointerInt(8007), + }, + Content: &proxmox.ConfigStorageContent{ + Backup: proxmox.PointerBool(true), + }, + BackupRetention: &proxmox.ConfigStorageBackupRetention{ + Last: proxmox.PointerInt(6), + Hourly: proxmox.PointerInt(5), + Daily: proxmox.PointerInt(4), + Monthly: proxmox.PointerInt(3), + Weekly: proxmox.PointerInt(2), + Yearly: proxmox.PointerInt(1), + }, +} + +var PBSEmpty = proxmox.ConfigStorage{ + Type: "pbs", + PBS: &proxmox.ConfigStoragePBS{ + Server: "10.20.1.1", + Datastore: "proxmox", + Username: "root@pam", + }, +} diff --git a/test/cli/Storage/storage-sub-tests/rbd.go b/test/cli/Storage/storage-sub-tests/rbd.go new file mode 100644 index 00000000..87b2f305 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/rbd.go @@ -0,0 +1,51 @@ +package storagesubtests + +import ( + "testing" + + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var RBDFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "rbd", + RBD: &proxmox.ConfigStorageRBD{ + Pool: "test-pool", + Monitors: []string{"10.20.1.1", "10.20.1.2", "10.20.1.3"}, + Username: "rbd-username", + Namespace: "ceph-namespace", + KRBD: true, + }, + Content: &proxmox.ConfigStorageContent{ + Container: proxmox.PointerBool(true), + DiskImage: proxmox.PointerBool(true), + }, +} + +var RBDEmpty = proxmox.ConfigStorage{ + Type: "rbd", + RBD: &proxmox.ConfigStorageRBD{ + Pool: "test-pool", + Monitors: []string{"10.20.1.3"}, + Username: "rbd-username", + Namespace: "ceph-namespace", + }, + Content: &proxmox.ConfigStorageContent{ + Container: proxmox.PointerBool(true), + }, +} + +func RBDGetFull(name string, t *testing.T) { + s := CloneJson(RBDFull) + s.ID = name + Get(s, name, t) +} + +func RBDGetEmpty(name string, t *testing.T) { + s := CloneJson(RBDEmpty) + s.ID = name + s.RBD.KRBD = false + s.Content.DiskImage = proxmox.PointerBool(false) + Get(s, name, t) +} diff --git a/test/cli/Storage/storage-sub-tests/smb.go b/test/cli/Storage/storage-sub-tests/smb.go new file mode 100644 index 00000000..8e0b86b6 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/smb.go @@ -0,0 +1,68 @@ +package storagesubtests + +import ( + "testing" + + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var SMBFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "smb", + SMB: &proxmox.ConfigStorageSMB{ + Username: "b.wayne", + Share: "NetworkShare", + Preallocation: proxmox.PointerString("full"), + Domain: "organization.pve", + Server: "10.20.1.1", + Version: proxmox.PointerString("3"), + }, + Content: &proxmox.ConfigStorageContent{ + Backup: proxmox.PointerBool(true), + Container: proxmox.PointerBool(true), + DiskImage: proxmox.PointerBool(true), + Iso: proxmox.PointerBool(true), + Snippets: proxmox.PointerBool(true), + Template: proxmox.PointerBool(true), + }, + BackupRetention: &proxmox.ConfigStorageBackupRetention{ + Last: proxmox.PointerInt(6), + Hourly: proxmox.PointerInt(5), + Daily: proxmox.PointerInt(4), + Monthly: proxmox.PointerInt(3), + Weekly: proxmox.PointerInt(2), + Yearly: proxmox.PointerInt(1), + }, +} + +var SMBEmpty = proxmox.ConfigStorage{ + Type: "smb", + SMB: &proxmox.ConfigStorageSMB{ + Username: "b.wayne", + Share: "NetworkShare", + Domain: "organization.pve", + Server: "10.20.1.1", + }, + Content: &proxmox.ConfigStorageContent{ + Snippets: proxmox.PointerBool(true), + }, +} + +func SMBGetFull(name string, t *testing.T) { + s := CloneJson(SMBFull) + s.ID = name + Get(s, name, t) +} + +func SMBGetEmpty(name string, t *testing.T) { + s := CloneJson(SMBEmpty) + s.ID = name + s.SMB.Preallocation = proxmox.PointerString("metadata") + s.Content.Backup = proxmox.PointerBool(false) + s.Content.Container = proxmox.PointerBool(false) + s.Content.DiskImage = proxmox.PointerBool(false) + s.Content.Iso = proxmox.PointerBool(false) + s.Content.Template = proxmox.PointerBool(false) + Get(s, name, t) +} diff --git a/test/cli/Storage/storage-sub-tests/standard.go b/test/cli/Storage/storage-sub-tests/standard.go new file mode 100644 index 00000000..0b56edef --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/standard.go @@ -0,0 +1,55 @@ +package storagesubtests + +import ( + "testing" + + _ "github.com/Telmate/proxmox-api-go/cli/command/commands" + "github.com/Telmate/proxmox-api-go/proxmox" + cliTest "github.com/Telmate/proxmox-api-go/test/cli" +) + +func Cleanup(name string, t *testing.T) { + Test := cliTest.Test{ + ReqErr: true, + ErrContains: name, + Args: []string{"-i", "delete", "storage", name}, + } + Test.StandardTest(t) +} + +func Delete(name string, t *testing.T) { + Test := cliTest.Test{ + Expected: name, + Contains: true, + ReqErr: false, + Args: []string{"-i", "delete", "storage", name}, + } + Test.StandardTest(t) +} + +func Get(s *proxmox.ConfigStorage, name string, t *testing.T) { + cliTest.SetEnvironmentVariables() + Test := cliTest.Test{ + OutputJson: InlineMarshal(s), + Args: []string{"-i", "get", "storage", name}, + } + Test.StandardTest(t) +} + +func Create(s *proxmox.ConfigStorage, name string, t *testing.T) { + createOrUpdate(s, name, "create", t) +} + +func Update(s *proxmox.ConfigStorage, name string, t *testing.T) { + createOrUpdate(s, name, "update", t) +} + +func createOrUpdate(s *proxmox.ConfigStorage, name, command string, t *testing.T) { + Test := cliTest.Test{ + InputJson: InlineMarshal(s), + Expected: "(" + name + ")", + Contains: true, + Args: []string{"-i", command, "storage", name}, + } + Test.StandardTest(t) +} diff --git a/test/cli/Storage/storage-sub-tests/zfs-over-iscsi.go b/test/cli/Storage/storage-sub-tests/zfs-over-iscsi.go new file mode 100644 index 00000000..78c2a36c --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/zfs-over-iscsi.go @@ -0,0 +1,32 @@ +package storagesubtests + +import ( + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var ZFSoverISCSIFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "zfs-over-iscsi", + ZFSoverISCSI: &proxmox.ConfigStorageZFSoverISCSI{ + Portal: "test-portal", + Pool: "test-pool", + Blocksize: proxmox.PointerString("8k"), + Target: "test-target", + Thinprovision: true, + ISCSIprovider: "iet", + }, + Content: &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + }, +} + +var ZFSoverISCSIEmpty = proxmox.ConfigStorage{ + Type: "zfs-over-iscsi", + ZFSoverISCSI: &proxmox.ConfigStorageZFSoverISCSI{ + Portal: "test-portal", + Pool: "test-pool", + Target: "test-target", + ISCSIprovider: "iet", + }, +} diff --git a/test/cli/Storage/storage-sub-tests/zfs-over-iscsi_comstar.go b/test/cli/Storage/storage-sub-tests/zfs-over-iscsi_comstar.go new file mode 100644 index 00000000..1f2c48e4 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/zfs-over-iscsi_comstar.go @@ -0,0 +1,38 @@ +package storagesubtests + +import ( + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var ZFSoverISCSI_ComstarFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "zfs-over-iscsi", + ZFSoverISCSI: &proxmox.ConfigStorageZFSoverISCSI{ + Portal: "test-portal", + Pool: "test-pool", + Blocksize: proxmox.PointerString("8k"), + Target: "test-target", + Thinprovision: true, + ISCSIprovider: "comstar", + Comstar: &proxmox.ConfigStorageZFSoverISCSI_Comstar{ + TargetGroup: "t-group", + HostGroup: "h-group", + Writecache: true, + }, + }, + Content: &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + }, +} + +var ZFSoverISCSI_ComstarEmpty = proxmox.ConfigStorage{ + Type: "zfs-over-iscsi", + ZFSoverISCSI: &proxmox.ConfigStorageZFSoverISCSI{ + Portal: "test-portal", + Pool: "test-pool", + Target: "test-target", + ISCSIprovider: "comstar", + Comstar: &proxmox.ConfigStorageZFSoverISCSI_Comstar{}, + }, +} diff --git a/test/cli/Storage/storage-sub-tests/zfs-over-iscsi_istgt.go b/test/cli/Storage/storage-sub-tests/zfs-over-iscsi_istgt.go new file mode 100644 index 00000000..4016a747 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/zfs-over-iscsi_istgt.go @@ -0,0 +1,36 @@ +package storagesubtests + +import ( + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var ZFSoverISCSI_IstgtFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "zfs-over-iscsi", + ZFSoverISCSI: &proxmox.ConfigStorageZFSoverISCSI{ + Portal: "test-portal", + Pool: "test-pool", + Blocksize: proxmox.PointerString("8k"), + Target: "test-target", + Thinprovision: true, + ISCSIprovider: "istgt", + Istgt: &proxmox.ConfigStorageZFSoverISCSI_istgt{ + Writecache: true, + }, + }, + Content: &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + }, +} + +var ZFSoverISCSI_IstgtEmpty = proxmox.ConfigStorage{ + Type: "zfs-over-iscsi", + ZFSoverISCSI: &proxmox.ConfigStorageZFSoverISCSI{ + Portal: "test-portal", + Pool: "test-pool", + Target: "test-target", + ISCSIprovider: "istgt", + Istgt: &proxmox.ConfigStorageZFSoverISCSI_istgt{}, + }, +} diff --git a/test/cli/Storage/storage-sub-tests/zfs-over-iscsi_lio.go b/test/cli/Storage/storage-sub-tests/zfs-over-iscsi_lio.go new file mode 100644 index 00000000..d9c8dd66 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/zfs-over-iscsi_lio.go @@ -0,0 +1,38 @@ +package storagesubtests + +import ( + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var ZFSoverISCSI_LioFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "zfs-over-iscsi", + ZFSoverISCSI: &proxmox.ConfigStorageZFSoverISCSI{ + Portal: "test-portal", + Pool: "test-pool", + Blocksize: proxmox.PointerString("8k"), + Target: "test-target", + Thinprovision: true, + ISCSIprovider: "lio", + LIO: &proxmox.ConfigStorageZFSoverISCSI_LIO{ + TargetPortalGroup: "t-group", + }, + }, + Content: &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + }, +} + +var ZFSoverISCSI_LioEmpty = proxmox.ConfigStorage{ + Type: "zfs-over-iscsi", + ZFSoverISCSI: &proxmox.ConfigStorageZFSoverISCSI{ + Portal: "test-portal", + Pool: "test-pool", + Target: "test-target", + ISCSIprovider: "lio", + LIO: &proxmox.ConfigStorageZFSoverISCSI_LIO{ + TargetPortalGroup: "t-group", + }, + }, +} diff --git a/test/cli/Storage/storage-sub-tests/zfs.go b/test/cli/Storage/storage-sub-tests/zfs.go new file mode 100644 index 00000000..8d20bfb7 --- /dev/null +++ b/test/cli/Storage/storage-sub-tests/zfs.go @@ -0,0 +1,46 @@ +package storagesubtests + +import ( + "testing" + + "github.com/Telmate/proxmox-api-go/proxmox" +) + +var ZFSFull = proxmox.ConfigStorage{ + Enable: true, + Nodes: []string{"pve"}, + Type: "zfs", + ZFS: &proxmox.ConfigStorageZFS{ + Pool: "test-pool", + Blocksize: proxmox.PointerString("4k"), + Thinprovision: true, + }, + Content: &proxmox.ConfigStorageContent{ + Container: proxmox.PointerBool(true), + DiskImage: proxmox.PointerBool(true), + }, +} + +var ZFSEmpty = proxmox.ConfigStorage{ + Type: "zfs", + ZFS: &proxmox.ConfigStorageZFS{ + Pool: "test-pool", + }, + Content: &proxmox.ConfigStorageContent{ + DiskImage: proxmox.PointerBool(true), + }, +} + +func ZFSGetFull(name string, t *testing.T) { + s := CloneJson(ZFSFull) + s.ID = name + Get(s, name, t) +} + +func ZFSGetEmpty(name string, t *testing.T) { + s := CloneJson(ZFSEmpty) + s.ID = name + s.ZFS.Blocksize = proxmox.PointerString("8k") + s.Content.Container = proxmox.PointerBool(false) + Get(s, name, t) +}