I don't fancy myself as much of a programmer, so please bear with me.
foreach (@$hostViews ) {
my $netMgr = Vim::get_view(mo_ref => $_->configManager->networkSystem);
my @physicalNicHintInfo = $netMgr->QueryNetworkHint();
foreach (@physicalNicHintInfo){
foreach ( @{$_} ){
my $device = $_->device;
my $port = $_->connectedSwitchPort->portId;
print "$device\n";
}
}
}
I get back the correct info for $device if I comment out the line where I access $_->connectedSwitchPort, if I don't comment it out I get:
Can't call method "portId" on an undefined value ( at the connectedSwitchPort line ).
Any help would be appreciated.
Yep, that's the same thing I get when I'm attached to a HP Procurve, there's no CDP traffic, so the cdpinfo is null...
Are you at a point where it works with the ESX 3.5 Update 1 box, or are you still not able to get to the data you need?
I should have mentioned that my goal is to pull portId and devId from the CDP info of all my vmnics across all my hosts across all my VCs.
The code looks reasonable to me.
Unfortunately, I don't have a Cisco switch in my lab, so the vim.host.PhysicalNic.CdpInfo property has a value of null and I can't get past that.
I was deconstructing the data returned from the call to QueryNetworkHint() and mine looks like this:
(vim.host.PhysicalNic.NetworkHint)
[ (vim.host.PhysicalNic.NetworkHint)
{ dynamicType = ,
device = "vmnic1",
subnet = (vim.host.PhysicalNic.NetworkHint.IpNetwork)
[ (vim.host.PhysicalNic.NetworkHint.IpNetwork)
{ dynamicType = , vlanId = 254, ipSubnet = "10.16.254.102-10.16.254.103", }
],
connectedSwitchPort = (vim.host.PhysicalNic.CdpInfo) null,
}, ...
Following your syntax, I can use
my $vlan = $_->subnet->[0]->vlanId;
to return the VLAN ID of the first portgroup on the vSwitch, so I don't see a syntax problem -- the possible issue I see is whether the data is actually there (since the API specifies that everything there is optional). Look at the output from the MOB here
https://YOURESXHOST/mob/?moid=networkSystem&method=queryNetworkHint
and, if you can, post what comes back.
Doug
DougBaer,
I get quite a lot of data when I hit that URL ( which would require a lot of sanatization before I could post it here ), so I tried the same script against a different host and it worked fine. I don't know why I didn't try it elsewhere before.
Edit: Actually, it looks like it breaks down when I have a vmnic that is connected to no virtualswitch, which makes some sense considering cdpinfo is turned on/off at the vswitch level
Yep, that's the same thing I get when I'm attached to a HP Procurve, there's no CDP traffic, so the cdpinfo is null...
Are you at a point where it works with the ESX 3.5 Update 1 box, or are you still not able to get to the data you need?
Yup, have it working now, just had to do
if (defined $_->connectedSwitchPort){
... pull CDP info...
}
Thanks for the help, you set me along the right path.
Dominic,
Care to share the resulting script?
Best regards,
Edward L. Haletky
VMware Communities User Moderator
====
Author of the book 'VMWare ESX Server in the Enterprise: Planning and Securing Virtualization Servers', Copyright 2008 Pearson Education.
CIO Virtualization Blog: http://www.cio.com/blog/index/topic/168354
As well as the Virtualization Wiki at http://www.astroarch.com/wiki/index.php/Virtualization
You've helped me quite a bit in the past with your website (patching ESX before VUM was around, for example), so I'm glad I could do something