Skip to content

Commit

Permalink
Merge pull request #31 from surajsub/master
Browse files Browse the repository at this point in the history
Minor Cleanup
  • Loading branch information
surajsub authored May 30, 2020
2 parents fa874a9 + 74197a1 commit 65e287f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 38 deletions.
7 changes: 4 additions & 3 deletions clients/instance/ibm-pi-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_images"
"github.com/IBM-Cloud/power-go-client/power/models"
"log"
"time"
)

type IBMPIImageClient struct {
Expand All @@ -23,7 +24,7 @@ func NewIBMPIImageClient(sess *ibmpisession.IBMPISession, powerinstanceid string

func (f *IBMPIImageClient) Get(id, powerinstanceid string) (*models.Image, error) {

params := p_cloud_images.NewPcloudCloudinstancesImagesGetParams().WithCloudInstanceID(powerinstanceid).WithImageID(id)
params := p_cloud_images.NewPcloudCloudinstancesImagesGetParamsWithTimeout(30 * time.Second).WithCloudInstanceID(powerinstanceid).WithImageID(id)
resp, err := f.session.Power.PCloudImages.PcloudCloudinstancesImagesGet(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil || resp.Payload == nil {
Expand All @@ -35,7 +36,7 @@ func (f *IBMPIImageClient) Get(id, powerinstanceid string) (*models.Image, error

func (f *IBMPIImageClient) GetAll(powerinstanceid string) (*models.Images, error) {

params := p_cloud_images.NewPcloudCloudinstancesImagesGetallParams().WithCloudInstanceID(powerinstanceid)
params := p_cloud_images.NewPcloudCloudinstancesImagesGetallParamsWithTimeout(30 * time.Second).WithCloudInstanceID(powerinstanceid)
resp, err := f.session.Power.PCloudImages.PcloudCloudinstancesImagesGetall(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil || resp.Payload == nil {
log.Printf("Failed to perform the operation... %v", err)
Expand Down Expand Up @@ -73,7 +74,7 @@ func (f *IBMPIImageClient) Create(name, imageid string, powerinstanceid string)

// Delete ...
func (f *IBMPIImageClient) Delete(id string, powerinstanceid string) error {
params := p_cloud_images.NewPcloudCloudinstancesImagesDeleteParams().WithCloudInstanceID(powerinstanceid).WithImageID(id)
params := p_cloud_images.NewPcloudCloudinstancesImagesDeleteParamsWithTimeout(30 * time.Second).WithCloudInstanceID(powerinstanceid).WithImageID(id)
_, err := f.session.Power.PCloudImages.PcloudCloudinstancesImagesDelete(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil {
return errors.ToError(err)
Expand Down
25 changes: 12 additions & 13 deletions clients/instance/ibm-pi-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_p_vm_instances"
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_s_a_p"
"github.com/IBM-Cloud/power-go-client/power/models"

"log"
)

Expand All @@ -27,7 +26,7 @@ func NewIBMPIInstanceClient(sess *ibmpisession.IBMPISession, powerinstanceid str
//Get information about a single pvm only
func (f *IBMPIInstanceClient) Get(id, powerinstanceid string) (*models.PVMInstance, error) {

params := p_cloud_p_vm_instances.NewPcloudPvminstancesGetParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesGetParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)
resp, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesGet(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil || resp.Payload == nil {
log.Printf("Failed to perform the operation... %v", err)
Expand All @@ -40,7 +39,7 @@ func (f *IBMPIInstanceClient) Get(id, powerinstanceid string) (*models.PVMInstan

func (f *IBMPIInstanceClient) GetAll(powerinstanceid string) (*models.PVMInstances, error) {

params := p_cloud_p_vm_instances.NewPcloudPvminstancesGetallParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesGetallParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid)
resp, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesGetall(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil || resp.Payload == nil {
log.Printf("Failed to perform the operation... %v", err)
Expand All @@ -54,7 +53,7 @@ func (f *IBMPIInstanceClient) GetAll(powerinstanceid string) (*models.PVMInstanc
func (f *IBMPIInstanceClient) Create(powerdef *p_cloud_p_vm_instances.PcloudPvminstancesPostParams, powerinstanceid string) (*models.PVMInstanceList, error) {

log.Printf("Calling the Power PVM Create Method")
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPostParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithBody(powerdef.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPostParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithBody(powerdef.Body)

log.Printf("Printing the params to be passed %+v", params)

Expand Down Expand Up @@ -89,7 +88,7 @@ func (f *IBMPIInstanceClient) Create(powerdef *p_cloud_p_vm_instances.PcloudPvmi
func (f *IBMPIInstanceClient) Delete(id, powerinstanceid string) error {

log.Printf("Calling the Power PVM Delete Method")
params := p_cloud_p_vm_instances.NewPcloudPvminstancesDeleteParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesDeleteParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)
_, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesDelete(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil {
Expand All @@ -103,7 +102,7 @@ func (f *IBMPIInstanceClient) Delete(id, powerinstanceid string) error {
func (f *IBMPIInstanceClient) Update(id, powerinstanceid string, powerupdateparams *p_cloud_p_vm_instances.PcloudPvminstancesPutParams) (*models.PVMInstanceUpdateResponse, error) {

log.Printf("Calling the Power PVM Update Instance Method")
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPutParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id).WithBody(powerupdateparams.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPutParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id).WithBody(powerupdateparams.Body)
resp, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesPut(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil {
Expand All @@ -118,7 +117,7 @@ func (f *IBMPIInstanceClient) Action(poweractionparams *p_cloud_p_vm_instances.P

log.Printf("Calling the Power PVM Action Method")
log.Printf("the params are %s - powerinstance id is %s", id, powerinstanceid)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesActionPostParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id).WithBody(poweractionparams.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesActionPostParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id).WithBody(poweractionparams.Body)

log.Printf("printing the poweraction params %+v", params)

Expand All @@ -134,7 +133,7 @@ func (f *IBMPIInstanceClient) Action(poweractionparams *p_cloud_p_vm_instances.P
// Generate the Console URL

func (f *IBMPIInstanceClient) PostConsoleURL(id, powerinstanceid string) (models.Object, error) {
params := p_cloud_p_vm_instances.NewPcloudPvminstancesConsolePostParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesConsolePostParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)

postok, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesConsolePost(params, ibmpisession.NewAuth(f.session, powerinstanceid))

Expand All @@ -148,7 +147,7 @@ func (f *IBMPIInstanceClient) PostConsoleURL(id, powerinstanceid string) (models

func (f *IBMPIInstanceClient) CaptureInstanceToImageCatalog(id, powerinstanceid string, picaptureparams *p_cloud_p_vm_instances.PcloudPvminstancesCapturePostParams) (models.Object, error) {

params := p_cloud_p_vm_instances.NewPcloudPvminstancesCapturePostParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id).WithBody(picaptureparams.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesCapturePostParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id).WithBody(picaptureparams.Body)
postok, _, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesCapturePost(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil {
return nil, errors.ToError(err)
Expand All @@ -160,7 +159,7 @@ func (f *IBMPIInstanceClient) CaptureInstanceToImageCatalog(id, powerinstanceid
// Create a snapshot of the instance
func (f *IBMPIInstanceClient) CreatePvmSnapShot(snapshotdef *p_cloud_p_vm_instances.PcloudPvminstancesSnapshotsPostParams, pvminstanceid, powerinstanceid string) (*models.SnapshotCreateResponse, error) {
log.Printf("Calling the Power PVM Snaphshot Method and printing the following data %s - %s - %s", snapshotdef.Body.Description, snapshotdef.Body.Name, snapshotdef.Body.VolumeIds)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsPostParamsWithTimeout(f.session.Timeout).WithPvmInstanceID(pvminstanceid).WithCloudInstanceID(powerinstanceid).WithBody(snapshotdef.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsPostParamsWithTimeout(30).WithPvmInstanceID(pvminstanceid).WithCloudInstanceID(powerinstanceid).WithBody(snapshotdef.Body)
snapshotpostaccepted, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesSnapshotsPost(params, ibmpisession.NewAuth(f.session, powerinstanceid))

log.Printf("*** Printing the error from the snapshot call *** %s", err)
Expand All @@ -179,7 +178,7 @@ func (f *IBMPIInstanceClient) CreatePvmSnapShot(snapshotdef *p_cloud_p_vm_instan

func (f *IBMPIInstanceClient) CreateClone(clonedef *p_cloud_p_vm_instances.PcloudPvminstancesClonePostParams, pvminstanceid, powerinstanceid string) (*models.PVMInstance, error) {
log.Printf("Calling the Power PVM Clone Method")
params := p_cloud_p_vm_instances.NewPcloudPvminstancesClonePostParamsWithTimeout(f.session.Timeout).WithPvmInstanceID(pvminstanceid).WithCloudInstanceID(powerinstanceid).WithBody(clonedef.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesClonePostParamsWithTimeout(30).WithPvmInstanceID(pvminstanceid).WithCloudInstanceID(powerinstanceid).WithBody(clonedef.Body)
clonePost, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesClonePost(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil {

Expand All @@ -195,7 +194,7 @@ func (f *IBMPIInstanceClient) GetSnapShotVM(powerinstanceid, pvminstanceid strin
log.Printf("Calling the GetSnapshot for vm Method..")
log.Printf("The input pvmid name is %s and to the cloudinstance id %s", pvminstanceid, powerinstanceid)

params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsGetallParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(pvminstanceid)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsGetallParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(pvminstanceid)
resp, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesSnapshotsGetall(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil || resp.Payload == nil {
Expand All @@ -210,7 +209,7 @@ func (f *IBMPIInstanceClient) GetSnapShotVM(powerinstanceid, pvminstanceid strin

func (f *IBMPIInstanceClient) RestoreSnapShotVM(powerinstanceid, pvminstanceid, snapshotid, restoreAction string, restoreparams *p_cloud_p_vm_instances.PcloudPvminstancesSnapshotsRestorePostParams) (*models.Snapshot, error) {
log.Printf("Performing the snapshot restore for lpar with instanceid [%s] and snapshotid [%s] ", pvminstanceid, snapshotid)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsRestorePostParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(pvminstanceid).WithSnapshotID(snapshotid).WithRestoreFailAction(&restoreAction).WithBody(restoreparams.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsRestorePostParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(pvminstanceid).WithSnapshotID(snapshotid).WithRestoreFailAction(&restoreAction).WithBody(restoreparams.Body)
resp, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesSnapshotsRestorePost(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil || resp.Payload.SnapshotID != nil {
Expand Down
9 changes: 5 additions & 4 deletions clients/instance/ibm-pi-network.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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_networks"
Expand Down Expand Up @@ -129,15 +130,15 @@ func (f *IBMPINetworkClient) GetPort(id string, powerinstanceid string, network_

//Create

func (f *IBMPINetworkClient) CreatePort(id string, powerinstanceid string, networportdef *p_cloud_networks.PcloudNetworksPortsPostParams) (*models.NetworkPort, error) {
params := p_cloud_networks.NewPcloudNetworksPortsPostParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithNetworkID(id).WithBody(networportdef.Body)
func (f *IBMPINetworkClient) CreatePort(id string, powerinstanceid string, networkportdef *p_cloud_networks.PcloudNetworksPortsPostParams) (*models.NetworkPort, error) {
params := p_cloud_networks.NewPcloudNetworksPortsPostParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithNetworkID(id).WithBody(networkportdef.Body)
resp, err := f.session.Power.PCloudNetworks.PcloudNetworksPortsPost(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil || resp.Payload == nil {
log.Printf("Failed to create the network port")

return nil, errors.ToError(err)
}
return resp.Payload, nil
return resp.Payload, fmt.Errorf("Failed to create the network port for cloud instance id [%s] ", powerinstanceid)
}

// Delete
Expand Down
10 changes: 5 additions & 5 deletions clients/instance/ibm-pi-snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (f *IBMPISnapshotClient) Get(id, powerinstanceid string) (*models.Snapshot,
log.Printf("Calling the Snapshotget Method..")
log.Printf("The input snapshot name is %s and to the cloudinstance id %s", id, powerinstanceid)

params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsGetParams().WithCloudInstanceID(powerinstanceid).WithSnapshotID(id)
params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsGetParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithSnapshotID(id)
resp, err := f.session.Power.PCloudSnapshots.PcloudCloudinstancesSnapshotsGet(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil || resp.Payload == nil {
Expand All @@ -41,7 +41,7 @@ func (f *IBMPISnapshotClient) Get(id, powerinstanceid string) (*models.Snapshot,
// Delete ...
func (f *IBMPISnapshotClient) Delete(id string, powerinstanceid string) error {
//var cloudinstanceid = f.session.PowerServiceInstance
params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsDeleteParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithSnapshotID(id)
params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsDeleteParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithSnapshotID(id)
_, err := f.session.Power.PCloudSnapshots.PcloudCloudinstancesSnapshotsDelete(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil {
return errors.ToError(err)
Expand All @@ -52,7 +52,7 @@ func (f *IBMPISnapshotClient) Delete(id string, powerinstanceid string) error {
// Update..
func (f *IBMPISnapshotClient) Update(id, powerinstanceid string, snapshotdef *models.SnapshotUpdate) (models.Object, error) {

params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsPutParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithSnapshotID(id).WithBody(snapshotdef)
params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsPutParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithSnapshotID(id).WithBody(snapshotdef)

resp, err := f.session.Power.PCloudSnapshots.PcloudCloudinstancesSnapshotsPut(params, ibmpisession.NewAuth(f.session, powerinstanceid))

Expand All @@ -68,7 +68,7 @@ func (f *IBMPISnapshotClient) Update(id, powerinstanceid string, snapshotdef *mo
func (f *IBMPISnapshotClient) GetAll(id, powerinstanceid string) (*models.Snapshots, error) {

log.Printf("Calling the Power Snapshots GetAll Method")
params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsGetallParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid)
params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsGetallParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid)
resp, err := f.session.Power.PCloudSnapshots.PcloudCloudinstancesSnapshotsGetall(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil {
return nil, errors.ToError(err)
Expand All @@ -81,7 +81,7 @@ func (f *IBMPISnapshotClient) GetAll(id, powerinstanceid string) (*models.Snapsh

func (f *IBMPISnapshotClient) Create(pvminstanceid, powerinstanceid, snapshotid, restorefailAction string) (*models.Snapshot, error) {
log.Printf("Calling the Power Snapshots Restore Method")
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsRestorePostParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithCloudInstanceID(pvminstanceid).WithSnapshotID(snapshotid).WithRestoreFailAction(&restorefailAction)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsRestorePostParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithCloudInstanceID(pvminstanceid).WithSnapshotID(snapshotid).WithRestoreFailAction(&restorefailAction)
resp, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesSnapshotsRestorePost(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil {
return nil, fmt.Errorf("Failed to create the restore")
Expand Down
Loading

0 comments on commit 65e287f

Please sign in to comment.