Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Add Snaphots #420

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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