-
Notifications
You must be signed in to change notification settings - Fork 76
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for NSX-T Alb General Settings #403
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f0f6a4d
Add support for NSX-T Alb General Settings
Didainius 61da26e
Add PR number
Didainius 8ba0ed8
Rename GeneralSettings to Settings
Didainius 1c5e343
Merge branch 'master' into alb_general_settings-pr
Didainius c7f8ab3
[skip ci] fix comment spelling
Didainius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,2 @@ | ||
* Added type `NsxtAlbConfig` and functions `NsxtEdgeGateway.UpdateAlbSettings`, `NsxtEdgeGateway.GetAlbSettings`, | ||
`NsxtEdgeGateway.DisableAlb` [GH-403] | ||
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
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,66 @@ | ||
package govcd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/vmware/go-vcloud-director/v2/types/v56" | ||
) | ||
|
||
// GetAlbSettings retrieves NSX-T ALB settings for a particular Edge Gateway | ||
func (egw *NsxtEdgeGateway) GetAlbSettings() (*types.NsxtAlbConfig, error) { | ||
client := egw.client | ||
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayAlb | ||
apiVersion, err := client.getOpenApiHighestElevatedVersion(endpoint) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, egw.EdgeGateway.ID)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
typeResponse := &types.NsxtAlbConfig{} | ||
err = client.OpenApiGetItem(apiVersion, urlRef, nil, &typeResponse, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return typeResponse, nil | ||
} | ||
|
||
// UpdateAlbSettings updates NSX-T ALB settings for a particular Edge Gateway | ||
func (egw *NsxtEdgeGateway) UpdateAlbSettings(config *types.NsxtAlbConfig) (*types.NsxtAlbConfig, error) { | ||
client := egw.client | ||
endpoint := types.OpenApiPathVersion1_0_0 + types.OpenApiEndpointEdgeGatewayAlb | ||
apiVersion, err := client.getOpenApiHighestElevatedVersion(endpoint) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
urlRef, err := client.OpenApiBuildEndpoint(fmt.Sprintf(endpoint, egw.EdgeGateway.ID)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
typeResponse := &types.NsxtAlbConfig{} | ||
err = client.OpenApiPutItem(apiVersion, urlRef, nil, config, typeResponse, nil) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return typeResponse, nil | ||
} | ||
|
||
// DisableAlb is a shortcut wrapping UpdateAlbSettings which disables ALB configuration | ||
func (egw *NsxtEdgeGateway) DisableAlb() error { | ||
config := &types.NsxtAlbConfig{ | ||
Enabled: false, | ||
} | ||
_, err := egw.UpdateAlbSettings(config) | ||
if err != nil { | ||
return fmt.Errorf("error disabling NSX-T ALB: %s", err) | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
//go:build nsxt || alb || functional || ALL | ||
// +build nsxt alb functional ALL | ||
|
||
package govcd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/vmware/go-vcloud-director/v2/types/v56" | ||
|
||
. "gopkg.in/check.v1" | ||
) | ||
|
||
func (vcd *TestVCD) Test_GetAlbSettings(check *C) { | ||
skipNoNsxtAlbConfiguration(vcd, check) | ||
skipOpenApiEndpointTest(vcd, check, types.OpenApiPathVersion1_0_0+types.OpenApiEndpointEdgeGatewayAlb) | ||
|
||
edge, err := vcd.nsxtVdc.GetNsxtEdgeGatewayByName(vcd.config.VCD.Nsxt.EdgeGateway) | ||
check.Assert(err, IsNil) | ||
|
||
albSettings, err := edge.GetAlbSettings() | ||
check.Assert(err, IsNil) | ||
check.Assert(albSettings, NotNil) | ||
check.Assert(albSettings.Enabled, Equals, false) | ||
} | ||
|
||
func (vcd *TestVCD) Test_UpdateAlbSettings(check *C) { | ||
if vcd.skipAdminTests { | ||
check.Skip(fmt.Sprintf(TestRequiresSysAdminPrivileges, check.TestName())) | ||
} | ||
skipNoNsxtAlbConfiguration(vcd, check) | ||
skipOpenApiEndpointTest(vcd, check, types.OpenApiPathVersion1_0_0+types.OpenApiEndpointEdgeGatewayAlb) | ||
|
||
controller, cloud, seGroup := spawnAlbControllerCloudServiceEngineGroup(vcd, check) | ||
edge, err := vcd.nsxtVdc.GetNsxtEdgeGatewayByName(vcd.config.VCD.Nsxt.EdgeGateway) | ||
check.Assert(err, IsNil) | ||
|
||
// Enable ALB on Edge Gateway with default ServiceNetworkDefinition | ||
albSettingsConfig := &types.NsxtAlbConfig{ | ||
Enabled: true, | ||
} | ||
enabledSettings, err := edge.UpdateAlbSettings(albSettingsConfig) | ||
check.Assert(err, IsNil) | ||
check.Assert(enabledSettings.Enabled, Equals, true) | ||
check.Assert(enabledSettings.ServiceNetworkDefinition, Equals, "192.168.255.1/25") | ||
|
||
// Disable ALB on Edge Gateway | ||
albSettingsConfig.Enabled = false | ||
disabledSettings, err := edge.UpdateAlbSettings(albSettingsConfig) | ||
check.Assert(err, IsNil) | ||
check.Assert(disabledSettings.Enabled, Equals, false) | ||
|
||
// Enable ALB on Edge Gateway with custom ServiceNetworkDefinition | ||
albSettingsConfig.Enabled = true | ||
albSettingsConfig.ServiceNetworkDefinition = "93.93.11.1/25" | ||
enabledSettingsCustomServiceDefinition, err := edge.UpdateAlbSettings(albSettingsConfig) | ||
check.Assert(err, IsNil) | ||
check.Assert(enabledSettingsCustomServiceDefinition.Enabled, Equals, true) | ||
check.Assert(enabledSettingsCustomServiceDefinition.ServiceNetworkDefinition, Equals, "93.93.11.1/25") | ||
|
||
// Disable ALB on Edge Gateway again and ensure it was disabled | ||
err = edge.DisableAlb() | ||
check.Assert(err, IsNil) | ||
|
||
albSettings, err := edge.GetAlbSettings() | ||
check.Assert(err, IsNil) | ||
check.Assert(albSettings, NotNil) | ||
check.Assert(albSettings.Enabled, Equals, false) | ||
|
||
// Remove objects | ||
err = seGroup.Delete() | ||
check.Assert(err, IsNil) | ||
err = cloud.Delete() | ||
check.Assert(err, IsNil) | ||
err = controller.Delete() | ||
check.Assert(err, IsNil) | ||
} |
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe worth mentioning the helper function too?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The helper function is a private one made for testing that should not be mentioned in the changes log.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I am on this one with dataclouder - it is an internal function used for testing only.