diff --git a/govc/USAGE.md b/govc/USAGE.md index 6e3de5a4b..9fca109b9 100644 --- a/govc/USAGE.md +++ b/govc/USAGE.md @@ -462,12 +462,13 @@ Examples: govc cluster.change -drs-vmotion-rate=4 ClusterC Options: - -drs-enabled= Enable DRS - -drs-mode= DRS behavior for virtual machines: manual, partiallyAutomated, fullyAutomated - -drs-vmotion-rate=0 Aggressiveness of vMotions (1-5) - -ha-enabled= Enable HA - -vsan-autoclaim= Autoclaim storage on cluster hosts - -vsan-enabled= Enable vSAN + -drs-enabled= 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= Enable HA admission control + -ha-enabled= Enable HA + -vsan-autoclaim= Autoclaim storage on cluster hosts + -vsan-enabled= Enable vSAN ``` ## cluster.create diff --git a/govc/cluster/change.go b/govc/cluster/change.go index b6a508090..63e49004b 100644 --- a/govc/cluster/change.go +++ b/govc/cluster/change.go @@ -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") @@ -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 diff --git a/govc/test/cluster.bats b/govc/test/cluster.bats index 8b9635fb5..04ee72b62 100755 --- a/govc/test/cluster.bats +++ b/govc/test/cluster.bats @@ -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")" +} diff --git a/simulator/cluster_compute_resource.go b/simulator/cluster_compute_resource.go index 4a1579d3e..cf9928536 100644 --- a/simulator/cluster_compute_resource.go +++ b/simulator/cluster_compute_resource.go @@ -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 @@ -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,