Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix backup struct naming and swagger metadata #1156

Merged
merged 7 commits into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions client/incus_storage_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -814,8 +814,8 @@ func (r *ProtocolIncus) RenameStoragePoolVolume(pool string, volType string, nam
return nil
}

// GetStoragePoolVolumeBackupNames returns a list of volume backup names.
func (r *ProtocolIncus) GetStoragePoolVolumeBackupNames(pool string, volName string) ([]string, error) {
// GetStorageVolumeBackupNames returns a list of volume backup names.
func (r *ProtocolIncus) GetStorageVolumeBackupNames(pool string, volName string) ([]string, error) {
if !r.HasExtension("custom_volume_backup") {
return nil, fmt.Errorf("The server is missing the required \"custom_volume_backup\" API extension")
}
Expand All @@ -832,14 +832,14 @@ func (r *ProtocolIncus) GetStoragePoolVolumeBackupNames(pool string, volName str
return urlsToResourceNames(baseURL, urls...)
}

// GetStoragePoolVolumeBackups returns a list of custom volume backups.
func (r *ProtocolIncus) GetStoragePoolVolumeBackups(pool string, volName string) ([]api.StoragePoolVolumeBackup, error) {
// GetStorageVolumeBackups returns a list of custom volume backups.
func (r *ProtocolIncus) GetStorageVolumeBackups(pool string, volName string) ([]api.StorageVolumeBackup, error) {
if !r.HasExtension("custom_volume_backup") {
return nil, fmt.Errorf("The server is missing the required \"custom_volume_backup\" API extension")
}

// Fetch the raw value
backups := []api.StoragePoolVolumeBackup{}
backups := []api.StorageVolumeBackup{}

_, err := r.queryStruct("GET", fmt.Sprintf("/storage-pools/%s/volumes/custom/%s/backups?recursion=1", url.PathEscape(pool), url.PathEscape(volName)), nil, "", &backups)
if err != nil {
Expand All @@ -849,14 +849,14 @@ func (r *ProtocolIncus) GetStoragePoolVolumeBackups(pool string, volName string)
return backups, nil
}

// GetStoragePoolVolumeBackup returns a custom volume backup.
func (r *ProtocolIncus) GetStoragePoolVolumeBackup(pool string, volName string, name string) (*api.StoragePoolVolumeBackup, string, error) {
// GetStorageVolumeBackup returns a custom volume backup.
func (r *ProtocolIncus) GetStorageVolumeBackup(pool string, volName string, name string) (*api.StorageVolumeBackup, string, error) {
if !r.HasExtension("custom_volume_backup") {
return nil, "", fmt.Errorf("The server is missing the required \"custom_volume_backup\" API extension")
}

// Fetch the raw value
backup := api.StoragePoolVolumeBackup{}
backup := api.StorageVolumeBackup{}
etag, err := r.queryStruct("GET", fmt.Sprintf("/storage-pools/%s/volumes/custom/%s/backups/%s", url.PathEscape(pool), url.PathEscape(volName), url.PathEscape(name)), nil, "", &backup)
if err != nil {
return nil, "", err
Expand All @@ -865,8 +865,8 @@ func (r *ProtocolIncus) GetStoragePoolVolumeBackup(pool string, volName string,
return &backup, etag, nil
}

// CreateStoragePoolVolumeBackup creates new custom volume backup.
func (r *ProtocolIncus) CreateStoragePoolVolumeBackup(pool string, volName string, backup api.StoragePoolVolumeBackupsPost) (Operation, error) {
// CreateStorageVolumeBackup creates new custom volume backup.
func (r *ProtocolIncus) CreateStorageVolumeBackup(pool string, volName string, backup api.StorageVolumeBackupsPost) (Operation, error) {
if !r.HasExtension("custom_volume_backup") {
return nil, fmt.Errorf("The server is missing the required \"custom_volume_backup\" API extension")
}
Expand All @@ -880,8 +880,8 @@ func (r *ProtocolIncus) CreateStoragePoolVolumeBackup(pool string, volName strin
return op, nil
}

// RenameStoragePoolVolumeBackup renames a custom volume backup.
func (r *ProtocolIncus) RenameStoragePoolVolumeBackup(pool string, volName string, name string, backup api.StoragePoolVolumeBackupPost) (Operation, error) {
// RenameStorageVolumeBackup renames a custom volume backup.
func (r *ProtocolIncus) RenameStorageVolumeBackup(pool string, volName string, name string, backup api.StorageVolumeBackupPost) (Operation, error) {
if !r.HasExtension("custom_volume_backup") {
return nil, fmt.Errorf("The server is missing the required \"custom_volume_backup\" API extension")
}
Expand All @@ -895,8 +895,8 @@ func (r *ProtocolIncus) RenameStoragePoolVolumeBackup(pool string, volName strin
return op, nil
}

// DeleteStoragePoolVolumeBackup deletes a custom volume backup.
func (r *ProtocolIncus) DeleteStoragePoolVolumeBackup(pool string, volName string, name string) (Operation, error) {
// DeleteStorageVolumeBackup deletes a custom volume backup.
func (r *ProtocolIncus) DeleteStorageVolumeBackup(pool string, volName string, name string) (Operation, error) {
if !r.HasExtension("custom_volume_backup") {
return nil, fmt.Errorf("The server is missing the required \"custom_volume_backup\" API extension")
}
Expand All @@ -910,8 +910,8 @@ func (r *ProtocolIncus) DeleteStoragePoolVolumeBackup(pool string, volName strin
return op, nil
}

// GetStoragePoolVolumeBackupFile requests the custom volume backup content.
func (r *ProtocolIncus) GetStoragePoolVolumeBackupFile(pool string, volName string, name string, req *BackupFileRequest) (*BackupFileResponse, error) {
// GetStorageVolumeBackupFile requests the custom volume backup content.
func (r *ProtocolIncus) GetStorageVolumeBackupFile(pool string, volName string, name string, req *BackupFileRequest) (*BackupFileResponse, error) {
if !r.HasExtension("custom_volume_backup") {
return nil, fmt.Errorf("The server is missing the required \"custom_volume_backup\" API extension")
}
Expand Down Expand Up @@ -977,7 +977,7 @@ func (r *ProtocolIncus) GetStoragePoolVolumeBackupFile(pool string, volName stri
}

// CreateStoragePoolVolumeFromISO creates a custom volume from an ISO file.
func (r *ProtocolIncus) CreateStoragePoolVolumeFromISO(pool string, args StoragePoolVolumeBackupArgs) (Operation, error) {
func (r *ProtocolIncus) CreateStoragePoolVolumeFromISO(pool string, args StorageVolumeBackupArgs) (Operation, error) {
err := r.CheckExtension("custom_volume_iso")
if err != nil {
return nil, err
Expand Down Expand Up @@ -1035,7 +1035,7 @@ func (r *ProtocolIncus) CreateStoragePoolVolumeFromISO(pool string, args Storage
}

// CreateStoragePoolVolumeFromBackup creates a custom volume from a backup file.
func (r *ProtocolIncus) CreateStoragePoolVolumeFromBackup(pool string, args StoragePoolVolumeBackupArgs) (Operation, error) {
func (r *ProtocolIncus) CreateStoragePoolVolumeFromBackup(pool string, args StorageVolumeBackupArgs) (Operation, error) {
if !r.HasExtension("custom_volume_backup") {
return nil, fmt.Errorf(`The server is missing the required "custom_volume_backup" API extension`)
}
Expand Down
22 changes: 11 additions & 11 deletions client/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,17 +353,17 @@ type InstanceServer interface {
UpdateStoragePoolVolumeSnapshot(pool string, volumeType string, volumeName string, snapshotName string, volume api.StorageVolumeSnapshotPut, ETag string) (err error)

// Storage volume backup functions ("custom_volume_backup" API extension)
GetStoragePoolVolumeBackupNames(pool string, volName string) (names []string, err error)
GetStoragePoolVolumeBackups(pool string, volName string) (backups []api.StoragePoolVolumeBackup, err error)
GetStoragePoolVolumeBackup(pool string, volName string, name string) (backup *api.StoragePoolVolumeBackup, ETag string, err error)
CreateStoragePoolVolumeBackup(pool string, volName string, backup api.StoragePoolVolumeBackupsPost) (op Operation, err error)
RenameStoragePoolVolumeBackup(pool string, volName string, name string, backup api.StoragePoolVolumeBackupPost) (op Operation, err error)
DeleteStoragePoolVolumeBackup(pool string, volName string, name string) (op Operation, err error)
GetStoragePoolVolumeBackupFile(pool string, volName string, name string, req *BackupFileRequest) (resp *BackupFileResponse, err error)
CreateStoragePoolVolumeFromBackup(pool string, args StoragePoolVolumeBackupArgs) (op Operation, err error)
GetStorageVolumeBackupNames(pool string, volName string) (names []string, err error)
GetStorageVolumeBackups(pool string, volName string) (backups []api.StorageVolumeBackup, err error)
GetStorageVolumeBackup(pool string, volName string, name string) (backup *api.StorageVolumeBackup, ETag string, err error)
CreateStorageVolumeBackup(pool string, volName string, backup api.StorageVolumeBackupsPost) (op Operation, err error)
RenameStorageVolumeBackup(pool string, volName string, name string, backup api.StorageVolumeBackupPost) (op Operation, err error)
DeleteStorageVolumeBackup(pool string, volName string, name string) (op Operation, err error)
GetStorageVolumeBackupFile(pool string, volName string, name string, req *BackupFileRequest) (resp *BackupFileResponse, err error)
CreateStoragePoolVolumeFromBackup(pool string, args StorageVolumeBackupArgs) (op Operation, err error)

// Storage volume ISO import function ("custom_volume_iso" API extension)
CreateStoragePoolVolumeFromISO(pool string, args StoragePoolVolumeBackupArgs) (op Operation, err error)
CreateStoragePoolVolumeFromISO(pool string, args StorageVolumeBackupArgs) (op Operation, err error)

// Cluster functions ("cluster" API extensions)
GetCluster() (cluster *api.Cluster, ETag string, err error)
Expand Down Expand Up @@ -532,9 +532,9 @@ type StoragePoolVolumeMoveArgs struct {
Project string
}

// The StoragePoolVolumeBackupArgs struct is used when creating a storage volume from a backup.
// The StorageVolumeBackupArgs struct is used when creating a storage volume from a backup.
// API extension: custom_volume_backup.
type StoragePoolVolumeBackupArgs struct {
type StorageVolumeBackupArgs struct {
// The backup file
BackupFile io.Reader

Expand Down
14 changes: 7 additions & 7 deletions cmd/incus/storage_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -1402,9 +1402,9 @@ func (c *cmdStorageVolumeInfo) Run(cmd *cobra.Command, args []string) error {
return err
}

var volBackups []api.StoragePoolVolumeBackup
var volBackups []api.StorageVolumeBackup
if client.HasExtension("custom_volume_backup") && volType == "custom" {
volBackups, err = client.GetStoragePoolVolumeBackups(resource.name, volName)
volBackups, err = client.GetStorageVolumeBackups(resource.name, volName)
if err != nil {
return err
}
Expand Down Expand Up @@ -2976,15 +2976,15 @@ func (c *cmdStorageVolumeExport) Run(cmd *cobra.Command, args []string) error {
return fmt.Errorf(i18n.G("Only \"custom\" volumes can be exported"))
}

req := api.StoragePoolVolumeBackupsPost{
req := api.StorageVolumeBackupsPost{
Name: "",
ExpiresAt: time.Now().Add(24 * time.Hour),
VolumeOnly: volumeOnly,
OptimizedStorage: c.flagOptimizedStorage,
CompressionAlgorithm: c.flagCompressionAlgorithm,
}

op, err := d.CreateStoragePoolVolumeBackup(name, volName, req)
op, err := d.CreateStorageVolumeBackup(name, volName, req)
if err != nil {
return fmt.Errorf(i18n.G("Failed to create storage volume backup: %w"), err)
}
Expand Down Expand Up @@ -3029,7 +3029,7 @@ func (c *cmdStorageVolumeExport) Run(cmd *cobra.Command, args []string) error {

defer func() {
// Delete backup after we're done
op, err = d.DeleteStoragePoolVolumeBackup(name, volName, backupName)
op, err = d.DeleteStorageVolumeBackup(name, volName, backupName)
if err == nil {
_ = op.Wait()
}
Expand Down Expand Up @@ -3061,7 +3061,7 @@ func (c *cmdStorageVolumeExport) Run(cmd *cobra.Command, args []string) error {
}

// Export tarball
_, err = d.GetStoragePoolVolumeBackupFile(name, volName, backupName, &backupFileRequest)
_, err = d.GetStorageVolumeBackupFile(name, volName, backupName, &backupFileRequest)
if err != nil {
_ = os.Remove(targetName)
progress.Done("")
Expand Down Expand Up @@ -3172,7 +3172,7 @@ func (c *cmdStorageVolumeImport) Run(cmd *cobra.Command, args []string) error {
Quiet: c.global.flagQuiet,
}

createArgs := incus.StoragePoolVolumeBackupArgs{
createArgs := incus.StorageVolumeBackupArgs{
BackupFile: &ioprogress.ProgressReader{
ReadCloser: file,
Tracker: &ioprogress.ProgressTracker{
Expand Down
6 changes: 3 additions & 3 deletions cmd/incusd/storage_buckets_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ var storagePoolBucketBackupsExportCmd = APIEndpoint{
// type: array
// description: List of storage bucket backups
// items:
// $ref: "#/definitions/StoragePoolBucketBackup"
// $ref: "#/definitions/StorageBucketBackup"
// "403":
// $ref: "#/responses/Forbidden"
// "500":
Expand Down Expand Up @@ -231,7 +231,7 @@ func storagePoolBucketBackupsGet(d *Daemon, r *http.Request) response.Response {
// description: Storage bucket backup
// required: true
// schema:
// $ref: "#/definitions/StoragePoolBucketBackupsPost"
// $ref: "#/definitions/StorageBucketBackupsPost"
// responses:
// "202":
// $ref: "#/responses/Operation"
Expand Down Expand Up @@ -431,7 +431,7 @@ func storagePoolBucketBackupsPost(d *Daemon, r *http.Request) response.Response
// description: Status code
// example: 200
// metadata:
// $ref: "#/definitions/StoragePoolBucketBackup"
// $ref: "#/definitions/StorageBucketBackup"
// "403":
// $ref: "#/responses/Forbidden"
// "500":
Expand Down
12 changes: 6 additions & 6 deletions cmd/incusd/storage_volumes_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ var storagePoolVolumeTypeCustomBackupExportCmd = APIEndpoint{
// type: array
// description: List of storage volume backups
// items:
// $ref: "#/definitions/StoragePoolVolumeBackup"
// $ref: "#/definitions/StorageVolumeBackup"
// "403":
// $ref: "#/responses/Forbidden"
// "500":
Expand Down Expand Up @@ -228,7 +228,7 @@ func storagePoolVolumeTypeCustomBackupsGet(d *Daemon, r *http.Request) response.
}

resultString := []string{}
resultMap := []*api.StoragePoolVolumeBackup{}
resultMap := []*api.StorageVolumeBackup{}

for _, backup := range backups {
if !recursion {
Expand Down Expand Up @@ -274,7 +274,7 @@ func storagePoolVolumeTypeCustomBackupsGet(d *Daemon, r *http.Request) response.
// description: Storage volume backup
// required: true
// schema:
// $ref: "#/definitions/StoragePoolVolumeBackupsPost"
// $ref: "#/definitions/StorageVolumeBackupsPost"
// responses:
// "202":
// $ref: "#/responses/Operation"
Expand Down Expand Up @@ -379,7 +379,7 @@ func storagePoolVolumeTypeCustomBackupsPost(d *Daemon, r *http.Request) response
return response.InternalError(err)
}

req := api.StoragePoolVolumeBackupsPost{}
req := api.StorageVolumeBackupsPost{}

err = json.Unmarshal(body, &req)
if err != nil {
Expand Down Expand Up @@ -504,7 +504,7 @@ func storagePoolVolumeTypeCustomBackupsPost(d *Daemon, r *http.Request) response
// description: Status code
// example: 200
// metadata:
// $ref: "#/definitions/StoragePoolVolumeBackup"
// $ref: "#/definitions/StorageVolumeBackup"
// "403":
// $ref: "#/responses/Forbidden"
// "500":
Expand Down Expand Up @@ -662,7 +662,7 @@ func storagePoolVolumeTypeCustomBackupPost(d *Daemon, r *http.Request) response.
return resp
}

req := api.StoragePoolVolumeBackupPost{}
req := api.StorageVolumeBackupPost{}
err = json.NewDecoder(r.Body).Decode(&req)
if err != nil {
return response.BadRequest(err)
Expand Down
Loading
Loading