Huawei.Ism.hyperv.PRO.Recovery (WriteActionModuleType)

Element properties:

TypeWriteActionModuleType
IsolationAny
AccessibilityInternal
RunAsDefault
InputTypeSystem.BaseData
OutputTypeSystem.CommandOutput

Member Modules:

ID Module Type TypeId RunAs 
Recovery WriteAction System.CommandExecuter Default

Overrideable Parameters:

IDParameterTypeSelector
EventDescriptionstring$Config/EventDescription$

Source Code:

<WriteActionModuleType ID="Huawei.Ism.hyperv.PRO.Recovery" Accessibility="Internal" Batching="false">
<Configuration>
<xsd:element xmlns:xsd="http://www.w3.org/2001/XMLSchema" name="EventDescription" type="xsd:string"/>
</Configuration>
<OverrideableParameters>
<OverrideableParameter ID="EventDescription" Selector="$Config/EventDescription$" ParameterType="string"/>
</OverrideableParameters>
<ModuleImplementation Isolation="Any">
<Composite>
<MemberModules>
<WriteAction ID="Recovery" TypeID="System!System.CommandExecuter">
<ApplicationName>%SystemRoot%\system32\windowspowershell\v1.0\powershell.exe</ApplicationName>
<WorkingDirectory/>
<CommandLine>
"&amp; '$file/RecoveryScript.ps1$' '$Config/EventDescription$'"
</CommandLine>
<TimeoutSeconds>86400</TimeoutSeconds>
<RequireOutput>false</RequireOutput>
<Files>
<File>
<Name>RecoveryScript.ps1</Name>
<Contents><Script>

Param($eventContent);
$eventContent = $eventContent.Split(':');

if($eventContent.Count -Lt 4)
{
$ParameterCountMsg = 'Huawei PROPack: Invalid number of parameters are passed to the script,Number of Parameters passed in to the script: ' + $eventContent.Count;
eventcreate /T Error /ID 1 /L APPLICATION /SO HuaweiVMMPro /D $ParameterCountMsg;
return;
}

$hostName = $eventContent[$eventContent.Count - 4].Replace('\n','').Trim();
$serverName = $eventContent[$eventContent.Count - 3].Trim();
#$serverName = "192.168.50.231";
$ProtipId = $eventContent[$eventContent.Count - 2].Trim();
$RecoveryOverrideFlag = $eventContent[$eventContent.Count - 1].Trim()[0];
$Error.Clear();
$checkSnapin = get-pssnapin | where { $_.Name -eq 'Microsoft.SystemCenter.VirtualMachineManager'};
if($checkSnapin.Name -ne 'Microsoft.SystemCenter.VirtualMachineManager')
{
$Error.Clear();
add-pssnapin "Microsoft.SystemCenter.VirtualMachineManager";
}
if( $Error.Count -ne 0 )
{
eventcreate /T Error /ID 2 /L APPLICATION /SO HuaweiVMMPRO /D $Error[0];
return;
}
$Error.Clear();
function new-array
{
$args
};
function FailGenericError
{
Set-PROTip -PROTipId $args[0] -LastError $args[1] -TipStatus Failed;
};
function PROTipFailNoHuaweiTargetHostToMigrate
{
$params = new-array $args[1];
Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed;
};
$Error.Clear();
function Main
{
$VmmserverObj = get-vmmserver -computerName $serverName;
if( $Error.Count -ne 0)
{
FailGenericError $ProtipId $Error[0];
return;
};

"124" &gt;&gt; D:\cy\scvmm2008cccy.txt;
$RecoveryOverrideFlag &gt;&gt; D:\cy\scvmm2008cccy.txt;

sleep 10

"1241" &gt;&gt; D:\cy\scvmm2008cccy.txt;

$Managednodeobj = get-vmhost -computername $hostName -vmmserver $VmmserverObj;
Set-PROTip -PROTipId $ProtipId -TipStatus Running;
$vmhost = get-vmhost -computername $hostName ;
$status = Set-VMHost -VMHost $vmhost -AvailableForPlacement $false;
if($status.AvailableForPlacement -ne $false)
{
FailGenericError $args[0] $Error[0];
};

switch($RecoveryOverrideFlag )
{
1
{
$Error.Clear();
$VMsonNode = $Managednodeobj | Get-VM ;
if(($Managednodeobj.VMs.Count -eq 0) -or ($Managednodeobj.VMs -eq $null))
{
$InfoMsg= 'Huawei PROPack: No VMs found on host: ' + $hostname;
eventcreate /T Information /ID 4 /L APPLICATION /SO HuaweiVMMPRO /D $InfoMsg;
Set-PROTip -PROTipId $ProtipId -TipStatus Resolved;
return;
};
$isThisNonClusterHost = $false;
$candidateVMs = @();
if($Managednodeobj.HostCluster -eq $null )
{
$isThisNonClusterHost = $true;
}
$hostList =@();
if($isThisNonClusterHost -eq $false)
{
foreach ( $tmpHost in $Managednodeobj.HostCluster.Nodes)
{
if( $tmpHost.Name -ne $Managednodeobj.Name )
{
$hostList = $hostList + $tmpHost;
}
}
foreach( $cVM in $Managednodeobj.VMs | where { $_.Status -eq 'Running' }| where { $_.IsHighlyAvailable -eq $TRUE }| where { $_.ExcludeFromPRO -ne $TRUE})
{
$candidateVMs = $candidateVMs + $cVM;
}
}
else
{
$allhosts = Get-VMHost -VMHostGroup $Managednodeobj.VMHostGroup;
foreach ($tmpHost in $allhosts )
{
$hostListnew = @();
$hostobjnew = get-vmhost -computername $tmpHost -vmmserver $VmmserverObj;
if($tmpHost.Name -ne $Managednodeobj.Name)
{
if($hostobjnew.HostCluster.Name -ne $null)
{
$hostListnew =$hostListnew + $tmpHost;
}
else
{
$hostList=$hostList + $tmpHost;
}
}
}
foreach( $cVM in $Managednodeobj.VMs | where { $_.Status -eq 'Running' }| where { $_.ExcludeFromPRO -ne $TRUE})
{
$candidateVMs = $candidateVMs + $cVM;
}
}
if($candidateVMs.Count -eq 0)
{
$InfoMsg= 'Huawei PROPack: No VMs found on host: ' + $hostname;
eventcreate /T Information /ID 5 /L APPLICATION /SO HuaweiVMMPRO /D $InfoMsg;
Set-PROTip -PROTipId $ProtipId -TipStatus Resolved;
return;
};
if(($hostList -eq $null) -or ($hostList.Count -eq 0))
{
$InfoMsg= 'Huawei PROPack: No taget host found to migrate VMs from source host: ' + $hostname;
eventcreate /T Information /ID 6 /L APPLICATION /SO HuaweiVMMPRO /D $InfoMsg;
PROTipFailNoHuaweiTargetHostToMigrate $ProtipId $hostName;
return;
}
if($isThisNonClusterHost -eq $false)
{
$isHighlyAvailable = $Managednodeobj.VMs | where { $_.Status -eq 'Running' }| where { $_.IsHighlyAvailable -eq $TRUE} | sort PerfCPUUtilization -Descending | where { $_.ExcludeFromPRO -ne $TRUE}
}
else
{
$isHighlyAvailable = $Managednodeobj.VMs | where { $_.Status -eq 'Running' } | sort PerfCPUUtilization -Descending | where { $_.ExcludeFromPRO -ne $TRUE}
};
$HostPlacmenetGoal = $VmmserverObj.get_PlacementGoal();
foreach( $selectedVM in $isHighlyAvailable)
{
$vmHostRatings = @();
$Error.Clear();
$getHostRating = @(Get-VMHostRating -VM $selectedVM -VMHost $hostList -IsMigration -UseDefaultPath -PlacementGoal $HostPlacmenetGoal);
$vmHostRatings = $vmHostRatings + ( $getHostRating | Sort-Object -property Rating -descending | where {$_.Rating -ne 0 } );
if($vmHostRatings -eq $null )
{
$InfoMsg= 'Huawei PROPack: Zero host rating found and unable to migrate VMs ';
eventcreate /T Information /ID 7 /L APPLICATION /SO HuaweiVMMPRO /D $InfoMsg;
PROTipFailNoHuaweiTargetHostToMigrate $ProtipId $hostName;
return;
};
$selectedVMHost = $hostList | where { ($_.Name -eq $vmHostRatings[0].VMHost.Name)};
if($selectedVMHost -eq $null)
{
$InfoMsg= 'Huawei PROPack: Unable to select a target host for VM migration.';
eventcreate /T Information /ID 8 /L APPLICATION /SO HuaweiVMMPRO /D $InfoMsg;
PROTipFailNoHuaweiTargetHostToMigrate $ProtipId $hostName;
return;
}
$Error.Clear();
if($isThisNonClusterHost -eq $false)
{
Move-VM -VM $selectedVM -VMHost $selectedVMHost -PROTipId $ProtipId;
}
else
{
$Error.Clear();
$defaultPaths = @($selectedVMHost.VMPaths | where { $_.StartsWith($vmHostRatings[0].PreferredVolume) -eq 1 });
if( $defaultPaths[0] -eq $null)
{
$ErrMsg= 'Huawei PROPack: Unable to find a Path to migrate VM from a non-clustered host: ' + $hostname;
eventcreate /T Error /ID 9 /L APPLICATION /SO HuaweiVMMPRO /D $ErrMsg;
PROTipFailNoHuaweiTargetHostToMigrate $ProtipId $hostName;
return;
};
Move-VM -VM $selectedVM -VMHost $selectedVMHost -Path $defaultPaths[0] -PROTipId $ProtipId;
}
if($Error.Count -ne 0)
{
$MigrationFailed = $true;
$ErrMsg= 'Huawei PROPack: VM migrate action failed,host: ' + $hostname;
eventcreate /T Error /ID 10 /L APPLICATION /SO HuaweiVMMPRO /D $ErrMsg;
}
};
if($MigrationFailed -eq $true)
{
$ErrMsg= 'Huawei PROPack: VM migrate action failed,host: ' + $hostname;
eventcreate /T Error /ID 11 /L APPLICATION /SO HuaweiVMMPRO /D $ErrMsg;
$ErrMsg= 'Huawei PROPack:VM(s) migration failed.';
FailGenericError $ProtipId $ErrMsg;
return;
}
Set-PROTip -PROTipId $ProtipId -TipStatus Resolved;
}
2
{
sleep 30
Set-PROTip -PROTipId $ProtipId -TipStatus Resolved;
}
default
{
$ErrMsg= 'Huawei PROPack: Unsupported Override Recovery Action. Entered recovery overriden value: ' + $RecoveryOverrideFlag + '. Please choose override value 1 or 2.';
eventcreate /T Error /ID 3 /L APPLICATION /SO HuaweiVMMPRO /D $ErrMsg;
FailGenericError $ProtipId $ErrMsg;
return;
}
}
}

Main;


</Script></Contents>
</File>
</Files>
</WriteAction>
</MemberModules>
<Composition>
<Node ID="Recovery"/>
</Composition>
</Composite>
</ModuleImplementation>
<OutputType>System!System.CommandOutput</OutputType>
<InputType>System!System.BaseData</InputType>
</WriteActionModuleType>