Skip to content

Commit

Permalink
add private datacenter capabilities to datacenter get and getAll (#480)
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Kita authored Oct 3, 2024
1 parent a2b5c28 commit 00de952
Showing 1 changed file with 43 additions and 16 deletions.
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
}

0 comments on commit 00de952

Please sign in to comment.