Skip to content

Commit

Permalink
Merge pull request #19 from surajsub/master
Browse files Browse the repository at this point in the history
Updated the client to add the snapshot code-version 1
  • Loading branch information
surajsub authored May 12, 2020
2 parents 8e43ae7 + 72ed3d8 commit 6504e94
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions clients/instance/ibm-pi-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,9 @@ func (f *IBMPIInstanceClient) CaptureInstanceToImageCatalog(id, powerinstanceid

// Create a snapshot of the instance

func (f *IBMPIInstanceClient) CreatePvmSnapShot(id, powerinstanceid string) (*models.SnapshotCreateResponse, error) {
func (f *IBMPIInstanceClient) CreatePvmSnapShot(pvminstanceid, powerinstanceid string, snapshotdef *p_cloud_p_vm_instances.PcloudPvminstancesSnapshotsPostParams) (*models.SnapshotCreateResponse, error) {
log.Printf("Calling the Power PVM Snaphshot Method")
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsPostParamsWithTimeout(f.session.Timeout).WithPvmInstanceID(id).WithCloudInstanceID(powerinstanceid)
params := p_cloud_p_vm_instances.NewPcloudPvminstancesSnapshotsPostParamsWithTimeout(f.session.Timeout).WithPvmInstanceID(pvminstanceid).WithCloudInstanceID(powerinstanceid).WithBody(snapshotdef.Body)
snapshotpostok, err := f.session.Power.PCloudPVMInstances.PcloudPvminstancesSnapshotsPost(params, ibmpisession.NewAuth(f.session, powerinstanceid))
if err != nil {
return nil, errors.ToError(err)
Expand Down
18 changes: 16 additions & 2 deletions clients/instance/ibm-pi-snapshot.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
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_p_vm_instances"
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_snapshots"
"github.com/IBM-Cloud/power-go-client/power/models"
"log"
Expand Down Expand Up @@ -48,9 +50,9 @@ func (f *IBMPISnapshotClient) Delete(id string, powerinstanceid string) error {
}

// Update..
func (f *IBMPISnapshotClient) Update(id, powerinstanceid string) (models.Object, error) {
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)
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 @@ -74,3 +76,15 @@ func (f *IBMPISnapshotClient) GetAll(id, powerinstanceid string) (*models.Snapsh
return resp.Payload, nil

}

// Restore a Snapshot

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)
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")
}
return resp.Payload, nil
}

0 comments on commit 6504e94

Please sign in to comment.