Skip to content

Commit

Permalink
Add workspace Get
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelkad committed Sep 29, 2023
1 parent db72303 commit 5423cf8
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 0 deletions.
40 changes: 40 additions & 0 deletions clients/instance/ibm-pi-workspaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package instance

import (
"context"
"fmt"

"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/IBM-Cloud/power-go-client/ibmpisession"
"github.com/IBM-Cloud/power-go-client/power/client/workspaces"
"github.com/IBM-Cloud/power-go-client/power/models"
)

// IBMPIWorkspacesClient
type IBMPIWorkspacesClient struct {
IBMPIClient
}

// NewIBMPIWorkspacesClient
func NewIBMPIWorkspacesClient(ctx context.Context, sess *ibmpisession.IBMPISession, cloudInstanceID string) *IBMPIWorkspacesClient {
return &IBMPIWorkspacesClient{
*NewIBMPIClient(ctx, sess, cloudInstanceID),
}
}

// Get a workspace
func (f *IBMPIWorkspacesClient) Get() (*models.Workspace, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := workspaces.NewV1WorkspacesGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithWorkspaceID(f.cloudInstanceID)
resp, err := f.session.Power.Workspaces.V1WorkspacesGet(params, f.session.AuthInfo(f.cloudInstanceID))
if err != nil {
return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf(errors.GetWorkspaceOperationFailed, f.cloudInstanceID, err))
}
if resp == nil || resp.Payload == nil {
return nil, fmt.Errorf("failed to Get Workspace %s", f.cloudInstanceID)
}
return resp.Payload, nil
}
3 changes: 3 additions & 0 deletions errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,9 @@ const DeleteSPPPlacementGroupOperationFailed = "failed to perform Delete Shared
const AddMemberSPPPlacementGroupOperationFailed = "failed to perform Add Member Operation for pool %s and shared processor pool placement group %s with error %w"
const DeleteMemberSPPPlacementGroupOperationFailed = "failed to perform Delete Member Operation for pool %s and shared processor pool placement group %s with error %w"

// start of workspaces
const GetWorkspaceOperationFailed = "failed to perform Get Workspace Operation for id %s with error %w"

// ErrorTarget ...
type ErrorTarget struct {
Name string
Expand Down
52 changes: 52 additions & 0 deletions examples/workspaces/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"context"
"log"

v "github.com/IBM-Cloud/power-go-client/clients/instance"
ps "github.com/IBM-Cloud/power-go-client/ibmpisession"

"github.com/IBM/go-sdk-core/v5/core"
)

func main() {
// token := ""
apiKey := ""
region := ""
zone := ""
accountID := ""
url := region + ".power-iaas.test.cloud.ibm.com"

piID := ""
// authenticator := &core.BearerTokenAuthenticator{
// BearerToken: token,
// }
authenticator := &core.IamAuthenticator{
ApiKey: apiKey,
// Uncomment for test environment
URL: "https://iam.test.cloud.ibm.com",
}
// Create the session
options := &ps.IBMPIOptions{
Authenticator: authenticator,
UserAccount: accountID,
Zone: zone,
URL: url,
Debug: true,
}

session, err := ps.NewIBMPISession(options)
if err != nil {
log.Fatal(err)
}
powerClient := v.NewIBMPIWorkspacesClient(context.Background(), session, piID)
if err != nil {
log.Fatal(err)
}
getWorkspace, err := powerClient.Get()
if err != nil {
log.Fatal(err)
}
log.Printf("***************[0]****************** %+v \n", *getWorkspace)
}

0 comments on commit 5423cf8

Please sign in to comment.