Skip to content

Commit

Permalink
Merge pull request #3262 from dougm/ha-admission-control
Browse files Browse the repository at this point in the history
govc: add cluster.change '-ha-admission-control-enabled' flag
  • Loading branch information
dougm authored Oct 17, 2023
2 parents c4befe0 + 5264e83 commit 846db5a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 6 deletions.
13 changes: 7 additions & 6 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -462,12 +462,13 @@ Examples:
govc cluster.change -drs-vmotion-rate=4 ClusterC
Options:
-drs-enabled=<nil> Enable DRS
-drs-mode= DRS behavior for virtual machines: manual, partiallyAutomated, fullyAutomated
-drs-vmotion-rate=0 Aggressiveness of vMotions (1-5)
-ha-enabled=<nil> Enable HA
-vsan-autoclaim=<nil> Autoclaim storage on cluster hosts
-vsan-enabled=<nil> Enable vSAN
-drs-enabled=<nil> Enable DRS
-drs-mode= DRS behavior for virtual machines: manual, partiallyAutomated, fullyAutomated
-drs-vmotion-rate=0 Aggressiveness of vMotions (1-5)
-ha-admission-control-enabled=<nil> Enable HA admission control
-ha-enabled=<nil> Enable HA
-vsan-autoclaim=<nil> Autoclaim storage on cluster hosts
-vsan-enabled=<nil> Enable vSAN
```

## cluster.create
Expand Down
5 changes: 5 additions & 0 deletions govc/cluster/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {

// HA
f.Var(flags.NewOptionalBool(&cmd.DasConfig.Enabled), "ha-enabled", "Enable HA")
f.Var(flags.NewOptionalBool(&cmd.DasConfig.AdmissionControlEnabled), "ha-admission-control-enabled", "Enable HA admission control")

// vSAN
f.Var(flags.NewOptionalBool(&cmd.VsanConfig.Enabled), "vsan-enabled", "Enable vSAN")
Expand Down Expand Up @@ -91,6 +92,10 @@ Examples:
}

func (cmd *change) Run(ctx context.Context, f *flag.FlagSet) error {
if f.NArg() == 0 {
return flag.ErrHelp
}

finder, err := cmd.Finder()
if err != nil {
return err
Expand Down
12 changes: 12 additions & 0 deletions govc/test/cluster.bats
Original file line number Diff line number Diff line change
Expand Up @@ -410,3 +410,15 @@ _EOF_
# run govc object.mv /DC0/host/DC0_C1/DC0_H0 /DC0/host
# assert_success
}

@test "cluster.change" {
vcsim_env

run govc cluster.change -drs-enabled -ha-enabled -ha-admission-control-enabled=false /DC0/host/DC0_C0
assert_success

config=$(govc object.collect -o -json /DC0/host/DC0_C0 | jq .configurationEx)
assert_equal true "$(jq -r .drsConfig.enabled <<<"$config")"
assert_equal true "$(jq -r .dasConfig.enabled <<<"$config")"
assert_equal false "$(jq -r .dasConfig.admissionControlEnabled <<<"$config")"
}
19 changes: 19 additions & 0 deletions simulator/cluster_compute_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,24 @@ func (c *ClusterComputeResource) AddHostTask(ctx *Context, add *types.AddHost_Ta
}
}

func (c *ClusterComputeResource) update(cfg *types.ClusterConfigInfoEx, cspec *types.ClusterConfigSpecEx) types.BaseMethodFault {
if cspec.DasConfig != nil {
if val := cspec.DasConfig.Enabled; val != nil {
cfg.DasConfig.Enabled = val
}
if val := cspec.DasConfig.AdmissionControlEnabled; val != nil {
cfg.DasConfig.AdmissionControlEnabled = val
}
}
if cspec.DrsConfig != nil {
if val := cspec.DrsConfig.Enabled; val != nil {
cfg.DrsConfig.Enabled = val
}
}

return nil
}

func (c *ClusterComputeResource) updateRules(cfg *types.ClusterConfigInfoEx, cspec *types.ClusterConfigSpecEx) types.BaseMethodFault {
for _, spec := range cspec.RulesSpec {
var i int
Expand Down Expand Up @@ -328,6 +346,7 @@ func (c *ClusterComputeResource) ReconfigureComputeResourceTask(ctx *Context, re
}

updates := []func(*types.ClusterConfigInfoEx, *types.ClusterConfigSpecEx) types.BaseMethodFault{
c.update,
c.updateRules,
c.updateGroups,
c.updateOverridesDAS,
Expand Down

0 comments on commit 846db5a

Please sign in to comment.