Skip to content

Commit

Permalink
lxd/storage/drivers/powerflex: Add volume restore support
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Pelizäus <[email protected]>
  • Loading branch information
roosterfish committed Oct 9, 2023
1 parent f603383 commit 2319853
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
17 changes: 17 additions & 0 deletions lxd/storage/drivers/driver_powerflex_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,23 @@ func (p *powerFlexClient) setVolumeSize(volumeID string, size string) error {
return nil
}

// overwriteVolume overwrites the volumes contents behind volumeID with the given snapshot.
func (p *powerFlexClient) overwriteVolume(volumeID string, snapshotID string) error {
body, err := p.createBodyReader(map[string]any{
"srcVolumeId": snapshotID,
})
if err != nil {
return err
}

err = p.requestAuthenticated(http.MethodPost, fmt.Sprintf("/api/instances/Volume::%s/action/overwriteVolumeContent", volumeID), body, nil)
if err != nil {
return fmt.Errorf("Failed to overwrite volume: %q: %w", volumeID, err)
}

return nil
}

// createVolumeSnapshot creates a new volume snapshot under the given systemID for the volume behind volumeID.
// The accessMode can be either ReadWrite or ReadOnly.
// The returned string represents the ID of the snapshot.
Expand Down
22 changes: 21 additions & 1 deletion lxd/storage/drivers/driver_powerflex_volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,27 @@ func (d *powerflex) VolumeSnapshots(vol Volume, op *operations.Operation) ([]str

// RestoreVolume restores a volume from a snapshot.
func (d *powerflex) RestoreVolume(vol Volume, snapshotName string, op *operations.Operation) error {
return ErrNotSupported
ourUnmount, err := d.UnmountVolume(vol, false, op)
if err != nil {
return err
}

if ourUnmount {
defer func() { _ = d.MountVolume(vol, op) }()
}

volumeID, err := d.powerFlex().getVolumeID(d.getVolumeName(vol, ""))
if err != nil {
return err
}

snapVol := NewVolume(d, d.name, vol.volType, vol.contentType, fmt.Sprintf("%s/%s", vol.Name(), snapshotName), nil, nil)
snapshotID, err := d.powerFlex().getVolumeID(d.getVolumeName(snapVol, ""))
if err != nil {
return err
}

return d.powerFlex().overwriteVolume(volumeID, snapshotID)
}

// RenameVolumeSnapshot renames a volume snapshot.
Expand Down

0 comments on commit 2319853

Please sign in to comment.