diff --git a/clients/instance/ibm-pi-workspaces.go b/clients/instance/ibm-pi-workspaces.go index 6771c7ba..2630e4a9 100644 --- a/clients/instance/ibm-pi-workspaces.go +++ b/clients/instance/ibm-pi-workspaces.go @@ -24,11 +24,11 @@ func NewIBMPIWorkspacesClient(ctx context.Context, sess *ibmpisession.IBMPISessi } // Get a workspace -func (f *IBMPIWorkspacesClient) Get() (*models.Workspace, error) { +func (f *IBMPIWorkspacesClient) Get(cloudInstanceID string) (*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) + params := workspaces.NewV1WorkspacesGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithWorkspaceID(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)) @@ -38,3 +38,19 @@ func (f *IBMPIWorkspacesClient) Get() (*models.Workspace, error) { } return resp.Payload, nil } + +// Get all workspaces +func (f *IBMPIWorkspacesClient) GetAll() (*models.Workspaces, error) { + if f.session.IsOnPrem() { + return nil, fmt.Errorf("operation not supported in satellite location, check documentation") + } + params := workspaces.NewV1WorkspacesGetallParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut) + resp, err := f.session.Power.Workspaces.V1WorkspacesGetall(params, f.session.AuthInfo(f.cloudInstanceID)) + if err != nil { + return nil, ibmpisession.SDKFailWithAPIError(err, fmt.Errorf("failed to Get all Workspaces: %w", err)) + } + if resp == nil || resp.Payload == nil { + return nil, fmt.Errorf("failed to Get all Workspaces") + } + return resp.Payload, nil +} diff --git a/examples/datacenters/main.go b/examples/datacenters/main.go new file mode 100644 index 00000000..1e657899 --- /dev/null +++ b/examples/datacenters/main.go @@ -0,0 +1,58 @@ +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.NewIBMPIDatacenterClient(context.Background(), session, piID) + if err != nil { + log.Fatal(err) + } + getDatacenter, err := powerClient.Get("dal12") + if err != nil { + log.Fatal(err) + } + log.Printf("***************[0]****************** %+v \n", getDatacenter) + getDatacenters, err := powerClient.GetAll() + if err != nil { + log.Fatal(err) + } + log.Printf("***************[1]****************** %+v \n", getDatacenters) +} diff --git a/examples/workspaces/main.go b/examples/workspaces/main.go index 8c323d31..2655aaa7 100644 --- a/examples/workspaces/main.go +++ b/examples/workspaces/main.go @@ -44,9 +44,14 @@ func main() { if err != nil { log.Fatal(err) } - getWorkspace, err := powerClient.Get() + getWorkspace, err := powerClient.Get(piID) if err != nil { log.Fatal(err) } log.Printf("***************[0]****************** %+v \n", *getWorkspace) + getWorkspaces, err := powerClient.GetAll() + if err != nil { + log.Fatal(err) + } + log.Printf("***************[1]****************** %+v \n", *getWorkspaces) }