Skip to content

Commit

Permalink
Add additional stratos safeguards (#217)
Browse files Browse the repository at this point in the history
* Add additional stratos safeguards

This adds safegaurds for:
- volume action (replicationEnabled)
- volume create-v1 (replicationEnabled)
- volume create-v2 (replicationEnabled)
- volume list (auxiliary and replicationEnabled)
- instance update (profileID)

* Add helper function to check on premise

Also rewords one error message.

* Refactor IsOnPrem function
  • Loading branch information
ismirlia authored Aug 28, 2023
1 parent 0d9a5e9 commit 55018c4
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 64 deletions.
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 @@ -3,7 +3,6 @@ package instance
import (
"context"
"fmt"
"strings"

"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/helpers"
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 strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsPostParams().
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 strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsGetParams().
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 strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsGetallParams().
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 strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsPutParams().
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 strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsDeleteParams().
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 strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsNetworksPutParams().
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 strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsNetworksDeleteParams().
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 strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_cloud_connections.NewPcloudCloudconnectionsVirtualprivatecloudsGetallParams().
Expand Down
5 changes: 2 additions & 3 deletions clients/instance/ibm-pi-dr-location.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package instance
import (
"context"
"fmt"
"strings"

"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/helpers"
Expand All @@ -26,7 +25,7 @@ func NewIBMPIDisasterRecoveryLocationClient(ctx context.Context, sess *ibmpisess

// Get the disaster recovery site details for the current location
func (f *IBMPIDisasterRecoveryLocationClient) Get() (*models.DisasterRecoveryLocation, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_disaster_recovery.NewPcloudLocationsDisasterrecoveryGetParams().
Expand All @@ -44,7 +43,7 @@ func (f *IBMPIDisasterRecoveryLocationClient) Get() (*models.DisasterRecoveryLoc

// Get all disaster recovery locations supported by Power Virtual Server
func (f *IBMPIDisasterRecoveryLocationClient) GetAll() (*models.DisasterRecoveryLocations, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_disaster_recovery.NewPcloudLocationsDisasterrecoveryGetallParams().
Expand Down
13 changes: 8 additions & 5 deletions clients/instance/ibm-pi-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package instance
import (
"context"
"fmt"
"strings"

"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/IBM-Cloud/power-go-client/ibmpisession"
Expand Down Expand Up @@ -56,8 +55,8 @@ func (f *IBMPIInstanceClient) GetAll() (*models.PVMInstances, error) {
// Create an Instance
func (f *IBMPIInstanceClient) Create(body *models.PVMInstanceCreate) (*models.PVMInstanceList, error) {
// Check for satellite differences in this endpoint
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) && (body.SoftwareLicenses != nil || body.SharedProcessorPool != "") {
return nil, fmt.Errorf("softwareLicenses and sharedProcessorPool parameters are not supported in satellite location, check documentation")
if f.session.IsOnPrem() && (body.SoftwareLicenses != nil || body.SharedProcessorPool != "") {
return nil, fmt.Errorf("software licenses and shared processor pool parameters are not supported in satellite location, check documentation")
}
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPostParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
Expand Down Expand Up @@ -92,6 +91,10 @@ func (f *IBMPIInstanceClient) Delete(id string) error {

// Update an Instance
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")
}
params := p_cloud_p_vm_instances.NewPcloudPvminstancesPutParams().
WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut).
WithCloudInstanceID(f.cloudInstanceID).WithPvmInstanceID(id).WithBody(body)
Expand Down Expand Up @@ -136,7 +139,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 strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_p_vm_instances.NewPcloudPvminstancesConsoleGetParams().
Expand All @@ -154,7 +157,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 strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_p_vm_instances.NewPcloudPvminstancesConsolePutParams().
Expand Down
5 changes: 2 additions & 3 deletions clients/instance/ibm-pi-network.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package instance
import (
"context"
"fmt"
"strings"

"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/helpers"
Expand Down Expand Up @@ -67,9 +66,9 @@ func (f *IBMPINetworkClient) Create(body *models.NetworkCreate) (*models.Network
body.AccessConfig = defaultAccessConfig
}
// Check for satellite differences in this endpoint
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) && body.Jumbo {
if f.session.IsOnPrem() && body.Jumbo {
return nil, fmt.Errorf("jumbo parameter is not supported in satellite location, use mtu instead")
} else if !strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) && ((body.Mtu != nil && *body.Mtu != 1450) || body.AccessConfig != "internal-only") {
} else if !f.session.IsOnPrem() && ((body.Mtu != nil && *body.Mtu != 1450) || body.AccessConfig != "internal-only") {
return nil, fmt.Errorf("mtu and accessConfig parameters are not supported in multi-zone location, check documentation")
}
params := p_cloud_networks.NewPcloudNetworksPostParams().
Expand Down
7 changes: 3 additions & 4 deletions clients/instance/ibm-pi-sap-instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package instance
import (
"context"
"fmt"
"strings"

"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/IBM-Cloud/power-go-client/ibmpisession"
Expand All @@ -25,7 +24,7 @@ func NewIBMPISAPInstanceClient(ctx context.Context, sess *ibmpisession.IBMPISess

// Create a SAP Instance
func (f *IBMPISAPInstanceClient) Create(body *models.SAPCreate) (*models.PVMInstanceList, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_s_a_p.NewPcloudSapPostParams().
Expand All @@ -49,7 +48,7 @@ func (f *IBMPISAPInstanceClient) Create(body *models.SAPCreate) (*models.PVMInst

// Get a SAP Profile
func (f *IBMPISAPInstanceClient) GetSAPProfile(id string) (*models.SAPProfile, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_s_a_p.NewPcloudSapGetParams().
Expand All @@ -67,7 +66,7 @@ func (f *IBMPISAPInstanceClient) GetSAPProfile(id string) (*models.SAPProfile, e

// Get All SAP Profiles
func (f *IBMPISAPInstanceClient) GetAllSAPProfiles(cloudInstanceID string) (*models.SAPProfiles, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_s_a_p.NewPcloudSapGetallParams().
Expand Down
11 changes: 5 additions & 6 deletions clients/instance/ibm-pi-shared-processor-pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package instance
import (
"context"
"fmt"
"strings"

"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_shared_processor_pools"
Expand All @@ -27,7 +26,7 @@ func NewIBMPISharedProcessorPoolClient(ctx context.Context, sess *ibmpisession.I

// Get a PI Shared Processor Pool
func (f *IBMPISharedProcessorPoolClient) Get(id string) (*models.SharedProcessorPoolDetail, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_shared_processor_pools.NewPcloudSharedprocessorpoolsGetParams().
Expand All @@ -45,7 +44,7 @@ func (f *IBMPISharedProcessorPoolClient) Get(id string) (*models.SharedProcessor

// Get All Shared Processor Pools
func (f *IBMPISharedProcessorPoolClient) GetAll() (*models.SharedProcessorPools, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_shared_processor_pools.NewPcloudSharedprocessorpoolsGetallParams().
Expand All @@ -63,7 +62,7 @@ func (f *IBMPISharedProcessorPoolClient) GetAll() (*models.SharedProcessorPools,

// Create a Shared Processor Pool
func (f *IBMPISharedProcessorPoolClient) Create(body *models.SharedProcessorPoolCreate) (*models.SharedProcessorPool, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_shared_processor_pools.NewPcloudSharedprocessorpoolsPostParams().
Expand All @@ -81,7 +80,7 @@ func (f *IBMPISharedProcessorPoolClient) Create(body *models.SharedProcessorPool

// Delete a Shared Processor Pool
func (f *IBMPISharedProcessorPoolClient) Delete(id string) error {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_shared_processor_pools.NewPcloudSharedprocessorpoolsDeleteParams().
Expand All @@ -96,7 +95,7 @@ func (f *IBMPISharedProcessorPoolClient) Delete(id string) error {

// Update a PI Shared Processor Pool
func (f *IBMPISharedProcessorPoolClient) Update(id string, body *models.SharedProcessorPoolUpdate) (*models.SharedProcessorPool, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_shared_processor_pools.NewPcloudSharedprocessorpoolsPutParams().
Expand Down
13 changes: 6 additions & 7 deletions clients/instance/ibm-pi-spp-placement-groups.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package instance
import (
"context"
"fmt"
"strings"

"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/power/client/p_cloud_s_p_p_placement_groups"
Expand All @@ -27,7 +26,7 @@ func NewIBMPISPPPlacementGroupClient(ctx context.Context, sess *ibmpisession.IBM

// Get a PI SPP Placement Group
func (f *IBMPISPPPlacementGroupClient) Get(id string) (*models.SPPPlacementGroup, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_s_p_p_placement_groups.NewPcloudSppplacementgroupsGetParams().
Expand All @@ -45,7 +44,7 @@ func (f *IBMPISPPPlacementGroupClient) Get(id string) (*models.SPPPlacementGroup

// Get All SPP Placement Groups
func (f *IBMPISPPPlacementGroupClient) GetAll() (*models.SPPPlacementGroups, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_s_p_p_placement_groups.NewPcloudSppplacementgroupsGetallParams().
Expand All @@ -63,7 +62,7 @@ func (f *IBMPISPPPlacementGroupClient) GetAll() (*models.SPPPlacementGroups, err

// Create a SPP Placement Group
func (f *IBMPISPPPlacementGroupClient) Create(body *models.SPPPlacementGroupCreate) (*models.SPPPlacementGroup, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_s_p_p_placement_groups.NewPcloudSppplacementgroupsPostParams().
Expand All @@ -81,7 +80,7 @@ func (f *IBMPISPPPlacementGroupClient) Create(body *models.SPPPlacementGroupCrea

// Delete a SPP Placement Group
func (f *IBMPISPPPlacementGroupClient) Delete(id string) error {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_s_p_p_placement_groups.NewPcloudSppplacementgroupsDeleteParams().
Expand All @@ -96,7 +95,7 @@ func (f *IBMPISPPPlacementGroupClient) Delete(id string) error {

// Add an Instance to a SPP Placement Group
func (f *IBMPISPPPlacementGroupClient) AddMember(id string, sppID string) (*models.SPPPlacementGroup, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_s_p_p_placement_groups.NewPcloudSppplacementgroupsMembersPostParams().
Expand All @@ -115,7 +114,7 @@ func (f *IBMPISPPPlacementGroupClient) AddMember(id string, sppID string) (*mode

// Remove an Instance to a SPP Placement Group
func (f *IBMPISPPPlacementGroupClient) DeleteMember(id string, sppID string) (*models.SPPPlacementGroup, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_s_p_p_placement_groups.NewPcloudSppplacementgroupsMembersDeleteParams().
Expand Down
7 changes: 3 additions & 4 deletions clients/instance/ibm-pi-volume-onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package instance
import (
"context"
"fmt"
"strings"

"github.com/IBM-Cloud/power-go-client/errors"
"github.com/IBM-Cloud/power-go-client/helpers"
Expand All @@ -26,7 +25,7 @@ func NewIBMPIVolumeOnboardingClient(ctx context.Context, sess *ibmpisession.IBMP

// Get the information of volume onboarding operation
func (f *IBMPIVolumeOnboardingClient) Get(id string) (*models.VolumeOnboarding, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_volume_onboarding.NewPcloudVolumeOnboardingGetParams().
Expand All @@ -44,7 +43,7 @@ func (f *IBMPIVolumeOnboardingClient) Get(id string) (*models.VolumeOnboarding,

// Get All volume onboardings for this cloud instance
func (f *IBMPIVolumeOnboardingClient) GetAll() (*models.VolumeOnboardings, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_volume_onboarding.NewPcloudVolumeOnboardingGetallParams().
Expand All @@ -62,7 +61,7 @@ func (f *IBMPIVolumeOnboardingClient) GetAll() (*models.VolumeOnboardings, error

// Onboard auxiliary volumes to target site
func (f *IBMPIVolumeOnboardingClient) CreateVolumeOnboarding(body *models.VolumeOnboardingCreate) (*models.VolumeOnboardingCreateResponse, error) {
if strings.Contains(f.session.Options.Zone, helpers.PIStratosRegionPrefix) {
if f.session.IsOnPrem() {
return nil, fmt.Errorf("operation not supported in satellite location, check documentation")
}
params := p_cloud_volume_onboarding.NewPcloudVolumeOnboardingPostParams().
Expand Down
Loading

0 comments on commit 55018c4

Please sign in to comment.