VMware Cloud Community
FredericPerrin
Enthusiast
Enthusiast

Using the new Set-VMGuestNetworkInterface

Hello,

As anybody tried using the shiny new {Get,Set}-VMGuestNetworkInterface ? It looks like there is a bug when the host has several network interface, as the following sample shows. $vminst is a freshly installed RHEL 5.4 VM, and it has two network interfaces : eth0 and eth1. I first select eth1, then try to change its IP address ; but as the output from Set-VMGuestNetworkInterface shows, eth0 is modified (and I can verify that from the guest itself). I can't check whether I'm using correctly this new cmdlet, as as pages that mention it seem to be copy-pasta of the release notes. Additionnally, man {Get,Set}-VMNetworkInterface doesn't show how to chain the two together...

[vSphere PowerCLI] H:\vmware\Scripts\trunk> $eth1 = Get-VMGuestNetworkInterface -VM $vminst -HostUser $Login -HostPassword $Password  -GuestUser $guser -GuestPasword $gpasswd |? { $_.Name -eq "eth1" }
[vSphere PowerCLI] H:\vmware\Scripts\trunk> $eth1

VMId             : VirtualMachine-672
SubnetMask       : 255.255.255.128
NicId            : VirtualMachine-672/4001
Name             : eth1
IPPolicy         : Static
Ip               : 172.25.126.16
Dns              : {139.54.40.6, 135.120.0.246}
DefaultGateway   :
Description      : Ethernet
Mac              : 00:0C:29:0A:40:6D
RouteInterfaceId : eth1
DnsPolicy        : Dhcp
WinsPolicy       :
Wins             :

[vSphere PowerCLI] H:\vmware\Scripts\trunk> Set-VMGuestNetworkInterface -VMGuestNetworkInterface $eth1 -HostUser $Login -HostPassword $Password  -GuestUser $guser -GuestPassword $gpasswd -Ip 1.2.3.4

VMId             : VirtualMachine-672
SubnetMask       : 255.255.255.192
NicId            : VirtualMachine-672/4000
Name             : eth0
IPPolicy         : Static
Ip               : 1.2.3.4
Dns              : {139.54.40.6, 135.120.0.246}
DefaultGateway   : 172.25.205.254
Description      : Ethernet
Mac              : 00:0C:29:0A:40:63
RouteInterfaceId : eth0
DnsPolicy        : Dhcp
WinsPolicy       :
Wins             :
 

Reply
0 Kudos
13 Replies
LucD
Leadership
Leadership

The documentation for these cmdlets is in the vSPhere PowerCLI Cmdlets Reference on the machine where you installed PowerCLI 4u1.

And you can get a web-based cmdlet reference here (thanks Mariana).

Btw couldn't get this to work on Red Hat 3 & 4 nor on Suse 8/9.

The Get-VmGuestNetworkInterface always seems to come back with a message like "Unable to parse script out".


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

FredericPerrin
Enthusiast
Enthusiast

The document you link to doesn't have more information than the online "Get-Help Set-VMGuestNet*" man page, or does it ?

However, you gave me an idea: the help mentions adding OS-specific scripts to .../PowerCLI/Scripts. Sure enough, the script that applies the parameters is there. It is a Perl script that edits /etc/sysconfig/network-script/ifcfg-$interface and then runs "service network restart". If we add something that log @ARGV, we see that the script is passed the wrong value for @ARGV[0] aka $interface. Well, off to report a VMware bug...

Reply
0 Kudos
FredericPerrin
Enthusiast
Enthusiast

LucD, I also get this error when my interfaces are not all named ethX, or when the script Script/GetVMGuestNetworkInterface (you'll find it in the PowerCLI installation directory) can't open the files /etc/sysconf/network-scripts/ifcfg-ethX. Try copying this script to a VM, it is a simple Perl script that parses the output from ifconfig, route, and the ifcfg-ethX files. Of course, if your "old" RHEL4 VM don't use the ifcfg-ethX scripts for configuration, or if the output format from route or ifconfig has been modified between that and RHEL5, you will need to write an equivalent script.

Also, since I couldn't track our support contract yet, in the meantime I'll dump here the bug report, if a VMware technicians happens to pass here.

When using the Set-VMGuestNetworkInterface against a RHEL 5.4 guest running on ESX4, the wrong network interface is configured. The guest has two network interfaces, eth0 and eth1 (and lo, the loopback interface). For logging purpose, I added at the end of the file "C:/Program Files/VMware/Infrastructure/vSphere PowerCLI/Scripts/SetVMGuestNetworkInterface_LinuxGuest" the following:

 open(LOGFILE, ">>", "/var/log/setNIC");
print LOGFILE "@ARGV", "\n";
close(LOGFILE); 

The following transcript shows the problem:

 [vSphere PowerCLI] H:\> $rh = (get-VM)[3]
[vSphere PowerCLI] H:\> $rh.Guest.GuestId
rhel5Guest
[vSphere PowerCLI] H:\> $eth1 = Get-VMGuestNetworkInterface -VM $rh |? { $_.Name -eq "eth1" }
[vSphere PowerCLI] H:\> $eth1

VMId             : VirtualMachine-672
SubnetMask       : 255.255.255.128
NicId            : VirtualMachine-672/4001
Name             : eth1
IPPolicy         : Static
Ip               : 172.25.126.16
Dns              : {139.54.40.6, 135.120.0.246}
DefaultGateway   :
Description      : Ethernet
Mac              : 00:0C:29:0A:40:6D
RouteInterfaceId : eth1
DnsPolicy        : Dhcp
WinsPolicy       :
Wins             :

[vSphere PowerCLI] H:\> Set-VMGuestNetworkInterface -VmGuestNetworkInterface $eth1 -Ip 1.2.3.4

VMId             : VirtualMachine-672
SubnetMask       : 255.255.255.192
NicId            : VirtualMachine-672/4000
Name             : eth0
IPPolicy         : Static
Ip               : 1.2.3.4
Dns              : {139.54.40.6, 135.120.0.246}
DefaultGateway   : 172.25.205.254
Description      : Ethernet
Mac              : 00:0C:29:0A:40:63
RouteInterfaceId : eth0
DnsPolicy        : Dhcp
WinsPolicy       :
Wins             :

[vSphere PowerCLI] H:\> Get-VMGuestNetworkInterface -VM $rh
VMId             : VirtualMachine-672
SubnetMask       : 255.255.255.192
NicId            : VirtualMachine-672/4000
Name             : eth0
IPPolicy         : Static
Ip               : 1.2.3.4
Dns              : {139.54.40.6, 135.120.0.246}
DefaultGateway   : 172.25.205.254
Description      : Ethernet
Mac              : 00:0C:29:0A:40:63
RouteInterfaceId : eth0
DnsPolicy        : Dhcp
WinsPolicy       :
Wins             :

VMId             : VirtualMachine-672
SubnetMask       : 255.255.255.128
NicId            : VirtualMachine-672/4001
Name             : eth1
IPPolicy         : Static
Ip               : 172.25.126.16
Dns              : {139.54.40.6, 135.120.0.246}
DefaultGateway   :
Description      : Ethernet
Mac              : 00:0C:29:0A:40:6D
RouteInterfaceId : eth1
DnsPolicy        : Dhcp
WinsPolicy       :
Wins             :

VMId             : VirtualMachine-672
SubnetMask       : 255.0.0.0
NicId            :
Name             : lo
IPPolicy         : Static
Ip               : 127.0.0.1
Dns              : {139.54.40.6, 135.120.0.246}
DefaultGateway   :
Description      : Local Loopback
Mac              :
RouteInterfaceId : lo
DnsPolicy        : Dhcp
WinsPolicy       :
Wins             :

[vSphere PowerCLI] H:\> (Get-VMHost|Get-View).Config.Product.Fullname
VMware ESX 4.0.0 build-175625
[vSphere PowerCLI] H:\> Get-VIToolkitVersion

PowerCLI Version
----------------
VMware vSphere PowerCLI 4.0 U1 build 208462 

As the output shows, it is eth0 that is modified, and not eth1. This is confirmed by looking at the output from "ifconfig" inside the guest.

The content of /var/log/setNIC after running the previous transcript is:

 eth0 static 1.2.3.4 (etc.) 

This shows that the SetVMGuestNetworkInterface_LinuxGuest script is given the wrong interface name as a parameter.

Reply
0 Kudos
nnedev
VMware Employee
VMware Employee

Hi folks,

Thank you for your feedback.

FredericPerrin: This seems to be a problem in the Set-VMGuestNetwork cmdlet. I'll file a bug in our bug tracking system.The issue will be fixed in a future relase.

LucD: There is something specific for your local environment that is not handled in our parsing module. Please send us the output of the "ifconfig" command for the operating system where Get-VMGuestNetworkInterface cmdlet throws exception.

Thanks,

Nedko

Regards, Nedko Nedev PowerCLI Development Team
FredericPerrin
Enthusiast
Enthusiast

Oh, nice to know, . Is there a bug tracker where I can follow updates on this issue ?

Reply
0 Kudos
nnedev
VMware Employee
VMware Employee

Our bug tracker system is internal. I'll add a note in the bug for the developer to post a message in this thread when the issue is resolved and the fix is released.

Thanks,

Nedko

Regards, Nedko Nedev PowerCLI Development Team
Reply
0 Kudos
trent1980
Enthusiast
Enthusiast

is there any update on this?

I thought I would be clever and try to weed out the NIC I wanted to change but it looks like it just edits the first one returned.

code:

$GuestInterface298 = $GuestInterfaceAll | where {$_.Name -like "VLAN 298"}

and then passed $GuestInterface298 in the Set-VMGuestNetworkInterface command.

Any help? I need to edit a bunch of boxes and only want to edit 1 of the 3 nics.

For the record, my interface is 1 in the array, not 0. 0 keeps getting edited.

I tried: Set-VMGuestNetworkInterface -VMGuestNetworkInterface $GuestInterfaceAll[1] -HostCredential $HostCred -GuestCredential $GuestCred -DNS $pdnswins

but it still edits 0, not 1.

Reply
0 Kudos
nnedev
VMware Employee
VMware Employee

Hi,

Is this the latest version of PowerCLI - 4.1? I believe the issue is resolved.

Regards,

Nedko Nedev

PowerCLI Development Team

Regards, Nedko Nedev PowerCLI Development Team
Reply
0 Kudos
ggochkov
VMware Employee
VMware Employee

I'm using latest release of PowerCLI - build#264274 and cannot reproduce the issue on linux RedHat 5. What is the OS of you VM?

Reply
0 Kudos
trent1980
Enthusiast
Enthusiast

Sorry, I should have given more detail. The VM's that I am testing against are windows XP. They have 3 nics each (0,1,2) and it's almost always the case that the nic I need to edit is the second (1) nic in the machine. I run a little check and then want to pass which nic to edit in:

Set-VMGuestNetworkInterface -VMGuestNetworkInterface $GuestInterfaceAll[$counter] -HostCredential $HostCred -GuestCredential $GuestCred -DNS $pdnswins

Even if I manually put $GuestInterfaceAll[1] , it still edits $GuestInterfaceAll[0].

INFO:

PowerCLI Version -> VMware vSphere PowerCLI 4.0 U1 build 208462

vCenter -> Version 4.0.0 build 208111

ESX Host -> Version 4.0.0 build 208167

Guest VM -> Windows XP

Reply
0 Kudos
trent1980
Enthusiast
Enthusiast

PowerCLI Version -> VMware vSphere PowerCLI 4.0 U1 build 208462

vCenter -> Version 4.0.0 build 208111

ESX Host -> Version 4.0.0 build 208167

Guest VM -> Windows XP

Reply
0 Kudos
nnedev
VMware Employee
VMware Employee

The issue is resolved in the latest release - PowerCLI 4.1. You need to upgrade.

Regards,

Nedko Nedev

PowerCLI Development Team

Regards, Nedko Nedev PowerCLI Development Team
Reply
0 Kudos
trentontaylor
Contributor
Contributor

sorry ...

read 4.1 as 4.0.1

It is working now -- Thanks for the help

Reply
0 Kudos