Skip to content

Commit

Permalink
Merge pull request #111 from IBM-Cloud/revert-110-dev
Browse files Browse the repository at this point in the history
Revert "Refactor placement groups and others"
  • Loading branch information
yussufsh authored Dec 9, 2021
2 parents 988d113 + 1366254 commit 7f83d6e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 135 deletions.
58 changes: 19 additions & 39 deletions clients/instance/ibm-pi-cloud-instance.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package instance

import (
"context"
"fmt"

"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/go-openapi/runtime"

"github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_instances"
Expand All @@ -16,60 +12,44 @@ import (
// IBMPICloudInstanceClient ...
type IBMPICloudInstanceClient struct {
session *ibmpisession.IBMPISession
cloudInstanceID string
authInfo runtime.ClientAuthInfoWriter
ctx context.Context
powerinstanceid string
}

// NewIBMPICloudInstanceClient ...
func NewIBMPICloudInstanceClient(ctx context.Context, sess *ibmpisession.IBMPISession, cloudInstanceID string) *IBMPICloudInstanceClient {
authInfo := ibmpisession.NewAuth(sess, cloudInstanceID)
func NewIBMPICloudInstanceClient(sess *ibmpisession.IBMPISession, powerinstanceid string) *IBMPICloudInstanceClient {
return &IBMPICloudInstanceClient{
sess,
cloudInstanceID,
authInfo,
ctx,
session: sess,
powerinstanceid: powerinstanceid,
}
}

// Get information about a cloud instance
func (f *IBMPICloudInstanceClient) Get(id string) (*models.CloudInstance, error) {
params := p_cloud_instances.NewPcloudCloudinstancesGetParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
WithCloudInstanceID(id)
resp, err := f.session.Power.PCloudInstances.PcloudCloudinstancesGet(params, f.authInfo)
func (f *IBMPICloudInstanceClient) Get(powerinstanceid string) (*models.CloudInstance, error) {
params := p_cloud_instances.NewPcloudCloudinstancesGetParams().WithCloudInstanceID(powerinstanceid)
resp, err := f.session.Power.PCloudInstances.PcloudCloudinstancesGet(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil {
return nil, fmt.Errorf(errors.GetCloudInstanceOperationFailed, id, err)
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Cloud Instance %s", id)
return nil, fmt.Errorf(errors.GetCloudInstanceOperationFailed, powerinstanceid, err)
}
return resp.Payload, nil
}

// Update a cloud instance
func (f *IBMPICloudInstanceClient) Update(id string, body *models.CloudInstanceUpdate) (*models.CloudInstance, error) {
params := p_cloud_instances.NewPcloudCloudinstancesPutParams().
WithContext(f.ctx).WithTimeout(helpers.PIUpdateTimeOut).
WithCloudInstanceID(id).WithBody(body)
resp, err := f.session.Power.PCloudInstances.PcloudCloudinstancesPut(params, f.authInfo)
func (f *IBMPICloudInstanceClient) Update(powerinstanceid string, updateparams *p_cloud_instances.PcloudCloudinstancesPutParams) (*models.CloudInstance, error) {
params := p_cloud_instances.NewPcloudCloudinstancesPutParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithBody(updateparams.Body)
resp, err := f.session.Power.PCloudInstances.PcloudCloudinstancesPut(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil {
return nil, fmt.Errorf(errors.UpdateCloudInstanceOperationFailed, id, err)
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to update the Cloud instance %s", id)
return nil, fmt.Errorf(errors.UpdateCloudInstanceOperationFailed, powerinstanceid, err)

}
return resp.Payload, nil
}

// Delete a Cloud instance
func (f *IBMPICloudInstanceClient) Delete(id string) error {
params := p_cloud_instances.NewPcloudCloudinstancesDeleteParams().
WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).
WithCloudInstanceID(id)
_, err := f.session.Power.PCloudInstances.PcloudCloudinstancesDelete(params, f.authInfo)
if err != nil {
return fmt.Errorf(errors.DeleteCloudInstanceOperationFailed, id, err)
func (f *IBMPICloudInstanceClient) Delete(powerinstanceid string) (models.Object, error) {
params := p_cloud_instances.NewPcloudCloudinstancesDeleteParams().WithCloudInstanceID(powerinstanceid)
resp, err := f.session.Power.PCloudInstances.PcloudCloudinstancesDelete(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil || resp.Payload == nil {
return nil, fmt.Errorf(errors.DeleteCloudInstanceOperationFailed, powerinstanceid, err)
}
return nil
return resp.Payload, nil
}
113 changes: 43 additions & 70 deletions clients/instance/ibm-pi-placement-groups.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package instance

import (
"context"
"fmt"

"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_placement_groups"
"github.com/go-openapi/runtime"

"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/IBM-Cloud/power-go-client/ibmpisession"
Expand All @@ -16,107 +13,83 @@ import (
//IBMPIPlacementGroupClient ...
type IBMPIPlacementGroupClient struct {
session *ibmpisession.IBMPISession
cloudInstanceID string
authInfo runtime.ClientAuthInfoWriter
ctx context.Context
powerinstanceid string
}

// NewIBMPIPlacementGroupClient ...
func NewIBMPIPlacementGroupClient(ctx context.Context, sess *ibmpisession.IBMPISession, cloudInstanceID string) *IBMPISAPInstanceClient {
authInfo := ibmpisession.NewAuth(sess, cloudInstanceID)
return &IBMPISAPInstanceClient{
// NewIBMPIImageClient ...
func NewIBMPIPlacementGroupClient(sess *ibmpisession.IBMPISession, powerinstanceid string) *IBMPIPlacementGroupClient {
return &IBMPIPlacementGroupClient{
session: sess,
cloudInstanceID: cloudInstanceID,
authInfo: authInfo,
ctx: ctx,
powerinstanceid: powerinstanceid,
}
}

// Get PI Placementgroup
func (f *IBMPIPlacementGroupClient) Get(id string) (*models.PlacementGroup, error) {
params := p_cloud_placement_groups.NewPcloudPlacementgroupsGetParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
WithCloudInstanceID(f.cloudInstanceID).WithPlacementGroupID(id)
resp, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsGet(params, f.authInfo)
func (f *IBMPIPlacementGroupClient) Get(id, powerinstanceid string) (*models.PlacementGroup, error) {

params := p_cloud_placement_groups.NewPcloudPlacementgroupsGetParamsWithTimeout(helpers.PIGetTimeOut).WithCloudInstanceID(powerinstanceid).WithPlacementGroupID(id)
resp, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsGet(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil {
return nil, fmt.Errorf(errors.GetPlacementGroupOperationFailed, id, err)
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Placement Group %s", id)
}
return resp.Payload, nil
}

// Get All placement groups
func (f *IBMPIPlacementGroupClient) GetAll() (*models.PlacementGroups, error) {
params := p_cloud_placement_groups.NewPcloudPlacementgroupsGetallParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
WithCloudInstanceID(f.cloudInstanceID)
resp, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsGetall(params, f.authInfo)
// GEt All placement groups

func (f *IBMPIPlacementGroupClient) GetAll(powerinstanceid string) (*models.PlacementGroups, error) {
params := p_cloud_placement_groups.NewPcloudPlacementgroupsGetallParamsWithTimeout(helpers.PIGetTimeOut).WithCloudInstanceID(powerinstanceid)
resp, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsGetall(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil {
return nil, fmt.Errorf("failed to Get All Placement Groups: %w", err)
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get all Placement Groups")
return nil, fmt.Errorf(errors.GetPlacementGroupOperationFailed, powerinstanceid, err)
}
return resp.Payload, nil
}

// Create the placement group
func (f *IBMPIPlacementGroupClient) Create(body *models.PlacementGroupCreate) (*models.PlacementGroup, error) {
params := p_cloud_placement_groups.NewPcloudPlacementgroupsPostParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
WithCloudInstanceID(f.cloudInstanceID).WithBody(body)
postok, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsPost(params, f.authInfo)
if err != nil {
return nil, fmt.Errorf(errors.CreatePlacementGroupOperationFailed, f.cloudInstanceID, err)
}
if postok == nil || postok.Payload == nil {
return nil, fmt.Errorf("failed to Create Placement Group")
//Create the placement group
func (f *IBMPIPlacementGroupClient) Create(powerdef *p_cloud_placement_groups.PcloudPlacementgroupsPostParams, powerinstanceid string) (*models.PlacementGroup, error) {

params := p_cloud_placement_groups.NewPcloudPlacementgroupsPostParamsWithTimeout(helpers.PICreateTimeOut).WithCloudInstanceID(powerinstanceid).WithBody(powerdef.Body)
result, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsPost(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil || result == nil || result.Payload == nil {
return nil, fmt.Errorf(errors.CreatePlacementGroupOperationFailed, powerinstanceid, err)
}
return postok.Payload, nil
return result.Payload, nil

}

// Delete Placement Group
func (f *IBMPIPlacementGroupClient) Delete(id string) error {
params := p_cloud_placement_groups.NewPcloudPlacementgroupsDeleteParams().
WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).
WithCloudInstanceID(f.cloudInstanceID).WithPlacementGroupID(id)
_, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsDelete(params, f.authInfo)
func (f *IBMPIPlacementGroupClient) Delete(id string, powerinstanceid string) error {
params := p_cloud_placement_groups.NewPcloudPlacementgroupsDeleteParamsWithTimeout(helpers.PIDeleteTimeOut).WithCloudInstanceID(powerinstanceid).WithPlacementGroupID(id)
_, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsDelete(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil {
return fmt.Errorf(errors.DeletePlacementGroupOperationFailed, id, err)
}
return nil
}

// Adding a member to a Placement Group
func (f *IBMPIPlacementGroupClient) AddMember(id string, body *models.PlacementGroupServer) (*models.PlacementGroup, error) {
params := p_cloud_placement_groups.NewPcloudPlacementgroupsMembersPostParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
WithCloudInstanceID(f.cloudInstanceID).WithPlacementGroupID(id).
WithBody(body)
postok, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsMembersPost(params, f.authInfo)
func (f *IBMPIPlacementGroupClient) Update(placementdef *p_cloud_placement_groups.PcloudPlacementgroupsMembersPostParams, placementgroupid, powerinstanceid string) (*models.PlacementGroup, error) {

params := p_cloud_placement_groups.NewPcloudPlacementgroupsMembersPostParamsWithTimeout(helpers.PICreateTimeOut).WithCloudInstanceID(powerinstanceid).WithPlacementGroupID(placementgroupid).WithBody(placementdef.Body)
resp, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsMembersPost(params, ibmpisession.NewAuth(f.session, f.powerinstanceid))

if err != nil {
return nil, fmt.Errorf(errors.AddMemberPlacementGroupOperationFailed, *body.ID, id, err)
return nil, fmt.Errorf(errors.UpdatePlacementGroupOperationFailed, powerinstanceid, placementgroupid, err)
}
if postok == nil || postok.Payload == nil {
return nil, fmt.Errorf("failed to Add Member for instance %s and placement group %s", *body.ID, id)
}
return postok.Payload, nil
return resp.Payload, nil
}

// Delete Member from Placement Group
func (f *IBMPIPlacementGroupClient) DeleteMember(id string, body *models.PlacementGroupServer) (*models.PlacementGroup, error) {
params := p_cloud_placement_groups.NewPcloudPlacementgroupsMembersDeleteParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
WithCloudInstanceID(f.cloudInstanceID).WithPlacementGroupID(id).
WithBody(body)
delok, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsMembersDelete(params, f.authInfo)
func (f *IBMPIPlacementGroupClient) DeleteMember(placementdef *p_cloud_placement_groups.PcloudPlacementgroupsMembersPostParams, placementgroupid, powerinstanceid string) (*models.PlacementGroup, error) {

params := p_cloud_placement_groups.NewPcloudPlacementgroupsMembersDeleteParamsWithTimeout(helpers.PICreateTimeOut).WithCloudInstanceID(powerinstanceid).WithPlacementGroupID(placementgroupid).WithBody(placementdef.Body)
resp, err := f.session.Power.PCloudPlacementGroups.PcloudPlacementgroupsMembersDelete(params, ibmpisession.NewAuth(f.session, f.powerinstanceid))

if err != nil {
return nil, fmt.Errorf(errors.DeleteMemberPlacementGroupOperationFailed, *body.ID, id, err)
return nil, fmt.Errorf(errors.DeleteMemberPlacementGroupOperationFailed, powerinstanceid, placementgroupid, err)
}
if delok == nil || delok.Payload == nil {
return nil, fmt.Errorf("failed to Delete Member for instance %s and placement group %s", *body.ID, id)
}
return delok.Payload, nil
return resp.Payload, nil
}
32 changes: 9 additions & 23 deletions clients/instance/ibm-pi-system-pools.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package instance

import (
"context"
"fmt"

"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/go-openapi/runtime"

"github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_system_pools"
Expand All @@ -16,33 +12,23 @@ import (
// IBMPISystemPoolClient ...
type IBMPISystemPoolClient struct {
session *ibmpisession.IBMPISession
cloudInstanceID string
authInfo runtime.ClientAuthInfoWriter
ctx context.Context
powerinstanceid string
}

// NewIBMPISystemPoolClient ...
func NewIBMPISystemPoolClient(ctx context.Context, sess *ibmpisession.IBMPISession, cloudInstanceID string) *IBMPISystemPoolClient {
authInfo := ibmpisession.NewAuth(sess, cloudInstanceID)
func NewIBMPISystemPoolClient(sess *ibmpisession.IBMPISession, powerinstanceid string) *IBMPISystemPoolClient {
return &IBMPISystemPoolClient{
sess,
cloudInstanceID,
authInfo,
ctx,
sess, powerinstanceid,
}
}

//Get the System Pools
func (f *IBMPISystemPoolClient) Get(id string) (models.SystemPools, error) {
params := p_cloud_system_pools.NewPcloudSystempoolsGetParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
WithCloudInstanceID(id)
resp, err := f.session.Power.PCloudSystemPools.PcloudSystempoolsGet(params, f.authInfo)
if err != nil {
return nil, fmt.Errorf(errors.GetSystemPoolsOperationFailed, id, err)
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to perform Get System Pools Operation for cloud instance id %s", id)
func (f *IBMPISystemPoolClient) Get(powerinstanceid string) (models.SystemPools, error) {
params := p_cloud_system_pools.NewPcloudSystempoolsGetParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid)
resp, err := f.session.Power.PCloudSystemPools.PcloudSystempoolsGet(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil || resp.Payload == nil {
return nil, fmt.Errorf(errors.GetSystemPoolsOperationFailed, powerinstanceid, err)
}
return resp.Payload, nil
}
6 changes: 3 additions & 3 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import (

// start of Placementgroup Messages

const GetPlacementGroupOperationFailed = "failed to perform Get Placement Group Operation for placement group %s with error %w"
const GetPlacementGroupOperationFailed = "failed to perform Get Placement Group Operation for placement group %s with error %w"
const CreatePlacementGroupOperationFailed = "failed to perform Create Placement Group Operation for powerinstanceid %s with error %w"
const DeletePlacementGroupOperationFailed = "failed to perform Delete Placement Group Operation for placement group %s with error %w"
const AddMemberPlacementGroupOperationFailed = "failed to perform Add Member Operation for instance %s and placement group %s with error %w"
const DeleteMemberPlacementGroupOperationFailed = "failed to perform Delete Member Operation for instance %s and placement group %s with error %w"
const UpdatePlacementGroupOperationFailed = "failed to perform Update Placement Group Operation for powerinstanceid %s and placement group %s with error %w"
const DeleteMemberPlacementGroupOperationFailed = "failed to perform Delete Placement Group Operation for powerinstanceid %s and placement group %s with error %w"

// start of Cloud Connection Messages

Expand Down

0 comments on commit 7f83d6e

Please sign in to comment.