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

Add Bulk Attach, Delete & Detach Volume #313

Merged
merged 7 commits into from
Feb 13, 2024
Merged
Changes from 1 commit
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
14 changes: 14 additions & 0 deletions clients/instance/ibm-pi-volume.go
Original file line number Diff line number Diff line change
@@ -286,3 +286,17 @@ func (f *IBMPIVolumeClient) BulkVolumeDelete(body *models.VolumesDelete) (*model
}
return partialResp.Payload, nil
}

// Bulk volutme attach
func (f *IBMPIVolumeClient) BulkVolumeAttach(pvmInstanceID string, body *models.VolumesAttach) (*models.VolumesAttachmentResponse, error) {
params := p_cloud_volumes.NewPcloudV2PvminstancesVolumesPostParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
WithCloudInstanceID(f.cloudInstanceID).WithPvmInstanceID(pvmInstanceID).WithBody(body)
resp, err := f.session.Power.PCloudVolumes.PcloudV2PvminstancesVolumesPost(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf(errors.AttachVolumesOperationFailed, body.VolumeIDs, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Attach volumes %s to server %s", body.VolumeIDs, pvmInstanceID)
}
return resp.Payload, nil
}
1 change: 1 addition & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
@@ -71,6 +71,7 @@ const DetachVolumeOperationFailed = "failed to perform the Detach volume Operati
const GetVolumeRemoteCopyRelationshipsOperationFailed = "failed to Get remote copy relationships of a volume %s for the cloud instance %s with error %w"
const GetVolumeFlashCopyMappingOperationFailed = "failed to Get flash copy mapping of a volume %s for the cloud instance %s with error %w"
const DetachVolumesOperationFailed = "failed to perfome the Detach volumes Operation V2 for pvminstance %s in cloud instance %s with error %w"
const AttachVolumesOperationFailed = "failed to perform the Attach volume Operation for volumes %s with error %w"

// start of volume onboarding
const GetVolumeOnboardingOperationFailed = "failed to perform the Get Volume Onboarding Operation for volume-onboarding ID:%s for the cloud instance %s with error %w"
16 changes: 13 additions & 3 deletions examples/bulk-volume-detach/main.go
Original file line number Diff line number Diff line change
@@ -125,7 +125,6 @@ func main() {
ImageID: &imageID,
NetworkIDs: []string{networkID},
ServerName: &serverName,
VolumeIDs: []string{volumeID, volumeID2},
Memory: &memory,
Processors: &processors,
ProcType: &procType,
@@ -156,16 +155,27 @@ func main() {
}
log.Printf("***************[6]****************** %+v \n", *getRespVM)
waitForInstanceAvailable(insID, powerClientVM)

log.Print("Attaching Volumes\n")
attachBody := &models.VolumesAttach{
VolumeIDs: []string{volumeID, volumeID2},
}
attachVolsResp, err := powerClientVolume.BulkVolumeAttach(insID, attachBody)
if err != nil {
log.Fatal(err)
}
log.Printf("***************[7]****************** %+v\n", *attachVolsResp)
time.Sleep(2 * time.Minute)

log.Print("Detaching Volumes\n")
detachBody := &models.VolumesDetach{
VolumeIDs: []string{volumeID, volumeID2},
}

createRespOkDetach, err := powerClientVolume.BulkVolumeDetach(insID, detachBody)
if err != nil {
log.Fatal(err)
}
log.Printf("***************[7]****************** %+v\n", *createRespOkDetach)
log.Printf("***************[8]****************** %+v\n", *createRespOkDetach)
log.Print("Deleting VM\n")
err = powerClientVM.Delete(insID)
if err != nil {
Loading