Compartir a través de


Escala de una capa de equipo (Script)

 

Se aplica a: System Center 2012 R2 Virtual Machine Manager, System Center 2012 - Virtual Machine Manager

Puede reducir la cantidad de recursos que está utilizando un servicio implementado mediante el escalado en el servicio. Para escalar de un servicio, puede quitar una máquina virtual desde un nivel de equipo o cambiar el estado de la máquina virtual. Definir si se puede escalar un nivel de equipo en estableciendo la InstanceMinimumCount parámetro para una plantilla de nivel de equipo.

La secuencia de comandos de este tema incluye dos conjuntos de parámetros. Ambos conjuntos de parámetros requieren que proporcione el nivel de servicio y equipo. Sin embargo, puede especificar que la máquina virtual quitarse con la RemoveVM cambie o realizar una acción en la máquina virtual utilizando la VMAction parámetro.

Renuncia

La siguiente secuencia de comandos comprueba si es capaz de escalar en un nivel asegurándose de que quitar una máquina virtual del servicio no hará que el servicio inferior al número mínimo de máquina para el nivel. La secuencia de comandos, a continuación, busca la máquina virtual creada más recientemente que se ejecuta en el nivel de equipo y cualquier elimina la máquina virtual o coloca la máquina virtual en una opción de Estados no están en ejecución.

#   Description:   The script verifies that you are able to scale in a tier and, if so,
#                  the script locates the most recently created virtual machine running
#                  on the computer tier and either removes the virtual machine or stops,
#                  pauses, stores, or saves the state of the virtual machine.

Param (
   [parameter(Mandatory=$true,ParameterSetName="RemoveVM")]
   [Switch]
   $RemoveVM,

   [parameter(Mandatory=$true,ParameterSetName="RetainVM")]
   [ValidateSet("Stop","Pause","SaveState","Store")]
   [String[]]
   $VMAction,

   [parameter(Mandatory=$true)]
   [String]
   $Service=$(throw "Please provide the name of a service."),

   [parameter(Mandatory=$true)]
   [String]
   $ComputerTier=$(throw "Please provide the name of a computer tier."),

   [parameter(Mandatory=$false,ParameterSetName="RetainVM")]
   [String]
   $LibraryServer,

   [parameter(Mandatory=$false,ParameterSetName="RetainVM")]
   [String]
   $LibraryPath
   )

# Get the service and the computer tier.
$ServiceInstance = Get-SCService -Name $Service
$Tier = Get-SCComputerTier -Service $ServiceInstance | where {$_.Name -eq $ComputerTier}

# Ensure that you are able to scale the tier in. 
If ($Tier.VMs.count -le $Tier.InstanceMinimumCount) {throw "You have reached the instance minimum for this tier."}

# Find the most recently created virtual machine in the tier that is running.
$VMs = @(Get-SCVirtualMachine | where {$_.ComputerTier -eq $Tier -and $_.Status -eq "Running"}) | sort -Property CreationTime -Descending
$VM = $VMs[0]

If ($RemoveVM)
{
   Stop-SCVirtualMachine -VM $VM -Force
   Remove-SCVirtualMachine -VM $VM
}
Else
{
   If ($VMAction -eq "Stop")
   {
      Stop-SCVirtualMachine -VM $VM
   }

   ElseIf ($VMAction -eq "Pause")
   {
      Suspend-SCVirtualMachine -VM $VM
   }

   ElseIf ($VMAction -eq "SaveState")
   {
      Stop-SCVirtualMachine -VM $VM -SaveState
   }

   ElseIf ($VMAction -eq "Store")
   {
      Save-SCVirtualMachine -VM $VM -LibraryServer $LibraryServer -SharePath $LibraryPath
   }

   Else
   {
      throw "You did not provide a valid action for the virtual machine."
   }
}