Repository navigation
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
}) |
Answered by
dougm
Sep 27, 2023
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)
}) |
0 replies
Answer selected by
SomniVertix
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to 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
mo.HostNetworkSystemdoes have methods attached to it (likewise for othermotypes), but you can use theobjectpackage to simplify fetching of the properties you need and invoking the method: