VMware Cloud Community
Ankushsethi
Enthusiast
Enthusiast
Jump to solution

Difference between Get-view -ID ((Get-view serviceinstance).content.Managerobject) and containview in MOB

Hello,

I have been trying to understand this and spent few hours to find out the answer which could help but did not get much information.

Basically we use get-view to use the API and same is available in MOB. but when i try to explore MOB .I see 4 different views for viewManager

Also when i create container view and try to invoke the method of managed object  it says it does not exist.

I am trying to do using pyVmomi to replicate  how we do in powercli

vc=connect.Connect("vCenterName","443","UserName","Password")

cm=vc.content.certificateManager

recursive=True

rootdirectory=vc.content.rootFlder

certmgr=vc.content.viewManager.CreateContainerView(rootdirectory,cm,recursive)

certmgr.CertMgrRefreshCertificates_Task(host'sMORef)

But I am getting error method is not found .

0 Kudos
1 Solution

Accepted Solutions
LucD
Leadership
Leadership
Jump to solution

That is because you are working with a MoRef (Managed Object Reference), not an object.

All methods and properties are available through the object, not the MoRef.

View the MoRef as a kind of pointer to the actual object.

To go from a MoRef to the corresponding object you use the Get-View cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

View solution in original post

4 Replies
LucD
Leadership
Leadership
Jump to solution

I try to stay far away from Python, but I guess that code is trying to do something like this.
Refresh the certificate on all ESXi nodes.

Connect-VIServer -Server 'vCenterName' -Port 443 -User 'UserName' -Password 'Password'

$si = Get-View ServiceInstance


$viewMgr = Get-View -Id ViewManager

$recurse = $true

$cViewMoRef = $viewMgr.CreateContainerView($si.Content.RootFolder,'HostSystem',$recurse)

$cView = Get-View -Id $cViewMoRef


$certMgr = Get-View -Id $si.Content.CertificateManager

$certMgr.CertMgrRefreshCertificates_Task($cView.View)


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
Ankushsethi
Enthusiast
Enthusiast
Jump to solution

Hello Luc,

thank for your quick   response .

yes you are correct i was trying to use same way as we use in powercli.

Can you please suggest

why we Do not do see method related to managed object until we pass their ID again to get-view

example

Cm=get-view serviceinstance.content.certificatemanager
cm|gm  It usually provide no method to refresh

cmgr=get-view -id cm. # passing id of certificate manager
I will get all methods

any technical logic behind this ?

i was in assumption line 1 provide ID to me

then another view for corresponding object

but i have seen some managedObject directly provide method in first command only

Example Sessionmanager

get-view sessionmanager will give all method and we do not need 2 nd line where we pass ID

0 Kudos
Ankushsethi
Enthusiast
Enthusiast
Jump to solution

That is the only roadblock in python i am facing

i created the view but no method is coming

0 Kudos
LucD
Leadership
Leadership
Jump to solution

That is because you are working with a MoRef (Managed Object Reference), not an object.

All methods and properties are available through the object, not the MoRef.

View the MoRef as a kind of pointer to the actual object.

To go from a MoRef to the corresponding object you use the Get-View cmdlet.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference