From 449504074bd13bc2ca7290a1c4205b4da527e724 Mon Sep 17 00:00:00 2001 From: suraj Date: Sat, 23 May 2020 15:55:58 -0500 Subject: [PATCH] Added the client for Cloud Instance --- clients/instance/ibm-pi-cloud-instance.go | 64 +++++++++++++++++++++++ clients/instance/ibm-pi-tenant.go | 13 ----- helpers/constants.go | 1 + 3 files changed, 65 insertions(+), 13 deletions(-) create mode 100644 clients/instance/ibm-pi-cloud-instance.go diff --git a/clients/instance/ibm-pi-cloud-instance.go b/clients/instance/ibm-pi-cloud-instance.go new file mode 100644 index 00000000..477cb3a2 --- /dev/null +++ b/clients/instance/ibm-pi-cloud-instance.go @@ -0,0 +1,64 @@ +package instance + +import ( + "github.com/IBM-Cloud/power-go-client/errors" + "github.com/IBM-Cloud/power-go-client/ibmpisession" + "github.com/IBM-Cloud/power-go-client/power/client/p_cloud_instances" + "github.com/IBM-Cloud/power-go-client/power/models" + "log" +) + +type IBMPICloudInstanceClient struct { + session *ibmpisession.IBMPISession + powerinstanceid string +} + +// IBMPICloudInstanceClient ... +func NewIBMPICloudInstanceClient(sess *ibmpisession.IBMPISession, powerinstanceid string) *IBMPICloudInstanceClient { + return &IBMPICloudInstanceClient{ + session: sess, + powerinstanceid: powerinstanceid, + } +} + +// Get information about a cloud instance +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 { + log.Printf("Failed to perform the operation... %v", err) + return nil, errors.ToError(err) + } + return resp.Payload, nil +} + +// Update a cloud instance + +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 { + log.Printf("Failed to perform the update operations %v", err) + return nil, errors.ToError(err) + + } + return resp.Payload, nil +} + +// Delete a Cloud instance + +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 { + log.Printf("Failed to perform the operation... %v", err) + return nil, errors.ToError(err) + } + return resp.Payload, nil +} diff --git a/clients/instance/ibm-pi-tenant.go b/clients/instance/ibm-pi-tenant.go index b8631b09..934d5673 100644 --- a/clients/instance/ibm-pi-tenant.go +++ b/clients/instance/ibm-pi-tenant.go @@ -1,10 +1,8 @@ package instance import ( - "fmt" "github.com/IBM-Cloud/power-go-client/errors" "github.com/IBM-Cloud/power-go-client/ibmpisession" - "github.com/IBM-Cloud/power-go-client/power/client/p_cloud_instances" "github.com/IBM-Cloud/power-go-client/power/client/p_cloud_tenants" "github.com/IBM-Cloud/power-go-client/power/models" "log" @@ -34,14 +32,3 @@ func (f *IBMPITenantClient) Get(powerinstanceid string) (*models.Tenant, error) } return resp.Payload, nil } - -func (f *IBMPITenantClient) GetServiceInstanceData(powerinstanceid string) (*models.CloudInstance, error) { - params := p_cloud_instances.NewPcloudCloudinstancesGetParams().WithCloudInstanceID(powerinstanceid) - serviceinstanceresp, err := f.session.Power.PCloudInstances.PcloudCloudinstancesGet(params, ibmpisession.NewAuth(f.session, powerinstanceid)) - - if err != nil || serviceinstanceresp.Payload == nil { - fmt.Errorf("Failed to make the call to get the Service Instance operation", err) - return nil, errors.ToError(err) - } - return serviceinstanceresp.Payload, nil -} diff --git a/helpers/constants.go b/helpers/constants.go index 19c467f0..8f85a3ef 100644 --- a/helpers/constants.go +++ b/helpers/constants.go @@ -25,6 +25,7 @@ const ( PIInstanceMaxProc = "pi_maxproc" PIInstanceMaxMem = "pi_maxmem" PIInstanceReboot = "pi_reboot" + PITenantId = "pi_tenant_id" PIInstanceHealthStatus = "pi_health_status" PIInstanceReplicants = "pi_replicants"