Skip to content

Commit

Permalink
Add Snaphots (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkad authored Jul 11, 2024
1 parent 9b9e06d commit 425ad33
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
30 changes: 30 additions & 0 deletions clients/instance/ibm-pi-snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"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/client/snapshots"

"github.com/IBM-Cloud/power-go-client/power/models"
)

Expand Down Expand Up @@ -96,3 +98,31 @@ func (f *IBMPISnapshotClient) Create(instanceID, snapshotID, restoreFailAction s
}
return resp.Payload, nil
}

// Get a SnapshotV1
func (f *IBMPISnapshotClient) V1SnapshotsGet(id string) (*models.SnapshotV1, error) {
params := snapshots.NewV1SnapshotsGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithSnapshotID(id)
resp, err := f.session.Power.Snapshots.V1SnapshotsGet(params, f.session.AuthInfo(f.cloudInstanceID))

if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get PI Snapshot %s: %w", id, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get PI Snapshot %s", id)
}
return resp.Payload, nil
}

// Get All SnapshotsV1
func (f *IBMPISnapshotClient) V1SnapshotsGetall() (*models.SnapshotList, error) {
params := snapshots.NewV1SnapshotsGetallParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
resp, err := f.session.Power.Snapshots.V1SnapshotsGetall(params, f.session.AuthInfo(f.cloudInstanceID))

if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get all PI Snapshots: %w", err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get all PI Snapshots")
}
return resp.Payload, nil
}
13 changes: 13 additions & 0 deletions examples/snapshot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ func main() {
instance_id := " < INSTANCE ID > "
snap_name := " < SNAPSHOT NAME > "
description := " < DESCRIPTION > "
snapshot_id := " < SNAPSHOT ID > "

authenticator := &core.BearerTokenAuthenticator{
BearerToken: token,
Expand Down Expand Up @@ -81,4 +82,16 @@ func main() {
}
log.Printf("***************[4]****************** %+v \n", err)

// ***************[] SnapshotsV1 []******************
getAllSnapV1Resp, err := powerSnapClient.V1SnapshotsGetall()
if err != nil {
log.Fatal(err)
}
log.Printf("***************[5]****************** %+v \n", getAllSnapV1Resp)

getSnapV1Resp, err := powerSnapClient.V1SnapshotsGet(snapshot_id)
if err != nil {
log.Fatal(err)
}
log.Printf("***************[6]****************** %+v \n", getSnapV1Resp)
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/IBM-Cloud/power-go-client

go 1.22
go 1.22.0

require (
github.com/IBM/go-sdk-core/v5 v5.15.3
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
github.com/onsi/gomega v1.29.0 h1:KIA/t2t5UBzoirT4H9tsML45GEbo3ouUnBHsCfD2tVg=
github.com/onsi/gomega v1.29.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+1B0VhjKrZUs=
github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
Expand Down

0 comments on commit 425ad33

Please sign in to comment.