Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

govc: add storage.policy.info flag to query IO filters #3570

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions govc/storage/policy/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ type info struct {

compliance bool
storage bool
iofilters bool
}

func init() {
Expand All @@ -53,6 +54,10 @@ func (cmd *info) Register(ctx context.Context, f *flag.FlagSet) {

f.BoolVar(&cmd.storage, "s", false, "Check Storage Compatibility")
f.BoolVar(&cmd.compliance, "c", false, "Check VM Compliance")

if cli.ShowUnreleased() {
f.BoolVar(&cmd.iofilters, "i", false, "Query IO Filters")
}
}

func (cmd *info) Process(ctx context.Context) error {
Expand All @@ -79,9 +84,10 @@ Examples:
}

type Policy struct {
Profile types.BasePbmProfile `json:"profile"`
CompliantVM []string `json:"compliantVM"`
CompatibleDatastores []string `json:"compatibleDatastores"`
Profile types.BasePbmProfile `json:"profile"`
CompliantVM []string `json:"compliantVM"`
CompatibleDatastores []string `json:"compatibleDatastores"`
FilterMap []types.PbmProfileToIofilterMap `json:"filterMap,omitempty"`
}

type infoResult struct {
Expand Down Expand Up @@ -190,6 +196,13 @@ func (cmd *info) Run(ctx context.Context, f *flag.FlagSet) error {
}
}

if cmd.iofilters {
policy.FilterMap, err = c.QueryIOFiltersFromProfileId(ctx, p.ProfileId.UniqueId)
if err != nil {
return err
}
}

policies = append(policies, policy)
}

Expand Down
6 changes: 6 additions & 0 deletions govc/test/storage.bats
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ load test_helper

run govc storage.policy.info "vSAN Default Storage Policy"
assert_success

run env GOVC_SHOW_UNRELEASED=true govc storage.policy.info -json -i "VM Encryption Policy"
assert_success

kind="$(jq -r .policies[].filterMap[].iofilters[].filterType <<<"$output")"
assert_equal "ENCRYPTION" "$kind"
}

@test "storage.policy.create" {
Expand Down
4 changes: 2 additions & 2 deletions pbm/methods/internal_methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import (
)

type PbmQueryIOFiltersFromProfileIdBody struct {
Req *types.PbmQueryIOFiltersFromProfileId `xml:"urn:pbm PbmQueryIOFiltersFromProfileId,omitempty"`
Res *types.PbmQueryIOFiltersFromProfileIdResponse `xml:"urn:pbm PbmQueryIOFiltersFromProfileIdResponse,omitempty"`
Req *types.PbmQueryIOFiltersFromProfileId `xml:"urn:internalpbm PbmQueryIOFiltersFromProfileId,omitempty"`
Res *types.PbmQueryIOFiltersFromProfileIdResponse `xml:"urn:internalpbm PbmQueryIOFiltersFromProfileIdResponse,omitempty"`
Fault_ *soap.Fault `xml:"http://schemas.xmlsoap.org/soap/envelope/ Fault,omitempty"`
}

Expand Down
17 changes: 15 additions & 2 deletions simulator/simulator.go
Original file line number Diff line number Diff line change
Expand Up @@ -315,16 +315,29 @@ type response struct {
}

func (r *response) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
val := reflect.ValueOf(r.Body).Elem().FieldByName("Res")
body := reflect.ValueOf(r.Body).Elem()
val := body.FieldByName("Res")
if !val.IsValid() {
return fmt.Errorf("%T: invalid response type (missing 'Res' field)", r.Body)
}
if val.IsNil() {
return fmt.Errorf("%T: invalid response (nil 'Res' field)", r.Body)
}

// Default response namespace
ns := "urn:" + r.Namespace
// Override namespace from struct tag if defined
field, _ := body.Type().FieldByName("Res")
if tag := field.Tag.Get("xml"); tag != "" {
tags := strings.Split(tag, " ")
if len(tags) > 0 && strings.HasPrefix(tags[0], "urn") {
ns = tags[0]
}
}

res := xml.StartElement{
Name: xml.Name{
Space: "urn:" + r.Namespace,
Space: ns,
Local: val.Elem().Type().Name(),
},
}
Expand Down
Loading