From 136625436567f0578658eef41771ab2ce8f7b047 Mon Sep 17 00:00:00 2001 From: Yussuf Shaikh Date: Thu, 9 Dec 2021 22:15:14 +0530 Subject: [PATCH] Revert "Refactor placement groups and others" --- clients/instance/ibm-pi-cloud-instance.go | 58 ++++------ clients/instance/ibm-pi-placement-groups.go | 113 ++++++++------------ clients/instance/ibm-pi-system-pools.go | 32 ++---- errors/errors.go | 6 +- 4 files changed, 74 insertions(+), 135 deletions(-) diff --git a/clients/instance/ibm-pi-cloud-instance.go b/clients/instance/ibm-pi-cloud-instance.go index 85845e36..61d9b91f 100644 --- a/clients/instance/ibm-pi-cloud-instance.go +++ b/clients/instance/ibm-pi-cloud-instance.go @@ -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" @@ -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 } diff --git a/clients/instance/ibm-pi-placement-groups.go b/clients/instance/ibm-pi-placement-groups.go index 070a898c..e650ecee 100644 --- a/clients/instance/ibm-pi-placement-groups.go +++ b/clients/instance/ibm-pi-placement-groups.go @@ -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" @@ -16,73 +13,57 @@ 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) } @@ -90,33 +71,25 @@ func (f *IBMPIPlacementGroupClient) Delete(id string) error { } // 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 } diff --git a/clients/instance/ibm-pi-system-pools.go b/clients/instance/ibm-pi-system-pools.go index 5fe32bfa..c8ace83d 100644 --- a/clients/instance/ibm-pi-system-pools.go +++ b/clients/instance/ibm-pi-system-pools.go @@ -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" @@ -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 } diff --git a/errors/errors.go b/errors/errors.go index 3cbe6299..1a024891 100644 --- a/errors/errors.go +++ b/errors/errors.go @@ -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