Skip to content

Commit

Permalink
Standardize off/on prem error message (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
ismirlia authored Jan 30, 2025
1 parent ab318b6 commit 317d549
Show file tree
Hide file tree
Showing 25 changed files with 76 additions and 90 deletions.
1 change: 0 additions & 1 deletion clients/instance/ibm-pi-clonevolumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"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/p_cloud_volumes"
Expand Down
17 changes: 8 additions & 9 deletions clients/instance/ibm-pi-cloud-connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"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/p_cloud_cloud_connections"
"github.com/IBM-Cloud/power-go-client/power/models"
Expand All @@ -27,7 +26,7 @@ func NewIBMPICloudConnectionClient(ctx context.Context, sess *ibmpisession.IBMPI
// Create a Cloud Connection
func (f *IBMPICloudConnectionClient) Create(body *models.CloudConnectionCreate) (*models.CloudConnection, *models.CloudConnectionCreateResponse, error) {
if f.session.IsOnPrem() {
return nil, nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsPostParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
Expand All @@ -51,7 +50,7 @@ func (f *IBMPICloudConnectionClient) Create(body *models.CloudConnectionCreate)
// Get a Cloud Connection
func (f *IBMPICloudConnectionClient) Get(id string) (*models.CloudConnection, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsGetParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
Expand All @@ -69,7 +68,7 @@ func (f *IBMPICloudConnectionClient) Get(id string) (*models.CloudConnection, er
// Get All Cloud Connections
func (f *IBMPICloudConnectionClient) GetAll() (*models.CloudConnections, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsGetallParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
Expand All @@ -87,7 +86,7 @@ func (f *IBMPICloudConnectionClient) GetAll() (*models.CloudConnections, error)
// Update a Cloud Connection
func (f *IBMPICloudConnectionClient) Update(id string, body *models.CloudConnectionUpdate) (*models.CloudConnection, *models.JobReference, error) {
if f.session.IsOnPrem() {
return nil, nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsPutParams().
WithContext(f.ctx).WithTimeout(helpers.PIUpdateTimeOut).
Expand All @@ -109,7 +108,7 @@ func (f *IBMPICloudConnectionClient) Update(id string, body *models.CloudConnect
// Delete a Cloud Connection
func (f *IBMPICloudConnectionClient) Delete(id string) (*models.JobReference, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsDeleteParams().
WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).
Expand All @@ -127,7 +126,7 @@ func (f *IBMPICloudConnectionClient) Delete(id string) (*models.JobReference, er
// Add a Network to a Cloud Connection
func (f *IBMPICloudConnectionClient) AddNetwork(id, networkID string) (models.Object, *models.JobReference, error) {
if f.session.IsOnPrem() {
return nil, nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsNetworksPutParams().
WithContext(f.ctx).WithTimeout(helpers.PIUpdateTimeOut).
Expand All @@ -149,7 +148,7 @@ func (f *IBMPICloudConnectionClient) AddNetwork(id, networkID string) (models.Ob
// Delete a Network from a Cloud Connection
func (f *IBMPICloudConnectionClient) DeleteNetwork(id, networkID string) (models.Object, *models.JobReference, error) {
if f.session.IsOnPrem() {
return nil, nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsNetworksDeleteParams().
WithContext(f.ctx).WithTimeout(helpers.PIDeleteTimeOut).
Expand All @@ -171,7 +170,7 @@ func (f *IBMPICloudConnectionClient) DeleteNetwork(id, networkID string) (models
// Get all VPCs for a Cloud Instance
func (f *IBMPICloudConnectionClient) GetVPC() (*models.CloudConnectionVirtualPrivateClouds, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsVirtualprivatecloudsGetallParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
Expand Down
1 change: 0 additions & 1 deletion clients/instance/ibm-pi-cloud-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"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/p_cloud_instances"
"github.com/IBM-Cloud/power-go-client/power/models"
Expand Down
1 change: 0 additions & 1 deletion clients/instance/ibm-pi-dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"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/p_cloud_service_d_h_c_p"
"github.com/IBM-Cloud/power-go-client/power/models"
Expand Down
20 changes: 10 additions & 10 deletions clients/instance/ibm-pi-host-groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewIBMPIHostGroupsClient(ctx context.Context, sess *ibmpisession.IBMPISessi
// Get All available hosts
func (f *IBMPIHostGroupsClient) GetAvailableHosts() (models.AvailableHostList, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := host_groups.NewV1AvailableHostsParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
resp, err := f.session.Power.HostGroups.V1AvailableHosts(params, f.session.AuthInfo(f.cloudInstanceID))
Expand All @@ -42,7 +42,7 @@ func (f *IBMPIHostGroupsClient) GetAvailableHosts() (models.AvailableHostList, e
// Get all host groups
func (f *IBMPIHostGroupsClient) GetHostGroups() (models.HostGroupList, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := host_groups.NewV1HostGroupsGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
resp, err := f.session.Power.HostGroups.V1HostGroupsGet(params, f.session.AuthInfo(f.cloudInstanceID))
Expand All @@ -59,7 +59,7 @@ func (f *IBMPIHostGroupsClient) GetHostGroups() (models.HostGroupList, error) {
// Create a host group
func (f *IBMPIHostGroupsClient) CreateHostGroup(body *models.HostGroupCreate) (*models.HostGroup, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := host_groups.NewV1HostGroupsPostParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithBody(body)
resp, err := f.session.Power.HostGroups.V1HostGroupsPost(params, f.session.AuthInfo(f.cloudInstanceID))
Expand All @@ -76,7 +76,7 @@ func (f *IBMPIHostGroupsClient) CreateHostGroup(body *models.HostGroupCreate) (*
// Update a host group
func (f *IBMPIHostGroupsClient) UpdateHostGroup(body *models.HostGroupShareOp, id string) (*models.HostGroup, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := host_groups.NewV1HostGroupsIDPutParams().WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).WithBody(body).WithHostGroupID(id)
resp, err := f.session.Power.HostGroups.V1HostGroupsIDPut(params, f.session.AuthInfo(f.cloudInstanceID))
Expand All @@ -93,7 +93,7 @@ func (f *IBMPIHostGroupsClient) UpdateHostGroup(body *models.HostGroupShareOp, i
// Get a host group
func (f *IBMPIHostGroupsClient) GetHostGroup(id string) (*models.HostGroup, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := host_groups.NewV1HostGroupsIDGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostGroupID(id)
resp, err := f.session.Power.HostGroups.V1HostGroupsIDGet(params, f.session.AuthInfo(f.cloudInstanceID))
Expand All @@ -110,7 +110,7 @@ func (f *IBMPIHostGroupsClient) GetHostGroup(id string) (*models.HostGroup, erro
// Get all hosts
func (f *IBMPIHostGroupsClient) GetHosts() (models.HostList, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
hostReference := true
params := host_groups.NewV1HostsGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut)
Expand All @@ -129,7 +129,7 @@ func (f *IBMPIHostGroupsClient) GetHosts() (models.HostList, error) {
// Create a host
func (f *IBMPIHostGroupsClient) CreateHost(body *models.HostCreate) (models.HostList, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := host_groups.NewV1HostsPostParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithBody(body)
resp, err := f.session.Power.HostGroups.V1HostsPost(params, f.session.AuthInfo(f.cloudInstanceID))
Expand All @@ -146,7 +146,7 @@ func (f *IBMPIHostGroupsClient) CreateHost(body *models.HostCreate) (models.Host
// Get a host
func (f *IBMPIHostGroupsClient) GetHost(id string) (*models.Host, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
hostReference := true
params := host_groups.NewV1HostsIDGetParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostID(id)
Expand All @@ -165,7 +165,7 @@ func (f *IBMPIHostGroupsClient) GetHost(id string) (*models.Host, error) {
// Update a host
func (f *IBMPIHostGroupsClient) UpdateHost(body *models.HostPut, id string) (*models.Host, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := host_groups.NewV1HostsIDPutParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostID(id).WithBody(body)
resp, err := f.session.Power.HostGroups.V1HostsIDPut(params, f.session.AuthInfo(f.cloudInstanceID))
Expand All @@ -182,7 +182,7 @@ func (f *IBMPIHostGroupsClient) UpdateHost(body *models.HostPut, id string) (*mo
// Delete a host
func (f *IBMPIHostGroupsClient) DeleteHost(id string) error {
if f.session.IsOnPrem() {
return fmt.Errorf("operation not supported in satellite location, check documentation")
return fmt.Errorf(helpers.NotOnPremSupported)
}
params := host_groups.NewV1HostsIDDeleteParams().WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).WithHostID(id)
resp, err := f.session.Power.HostGroups.V1HostsIDDelete(params, f.session.AuthInfo(f.cloudInstanceID))
Expand Down
8 changes: 3 additions & 5 deletions clients/instance/ibm-pi-image.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ import (
"context"
"fmt"

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

"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/p_cloud_images"
"github.com/IBM-Cloud/power-go-client/power/models"
"github.com/IBM/go-sdk-core/v5/core"
)

// IBMPIImageClient
Expand Down Expand Up @@ -81,7 +79,7 @@ func (f *IBMPIImageClient) Create(body *models.CreateImage) (*models.Image, erro
func (f *IBMPIImageClient) CreateCosImage(body *models.CreateCosImageImportJob) (imageJob *models.JobReference, err error) {
// Check for satellite differences in this endpoint
if !f.session.IsOnPrem() && body.Checksum {
return nil, fmt.Errorf("checksum parameter is not supported off-premise")
return nil, fmt.Errorf("checksum parameter is not supported in off-prem location")
}
params := p_cloud_images.NewPcloudV1CloudinstancesCosimagesPostParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
Expand All @@ -100,7 +98,7 @@ func (f *IBMPIImageClient) CreateCosImage(body *models.CreateCosImageImportJob)
func (f *IBMPIImageClient) ExportImage(id string, body *models.ExportImage) (*models.JobReference, error) {
// Check for satellite differences in this endpoint
if !f.session.IsOnPrem() && body.Checksum {
return nil, fmt.Errorf("checksum parameter is not supported off-premise")
return nil, fmt.Errorf("checksum parameter is not supported in off-prem location")
}
params := p_cloud_images.NewPcloudV2ImagesExportPostParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
Expand Down
10 changes: 5 additions & 5 deletions clients/instance/ibm-pi-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (f *IBMPIInstanceClient) GetAll() (*models.PVMInstances, error) {
func (f *IBMPIInstanceClient) Create(body *models.PVMInstanceCreate) (*models.PVMInstanceList, error) {
// Check for satellite differences in this endpoint
if f.session.IsOnPrem() && (body.DeploymentTarget != nil || body.DeploymentType != "") {
return nil, fmt.Errorf("deployment target and deployment type parameters are not supported in satellite location, check documentation")
return nil, fmt.Errorf("deployment target and deployment type parameters are not supported in satellite location")
}
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPostParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
Expand Down Expand Up @@ -105,7 +105,7 @@ func (f *IBMPIInstanceClient) DeleteWithBody(id string, body *models.PVMInstance
func (f *IBMPIInstanceClient) Update(id string, body *models.PVMInstanceUpdate) (*models.PVMInstanceUpdateResponse, error) {
// Check for satellite differences in this endpoint
if f.session.IsOnPrem() && body.SapProfileID != "" {
return nil, fmt.Errorf("sap profile id parameter is not supported in satellite location, check documentation")
return nil, fmt.Errorf("sap profile id parameter is not supported in satellite location")
}
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPutParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
Expand Down Expand Up @@ -152,7 +152,7 @@ func (f *IBMPIInstanceClient) PostConsoleURL(id string) (*models.PVMInstanceCons
// List the available Console Languages for an Instance
func (f *IBMPIInstanceClient) GetConsoleLanguages(id string) (*models.ConsoleLanguages, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := p_cloud_p_vm_instances.NewPcloudPvminstancesConsoleGetParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
Expand All @@ -170,7 +170,7 @@ func (f *IBMPIInstanceClient) GetConsoleLanguages(id string) (*models.ConsoleLan
// Update the available Console Languages for an Instance
func (f *IBMPIInstanceClient) UpdateConsoleLanguage(id string, body *models.ConsoleLanguage) (*models.ConsoleLanguage, error) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
return nil, fmt.Errorf(helpers.NotOnPremSupported)
}
params := p_cloud_p_vm_instances.NewPcloudPvminstancesConsolePutParams().
WithContext(f.ctx).WithTimeout(helpers.PIUpdateTimeOut).
Expand All @@ -190,7 +190,7 @@ func (f *IBMPIInstanceClient) UpdateConsoleLanguage(id string, body *models.Cons
func (f *IBMPIInstanceClient) CaptureInstanceToImageCatalog(id string, body *models.PVMInstanceCapture) error {
// Check for satellite differences in this endpoint
if !f.session.IsOnPrem() && body.Checksum {
return fmt.Errorf("checksum parameter is not supported off-premise")
return fmt.Errorf("checksum parameter is not supported in off-prem location")
}
params := p_cloud_p_vm_instances.NewPcloudPvminstancesCapturePostParams().
WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut).
Expand Down
1 change: 0 additions & 1 deletion clients/instance/ibm-pi-job.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"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/p_cloud_jobs"
"github.com/IBM-Cloud/power-go-client/power/models"
Expand Down
1 change: 0 additions & 1 deletion clients/instance/ibm-pi-key.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

"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/p_cloud_tenants_ssh_keys"
"github.com/IBM-Cloud/power-go-client/power/models"
Expand Down
Loading

0 comments on commit 317d549

Please sign in to comment.