Skip to content

Commit

Permalink
feat(region): options: allow setting default vpc external access mode
Browse files Browse the repository at this point in the history
  • Loading branch information
yousong committed Nov 30, 2020
1 parent f80c6a2 commit 0ea12ff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
13 changes: 10 additions & 3 deletions pkg/compute/models/vpcs.go
Expand Up @@ -36,6 +36,7 @@ import (
"yunion.io/x/onecloud/pkg/cloudcommon/db/quotas"
"yunion.io/x/onecloud/pkg/cloudcommon/db/taskman"
"yunion.io/x/onecloud/pkg/cloudprovider"
"yunion.io/x/onecloud/pkg/compute/options"
"yunion.io/x/onecloud/pkg/httperrors"
"yunion.io/x/onecloud/pkg/mcclient"
"yunion.io/x/onecloud/pkg/util/rbacutils"
Expand Down Expand Up @@ -623,7 +624,13 @@ func (manager *SVpcManager) InitializeData() error {
}
}

{ // initialize default external_access_mode for onecloud vpc
if defaultMode := options.Options.DefaultVpcExternalAccessMode; defaultMode == "" {
options.Options.DefaultVpcExternalAccessMode = api.VPC_EXTERNAL_ACCESS_MODE_EIP_DISTGW
} else if !utils.IsInStringArray(defaultMode, api.VPC_EXTERNAL_ACCESS_MODES) {
return errors.Errorf("invalid DefaultVpcExternalAccessMode, got %s, want %s", defaultMode, api.VPC_EXTERNAL_ACCESS_MODES)
}
{
// initialize default external_access_mode for onecloud vpc
var vpcs []SVpc
q := manager.Query().
IsNullOrEmpty("manager_id").
Expand All @@ -635,7 +642,7 @@ func (manager *SVpcManager) InitializeData() error {
for i := range vpcs {
vpc := &vpcs[i]
if _, err := db.Update(vpc, func() error {
vpc.ExternalAccessMode = api.VPC_EXTERNAL_ACCESS_MODE_EIP_DISTGW
vpc.ExternalAccessMode = options.Options.DefaultVpcExternalAccessMode
return nil
}); err != nil {
return errors.Wrap(err, "db set default external_access_mode")
Expand Down Expand Up @@ -686,7 +693,7 @@ func (manager *SVpcManager) ValidateCreateData(
} else {
input.Status = api.VPC_STATUS_AVAILABLE
if input.ExternalAccessMode == "" {
input.ExternalAccessMode = api.VPC_EXTERNAL_ACCESS_MODE_EIP_DISTGW
input.ExternalAccessMode = options.Options.DefaultVpcExternalAccessMode
}
if !utils.IsInStringArray(input.ExternalAccessMode, api.VPC_EXTERNAL_ACCESS_MODES) {
return input, httperrors.NewInputParameterError("invalid external_access_mode %q, want %s",
Expand Down
2 changes: 2 additions & 0 deletions pkg/compute/options/options.go
Expand Up @@ -158,6 +158,8 @@ type ComputeOptions struct {

DefaultNetworkGatewayAddressEsxi uint32 `help:"Default address for network gateway" default:"1"`

DefaultVpcExternalAccessMode string `help:"default external access mode for on-premise vpc"`

NoCheckOsTypeForCachedImage bool `help:"Don't check os type for cached image"`

esxi.EsxiOptions
Expand Down

0 comments on commit 0ea12ff

Please sign in to comment.