Skip to content
Open
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ linters:
formatters:
enable:
- gofmt
- goimports
- goimports
69 changes: 69 additions & 0 deletions block/provider/create_group_snapshot.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright 2026 IBM Corp.
*
* 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 provider

import (
"time"

"github.com/IBM/ibmcloud-volume-interface/lib/metrics"
"github.com/IBM/ibmcloud-volume-interface/lib/provider"
userError "github.com/IBM/ibmcloud-volume-vpc/common/messages"
"github.com/IBM/ibmcloud-volume-vpc/common/vpcclient/models"
"go.uber.org/zap"
)

// CreateGroupSnapshot creates a snapshot consistency group for the given source volume IDs
func (vpcs *VPCSession) CreateGroupSnapshot(sourceVolumeIDs []string, groupSnapshotParameters provider.GroupSnapshotParameters) (*provider.GroupSnapshot, error) {
vpcs.Logger.Info("Entry CreateGroupSnapshot", zap.Reflect("groupSnapshotParameters", groupSnapshotParameters), zap.Reflect("sourceVolumeIDs", sourceVolumeIDs))
defer vpcs.Logger.Info("Exit CreateGroupSnapshot", zap.Reflect("groupSnapshotParameters", groupSnapshotParameters), zap.Reflect("sourceVolumeIDs", sourceVolumeIDs))
defer metrics.UpdateDurationFromStart(vpcs.Logger, "CreateGroupSnapshot", time.Now())

// Build the snapshot templates for each source volume
snapshotTemplates := make([]models.GroupSnapshotTemplate, 0, len(sourceVolumeIDs))
for _, volID := range sourceVolumeIDs {
snapshotTemplates = append(snapshotTemplates, models.GroupSnapshotTemplate{
SourceVolume: &models.SourceVolume{
ID: volID,
},
})
}

reqBody := &models.SnapshotConsistencyGroupRequest{
Name: groupSnapshotParameters.Name,
ResourceGroup: &models.ResourceGroup{
ID: groupSnapshotParameters.ResourceGroup,
},
Snapshots: snapshotTemplates,
DeleteSnapshotsOnDelete: true,
}

var (
result *models.SnapshotConsistencyGroupResponse
err error
)
err = retry(vpcs.Logger, func() error {
result, err = vpcs.Apiclient.SnapshotConsistencyGroupService().CreateSnapshotConsistencyGroup(reqBody, vpcs.Logger)
return err
})
if err != nil {
return nil, userError.GetUserError("FailedToCreateGroupSnapshot", err)
}

vpcs.Logger.Info("Successfully created snapshot consistency group", zap.Reflect("GroupSnapshot", result))

return vpcs.getGroupSnapshotWithMembers(result)
}
Loading
Loading