-
Notifications
You must be signed in to change notification settings - Fork 916
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
vcsim: add PropertyCollector index support #3451
Conversation
ca415fe
to
dd81bd7
Compare
PropertyCollector supports use of index (unique key) to collect a single array element. Further, a property path may also be applied to the given element.
run govc vm.change -e "guestinfo.a=1" -e "guestinfo.b=2" | ||
assert_success | ||
|
||
run govc object.collect -json $GOVC_VM 'config.extraConfig["guestinfo.b"]' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you have guestinfo.abc=3
does that match (ie. substring match) or is it doing an exact token match between the separators?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's exact afaik, equal to the Key
field of the array type.
return reflect.Value{}, errInvalidField | ||
} | ||
|
||
field := item.FieldByName("Key") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am having trouble tracing how we get here, so maybe this is a non-issue, but what if the property path is for an array of non-struct types, such as an array of integers or strings? I believe a numerical index should work in that case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
afaik, property path array index can only be used when struct has a key
field, see for example:
% govc object.collect $GOVC_VM disabledMethod
disabledMethod []string MakePrimaryVM_Task,TerminateFaultTolerantVM_Task,...
% govc object.collect $GOVC_VM 'disabledMethod[1]'
govc: ServerFaultCode: InvalidProperty
Another case, AuthorizationRole has no key
field. And while it does have a unique roleId
field, same InvalidProperty
result when using a valid roleId
% id=$(govc object.collect -o -json AuthorizationManager:AuthorizationManager roleList | jq .roleList[].roleId | head -1)
% govc object.collect AuthorizationManager:AuthorizationManager "roleList[$id]"
govc: ServerFaultCode: InvalidProperty
This doc also seems to indicate must be key-based:
Nested properties can also refer to entries in a key-based array
PR vmware#3451 changed mo.ApplyPropertyChange() to panic() on invalid property path. CancelTask had such a property for TaskInfo, 'canceled'. Fixed to 'cancelled' and adds test coverage for the CancelTask method. Fixes vmware#3506
PropertyCollector supports use of index (unique key) to collect a single array element. Further, a property path may also be applied to the given element.