VMware {code} Community
piuhapofuhpaosf
Contributor
Contributor

Refresh Network Information

I have a script that automates the creation of port groups on an ESX server. It just uses the esxcfg-vswitch tool that comes on each ESX server. The script works just as it should - I can create, update and delete port groups. However, when I create a port group and then use the perl api (VIPerlToolkit) to query the host for configured port groups (returned by $host_view->network), the newly created port group doesn't show up in the list until I hit the "Refresh" link on the Networking Configuration screen in the VI Client. This obviously makes automation rather difficult since the whole point of the automation is to remove the need to use the VI Client. So, the question is, does the Perl API provide a way to refresh the network information (the equivalent of clicking the "Refresh" link on the network config screen)? I've used $host_view->update_view_data(), but this appears to have no affect on the network list ($host_view->network). Any help would be much appreciated.

Thanks,

David

Reply
0 Kudos
4 Replies
DougBaer
Commander
Commander

When doing this from the SC, I use vimsh+sleep to kick the refresh.

  1. vimsh -n -e "/internalsvc/refresh_network"

  2. sleep 40

However, you can also restart the management agents and sleep (it usually takes longer, depending on the box):

  1. service mgmt-vmware restart

  2. sleep 90

I swear I've seem something in the Perl API and will go look now...

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
Reply
0 Kudos
DougBaer
Commander
Commander

I think what you are looking for is

RefreshNetworkSystem - "Refresh the network information and settings to pick up any changes that might have occurred."

You can find it here: http://www.vmware.com/support/developer/vc-sdk/visdk25pubs/ReferenceGuide/index.html

Call it on the HostNetworkSystem object

(To get an mor of HostNetworkSystem, you can traverse from the HostSystem.configManager.networkSystem)...

my $hostViews = Vim::find_entity_views(view_type => 'HostSystem' );

foreach (@$hostViews ) {

my $netMgr = Vim::get_view(mo_ref => $_->configManager->networkSystem);

$netMgr->RefreshNetworkSystem();

}

HTH

Doug Baer, Solution Architect, Advanced Services, Broadcom | VCDX #019, vExpert 2012-23
Reply
0 Kudos
piuhapofuhpaosf
Contributor
Contributor

That is exactly what I was looking for. Thanks so much for that.

Reply
0 Kudos
EmiDittler
Contributor
Contributor

Hi Doug,

Quesiton ,

I want to use your script but just to get the refresh information for 1 HOST, could you please make me a script where I can enter the host name please? thanks!!

Call it on the HostNetworkSystem object

(To get an mor of HostNetworkSystem, you can traverse from the HostSystem.configManager.networkSystem)...

my $hostViews = Vim::find_entity_views(view_type => 'HostSystem' );

foreach (@$hostViews ) {

  my $netMgr = Vim::get_view(mo_ref => $_->configManager->networkSystem);

  $netMgr->RefreshNetworkSystem();

}

Reply
0 Kudos