-
Notifications
You must be signed in to change notification settings - Fork 917
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
VmFolder info #1116
Comments
Can you be more specific? And using govc or the API directly? |
Hi dougm, Actually, i'm show virtual machines information with the sample file , except the name of the parent folder and i don't have any idea for query this task. (i use the API directly) Thanks, |
Sure, here's an example: modified examples/virtualmachines/main.go
@@ -55,14 +55,16 @@ func main() {
// Retrieve summary property for all machines
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.VirtualMachine.html
var vms []mo.VirtualMachine
- err = v.Retrieve(ctx, []string{"VirtualMachine"}, []string{"summary"}, &vms)
+ err = v.Retrieve(ctx, []string{"VirtualMachine"}, []string{"summary", "parent"}, &vms)
if err != nil {
log.Fatal(err)
}
// Print summary per vm (see also: govc/vm/info.go)
-
+ pc := c.PropertyCollector()
for _, vm := range vms {
- fmt.Printf("%s: %s\n", vm.Summary.Config.Name, vm.Summary.Config.GuestFullName)
+ var parent mo.Folder
+ pc.RetrieveOne(ctx, *vm.Parent, []string{"name"}, &parent)
+ fmt.Printf("%s/%s: %s\n", parent.Name, vm.Summary.Config.Name, vm.Summary.Config.GuestFullName)
}
} |
The VM annotation would only be set if -c or -m were also specified. Add -annotation flag to vm.change command. Fixes vmware#1116
Thanks for your good response. Thanks, |
In that case, you may want to use Finder instead of ContainerView. In this case, package main
import (
"context"
"fmt"
"log"
"github.com/vmware/govmomi/examples"
"github.com/vmware/govmomi/find"
)
func main() {
ctx := context.Background()
// Connect and login to ESX or vCenter
c, err := examples.NewClient(ctx)
if err != nil {
log.Fatal(err)
}
defer c.Logout(ctx)
finder := find.NewFinder(c.Client, false)
dc, err := finder.DatacenterOrDefault(ctx, "")
if err != nil {
log.Fatal(err)
}
finder.SetDatacenter(dc)
vms, err := finder.VirtualMachineList(ctx, "*")
if err != nil {
log.Fatal(err)
}
for _, vm := range vms {
fmt.Println(vm.InventoryPath)
}
} |
Many thanks Doug, i close this issue. |
Hi,
How to search Parent folder of a Virtual machine ?
Thanks,
The text was updated successfully, but these errors were encountered: