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 private datacenter capabilities to datacenter get and get all #480

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Changes from all commits
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
59 changes: 43 additions & 16 deletions clients/instance/ibm-pi-datacenters.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,53 @@ func NewIBMPIDatacenterClient(ctx context.Context, sess *ibmpisession.IBMPISessi
}
}
func (f *IBMPIDatacentersClient) Get(datacenterRegion string) (*models.Datacenter, error) {
params := datacenters.NewV1DatacentersGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithDatacenterRegion(datacenterRegion)
resp, err := f.session.Power.Datacenters.V1DatacentersGet(params)
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf(errors.GetDatacenterOperationFailed, f.cloudInstanceID, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Datacenter %s", datacenterRegion)
if !f.session.IsOnPrem() {
params := datacenters.NewV1DatacentersGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithDatacenterRegion(datacenterRegion)
resp, err := f.session.Power.Datacenters.V1DatacentersGet(params)

if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf(errors.GetDatacenterOperationFailed, f.cloudInstanceID, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Datacenter %s", datacenterRegion)
}
return resp.Payload, nil
} else {
params := datacenters.NewV1DatacentersPrivateGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithDatacenterRegion(datacenterRegion)
resp, err := f.session.Power.Datacenters.V1DatacentersPrivateGet(params, f.session.AuthInfo(f.cloudInstanceID))

if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf(errors.GetDatacenterOperationFailed, f.cloudInstanceID, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Private Datacenter %s", datacenterRegion)
}
return resp.Payload, nil
}
return resp.Payload, nil
}

func (f *IBMPIDatacentersClient) GetAll() (*models.Datacenters, error) {
params := datacenters.NewV1DatacentersGetallParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut)
resp, err := f.session.Power.Datacenters.V1DatacentersGetall(params)
if !f.session.IsOnPrem() {
params := datacenters.NewV1DatacentersGetallParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut)
resp, err := f.session.Power.Datacenters.V1DatacentersGetall(params)

if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get all Datacenters: %w", err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get all Datacenters")
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get all Datacenters: %w", err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get all Datacenters")
}
return resp.Payload, nil
} else {
params := datacenters.NewV1DatacentersPrivateGetallParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut)
resp, err := f.session.Power.Datacenters.V1DatacentersPrivateGetall(params, f.session.AuthInfo(f.cloudInstanceID))

if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get all Datacenters: %w", err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get all private Datacenters")
}
return resp.Payload, nil
}
return resp.Payload, nil
}