-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add volume-onboarding & dr-locations methods (#188)
* Add volume-onboarding & dr-locations methods * feedback resolved
- Loading branch information
1 parent
0216680
commit 2e528d5
Showing
7 changed files
with
332 additions
and
5 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package instance | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/IBM-Cloud/power-go-client/errors" | ||
"github.com/IBM-Cloud/power-go-client/helpers" | ||
"github.com/IBM-Cloud/power-go-client/ibmpisession" | ||
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_disaster_recovery" | ||
"github.com/IBM-Cloud/power-go-client/power/models" | ||
) | ||
|
||
// IBMPIDisasterRecoveryLocationClient | ||
type IBMPIDisasterRecoveryLocationClient struct { | ||
IBMPIClient | ||
} | ||
|
||
// NewIBMPIDisasterRecoveryLocationClient | ||
func NewIBMPIDisasterRecoveryLocationClient(ctx context.Context, sess *ibmpisession.IBMPISession, cloudInstanceID string) *IBMPIDisasterRecoveryLocationClient { | ||
return &IBMPIDisasterRecoveryLocationClient{ | ||
*NewIBMPIClient(ctx, sess, cloudInstanceID), | ||
} | ||
} | ||
|
||
// Get the disaster recovery site details for the current location | ||
func (f *IBMPIDisasterRecoveryLocationClient) Get() (*models.DisasterRecoveryLocation, error) { | ||
params := p_cloud_disaster_recovery.NewPcloudLocationsDisasterrecoveryGetParams(). | ||
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut). | ||
WithCloudInstanceID(f.cloudInstanceID) | ||
resp, err := f.session.Power.PCloudDisasterRecovery.PcloudLocationsDisasterrecoveryGet(params, f.session.AuthInfo(f.cloudInstanceID)) | ||
if err != nil { | ||
return nil, fmt.Errorf(errors.GetDisasterRecoveryLocationOperationFailed, f.cloudInstanceID, err) | ||
} | ||
if resp == nil || resp.Payload == nil { | ||
return nil, fmt.Errorf("failed to perform the Get Disaster Recovery Location for the cloud instance %s", f.cloudInstanceID) | ||
} | ||
return resp.Payload, nil | ||
} | ||
|
||
// Get all disaster recovery locations supported by Power Virtual Server | ||
func (f *IBMPIDisasterRecoveryLocationClient) GetAll() (*models.DisasterRecoveryLocations, error) { | ||
params := p_cloud_disaster_recovery.NewPcloudLocationsDisasterrecoveryGetallParams(). | ||
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut) | ||
resp, err := f.session.Power.PCloudDisasterRecovery.PcloudLocationsDisasterrecoveryGetall(params, f.session.AuthInfo(f.cloudInstanceID)) | ||
if err != nil { | ||
return nil, fmt.Errorf(errors.GetAllDisasterRecoveryLocationOperationFailed, err) | ||
} | ||
if resp == nil || resp.Payload == nil { | ||
return nil, fmt.Errorf("failed to Get All Disaster Recovery Location of Power Virtual Server") | ||
} | ||
return resp.Payload, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
package instance | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/IBM-Cloud/power-go-client/errors" | ||
"github.com/IBM-Cloud/power-go-client/helpers" | ||
"github.com/IBM-Cloud/power-go-client/ibmpisession" | ||
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_volume_onboarding" | ||
"github.com/IBM-Cloud/power-go-client/power/models" | ||
) | ||
|
||
// IBMPIVolumeOnboardingClient | ||
type IBMPIVolumeOnboardingClient struct { | ||
IBMPIClient | ||
} | ||
|
||
// NewIBMPIVolumeOnboardingClient | ||
func NewIBMPIVolumeOnboardingClient(ctx context.Context, sess *ibmpisession.IBMPISession, cloudInstanceID string) *IBMPIVolumeOnboardingClient { | ||
return &IBMPIVolumeOnboardingClient{ | ||
*NewIBMPIClient(ctx, sess, cloudInstanceID), | ||
} | ||
} | ||
|
||
// Get the information of volume onboarding operation | ||
func (f *IBMPIVolumeOnboardingClient) Get(id string) (*models.VolumeOnboarding, error) { | ||
params := p_cloud_volume_onboarding.NewPcloudVolumeOnboardingGetParams(). | ||
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut). | ||
WithCloudInstanceID(f.cloudInstanceID).WithVolumeOnboardingID(id) | ||
resp, err := f.session.Power.PCloudVolumeOnboarding.PcloudVolumeOnboardingGet(params, f.session.AuthInfo(f.cloudInstanceID)) | ||
if err != nil { | ||
return nil, fmt.Errorf(errors.GetVolumeOnboardingOperationFailed, id, f.cloudInstanceID, err) | ||
} | ||
if resp == nil || resp.Payload == nil { | ||
return nil, fmt.Errorf("failed to Get Volume Onboarding for volume-onboarding ID:%s", id) | ||
} | ||
return resp.Payload, nil | ||
} | ||
|
||
// Get All volume onboardings for this cloud instance | ||
func (f *IBMPIVolumeOnboardingClient) GetAll() (*models.VolumeOnboardings, error) { | ||
params := p_cloud_volume_onboarding.NewPcloudVolumeOnboardingGetallParams(). | ||
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut). | ||
WithCloudInstanceID(f.cloudInstanceID) | ||
resp, err := f.session.Power.PCloudVolumeOnboarding.PcloudVolumeOnboardingGetall(params, f.session.AuthInfo(f.cloudInstanceID)) | ||
if err != nil { | ||
return nil, fmt.Errorf(errors.GetAllVolumeOnboardingsOperationFailed, f.cloudInstanceID, err) | ||
} | ||
if resp == nil || resp.Payload == nil { | ||
return nil, fmt.Errorf("failed to Get All Volume Onboardings for the cloud instance %s", f.cloudInstanceID) | ||
} | ||
return resp.Payload, nil | ||
} | ||
|
||
// Onboard auxiliary volumes to target site | ||
func (f *IBMPIVolumeOnboardingClient) CreateVolumeOnboarding(body *models.VolumeOnboardingCreate) (*models.VolumeOnboardingCreateResponse, error) { | ||
params := p_cloud_volume_onboarding.NewPcloudVolumeOnboardingPostParams(). | ||
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut). | ||
WithCloudInstanceID(f.cloudInstanceID).WithBody(body) | ||
resp, err := f.session.Power.PCloudVolumeOnboarding.PcloudVolumeOnboardingPost(params, f.session.AuthInfo(f.cloudInstanceID)) | ||
if err != nil { | ||
return nil, fmt.Errorf(errors.CreateVolumeOnboardingsOperationFailed, f.cloudInstanceID, err) | ||
} | ||
if resp == nil || resp.Payload == nil { | ||
return nil, fmt.Errorf("failed to Create Volume Onboarding") | ||
} | ||
return resp.Payload, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
v "github.com/IBM-Cloud/power-go-client/clients/instance" | ||
ps "github.com/IBM-Cloud/power-go-client/ibmpisession" | ||
"github.com/IBM/go-sdk-core/v5/core" | ||
) | ||
|
||
func main() { | ||
|
||
//session Inputs | ||
token := " < IAM TOKEN > " | ||
region := " < REGION > " | ||
zone := " < ZONE > " | ||
accountID := " < ACCOUNT ID > " | ||
url := region + ".power-iaas.test.cloud.ibm.com" | ||
|
||
// dr location inputs | ||
piID := " < POWER INSTANCE ID > " | ||
|
||
authenticator := &core.BearerTokenAuthenticator{ | ||
BearerToken: token, | ||
} | ||
// authenticator := &core.IamAuthenticator{ | ||
// ApiKey: "< API KEY >", | ||
// // Uncomment for test environment | ||
// URL: "https://iam.test.cloud.ibm.com", | ||
// } | ||
|
||
// Create the session | ||
options := &ps.IBMPIOptions{ | ||
Authenticator: authenticator, | ||
UserAccount: accountID, | ||
Zone: zone, | ||
URL: url, | ||
Debug: true, | ||
} | ||
session, err := ps.NewIBMPISession(options) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
powerClient := v.NewIBMPIDisasterRecoveryLocationClient(context.Background(), session, piID) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
getResp, err := powerClient.Get() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("***************[1]****************** %+v\n", *getResp) | ||
|
||
getAllResp, err := powerClient.GetAll() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("***************[2]****************** %+v\n", *getAllResp) | ||
} |
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,88 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
v "github.com/IBM-Cloud/power-go-client/clients/instance" | ||
ps "github.com/IBM-Cloud/power-go-client/ibmpisession" | ||
"github.com/IBM-Cloud/power-go-client/power/models" | ||
"github.com/IBM/go-sdk-core/v5/core" | ||
) | ||
|
||
func main() { | ||
|
||
//session Inputs | ||
token := " < IAM TOKEN > " | ||
region := " < REGION > " | ||
zone := " < ZONE > " | ||
accountID := " < ACCOUNT ID > " | ||
url := region + ".power-iaas.test.cloud.ibm.com" | ||
|
||
// volume-onboarding inputs | ||
piID := " < POWER INSTANCE ID > " | ||
auxVolName := " < NAME OF THE auxiliary volume > " | ||
sourceCRN := " < SOURCE CRN > " | ||
onboardingName := " < ONBOARDING NAME > " | ||
|
||
authenticator := &core.BearerTokenAuthenticator{ | ||
BearerToken: token, | ||
} | ||
|
||
// authenticator := &core.IamAuthenticator{ | ||
// ApiKey: "< API KEY >", | ||
// // Uncomment for test environment | ||
// URL: "https://iam.test.cloud.ibm.com", | ||
// } | ||
|
||
// Create the session | ||
options := &ps.IBMPIOptions{ | ||
Authenticator: authenticator, | ||
UserAccount: accountID, | ||
Zone: zone, | ||
URL: url, | ||
Debug: true, | ||
} | ||
session, err := ps.NewIBMPISession(options) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
powerClient := v.NewIBMPIVolumeOnboardingClient(context.Background(), session, piID) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
auxVols := []*models.AuxiliaryVolumeForOnboarding{} | ||
auxVols = append(auxVols, &models.AuxiliaryVolumeForOnboarding{ | ||
AuxVolumeName: &auxVolName, | ||
Name: onboardingName, | ||
}) | ||
|
||
vols := []*models.AuxiliaryVolumesForOnboarding{} | ||
vols = append(vols, &models.AuxiliaryVolumesForOnboarding{ | ||
AuxiliaryVolumes: auxVols, | ||
SourceCRN: &sourceCRN, | ||
}) | ||
body := &models.VolumeOnboardingCreate{ | ||
Volumes: vols, | ||
} | ||
|
||
createRespOk, err := powerClient.CreateVolumeOnboarding(body) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("***************[1]****************** %+v\n", *createRespOk) | ||
|
||
onboardingID := createRespOk.ID | ||
getResp, err := powerClient.Get(onboardingID) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("***************[2]****************** %+v \n", *getResp) | ||
|
||
getallResp, err := powerClient.GetAll() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
log.Printf("***************[3]****************** %+v \n", *getallResp) | ||
} |
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