Skip to content

Commit

Permalink
Merge pull request #3599 from dougm/govc-collect
Browse files Browse the repository at this point in the history
govc: rename 'object.collect' -> 'collect'
  • Loading branch information
dougm authored Oct 21, 2024
2 parents 7948ad8 + 407da6c commit 19de4ba
Show file tree
Hide file tree
Showing 7 changed files with 215 additions and 214 deletions.
130 changes: 65 additions & 65 deletions govc/USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ but appear via `govc $cmd -h`:
- [cluster.usage](#clusterusage)
- [cluster.vlcm.enable](#clustervlcmenable)
- [cluster.vlcm.info](#clustervlcminfo)
- [collect](#collect)
- [datacenter.create](#datacentercreate)
- [datacenter.info](#datacenterinfo)
- [datastore.cluster.change](#datastoreclusterchange)
Expand Down Expand Up @@ -290,7 +291,6 @@ but appear via `govc $cmd -h`:
- [namespace.vmclass.ls](#namespacevmclassls)
- [namespace.vmclass.rm](#namespacevmclassrm)
- [namespace.vmclass.update](#namespacevmclassupdate)
- [object.collect](#objectcollect)
- [object.destroy](#objectdestroy)
- [object.method](#objectmethod)
- [object.mv](#objectmv)
Expand Down Expand Up @@ -1165,6 +1165,67 @@ Options:
-cluster-id= The identifier of the cluster.
```

## collect

```
Usage: govc collect [OPTIONS] [MOID] [PROPERTY]...
Collect managed object properties.
MOID can be an inventory path or ManagedObjectReference.
MOID defaults to '-', an alias for 'ServiceInstance:ServiceInstance' or the root folder if a '-type' flag is given.
If a '-type' flag is given, properties are collected using a ContainerView object where MOID is the root of the view.
By default only the current property value(s) are collected. To wait for updates, use the '-n' flag or
specify a property filter. A property filter can be specified by prefixing the property name with a '-',
followed by the value to match.
The '-R' flag sets the Filter using the given XML encoded request, which can be captured by 'vcsim -trace' for example.
It can be useful for replaying property filters created by other clients and converting filters to Go code via '-O -dump'.
The '-type' flag value can be a managed entity type or one of the following aliases:
a VirtualApp
c ClusterComputeResource
d Datacenter
f Folder
g DistributedVirtualPortgroup
h HostSystem
m VirtualMachine
n Network
o OpaqueNetwork
p ResourcePool
r ComputeResource
s Datastore
w DistributedVirtualSwitch
Examples:
govc collect - content
govc collect -s HostSystem:ha-host hardware.systemInfo.uuid
govc collect -s /ha-datacenter/vm/foo overallStatus
govc collect -s /ha-datacenter/vm/foo -guest.guestOperationsReady true # property filter
govc collect -type m / name runtime.powerState # collect properties for multiple objects
govc collect -json -n=-1 EventManager:ha-eventmgr latestEvent | jq .
govc collect -json -s $(govc collect -s - content.perfManager) description.counterType | jq .
govc collect -R create-filter-request.xml # replay filter
govc collect -R create-filter-request.xml -O # convert filter to Go code
govc collect -s vm/my-vm summary.runtime.host | xargs govc ls -L # inventory path of VM's host
govc collect -dump -o "network/VM Network" # output Managed Object structure as Go code
govc collect -json -s $vm config | \ # use -json + jq to search array elements
jq -r 'select(.hardware.device[].macAddress == "00:50:56:99:c4:27") | .name'
Options:
-O=false Output the CreateFilter request itself
-R= Raw XML encoded CreateFilter request
-d=, Delimiter for array values
-n=0 Wait for N property updates
-o=false Output the structure of a single Managed Object
-s=false Output property value only
-type=[] Resource type. If specified, MOID is used for a container view root
-wait=0s Max wait time for updates
```

## datacenter.create

```
Expand Down Expand Up @@ -1383,9 +1444,9 @@ Examples:
govc datastore.info
govc datastore.info vsanDatastore
# info on Datastores shared between cluster hosts:
govc object.collect -s -d " " /dc1/host/k8s-cluster host | xargs govc datastore.info -H
govc collect -s -d " " /dc1/host/k8s-cluster host | xargs govc datastore.info -H
# info on Datastores shared between VM hosts:
govc ls /dc1/vm/*k8s* | xargs -n1 -I% govc object.collect -s % summary.runtime.host | xargs govc datastore.info -H
govc ls /dc1/vm/*k8s* | xargs -n1 -I% govc collect -s % summary.runtime.host | xargs govc datastore.info -H
Options:
-H=false Display info for Datastores shared between hosts
Expand Down Expand Up @@ -2518,7 +2579,7 @@ ROOT can be an inventory path or ManagedObjectReference.
ROOT defaults to '.', an alias for the root folder or DC if set.
Optional KEY VAL pairs can be used to filter results against object instance properties.
Use the govc 'object.collect' command to view possible object property keys.
Use the govc 'collect' command to view possible object property keys.
The '-type' flag value can be a managed entity type or one of the following aliases:
Expand Down Expand Up @@ -4839,67 +4900,6 @@ Options:
-memory=0 The amount of memory (in MB).
```

## object.collect

```
Usage: govc object.collect [OPTIONS] [MOID] [PROPERTY]...
Collect managed object properties.
MOID can be an inventory path or ManagedObjectReference.
MOID defaults to '-', an alias for 'ServiceInstance:ServiceInstance' or the root folder if a '-type' flag is given.
If a '-type' flag is given, properties are collected using a ContainerView object where MOID is the root of the view.
By default only the current property value(s) are collected. To wait for updates, use the '-n' flag or
specify a property filter. A property filter can be specified by prefixing the property name with a '-',
followed by the value to match.
The '-R' flag sets the Filter using the given XML encoded request, which can be captured by 'vcsim -trace' for example.
It can be useful for replaying property filters created by other clients and converting filters to Go code via '-O -dump'.
The '-type' flag value can be a managed entity type or one of the following aliases:
a VirtualApp
c ClusterComputeResource
d Datacenter
f Folder
g DistributedVirtualPortgroup
h HostSystem
m VirtualMachine
n Network
o OpaqueNetwork
p ResourcePool
r ComputeResource
s Datastore
w DistributedVirtualSwitch
Examples:
govc object.collect - content
govc object.collect -s HostSystem:ha-host hardware.systemInfo.uuid
govc object.collect -s /ha-datacenter/vm/foo overallStatus
govc object.collect -s /ha-datacenter/vm/foo -guest.guestOperationsReady true # property filter
govc object.collect -type m / name runtime.powerState # collect properties for multiple objects
govc object.collect -json -n=-1 EventManager:ha-eventmgr latestEvent | jq .
govc object.collect -json -s $(govc object.collect -s - content.perfManager) description.counterType | jq .
govc object.collect -R create-filter-request.xml # replay filter
govc object.collect -R create-filter-request.xml -O # convert filter to Go code
govc object.collect -s vm/my-vm summary.runtime.host | xargs govc ls -L # inventory path of VM's host
govc object.collect -dump -o "network/VM Network" # output Managed Object structure as Go code
govc object.collect -json -s $vm config | \ # use -json + jq to search array elements
jq -r 'select(.hardware.device[].macAddress == "00:50:56:99:c4:27") | .name'
Options:
-O=false Output the CreateFilter request itself
-R= Raw XML encoded CreateFilter request
-d=, Delimiter for array values
-n=0 Wait for N property updates
-o=false Output the structure of a single Managed Object
-s=false Output property value only
-type=[] Resource type. If specified, MOID is used for a container view root
-wait=0s Max wait time for updates
```

## object.destroy

```
Expand Down
6 changes: 3 additions & 3 deletions govc/datastore/info.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Copyright (c) 2015-2023 VMware, Inc. All Rights Reserved.
Copyright (c) 2015-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 @@ -81,9 +81,9 @@ Examples:
govc datastore.info
govc datastore.info vsanDatastore
# info on Datastores shared between cluster hosts:
govc object.collect -s -d " " /dc1/host/k8s-cluster host | xargs govc datastore.info -H
govc collect -s -d " " /dc1/host/k8s-cluster host | xargs govc datastore.info -H
# info on Datastores shared between VM hosts:
govc ls /dc1/vm/*k8s* | xargs -n1 -I% govc object.collect -s % summary.runtime.host | xargs govc datastore.info -H`
govc ls /dc1/vm/*k8s* | xargs -n1 -I% govc collect -s % summary.runtime.host | xargs govc datastore.info -H`
}

func intersect(common []types.ManagedObjectReference, refs []types.ManagedObjectReference) []types.ManagedObjectReference {
Expand Down
6 changes: 3 additions & 3 deletions govc/flags/debug.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
Copyright (c) 2014-2016 VMware, Inc. All Rights Reserved.
Copyright (c) 2014-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 Down Expand Up @@ -331,7 +331,7 @@ func (v *verbose) propertyValue(obj types.ManagedObjectReference, name string, p
val := v.value(pval)
if obj.Type != "Task" && !strings.HasPrefix(obj.Value, "session") {
if len(val) > 512 {
val = fmt.Sprintf("`govc object.collect -dump %s %s`", obj, name)
val = fmt.Sprintf("`govc collect -dump %s %s`", obj, name)
}
}
return fmt.Sprintf("%s\t%s:\t%s", v.mor(obj), name, val)
Expand Down
27 changes: 14 additions & 13 deletions govc/object/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ type collect struct {
}

func init() {
cli.Register("object.collect", &collect{})
cli.Register("collect", &collect{})
cli.Alias("collect", "object.collect")
}

func (cmd *collect) Register(ctx context.Context, f *flag.FlagSet) {
Expand Down Expand Up @@ -101,18 +102,18 @@ The '-type' flag value can be a managed entity type or one of the following alia
%s
Examples:
govc object.collect - content
govc object.collect -s HostSystem:ha-host hardware.systemInfo.uuid
govc object.collect -s /ha-datacenter/vm/foo overallStatus
govc object.collect -s /ha-datacenter/vm/foo -guest.guestOperationsReady true # property filter
govc object.collect -type m / name runtime.powerState # collect properties for multiple objects
govc object.collect -json -n=-1 EventManager:ha-eventmgr latestEvent | jq .
govc object.collect -json -s $(govc object.collect -s - content.perfManager) description.counterType | jq .
govc object.collect -R create-filter-request.xml # replay filter
govc object.collect -R create-filter-request.xml -O # convert filter to Go code
govc object.collect -s vm/my-vm summary.runtime.host | xargs govc ls -L # inventory path of VM's host
govc object.collect -dump -o "network/VM Network" # output Managed Object structure as Go code
govc object.collect -json -s $vm config | \ # use -json + jq to search array elements
govc collect - content
govc collect -s HostSystem:ha-host hardware.systemInfo.uuid
govc collect -s /ha-datacenter/vm/foo overallStatus
govc collect -s /ha-datacenter/vm/foo -guest.guestOperationsReady true # property filter
govc collect -type m / name runtime.powerState # collect properties for multiple objects
govc collect -json -n=-1 EventManager:ha-eventmgr latestEvent | jq .
govc collect -json -s $(govc collect -s - content.perfManager) description.counterType | jq .
govc collect -R create-filter-request.xml # replay filter
govc collect -R create-filter-request.xml -O # convert filter to Go code
govc collect -s vm/my-vm summary.runtime.host | xargs govc ls -L # inventory path of VM's host
govc collect -dump -o "network/VM Network" # output Managed Object structure as Go code
govc collect -json -s $vm config | \ # use -json + jq to search array elements
jq -r 'select(.hardware.device[].macAddress == "00:50:56:99:c4:27") | .name'`, atable)
}

Expand Down
2 changes: 1 addition & 1 deletion govc/object/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ ROOT can be an inventory path or ManagedObjectReference.
ROOT defaults to '.', an alias for the root folder or DC if set.
Optional KEY VAL pairs can be used to filter results against object instance properties.
Use the govc 'object.collect' command to view possible object property keys.
Use the govc 'collect' command to view possible object property keys.
The '-type' flag value can be a managed entity type or one of the following aliases:
Expand Down
12 changes: 6 additions & 6 deletions govc/test/alarms.bats
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ load test_helper
run govc alarms $vm
assert_success

run govc object.collect -s $vm triggeredAlarmState
run govc collect -s $vm triggeredAlarmState
assert_success "" # empty

run env GOVC_SHOW_UNRELEASED=true govc event.post -s info -i vcsim.vm.success $vm
Expand All @@ -42,7 +42,7 @@ load test_helper
run jq -r .[].event.eventTypeId <<<"$alarms"
assert_success "vcsim.vm.failure"

run govc object.collect -json -s $vm triggeredAlarmState
run govc collect -json -s $vm triggeredAlarmState
assert_success
state="$output"
run jq -r .[].overallStatus <<<"$state"
Expand All @@ -53,7 +53,7 @@ load test_helper
run govc alarms -ack
assert_success

run govc object.collect -json -s $vm triggeredAlarmState
run govc collect -json -s $vm triggeredAlarmState
assert_success
state="$output"
run jq -r .[].overallStatus <<<"$state"
Expand All @@ -64,10 +64,10 @@ load test_helper
run env GOVC_SHOW_UNRELEASED=true govc event.post -s info -i vcsim.vm.success $vm
assert_success

run govc object.collect -s $vm triggeredAlarmState
run govc collect -s $vm triggeredAlarmState
assert_success "" # empty

run govc object.collect -s / triggeredAlarmState
run govc collect -s / triggeredAlarmState
assert_success "" # empty
}

Expand All @@ -88,7 +88,7 @@ load test_helper
@test "alarm -esx" {
vcsim_env -esx

run govc object.collect -s - content.alarmManager
run govc collect -s - content.alarmManager
assert_success "" # empty, no AlarmManager

run govc alarm.info
Expand Down
Loading

0 comments on commit 19de4ba

Please sign in to comment.