How to run a managed object reference function? #3224
-
Looking to use the following method from the vsphere API: It says that its called from the "HostNetworkSystem" managed object, but whenever i try that it errors saying that it doesnt have that function. Example code: Run(func(ctx context.Context, c *vim25.Client) error {
// Create a view of HostSystem objects
m := view.NewManager(c)
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"HostNetworkSystem"}, true)
if err != nil {
return err
}
defer v.Destroy(ctx)
// Retrieve summary property for all hosts
// Reference: http://pubs.vmware.com/vsphere-60/topic/com.vmware.wssdk.apiref.doc/vim.HostNetworkSystem.html
var hns []mo.HostNetworkSystem
err = v.Retrieve(ctx, []string{"HostNetworkSystem"}, []string{}, &hns)
if err != nil {
return err
}
for _, hn := range hns {
hn.QueryNetworkHint()
}
return nil
}) |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can't use HostNetworkSystem with ContainerView
Where managed entity is VirtualMachine, HostSystem, etc. HostNetworkSystem is a property of HostConfigManager, which is a property of HostSystem. And HostSystem is managed entity. The generated simulator.Run(func(ctx context.Context, c *vim25.Client) error {
m := view.NewManager(c)
kind := []string{"HostSystem"}
v, err := m.CreateContainerView(ctx, c.ServiceContent.RootFolder, []string{"HostSystem"}, true)
if err != nil {
log.Fatal(err)
}
refs, err := v.Find(ctx, kind, nil)
if err != nil {
return err
}
for _, ref := range refs {
hn, err := object.NewHostSystem(c, ref).ConfigManager().NetworkSystem(ctx)
if err != nil {
return err
}
info, err := hn.QueryNetworkHint(ctx, nil)
if err != nil {
return err
}
_ = info // ...
}
return v.Destroy(ctx)
}) |
Beta Was this translation helpful? Give feedback.
You can't use HostNetworkSystem with ContainerView
Where managed entity is VirtualMachine, HostSystem, etc.
HostNetworkSystem is a property of HostConfigManager, which is a property of HostSystem. And HostSystem is managed entity.
The generated
mo.HostNetworkSystem
does have methods attached to it (likewise for othermo
types), but you can use theobject
package to simplify fetching of the properties you need and invoking the method: