Skip to content

Commit

Permalink
Merge pull request #3570 from dougm/storage-policy-filters
Browse files Browse the repository at this point in the history
govc: add storage.policy.info flag to query IO filters
  • Loading branch information
akutz authored Oct 3, 2024
2 parents 3db76c0 + 2613278 commit d1684ba
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 7 deletions.
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

0 comments on commit d1684ba

Please sign in to comment.