VMware Cloud Community
PA3CRZ
Contributor
Contributor

Strange error when (re)creating VM

HI,

I'm getting an error when recreating a VM, but before I can show what that error is, I need to explain a couple of things. Please bear with me :

We are testing our Disaster/Recovery procedures using VMware clusters located at two different sites by means of Powershell./PowerCLI.
For this, before the actual test, we storage-vmotion the VMs that need to be moved to the other site to a special lun on site 1. Data on this lun is being replicated to site 2 (HDS storage).
Next we bring down those VMs, split the storage path so the lun becomes available for VMware on site 2, and mount the special lun on site 2.

Then we initiate a Create-VM on site 2 so the VMs will become available on site 2. 
Next, and this is what my question will be about, we need to reapply the network portgroup settings for each VM.

The particular code for this part is as follows :

 

 

  $a = @()
  $n = Get-Networkadapter -Server $DestinServer  -VM $VMName
  ForEach ($nic in $n.Name) {
    $a += $nic.Substring($nic.Length - 1)
  }
  ForEach ($nr in $a) {
    $str = "Network adapter $nr"
    ForEach ($nic in $n) {
      If ($str -eq $nic.Name) {
        write-host "Setting $str to value " (Get-Variable -Name VMNIC$nr).Value
        if ((Get-Variable -Name CNCT$nr).Value -eq "True") {
          $connectstate = 1
        } else {
          $connectstate = 0
        }
        $nic | Set-NetworkAdapter -StartConnected $connectstate -Confirm:$false
        $nic | Set-NetworkAdapter -Portgroup (Get-variable -Name VMNic$nr).Value -Confirm:$false
      }
    }
  }

 

 

Earlier in the script I have created variables that contain the name of the network (e.g. $VMNic1 with value VLAN_120, $VMNic2 with value VLAN_100, etc) and whether this NIC was in the connected state (e.g. $CNCT1 with value True, $CNCT2 with value False, etc)

So, in a loop I'm applying the "old" network settings that were in effect on site 1 to the VMs on site 2.

Doing this, I am getting the following error :

 

 

The object or item referred DVS d7 ac 3a 50 a1 0c fb b1-a0 98 23 54 d1 cd 22 be cannot be found

 

 

(Also, see attached screenprint)

I can't find where this error is coming from, and strangely enough, after having issued the error the command does what I want it to do after all.
At first I thought that the error was generated due to the fact that I was connected to two vCenters (giving me one error and one ok message), but I rewrote my script so I am sure that I am connected to only one vCenter at a time (which is more correct when you are in a real D/R situation anyway). Still got the same message. Also, when reverting the entire situation (going back from site 2 to site 1) I got the same error again, but the command again also just worked.

To make things even more strange: when I replay the entire situation but with different VMs, I do not get the error....

So, in my opinion there is something fishy concerning the specific set of VMs used in the first run and the correlation of those VMs with a Virtual Switch.
A correlation that obviously does not exist with the VMs used in the second test.

Can anyone please tell me where to look for this correlation, and how to handle it in my D/R script ?
Since the command does work, although I get an error first, is it ok to just ignore this error and do a silentlycontinue ?

Hope my story was clear enough...

Thanks,
Hans

Moderator edit by wila: Moved thread to PowerCLI discussions area

Reply
0 Kudos
10 Replies
LucD
Leadership
Leadership

That error only occurs for VMs connected to a VDS.
One method I normally use to avoid this, is to connect the vNICs temporarily to a dummy portgroup on a VSS (before moving the VMS)


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

Reply
0 Kudos
PA3CRZ
Contributor
Contributor

Hi Luc,

Thanks for answering so soon.
This is strange, because all of our VMs are connected to a VDS.

Yet, when doing the same routine with another VM that is connected to the same virtual switch, this error did not pop up.

How can that be explained ? 

Reply
0 Kudos
LucD
Leadership
Leadership

If the port that is configured in the VMX is free, there is no error.
If another VM is using the port, you get the error.
The best is to get rid of that hard-coded port number.
One way is like I said earlier, move the vNIC temporarily to a VSS.
If that is not possible, you have to make sure that the port is free before doing the vMotion.


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

Reply
0 Kudos
PA3CRZ
Contributor
Contributor

Sorry Luc, forgive my ignorance.

Are you talking about the port id's as in this picture ?

 

If you are, I would go for the second option, but how do I free a port ?

Reply
0 Kudos
LucD
Leadership
Leadership

Are moving those VMs while they are powered on?
If the port is used on the destination. that means another entity is connected to it.


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

Reply
0 Kudos
PA3CRZ
Contributor
Contributor

Nope.

In our D/R testing we power off the VMs before we recreate them (using New-Vm ) on the other site....

Reply
0 Kudos
LucD
Leadership
Leadership

If such a port is used on the destination side, that means another entity is using it.
So you probably can not just disconnect ports I'm afraid.


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

Reply
0 Kudos
PA3CRZ
Contributor
Contributor

Hmmm,

As I said before, I get the error, but the next thing that happens is that the network is configured the right way.

Maybe the command sees that port is in use on the destination side, returns the error, and then configures the network on the next
available free port.

Would it be safe to just ignore the error (silentlycontinue) ?

Reply
0 Kudos
LucD
Leadership
Leadership

I'm not sure, I would in any case open an SR to ask for confirmation if it is safe to ignore.

Btw, if your assumption about the reconfig in the background is correct, there should be an event documenting that config change.
Perhaps have a look at the events for that VM during that timeframe?


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

Reply
0 Kudos
PA3CRZ
Contributor
Contributor

Thanks Luc,

Will do, and I will open an SR as well.

On to the next questions (coming soon to this theater 😎)

Reply
0 Kudos