Skip to content

Commit

Permalink
govc: add vsan.info -file-service-enabled flag
Browse files Browse the repository at this point in the history
  • Loading branch information
dougm committed Jun 24, 2024
1 parent e9f4cb7 commit c3c5ffb
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 13 deletions.
3 changes: 2 additions & 1 deletion govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7190,7 +7190,8 @@ Examples:
govc vsan.change -unmap-enabled=false ClusterA # disable unmap
Options:
-unmap-enabled=<nil> Enable Unmap
-file-service-enabled=<nil> Enable FileService
-unmap-enabled=<nil> Enable Unmap
```

## vsan.info
Expand Down
20 changes: 17 additions & 3 deletions govc/test/vsan.bats
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ load test_helper
@test "vsan.change" {
vcsim_env -cluster 2

run govc vsan.change DC0_C0
assert_failure # no flags specified

run govc vsan.info -json DC0_C0
assert_success
config=$(jq .clusters[].info.UnmapConfig <<<"$output")
assert_equal null "$config"

run govc vsan.change DC0_C0
assert_failure # no flags specified

run govc vsan.change -unmap-enabled DC0_C0
assert_success

Expand All @@ -21,4 +21,18 @@ load test_helper

config=$(jq .clusters[].info.UnmapConfig.Enable <<<"$output")
assert_equal true "$config"

run govc vsan.info -json DC0_C0
assert_success
config=$(jq .clusters[].info.FileServiceConfig <<<"$output")
assert_equal null "$config"

run govc vsan.change -file-service-enabled DC0_C0
assert_success

run govc vsan.info -json DC0_C0
assert_success

config=$(jq .clusters[].info.FileServiceConfig.Enabled <<<"$output")
assert_equal true "$config"
}
14 changes: 10 additions & 4 deletions govc/vsan/change.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Copyright (c) 2021 VMware, Inc. All Rights Reserved.
Copyright (c) 2021-2024 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -30,6 +30,7 @@ type change struct {
*flags.DatacenterFlag

unmap *bool
fs *bool
}

func init() {
Expand All @@ -41,6 +42,7 @@ func (cmd *change) Register(ctx context.Context, f *flag.FlagSet) {
cmd.DatacenterFlag.Register(ctx, f)

f.Var(flags.NewOptionalBool(&cmd.unmap), "unmap-enabled", "Enable Unmap")
f.Var(flags.NewOptionalBool(&cmd.fs), "file-service-enabled", "Enable FileService")
}

func (cmd *change) Usage() string {
Expand Down Expand Up @@ -80,10 +82,14 @@ func (cmd *change) Run(ctx context.Context, f *flag.FlagSet) error {

var spec types.VimVsanReconfigSpec

if cmd.unmap == nil && cmd.fs == nil {
return flag.ErrHelp
}
if cmd.unmap != nil {
spec.UnmapConfig = &types.VsanUnmapConfig{Enable: *cmd.unmap}
} else {
return flag.ErrHelp
}
if cmd.fs != nil {
spec.FileServiceConfig = &types.VsanFileServiceConfig{Enabled: *cmd.fs}
}

task, err := c.VsanClusterReconfig(ctx, cluster.Reference(), spec)
Expand Down
10 changes: 5 additions & 5 deletions govc/vsan/info.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2021-2023 VMware, Inc. All Rights Reserved.
Copyright (c) 2021-2024 VMware, Inc. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -112,12 +112,12 @@ func (r *infoResult) Write(w io.Writer) error {
for _, cluster := range r.Clusters {
fmt.Fprintf(tw, "Path:\t%s\n", cluster.Path)
fmt.Fprintf(tw, " Enabled:\t%t\n", *cluster.Info.Enabled)
unmapEnabled := false
if unmap := cluster.Info.UnmapConfig; unmap != nil {
unmapEnabled = unmap.Enable
fmt.Fprintf(tw, " Unmap Enabled:\t%t\n", unmap.Enable)
}
if fs := cluster.Info.FileServiceConfig; fs != nil {
fmt.Fprintf(tw, " FileService Enabled:\t%t\n", fs.Enabled)
}

fmt.Fprintf(tw, " Unmap Enabled:\t%t\n", unmapEnabled)
}

return tw.Flush()
Expand Down

0 comments on commit c3c5ffb

Please sign in to comment.