PRO で生成されるスクリプト(サンプル)
$hostName = 'JUNICHIA03.example64.jp'; $serverName = 'SCVMM.example64.jp'; $ProtipId = '23B785AC-2C4C-4C8A-A7DB-2E54A5E9A475';
$vmErrorCode = '1';
function new-array { $args }
function FailGenericError { Set-PROTip -PROTipId $args[0] -LastError $args[1] -TipStatus Failed; }
function FailHostNotFound { $params = new-array '{2D6FA041-3A11-C4A4-0870-43D3DA2A350E}' $args[1];
Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed; }
function FailNoVMFound {
switch($args[1]) {
1 { $params = new-array '{7909730C-BD3A-9639-75A4-C2CAB421E365}' $args[2]; }
2 { $params = new-array '{75DE3243-067A-7A38-369A-72E5516D3427}' $args[2]; } }
Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed; }
function FailNoVMToMigrate {
$params = new-array '{2BFEAC02-0B20-13B6-868E-90DBD1BE9325}' $args[1];
Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed; }
function FailNoHostToMigrateTo {
$params = new-array '{D33420DA-D858-F885-7C6E-B60F5EF4C990}' $args[1];
Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed; }
function FailInvalidErrorCode { $params = new-array '{CA516E68-8046-9013-25D6-15B8A512BD0C}';
Set-PROTip -PROTipId $args[0] -LastErrorOpsMgrString $params -TipStatus Failed; }
function Main {
$Error.Clear();
$serverObj = get-vmmserver -computerName $serverName;
if( $Error.Count -ne 0) { FailGenericError $ProtipId $Error[0]; return; }
Set-PROTip -PROTipId $ProtipId -TipStatus Running;
$hostobj = get-vmhost -computername $hostName -vmmserver $serverObj;
if( $hostobj -eq $null ) { FailHostNotFound $ProtipId $hostName; return; }
$allvms = $hostobj | Get-VM;
if(($hostobj.VMs -eq $null) -or ($hostobj.VMs.Count -eq 0)) { FailNoVMFound $ProtipId $vmErrorCode $hostName; return; }
$candidateVMs = @();
foreach( $cVM in $hostobj.VMs | where { $_.Status -eq 'Running' } | where { $_.ExcludeFromPRO -ne $TRUE} ) { $candidateVMs = $candidateVMs + $cVM; }
if($candidateVMs.Count -eq 0) { FailNoVMToMigrate $ProtipId $hostName; return; }
switch($vmErrorCode) {
1 { foreach( $tVM in ($candidateVMs | sort PerfCPUUtilization -Descending) ) { $selectedVM = $tVM; break; } if( $selectedVM.PerfCPUUtilization -eq 0 ) { FailNoVMFound $ProtipId $vmErrorCode $hostName; return; } }
2 { foreach( $tVM in ($candidateVMs | sort Memory -Descending) ) { $selectedVM = $tVM; break; } if( $selectedVM.Memory -eq 0 ){ FailNoVMFound $ProtipId $vmErrorCode $hostName; return; } } default { FailInvalidErrorCode $ProtipId; return; } } $isQuickMigration = $false; $hostList = @(); $allhosts = Get-VMHost -VMHostGroup $hostobj.VMHostGroup; if(($hostobj.HostCluster -ne $null ) -and ($hostobj.HostCluster.Nodes.Count -ne 1)){ foreach ( $tmpHost in $hostobj.HostCluster.Nodes ) { if( $tmpHost.Name -ne $hostobj.Name ) { $hostList = $hostList + $tmpHost; $isQuickMigration = $true; } } } else { foreach ( $tmpHost in $hostobj.VMHostGroup.Hosts ) { if( $tmpHost.Name -ne $hostobj.Name ) { $hostList = $hostList + $tmpHost; } } } if(($hostList -eq $null) -or ($hostList.Count -eq 0)) { FailNoHostToMigrateTo $ProtipId $hostName; return; }
$vmHostRatings = @(); $vmHostRatings = $vmHostRatings + ( @(Get-VMHostRating -VM $selectedVM -VMHost $hostList -IsMigration -UseDefaultPath) | Sort-Object -property Rating -descending | where { $_.Rating -ne 0 } );
if ( $vmHostRatings.Count -eq $null) { FailNoHostToMigrateTo $ProtipId $hostName; return; }
$selectedVMHost = $hostList | where { ($_.Name -eq $vmHostRatings[0].VMHost.Name) };
if($selectedVMHost -eq $null) { FailNoHostToMigrateTo $ProtipId $hostName; return; }
$Error.Clear();
if($isQuickMigration) { Move-VM -VM $selectedVM -VMHost $selectedVMHost -PROTipId $ProtipId; } else {
$defaultPaths = @($selectedVMHost.VMPaths | where { $_.StartsWith($vmHostRatings[0].PreferredVolume) -eq 1 });
if($defaultPaths[0] -eq $null) { FailNoHostToMigrateTo $ProtipId $hostName; return; }
Move-VM -VM $selectedVM -VMHost $selectedVMHost -Path $defaultPaths[0] -PROTipId $ProtipId; }
if( $Error.Count -ne 0) { FailGenericError $ProtipId $Error[0]; return; }
Set-PROTip -PROTipId $ProtipId -TipStatus Resolved; }
Main;
Comments
- Anonymous
January 01, 2003
The comment has been removed