-
Notifications
You must be signed in to change notification settings - Fork 9
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
Writable snapshot support #92
Closed
Closed
Changes from 8 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
24a693a
Add support for writeable snapshots.
donatwork f05ccaa
Refactor get calls.
donatwork 6b42565
Correct error message.
donatwork 00a9888
Fix test.
donatwork e34db27
Use more common spelling - writable.
donatwork f64c197
Include snapshots in quotas.
donatwork fa35ad0
Expose include_snapshot to public API.
donatwork 2318c27
Add unit tests for writable snapshots.
donatwork e26d228
Merge branch 'main' into writeable-snapshot
donatwork d254f9a
Add unit tests for writable snapshots.
donatwork File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
/* | ||
Copyright (c) 2025 Dell Inc, or its subsidiaries. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package v14 | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/dell/goisilon/api" | ||
) | ||
|
||
// GetIsiWritableSnapshots retrieves a list of writable snapshots. | ||
// | ||
// ctx: the context. | ||
// client: the API client. | ||
// Returns a list of writable snapshots and an error in case of failure. | ||
func GetIsiWritableSnapshots( | ||
ctx context.Context, | ||
client api.Client, | ||
) ([]*IsiWritableSnapshot, error) { | ||
var resp *IsiWritableSnapshotQueryResponse | ||
err := client.Get(ctx, writableSnapshotPath, "", nil, nil, &resp) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get writable snapshots from array: %v", err) | ||
} | ||
|
||
result := make([]*IsiWritableSnapshot, 0, resp.Total) | ||
result = append(result, resp.Writable...) | ||
|
||
for { | ||
if resp.Resume == "" { | ||
break | ||
} | ||
|
||
query := api.OrderedValues{ | ||
{[]byte("resume"), []byte(resp.Resume)}, | ||
} | ||
|
||
resp = nil | ||
err = client.Get(ctx, writableSnapshotPath, "", query, nil, &resp) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get writable snapshots (query mode) from array: %v", err) | ||
} | ||
|
||
result = append(result, resp.Writable...) | ||
donatwork marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
return result, err | ||
} | ||
|
||
// GetIsiWritableSnapshot retrieves a writable snapshot. | ||
// | ||
// ctx: the context. | ||
// client: the API client. | ||
// snapshotPath: the path of the snapshot. | ||
// | ||
// Returns the snapshot on success and error in case of failure. | ||
func GetIsiWritableSnapshot( | ||
ctx context.Context, | ||
client api.Client, | ||
snapshotPath string, | ||
) (*IsiWritableSnapshot, error) { | ||
var resp *IsiWritableSnapshotQueryResponse | ||
err := client.Get(ctx, writableSnapshotPath+snapshotPath, "", nil, nil, &resp) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to get writable snapshot: %v", err) | ||
} | ||
|
||
return resp.Writable[0], nil | ||
} | ||
|
||
// CreateWritableSnapshot creates a writable snapshot. | ||
// | ||
// ctx: the context. | ||
// client: the API client. | ||
// sourceSnapshot: the source snapshot name or ID. | ||
// destination: the destination path, must not be nested under the source snapshot. | ||
donatwork marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// | ||
// Returns the response and error. | ||
func CreateWritableSnapshot( | ||
ctx context.Context, | ||
client api.Client, | ||
sourceSnapshot string, | ||
destination string, | ||
) (resp *IsiWritableSnapshot, err error) { | ||
// PAPI calls: PUT https://1.2.3.4:8080//platform/14/snapshot/writable | ||
// Body: {"src_snap": sourceSnapshot, "dst_path": destination} | ||
|
||
body := map[string]string{ | ||
"src_snap": sourceSnapshot, | ||
"dst_path": destination, | ||
} | ||
|
||
err = client.Post(ctx, writableSnapshotPath, "", nil, nil, body, &resp) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to create writable snapshot: %v", err) | ||
} | ||
|
||
return resp, err | ||
} | ||
|
||
func RemoveWritableSnapshot( | ||
ctx context.Context, | ||
client api.Client, | ||
snapshotPath string, | ||
) error { | ||
return client.Delete(ctx, writableSnapshotPath+snapshotPath, "", nil, nil, nil) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better to retain the current behavior unless it is really required. Snapshot doesn't consume much space- maybe a few bytes for the metadata, and the size is not directly related to the source volume size.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Writable snaphots could diverge. I do agree that we probably should not include snapshots but this is in goscaleio so the work is already done to expose this so let the applications decide on the business rules. Does not hurt to keep it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although by exposing this we break compatibility. Terraform uses this module as well.