Skip to content

Commit

Permalink
Merge pull request #33 from surajsub/master
Browse files Browse the repository at this point in the history
Fix timeouts for get / post
  • Loading branch information
surajsub authored Jun 1, 2020
2 parents 568cf00 + 6dcbb59 commit 3b42099
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 30 deletions.
9 changes: 4 additions & 5 deletions clients/instance/ibm-pi-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ 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 @@ -24,7 +23,7 @@ func NewIBMPIImageClient(sess *ibmpisession.IBMPISession, powerinstanceid string

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

params := p_cloud_images.NewPcloudCloudinstancesImagesGetParamsWithTimeout(30 * time.Second).WithCloudInstanceID(powerinstanceid).WithImageID(id)
params := p_cloud_images.NewPcloudCloudinstancesImagesGetParamsWithTimeout(postTimeOut).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 @@ -36,7 +35,7 @@ func (f *IBMPIImageClient) Get(id, powerinstanceid string) (*models.Image, error

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

params := p_cloud_images.NewPcloudCloudinstancesImagesGetallParamsWithTimeout(30 * time.Second).WithCloudInstanceID(powerinstanceid)
params := p_cloud_images.NewPcloudCloudinstancesImagesGetallParamsWithTimeout(getTimeOut).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 All @@ -57,7 +56,7 @@ func (f *IBMPIImageClient) Create(name, imageid string, powerinstanceid string)
ImageID: imageid,
Source: &source,
}
params := p_cloud_images.NewPcloudCloudinstancesImagesPostParamsWithTimeout(f.session.Timeout).WithCloudInstanceID(powerinstanceid).WithBody(&body)
params := p_cloud_images.NewPcloudCloudinstancesImagesPostParamsWithTimeout(postTimeOut).WithCloudInstanceID(powerinstanceid).WithBody(&body)
resp, err, _ := f.session.Power.PCloudImages.PcloudCloudinstancesImagesPost(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err.Payload.State == "queued" {
log.Printf("Post is successful %s", *err.Payload.ImageID)
Expand All @@ -74,7 +73,7 @@ func (f *IBMPIImageClient) Create(name, imageid string, powerinstanceid string)

// Delete ...
func (f *IBMPIImageClient) Delete(id string, powerinstanceid string) error {
params := p_cloud_images.NewPcloudCloudinstancesImagesDeleteParamsWithTimeout(30 * time.Second).WithCloudInstanceID(powerinstanceid).WithImageID(id)
params := p_cloud_images.NewPcloudCloudinstancesImagesDeleteParamsWithTimeout(deleteTimeOut).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
24 changes: 12 additions & 12 deletions clients/instance/ibm-pi-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,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(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesGetParamsWithTimeout(postTimeOut).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 @@ -39,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(30).WithCloudInstanceID(powerinstanceid)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesGetallParamsWithTimeout(getTimeOut).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 @@ -53,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(30).WithCloudInstanceID(powerinstanceid).WithBody(powerdef.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPostParamsWithTimeout(postTimeOut).WithCloudInstanceID(powerinstanceid).WithBody(powerdef.Body)

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

Expand Down Expand Up @@ -88,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(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesDeleteParamsWithTimeout(deleteTimeOut).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)
_, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesDelete(params, ibmpisession.NewAuth(f.session, powerinstanceid))

if err != nil {
Expand All @@ -102,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(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id).WithBody(powerupdateparams.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPutParamsWithTimeout(postTimeOut).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 @@ -117,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(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id).WithBody(poweractionparams.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesActionPostParamsWithTimeout(postTimeOut).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id).WithBody(poweractionparams.Body)

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

Expand All @@ -133,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(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesConsolePostParamsWithTimeout(postTimeOut).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id)

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

Expand All @@ -147,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(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(id).WithBody(picaptureparams.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesCapturePostParamsWithTimeout(getTimeOut).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 @@ -159,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(30).WithPvmInstanceID(pvminstanceid).WithCloudInstanceID(powerinstanceid).WithBody(snapshotdef.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsPostParamsWithTimeout(postTimeOut).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 @@ -178,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(30).WithPvmInstanceID(pvminstanceid).WithCloudInstanceID(powerinstanceid).WithBody(clonedef.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesClonePostParamsWithTimeout(postTimeOut).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 @@ -194,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(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(pvminstanceid)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsGetallParamsWithTimeout(postTimeOut).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 @@ -209,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(30).WithCloudInstanceID(powerinstanceid).WithPvmInstanceID(pvminstanceid).WithSnapshotID(snapshotid).WithRestoreFailAction(&restoreAction).WithBody(restoreparams.Body)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsRestorePostParamsWithTimeout(postTimeOut).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
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.NewPcloudCloudinstancesSnapshotsGetParamsWithTimeout(30).WithCloudInstanceID(powerinstanceid).WithSnapshotID(id)
params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsGetParamsWithTimeout(f.session.Timeout).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(30).WithCloudInstanceID(powerinstanceid).WithSnapshotID(id)
params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsDeleteParamsWithTimeout(f.session.Timeout).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(30).WithCloudInstanceID(powerinstanceid).WithSnapshotID(id).WithBody(snapshotdef)
params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsPutParamsWithTimeout(f.session.Timeout).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(30).WithCloudInstanceID(powerinstanceid)
params := p_cloud_snapshots.NewPcloudCloudinstancesSnapshotsGetallParamsWithTimeout(f.session.Timeout).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(30).WithCloudInstanceID(powerinstanceid).WithCloudInstanceID(pvminstanceid).WithSnapshotID(snapshotid).WithRestoreFailAction(&restorefailAction)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsRestorePostParamsWithTimeout(f.session.Timeout).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 3b42099

Please sign in to comment.