forked from IBM-Cloud/power-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
db72303
commit 5423cf8
Showing
3 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |