From 55018c4a15d1fd1b86ec64674e6e32a3281a3262 Mon Sep 17 00:00:00 2001 From: ismirlia <90468712+ismirlia@users.noreply.github.com> Date: Mon, 28 Aug 2023 10:51:40 -0500 Subject: [PATCH] Add additional stratos safeguards (#217) * 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 --- clients/instance/ibm-pi-cloud-connection.go | 17 +++++++------- clients/instance/ibm-pi-dr-location.go | 5 ++-- clients/instance/ibm-pi-instance.go | 13 +++++++---- clients/instance/ibm-pi-network.go | 5 ++-- clients/instance/ibm-pi-sap-instance.go | 7 +++--- .../instance/ibm-pi-shared-processor-pool.go | 11 ++++----- .../instance/ibm-pi-spp-placement-groups.go | 13 +++++------ clients/instance/ibm-pi-volume-onboarding.go | 7 +++--- clients/instance/ibm-pi-volume.go | 16 +++++++++++++ clients/instance/ibm-pi-vpn-policy.go | 21 ++++++++--------- clients/instance/ibm-pi-vpn.go | 23 +++++++++---------- ibmpisession/session.go | 5 ++++ 12 files changed, 79 insertions(+), 64 deletions(-) diff --git a/clients/instance/ibm-pi-cloud-connection.go b/clients/instance/ibm-pi-cloud-connection.go index 9f734745..37849a46 100644 --- a/clients/instance/ibm-pi-cloud-connection.go +++ b/clients/instance/ibm-pi-cloud-connection.go @@ -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" @@ -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(). @@ -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(). @@ -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(). @@ -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(). @@ -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(). @@ -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(). @@ -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(). @@ -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(). diff --git a/clients/instance/ibm-pi-dr-location.go b/clients/instance/ibm-pi-dr-location.go index 29599f8a..35d18773 100644 --- a/clients/instance/ibm-pi-dr-location.go +++ b/clients/instance/ibm-pi-dr-location.go @@ -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" @@ -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(). @@ -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(). diff --git a/clients/instance/ibm-pi-instance.go b/clients/instance/ibm-pi-instance.go index 640c80ea..cfa1add9 100644 --- a/clients/instance/ibm-pi-instance.go +++ b/clients/instance/ibm-pi-instance.go @@ -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" @@ -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). @@ -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) @@ -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(). @@ -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(). diff --git a/clients/instance/ibm-pi-network.go b/clients/instance/ibm-pi-network.go index cc4339cb..c573451c 100644 --- a/clients/instance/ibm-pi-network.go +++ b/clients/instance/ibm-pi-network.go @@ -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" @@ -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(). diff --git a/clients/instance/ibm-pi-sap-instance.go b/clients/instance/ibm-pi-sap-instance.go index b71cfb06..6614c3b2 100644 --- a/clients/instance/ibm-pi-sap-instance.go +++ b/clients/instance/ibm-pi-sap-instance.go @@ -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" @@ -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(). @@ -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(). @@ -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(). diff --git a/clients/instance/ibm-pi-shared-processor-pool.go b/clients/instance/ibm-pi-shared-processor-pool.go index 47908a2a..11c999a6 100644 --- a/clients/instance/ibm-pi-shared-processor-pool.go +++ b/clients/instance/ibm-pi-shared-processor-pool.go @@ -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" @@ -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(). @@ -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(). @@ -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(). @@ -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(). @@ -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(). diff --git a/clients/instance/ibm-pi-spp-placement-groups.go b/clients/instance/ibm-pi-spp-placement-groups.go index 7509b1db..7daaa17d 100644 --- a/clients/instance/ibm-pi-spp-placement-groups.go +++ b/clients/instance/ibm-pi-spp-placement-groups.go @@ -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" @@ -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(). @@ -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(). @@ -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(). @@ -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(). @@ -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(). @@ -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(). diff --git a/clients/instance/ibm-pi-volume-onboarding.go b/clients/instance/ibm-pi-volume-onboarding.go index a3b779f2..cd8dc92f 100644 --- a/clients/instance/ibm-pi-volume-onboarding.go +++ b/clients/instance/ibm-pi-volume-onboarding.go @@ -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" @@ -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(). @@ -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(). @@ -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(). diff --git a/clients/instance/ibm-pi-volume.go b/clients/instance/ibm-pi-volume.go index 73f900ba..dfb00085 100644 --- a/clients/instance/ibm-pi-volume.go +++ b/clients/instance/ibm-pi-volume.go @@ -44,6 +44,10 @@ func (f *IBMPIVolumeClient) GetAll() (*models.Volumes, error) { params := p_cloud_volumes.NewPcloudCloudinstancesVolumesGetallParams(). WithContext(f.ctx).WithTimeout(helpers.PIGetTimeOut). WithCloudInstanceID(f.cloudInstanceID) + // Check for satellite differences in this endpoint + if f.session.IsOnPrem() && (params.Auxiliary != nil && params.ReplicationEnabled != nil) { + return nil, fmt.Errorf("auxiliary and replication enabled parameters are not supported in satellite location, check documentation") + } resp, err := f.session.Power.PCloudVolumes.PcloudCloudinstancesVolumesGetall(params, f.session.AuthInfo(f.cloudInstanceID)) if err != nil { return nil, fmt.Errorf("failed to Get all Volumes for Cloud Instance %s: %w", f.cloudInstanceID, err) @@ -71,6 +75,10 @@ func (f *IBMPIVolumeClient) GetAllAffinityVolumes(affinity string) (*models.Volu // Create a VolumeV2 func (f *IBMPIVolumeClient) CreateVolumeV2(body *models.MultiVolumesCreate) (*models.Volumes, error) { + // Check for satellite differences in this endpoint + if f.session.IsOnPrem() && body.ReplicationEnabled != nil { + return nil, fmt.Errorf("replication enabled parameter is not supported in satellite location, check documentation") + } params := p_cloud_volumes.NewPcloudV2VolumesPostParams(). WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut). WithCloudInstanceID(f.cloudInstanceID).WithBody(body) @@ -86,6 +94,10 @@ func (f *IBMPIVolumeClient) CreateVolumeV2(body *models.MultiVolumesCreate) (*mo // Create a Volume func (f *IBMPIVolumeClient) CreateVolume(body *models.CreateDataVolume) (*models.Volume, error) { + // Check for satellite differences in this endpoint + if f.session.IsOnPrem() && body.ReplicationEnabled != nil { + return nil, fmt.Errorf("replication enabled parameter is not supported in satellite location, check documentation") + } params := p_cloud_volumes.NewPcloudCloudinstancesVolumesPostParams(). WithContext(f.ctx).WithTimeout(helpers.PICreateTimeOut). WithCloudInstanceID(f.cloudInstanceID).WithBody(body) @@ -215,6 +227,10 @@ func (f *IBMPIVolumeClient) UpdateVolumeAttach(id, volumeID string, body *models // Performs action on volume func (f *IBMPIVolumeClient) VolumeAction(id string, body *models.VolumeAction) error { + // Check for satellite differences in this endpoint + if f.session.IsOnPrem() && body.ReplicationEnabled != nil { + return fmt.Errorf("replication enabled parameter is not supported in satellite location, check documentation") + } params := p_cloud_volumes.NewPcloudCloudinstancesVolumesActionPostParams(). WithContext(f.ctx).WithTimeout(helpers.PIUpdateTimeOut). WithCloudInstanceID(f.cloudInstanceID).WithVolumeID(id).WithBody(body) diff --git a/clients/instance/ibm-pi-vpn-policy.go b/clients/instance/ibm-pi-vpn-policy.go index 75fa59d4..360a1be7 100644 --- a/clients/instance/ibm-pi-vpn-policy.go +++ b/clients/instance/ibm-pi-vpn-policy.go @@ -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" @@ -28,7 +27,7 @@ func NewIBMPIVpnPolicyClient(ctx context.Context, sess *ibmpisession.IBMPISessio // IKE Policies // Get an IKE Policy func (f *IBMPIVpnPolicyClient) GetIKEPolicy(id string) (*models.IKEPolicy, 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_v_p_n_policies.NewPcloudIkepoliciesGetParams(). @@ -46,7 +45,7 @@ func (f *IBMPIVpnPolicyClient) GetIKEPolicy(id string) (*models.IKEPolicy, error // Create an IKE Policy func (f *IBMPIVpnPolicyClient) CreateIKEPolicy(body *models.IKEPolicyCreate) (*models.IKEPolicy, 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_v_p_n_policies.NewPcloudIkepoliciesPostParams(). @@ -64,7 +63,7 @@ func (f *IBMPIVpnPolicyClient) CreateIKEPolicy(body *models.IKEPolicyCreate) (*m // Update an IKE Policy func (f *IBMPIVpnPolicyClient) UpdateIKEPolicy(id string, body *models.IKEPolicyUpdate) (*models.IKEPolicy, 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_v_p_n_policies.NewPcloudIkepoliciesPutParams(). @@ -83,7 +82,7 @@ func (f *IBMPIVpnPolicyClient) UpdateIKEPolicy(id string, body *models.IKEPolicy // Get All IKE Policies func (f *IBMPIVpnPolicyClient) GetAllIKEPolicies() (*models.IKEPolicies, 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_v_p_n_policies.NewPcloudIkepoliciesGetallParams(). @@ -101,7 +100,7 @@ func (f *IBMPIVpnPolicyClient) GetAllIKEPolicies() (*models.IKEPolicies, error) // Delete an IKE Policy func (f *IBMPIVpnPolicyClient) DeleteIKEPolicy(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_v_p_n_policies.NewPcloudIkepoliciesDeleteParams(). @@ -117,7 +116,7 @@ func (f *IBMPIVpnPolicyClient) DeleteIKEPolicy(id string) error { // IPSec Policies // Get an IPSec Policy func (f *IBMPIVpnPolicyClient) GetIPSecPolicy(id string) (*models.IPSecPolicy, 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_v_p_n_policies.NewPcloudIpsecpoliciesGetParams(). @@ -135,7 +134,7 @@ func (f *IBMPIVpnPolicyClient) GetIPSecPolicy(id string) (*models.IPSecPolicy, e // Create an IPSec Policy func (f *IBMPIVpnPolicyClient) CreateIPSecPolicy(body *models.IPSecPolicyCreate) (*models.IPSecPolicy, 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_v_p_n_policies.NewPcloudIpsecpoliciesPostParams(). @@ -153,7 +152,7 @@ func (f *IBMPIVpnPolicyClient) CreateIPSecPolicy(body *models.IPSecPolicyCreate) // Update an IPSec Policy func (f *IBMPIVpnPolicyClient) UpdateIPSecPolicy(id string, body *models.IPSecPolicyUpdate) (*models.IPSecPolicy, 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_v_p_n_policies.NewPcloudIpsecpoliciesPutParams(). @@ -172,7 +171,7 @@ func (f *IBMPIVpnPolicyClient) UpdateIPSecPolicy(id string, body *models.IPSecPo // Get All IPSec Policies func (f *IBMPIVpnPolicyClient) GetAllIPSecPolicies() (*models.IPSecPolicies, 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_v_p_n_policies.NewPcloudIpsecpoliciesGetallParams(). @@ -190,7 +189,7 @@ func (f *IBMPIVpnPolicyClient) GetAllIPSecPolicies() (*models.IPSecPolicies, err // Delete an IPSec Policy func (f *IBMPIVpnPolicyClient) DeleteIPSecPolicy(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_v_p_n_policies.NewPcloudIpsecpoliciesDeleteParams(). diff --git a/clients/instance/ibm-pi-vpn.go b/clients/instance/ibm-pi-vpn.go index c8634fa3..7d4c1144 100644 --- a/clients/instance/ibm-pi-vpn.go +++ b/clients/instance/ibm-pi-vpn.go @@ -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" @@ -27,7 +26,7 @@ func NewIBMPIVpnConnectionClient(ctx context.Context, sess *ibmpisession.IBMPISe // Get a VPN Connection func (f *IBMPIVpnConnectionClient) Get(id string) (*models.VPNConnection, 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_v_p_n_connections.NewPcloudVpnconnectionsGetParams(). @@ -45,7 +44,7 @@ func (f *IBMPIVpnConnectionClient) Get(id string) (*models.VPNConnection, error) // Create a VPN Connection func (f *IBMPIVpnConnectionClient) Create(body *models.VPNConnectionCreate) (*models.VPNConnectionCreateResponse, 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_v_p_n_connections.NewPcloudVpnconnectionsPostParams(). @@ -63,7 +62,7 @@ func (f *IBMPIVpnConnectionClient) Create(body *models.VPNConnectionCreate) (*mo // Update a VPN Connection func (f *IBMPIVpnConnectionClient) Update(id string, body *models.VPNConnectionUpdate) (*models.VPNConnection, 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_v_p_n_connections.NewPcloudVpnconnectionsPutParams(). @@ -82,7 +81,7 @@ func (f *IBMPIVpnConnectionClient) Update(id string, body *models.VPNConnectionU // Get All VPN Connections func (f *IBMPIVpnConnectionClient) GetAll() (*models.VPNConnections, 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_v_p_n_connections.NewPcloudVpnconnectionsGetallParams(). @@ -100,7 +99,7 @@ func (f *IBMPIVpnConnectionClient) GetAll() (*models.VPNConnections, error) { // Delete a VPN Connection func (f *IBMPIVpnConnectionClient) 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_v_p_n_connections.NewPcloudVpnconnectionsDeleteParams(). @@ -118,7 +117,7 @@ func (f *IBMPIVpnConnectionClient) Delete(id string) (*models.JobReference, erro // Get a VPN Connection's Network func (f *IBMPIVpnConnectionClient) GetNetwork(id string) (*models.NetworkIDs, 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_v_p_n_connections.NewPcloudVpnconnectionsNetworksGetParams(). @@ -136,7 +135,7 @@ func (f *IBMPIVpnConnectionClient) GetNetwork(id string) (*models.NetworkIDs, er // Attach a Network to a VPN Connection func (f *IBMPIVpnConnectionClient) AddNetwork(id, networkID 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_v_p_n_connections.NewPcloudVpnconnectionsNetworksPutParams(). @@ -155,7 +154,7 @@ func (f *IBMPIVpnConnectionClient) AddNetwork(id, networkID string) (*models.Job // Detach a Network from a VPN Connection func (f *IBMPIVpnConnectionClient) DeleteNetwork(id, networkID 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_v_p_n_connections.NewPcloudVpnconnectionsNetworksDeleteParams(). @@ -174,7 +173,7 @@ func (f *IBMPIVpnConnectionClient) DeleteNetwork(id, networkID string) (*models. // Get a VPN Connection's Subnet func (f *IBMPIVpnConnectionClient) GetSubnet(id string) (*models.PeerSubnets, 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_v_p_n_connections.NewPcloudVpnconnectionsPeersubnetsGetParams(). @@ -192,7 +191,7 @@ func (f *IBMPIVpnConnectionClient) GetSubnet(id string) (*models.PeerSubnets, er // Attach a Subnet to a VPN Connection func (f *IBMPIVpnConnectionClient) AddSubnet(id, subnet string) (*models.PeerSubnets, 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_v_p_n_connections.NewPcloudVpnconnectionsPeersubnetsPutParams(). @@ -211,7 +210,7 @@ func (f *IBMPIVpnConnectionClient) AddSubnet(id, subnet string) (*models.PeerSub // Detach a Subnet from a VPN Connection func (f *IBMPIVpnConnectionClient) DeleteSubnet(id, subnet string) (*models.PeerSubnets, 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_v_p_n_connections.NewPcloudVpnconnectionsPeersubnetsDeleteParams(). diff --git a/ibmpisession/session.go b/ibmpisession/session.go index f62f09e1..5389d38b 100644 --- a/ibmpisession/session.go +++ b/ibmpisession/session.go @@ -124,3 +124,8 @@ func (s *IBMPISession) AuthInfo(cloudInstanceID string) runtime.ClientAuthInfoWr return r.SetHeaderParam("CRN", fmt.Sprintf(s.CRNFormat, cloudInstanceID)) }) } + +// IsOnPrem returns true if the operation is being done on premise (at a satellite region) +func (s *IBMPISession) IsOnPrem() bool { + return strings.Contains(s.Options.Zone, helpers.PIStratosRegionPrefix) +}