PowerCLI

 View Only
Expand all | Collapse all

script fails after U1 update

  • 1.  script fails after U1 update

    Posted Dec 12, 2009 02:29 AM

    hello,

    I have a script that i use to configure hosts after they are built from the iso.

    I tracked it down to the begining of the script but not sure how to fix. any ideas?

    it looks like it fails right after I add second nic to the vswitch0. Host that I'm building looses network connectivity and when I go via ILO, there is no nic assigned to management network.

    Here is my code:

    basically what we do here is add vmotion portgroup to vswitch0 and then add second nic to the switch which will be active nic for vmotion and standby nic for management traffic.

    Any help is greatly appriciated.

    1. Remove the Default "VM Network" portgroup from vSwitch0

    $vs = get-virtualswitch -vmhost $vmhost -name vSwitch0

    $vpg = get-virtualportgroup -virtualswitch $vs -name 'VM Network'

    remove-virtualportgroup -VirtualPortGroup $vpg -Confirm:$false

    1. Add VMK PortGroup and Port for VMotion on vSwitch0

    $vmovs = Get-VirtualSwitch -VMHost $vmhost -Name "vSwitch0"

    New-VMHostNetworkAdapter -VMHost $vmhost -PortGroup VMotion -VirtualSwitch $vmovs -IP $vmoip -SubnetMask 255.255.255.0 -VMotionEnabled $true

    1. Add A VLAN TAG for the VMotion Interface

    $vs = Get-VirtualSwitch -VMHost $vmHost -Name vSwitch0

    $vpg = Get-VirtualPortGroup -VirtualSwitch $vs -Name VMotion

    $newVpg = Set-VirtualPortGroup -VirtualPortGroup $vpg -VLanId $vmoVLanId

    echo " ## Add VMNIC2 to vSwitch0"

    1. Adds VMNIC2 to vSwitch0

    $vs = Get-VirtualSwitch -VMHost $vmHost -Name vSwitch0

    Set-VirtualSwitch -VirtualSwitch $vs -Nic $vmonic



  • 2.  RE: script fails after U1 update

    Posted Dec 13, 2009 10:23 AM

    Perhaps you are using the incorrect nic as the 2nd nic ?

    Do you get any errors in the script ?

    Is there anything in the Task & Events tab for the new host in the vSPhere client ?

    Perhaps a short description of the HW architecture would make things clearer to understand.



  • 3.  RE: script fails after U1 update

    Posted Dec 13, 2009 05:57 PM

    Hi Luc,

    sorry i was in a hurry when i posted this. let me give more details

    Hosts are HP Blades BL490 G6. Error that i recieved in the script was basically connection to host lost. at that same time host stopped replying to pings. I went in via ILO and in the management network, under network adapters there were no nics defined. This happened on 2 hosts that I tried. I tried to enable the NIC via ILO. that worked and I was able to connect to the host. when I went into networking configuration of the host, management portgroup didn't have Management Traffic check box enabled.

    Since I had to get these 16 hosts built and ready to go, I uninstalled PowerCLI 4.0.1 U1 and installed back the original PowerCLI 4.0.0. As soon as new version was installed I had no problems building these hosts. So its defintely some change in the U1 that caused the issue.



  • 4.  RE: script fails after U1 update

    Posted Dec 13, 2009 06:38 PM

    One of the changes in PowerCLI 4u1 that could have an impact is the Connect-ViServer cmdlet.

    In the last release you can now open connections to multiple vCenters or ESX/ESXi servers in parallel.

    There is a new global variable $DefaultVIServers which contains all the connections you have open.

    Could it be that, at the moment you notice the problem, you are not connected to the ESX/ESXi server you think ?

    The actual connection can be found in the global variable $DefaultVIServer or in element 0 (zero) of the $DefaultVIServers array.

    Do you perhaps have a screenshot or log entry of the exact error message (with the line number in the script) ?

    Could help finding the problem.



  • 5.  RE: script fails after U1 update

    Posted Dec 13, 2009 06:45 PM

    I didn't take a screenshot of the error and log entry has been wiped out because i rebuilt the host.

    Main issue is that esx host that I'm configuring looses connection to the network. so at that point the script can't connect to it. I setup a conitunous ping to the server and as soon as this line runs (I think its this one)

    Set-VirtualSwitch -VirtualSwitch $vs -Nic $vmonic

    I start getting "request timed out" on the pings and script starts failing on the next line in which I configure Guest vswitch.

    I'm going to install Update1 again and run the script one more time. this way I can save the screenshots and logs



  • 6.  RE: script fails after U1 update

    Posted Dec 13, 2009 07:00 PM

    Good idea.

    Perhaps you could also print the content of $vmonic before that line.



  • 7.  RE: script fails after U1 update

    Posted Dec 13, 2009 07:11 PM

    so i'm breaking down the script pieces at a time. content of $vmonic is vmnic4 which is correct nic for vmotion in my script. everything upto last line is working without any problems. what I noticed though is that management traffic check box is not checked. can this be the cause of the problem?



  • 8.  RE: script fails after U1 update

    Posted Dec 13, 2009 07:29 PM

    On a line by itself just before the Set-VirtualSwitch line

    $vmonic
    



  • 9.  RE: script fails after U1 update

    Posted Dec 13, 2009 07:31 PM

    Yep got that one. that was a really stupid quesiton on my part. sorry :smileyhappy:

    I edited my post while you replied:

    so i'm breaking down the script pieces at a time. content of $vmonic is

    vmnic4 which is correct nic for vmotion in my script. everything upto

    last line is working without any problems. what I noticed though is

    that management traffic check box is not checked. can this be the cause

    of the problem?



  • 10.  RE: script fails after U1 update

    Posted Dec 13, 2009 08:49 PM

    Ok so I can confirm now that "Set-VirtualSwitch -VirtualSwitch $vs -Nic $vmonic" causes the problem

    As soon as I ran the script with this line in it, server started "request timed out"

    Script returned the following error:

    Set-VirtualSwitch : 12/13/2009 2:39:06 PM Set-VirtualSwitch 52bb84c3-ae73

    -34e0-7347-fc014eb6a148 The underlying connection was closed: A connection t

    hat was expected to be kept alive was closed by the server.

    At V:\test.ps1:13 char:18

    + Set-VirtualSwitch <<<< -VirtualSwitch $vs -Nic $vmonic | Out-File -Append "$

    LogFile" -ev +err

    + CategoryInfo : NotSpecified: (:smileyhappy: Set-VirtualSwitch, ViError

    + FullyQualifiedErrorId : Client20_VirtualNetworkService_SetVirtualSwitch2

    5_ViError,VMware.VimAutomation.Commands.SetVirtualSwitch



  • 11.  RE: script fails after U1 update

    Posted Dec 13, 2009 10:27 PM

    Ok, got some question that should allow me to get a picture of your architecture and configuration.

    You have 1 or more vSwitch on your ESX host when you run this script ?

    How many and which pNICs are connected to this/these vSwitch(es) before you execute the Set-VirtualSwitch cmdlet ?

    What portgroups are defined on that/these vSwitch(es) ?

    Which pNICs is/are each of the portgroups using ?

    Where did you see this "Management Traffic" checkbox ?

    Perhaps you could include a screenshot of the networking pane ?

    Something like this



  • 12.  RE: script fails after U1 update

    Posted Dec 14, 2009 02:38 AM

    Thanks for helping out Luc.

    Let me give you an overview without going into details.

    After the host is built via the iso we have a host with 1 vswitch: vSwitch0

    it contains 2 port groups: VM Network and Management Network. Both are assigned to vmnic0 by default installer.

    what the script does is the following:

    1) remove vm network portgroup.

    2) Add portgroup named VMotion

    3) Add vlan tag to vmotion port group

    At this point vswitch0 has 2 portgroups: Management Network and VMotion. This is the last step before the step at which host looses connectivity to the network. What I'm trying to do is vmnic4 to vswitch0 and then adjust active/standby nics of vswitch0. vmnic0 is active for management network and standby for vmotion and vice versa.

    I'm attaching 2 screen shots of what i'm talking about. I removed IP information from the screenshots. Main intresting thing is that PowerCLI 4.0.0 works without any issues and PowerCLI 4.0.1 fails at that step. Also I attached a screen shot of management network checkbox.



  • 13.  RE: script fails after U1 update

    Posted Dec 14, 2009 09:49 PM

    Thanks for the info but I'm still confused.

    In your screenshot I see 2 VMkernel portgroups and no Service Console.

    And to be honest I never saw that Management traffic option before.

    Perhaps because there is no Service Console ?

    Is that on purpose that you have 2 VMkernel portgroups and no Service Console portgroup ?



  • 14.  RE: script fails after U1 update

    Posted Dec 14, 2009 09:59 PM

    These are esx4i hosts. Esx4i doesn't have service console. you can only select VMKernel Portgroup and then u can enable Management traffic on One port group and Vmotion traffic on the second portgroup. its a bit different than ESX4 with a service console



  • 15.  RE: script fails after U1 update

    Posted Dec 14, 2009 10:07 PM

    Oops,should have known that.

    I'll fire up an ESXi and check on there.



  • 16.  RE: script fails after U1 update

    Posted Dec 21, 2009 10:16 PM

    LucD -sorry to be a pest but did u get a chance to try this on your esx4i host?

    thanks

    Alex



  • 17.  RE: script fails after U1 update
    Best Answer

    Posted Dec 22, 2009 12:23 AM

    Alex, sorry to have kept you waiting.

    I did the test and I can see the same error you're seeing.

    Tests were done ESXi 4.0.0, 208167 and with PowerCLU 4u1.

    A simple setup with 1 NIC attached to vSwitch0.

    I try to add a 2nd NIC (vmnic1) to vSwitch0.

    Notice that the ping starts to fail

    It seems that I lost the original NIC (vmnic0).

    This behavior contradicts the text with the -Nic parameter.

    So at least the help text for the cmdlet is incorrect. It's apparently not an "add" but a "replace".

    The bypass for this problem is quite simple

    $nic = (Get-VirtualSwitch -VMHost $esx -Name "vSwitch0").nic
    $nic += "vmnic1"
    Get-VirtualSwitch -Name "vSwitch0" -VMHost $esx | Set-VirtualSwitch -Nic $nic
    



  • 18.  RE: script fails after U1 update

    Posted Dec 22, 2009 12:57 AM

    Thank you for your help. I will try it when i get to the office.

    Have a happy holidays



  • 19.  RE: script fails after U1 update

    Posted Dec 24, 2009 10:28 PM

    LucD - this worked perfectly but I do have a question. how can i add more than one vmnic with += command? what is the correct syntax for that?

    lets say i want to add vmnic1 and vmnic2 to the vswitch? i can't seem to figure out the syntax for it.

    thansk

    Alex



  • 20.  RE: script fails after U1 update

    Posted Dec 24, 2009 11:09 PM

    The += operator in PowerShell is shorthand notitation for an addition combined with an assignment.

    Let me explain with the following example

    $a = $a + 1
    $a += 1
    

    Both of the above lines do the same, add 1 to the variable $a.

    For the NICs you could just do it like this

    $nic += "vmnic1","vmnic2"
    

    Important to note, the comma operator creates an array with the 2 new NICs.

    And the $nic variable was already an array, albeit with perhaps only 1 element.

    So you are adding 2 arrays together.

    Don't you just love PowerShell :smileywink:



  • 21.  RE: script fails after U1 update

    Posted Dec 24, 2009 11:23 PM

    :smileyhappy:

    Its actually very powerful once you figure out all the little things. i was very close but had a spaces around the comma and was getting an error :smileyhappy:

    thansks again