Hello,
I want to rename a portgroup without changing portgroup policies. With the code I wrote, the portgroup is rename but if the portgroup policies are different from vSwitch policies the portgroup is reset to the vswitch policies. Is there a simple way to save portgroup policies or a better way to rename portgroup ?
Thank you
Dominic
Sample code :
my $newName = $nameOpt;
my $pgName = $pgOpt;
my $indic = 0;
my $hostviews = Vim::find_entity_views(view_type => 'HostSystem');
if ($hostviews) {
foreach (@$hostviews) {
my $hostview = $_;
my $netview = Vim::get_view (mo_ref => $hostview->configManager->networkSystem);
foreach my $portgroup (@{$netview->networkConfig->portgroup}) {
if ($portgroup->spec->name eq $pgName) {
$indic = 1;
my $vSwitch = $portgroup->spec->vswitchName;
my $vlanId = $portgroup->spec->vlanId;
my $hostNetPolicy = new HostNetworkPolicy();
my $hostPGSpec = new HostPortGroupSpec (name => $newName,
policy => $hostNetPolicy,
vlanId => $vlanId,
vswitchName => $vSwitch);
eval {$netview->UpdatePortGroup(pgName => $pgName, portgrp => $hostPGSpec); };
if ($@) {
print_screen('clear','red',$@->fault_string, '-> ' . $pgName);
#VIExt::fail($@->fault_string);
} else {
print_screen('clear','green','PortGroup has been renamed : ', $vSwitch . ' : ' . $pgName . ' -> ' . $newName);
}
.......................
What's the behavior when doing this using the vSphere Client? I would expect that a rename would not modify any defined policies, unless as part of the rename the user would like to update the configuration of the portgroup. I would say, probably best option is to capture the settings, create your change spec and use the UpdatePortGroup() as you are now ... I would consider this a bug if it defaults your policy upon a rename, you may want to file a SR if you have SDK support with VMware.
=========================================================================
William Lam
VMware vExpert 2009
VMware ESX/ESXi scripts and resources at:
VMware Code Central - Scripts/Sample code for Developers and Administrators
![]()
If you find this information useful, please award points for "correct" or "helpful".
