Skip to content

Commit

Permalink
Merge pull request #29 from surajsub/master
Browse files Browse the repository at this point in the history
Added the client for Cloud Instance
  • Loading branch information
surajsub authored May 23, 2020
2 parents 9d08307 + 4495040 commit 46bd8fa
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 13 deletions.
64 changes: 64 additions & 0 deletions clients/instance/ibm-pi-cloud-instance.go
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 0 additions & 13 deletions clients/instance/ibm-pi-tenant.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
}
1 change: 1 addition & 0 deletions helpers/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 46bd8fa

Please sign in to comment.