Skip to content

Commit

Permalink
vcsim: add vSAN FileServiceConfig support
Browse files Browse the repository at this point in the history
govc: add vsan.info -file-service-enabled flag

Issue vmware#3430
  • Loading branch information
dougm committed May 5, 2024
1 parent f0980d5 commit 9b8026f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 9 deletions.
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"
}
10 changes: 8 additions & 2 deletions govc/vsan/change.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 4 additions & 4 deletions govc/vsan/info.go
Original file line number Diff line number Diff line change
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
3 changes: 3 additions & 0 deletions vsan/simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func (s *ClusterConfigSystem) VsanClusterReconfig(ctx *simulator.Context, req *t
if req.VsanReconfigSpec.UnmapConfig != nil {
info.UnmapConfig = req.VsanReconfigSpec.UnmapConfig
}
if req.VsanReconfigSpec.FileServiceConfig != nil {
info.FileServiceConfig = req.VsanReconfigSpec.FileServiceConfig
}
return nil, nil
})

Expand Down

0 comments on commit 9b8026f

Please sign in to comment.