diff --git a/clients/instance/ibm-pi-snapshot.go b/clients/instance/ibm-pi-snapshot.go index 676c9647..5fe18aae 100644 --- a/clients/instance/ibm-pi-snapshot.go +++ b/clients/instance/ibm-pi-snapshot.go @@ -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" ) @@ -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 +} diff --git a/examples/snapshot/main.go b/examples/snapshot/main.go index db5ead3d..55403a16 100644 --- a/examples/snapshot/main.go +++ b/examples/snapshot/main.go @@ -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, @@ -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) } diff --git a/go.mod b/go.mod index 49b13a69..017e73ae 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index fd49abf1..0ae0fcce 100644 --- a/go.sum +++ b/go.sum @@ -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=