VMware Cloud Community
FirozeB_za
Enthusiast
Enthusiast

move-vm fails after cluster upgrade to 7.0 u3O

Hi Guys

 

Got a strange issue a affecting a successfully tested script that has suddenly broke. The script was till a day ago, and the only change is the one in the heading.

 

Script:

$VCenter="VCenter"
$TargetCluster="TargetCluster"  
 
$TargetDS="TestDS" 
 
$StoragePolicy="vSANStorage Policy"
$LogFileBasePath = (Get-Location).tostring() + "\Log\"
 
$MailTo = "xxx@yyy.com"
 
$Batchfile = (Get-Location).tostring() + "\Mig.csv"
 
 
 
 
 
#Lets first Check that we have a log directory
 
IF (Test-Path $LogFileBasePath ) {
 
    write-host "Log Directory found found moving on"
     }   
    
   ELSE {
    
    write-host "Creating the directory for Diagnostic Logs" 
    New-Item -Path "$LogFileBasePath" -ItemType Directory -ErrorAction SilentlyContinue | Out-Null
    }
 
#function for logging to file
 
function Write-Log ($message)
{
$Date = (Get-Date -f "yyyyMMdd")
$LogDate = Get-Date -Format "yyyy:MM:dd hh:mm:ss"
$outContent = "$LogDate" + ":  " + "$message"
$LogFile = "$LogFileBasePath\" + "$Date" + ".log"
        Write-Host "$LogDate" ":" "$message" 
        Add-Content "$LogFile" $outContent
}
 
 
 
 
 
      Write-Log "Importing batch file: $Batchfile"
    try {
        $vms = Import-Csv $Batchfile
           
        }
catch {
        Write-Log "Failed to import batch file: $Batchfile cannot continue.Please check that you have specified a valid bath file to process"
        Break
#[Environment]::Exit(1) 
}
 
 
 
        Write-Log "Attempting to connect to vCenter server: $VCenter"
    try {
        Connect-VIServer $VCenter -credential (get-credential) -ErrorAction:Stop
        Write-Log "Connected to vCenter server: $VCenter"   
        }
catch {
        Write-Log "Could not connect to the vCenter server : $VCenter"
Break
        #[Environment]::Exit(1) 
}
 
 
# Get the Storage Policy in the vCenter
Write-Log "Locating storage policy: $StoragePolicy in vCenter:$vCenter"
    try {
        $SPBMPolicy = Get-SpbmStoragePolicy -Name $StoragePolicy 
        Write-Log "Located Storage Policy: $SPBMPolicy"   
        }
catch {
        Write-Log "Could not locate the Storage Policy defined"
        Break
#[Environment]::Exit(1) 
}
 
 
 
 
 
Write-Log "Locating an ACI integrated VDS that Cluster: $TargetCluster is connected to"
    try {
        $dvSwitch = Get-Cluster $TargetCluster | Get-VMhost | ? { $_.Connectionstate -eq "Connected"} | Sort-Object Name | Select-Object -first 1 | Get-VDSwitch | ? {$_.Name -like "*ACI*"}
        Write-Log "Located ACI integrated VDS named : $dvSwitch that Cluster: $TargetCluster is connected to"   
        }
catch {
        Write-Log "Failed to find a suitable VDS that Cluster: $TargetCluster is connected to"
        Break
#[Environment]::Exit(1) 
}
 
 
foreach ($vm in $vms) {
 
$vmname = $vm.vmname
 
#check that VM exists
$vmexists = get-vm $vmname -ErrorAction SilentlyContinue
 
    IF ($vmexists){
Write-Log "Located VM: $vmname"
#get the vm network adapters and check if PG's exist in vDS
$nics = @()
$nics = get-VM -Name $vmname | Get-NetworkAdapter
$niccount = $nics.count
$PGs = @()
foreach ($nic in $nics) {
 
$PGs += $dvSwitch | Get-VDPortgroup | Where-Object { $_.ExtensionData.Key -eq $nic.ExtensionData.Backing.Port.PortgroupKey }
 
IF ($PGs.Count -le 0) {
            $nics
            $PGs
            Write-Log "There was a problem locating one or more of the target port-groups for VM: $vmname on the ACI vDS that $TargetCluster is connected to"
}
}
#list all nics in order 
Write-Log "Listing $niccount network adapters"
$i = 0
foreach ($nic in $nics) {
Write-Log "VM: $vmname - NIC# $i Name: $($nic.name) - NIC# $i Network Name: $($nic.NetworkName) - PG ID: $($PGs[$i].ExtensionData.Key) - PG Name: $($PGs[$i].Name)"
        $i += 1
}
 
#attempt migration
try {
$migrate = move-vm -VM (get-vm $vmname) -VMotionPriority High -Destination (Get-Cluster $TargetCluster | Get-VMhost | ? { $_.Connectionstate -eq "Connected"} | Select -first 1) -Datastore (Get-Datastore -Server $VCenter -Name $TargetDS) -DiskStorageFormat Thin -StoragePolicy $SPBMPolicy -NetworkAdapter $nics -PortGroup $PGs -ErrorAction Stop
Write-Log "VM: $vmname has been migrated to cluster $TargetCluster and placed on DS: $TargetDS"
# Send the report email
Send-MailMessage -SmtpServer "mail.fnb.co.za" -To $MailTo -Subject "Successfully Migrated - $vmname" -Body "$vmname has been migrated." -From "migrations@cts-rbrdp01.fnb.co.za"
}
catch [exception]{
Write-Log "VM: $vmname has been NOT migrated"
Write-Log "Error Caught: $_"
# Send the report email
Send-MailMessage -SmtpServer "mail.fnb.co.za" -To $MailTo -Subject "Error during migration - $vmname" -Body "$vmname has NOT migrated.Please examine the log file for detailed error trace" -From "migrations@cts-rbrdp01.fnb.co.za"
}
 
 
 
}
 
 
ELSE{
Write-Log "Cannot Locate: $vmname . Please check that it is valid and correct in batch file if required"
# Send the report email
Send-MailMessage -SmtpServer "mail.fnb.co.za" -To $MailTo -Subject "Error during migration - $vmname" -Body "$vmname has NOT migrated as it could not be found. Please check that it is valid and correct in the batch file if required" -From "migrations@cts-rbrdp01.fnb.co.za"
}
}
 
 
 
 
 
Write-Log "All VMs in $Batchfile has been processed, please review the logfile"
 
#Disconnect from vCenter instances
Disconnect-VIServer $VCenter -confirm:$false
 
error attached
 
Cannot find the source but tried 3 tier cluster to 3 tier cluster and got the same error, VSAN to VSAN same error. 
 
Another important point is that the task still runs in vsphere but due to the error the script doesn't serialise migration.

 

0 Kudos
6 Replies
FirozeB_za
Enthusiast
Enthusiast

Tried the same on a vc with the an esxi 7.0 u3O cluster.

Script works successfully

Tried a vmotion without a datastore change, again successful in both cases (with and without 7.0 u3O)

could this be a 7.0 u3O bug that comes into play once we specify a DS change? 

Tags (1)
0 Kudos
LucD
Leadership
Leadership

So it works or not on 7.0.U30?
You seem to have conflicting statements here.

The error, as far as I can read it, doesn't seem to provide a lot of details.
Perhaps check the vpxd log on the VCSA for additional info.


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

0 Kudos
FirozeB_za
Enthusiast
Enthusiast

Hi Luc

typed while troubleshooting.

 

The script I posted errors via powercli but the task continues in vsphere despite this, my issue is that because the 'error' get caught the script moves on to the next vm in my list and therefore runs almost asynch.

Will check the VCSA logs although i search through aria logs and didn't find anything that stood out.

0 Kudos
FirozeB_za
Enthusiast
Enthusiast

seems to only trigger if the SPBM policy is provided as a parameter to the move-vm command

 

0 Kudos
LucD
Leadership
Leadership

Do you also get an error when you do the same from the Web Client?
I would in any case suggest opening an SR


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

FirozeB_za
Enthusiast
Enthusiast

So, my colleague has been digging through this today and it seems that its not move-vm thats broken but rather andthing powercli based that uses spbmpolicy. 

 

Actions via the gui works fine but any attempt to execute via powercli either throughs an error in the cmdlet utilizing the parameter or it the cmdlet is directly affecting spbmpolicy the command hangs indefinitely.

 

Have logged with VMware to see if they can uncover anything.

 

 

0 Kudos