2014-10-29 6 views
1

Azure PowerShell SDK의 일부인 특히 the commands described in this article으로 DSC를 사용하여 Azure 가상 머신에 대한 제품 릴리스 자동화에 대한 초기 테스트 단계를 완료했습니다.Azure VM에서 DSC 실행에 대한 피드백을 얻으려면 어떻게해야합니까?

PowerShell을 사용하여 DSC 구성을 올바르게 적용 할 수 있지만이 프로세스는 자동화되어 있으므로 구성 프로세스가 어떻게 진행되는지 피드백을 얻고 싶습니다. Update-AzureVM으로 전화 할 때 DSC 구성은 비동기 적으로 발생하지만, DSC 구성은 이후에 발생합니다. 그리고 컴퓨터에 로그인하지 않으면 어떻게되는지 알 수 없습니다 (또는 look at the updated Azure Portal which now shows this).

구성이 실패하면 자동 프로세스를 실패하고 싶습니다. 스크립트에서 구성 상태를 확인하고 정상적으로 성공 또는 실패를 감지하려면 어떻게해야합니까?

+1

설명

의 상태를 얻기 위해 추가 한? http://technet.microsoft.com/en-us/library/dn249926.aspx 기본적으로 이벤트 로그를 사용하여 상태를 확인합니다 – Paul

+0

@Paul 매우 흥미 롭습니다. VM에 대해이 명령을 실행해야한다고 생각합니다. 멀쩡해? Azure SDK를 사용하여 좀 더 자동화 된 것을 기대하고있었습니다. – julealgon

+0

로컬로 호출 할 수도 있지만 기본적으로 예라고 할 수 있습니다. Azure SDK에 특별한 cmdlet이 있는지는 확실하지 않지만 의심 스럽습니다. – Paul

답변

4

우리는 가져 오기 - AzureVMDscExtensionStatus 새로운 cmdlet을 실행 DSC 구성이 문서는 내가`은 Get-xDscOperation` 당신을 위해 무엇을 찾고있는 것 같아요 같은 http://blogs.msdn.com/b/powershell/archive/2015/02/27/introducing-get-azurevmdscextensionstatus-cmdlet-for-azure-powershell-dsc-extension.aspx

+0

절대적으로 완벽합니다. 내가 필요한 것! 업데이트 Nana 주셔서 감사합니다. 이 cmdlet을 사용하면 프로세스가 훨씬 안정적 일 것입니다. – julealgon

1

몇 가지 방법이 있습니다. 최근 게시물 here에 설명 된대로 REST 기반 API를 호출 할 수 있습니다.

또한과 같이 (단지 REST 응답을 구문 분석 등) 값에 드릴은 Get-AzureVM을 사용할 수는 :

((@ 바탕으로 Get-AzureVM -ServiceName "" -Name "").ResourceExtensionStatusList | Where-Object { $_.HandlerName -eq 'Microsoft.PowerShell.DSC' }).ExtensionSettingStatus.Status

+0

아주 좋습니다. 이것으로, 필자는 스크립트에서 해당 필드를 읽고 호출자에게 값을보고하는 루프를 만들 수 있다고 가정합니다. 가능한 값이 어딘가에 기록되어 있습니까? 적어도 스크립트를 중단하고 결과를보고 할 수 있도록 종료 상태를 알아야합니다. – julealgon

0

다윗의 제안, 나는 폴링을 만들어 결국 함수를 사용하여 상태 변경을 감지하고 내 주 스크립트로 다시보고하십시오.

먼저 DSC 작업을 성공적으로 감지하면 루프를 끝내야하는지,)

VM의 DSC 확장 프로그램에서 사용하는 파일에서 드릴 다운하여 가능한 상태 코드를 찾고 해당 조건을 기반으로합니다. 상태 코드는 DSC 확장이 설치된 가상 시스템의 C:\Packages\Plugins\Microsoft.Powershell.DSC\1.4.0.0\bin\DscExtensionStatus.psm1에서 찾을 수 있습니다. 다음은 상태 코드는 DSC 확장 버전 1.4.0.0의과 같습니다

$DSC_Status = @{ 
    Initializing = @{ 
     Code = 1 
     Message = "Initializing DSC extension." 
    } 
    Completed = @{ 
     Code = 2 
     Message = "DSC configuration was applied successfully." 
    } 
    Enabled = @{ 
     Code = 3 
     Message = "PowerShell DSC has been enabled." 
    } 
    RebootingInstall = @{ 
     Code = 4 
     Message = "Rebooting VM to complete installation." 
    } 
    RebootingDsc = @{ 
     Code = 5 
     Message = "Rebooting VM to apply DSC configuration." 
    } 
    Applying = @{ 
     Code = 6 
     Message = "Applying DSC configuration to VM." 
    } 

    # 
    # Errors 
    # 
    GenericError = 100; # The message for this error is provided by the specific exception 

    InstallError = @{ 
     Code = 101 
     Message = "The DSC Extension was not installed correctly, please check the logs on the VM." 
    } 
    WtrInstallError = @{ 
     Code = 102 
     Message = "WTR was not installed correctly, please check the logs on the VM." 
    } 
} 

기능의 논리는 마치 하나의 DSC 작업에서없는 즉, 상태 변화, 지속하기 때문에 다소 복잡하지만,에서 전체 확장 자체. 그 때문에 상태를 먼저 선택하여 업데이트를 찾으려고했습니다. timestamp 필드를 사용하여 새 상태를 감지했습니다. 여기에 코드입니다 :

function Wait-AzureDSCExtensionJob 
{ 
    [CmdletBinding()] 
    Param(
     [Parameter(Mandatory)] 
     [string] $ServiceName, 

     [int] $RefreshIntervalSeconds = 15 
    ) 

    Begin 
    { 
     $statusFormat = ` 
      @{Label = 'Timestamp'; Expression = {$_.TimestampUtc}}, 
      @{Label = 'Status'; Expression = {"$($_.Code) - $($_.Status)"}}, ` 
      @{Label = 'Message'; Expression = {$_.FormattedMessage.Message}} 

     Write-Verbose 'Getting starting point status...' 
     $previousStatus = Get-AzureDscStatus -ServiceName:$ServiceName 
     Write-Verbose "Status obtained: $($previousStatus | Format-List $statusFormat | Out-String)" 
     Write-Verbose 'This status will be used as the starting point for discovering new updates.' 
    } 
    Process 
    { 
     do 
     { 
      Write-Verbose "Waiting for the next check cycle. $RefreshIntervalSeconds seconds left..." 
      Start-Sleep -Seconds:$RefreshIntervalSeconds 

      $currentStatus = Get-AzureDscStatus -ServiceName:$ServiceName 
      if ($previousStatus.TimestampUtc -eq $currentStatus.TimestampUtc) 
      { 
       Write-Verbose 'Status has not changed since the last check.' 
       $statusUpdated = $false 
      } 
      else 
      { 
       Write-Verbose "Status updated: $($currentStatus | Format-List $statusFormat | Out-String)" 
       $previousStatus = $currentStatus 
       $statusUpdated = $true 
      } 

      # Script with default message codes for the DSC Extension: 
      # On Target VM: "C:\Packages\Plugins\Microsoft.Powershell.DSC\1.4.0.0\bin\DscExtensionStatus.psm1" 
     } until ($statusUpdated -and (($currentStatus.Code -eq 2) -or ($currentStatus.Code -ge 100))) 
    } 
    End 
    { 
     switch ($currentStatus.Code) 
     { 
      2 {Write-Verbose 'Configuration finished successfully.'; break} 
      default {throw "Configuration failed: $($currentStatus.Status)"} 
     } 
    } 
} 

function Get-AzureDscStatus 
{ 
    [CmdletBinding()] 
    Param(
     [Parameter(Mandatory)] 
     [string] $ServiceName 
    ) 

    Begin 
    { 
     $vm = Get-AzureVM -ServiceName:$ServiceName 
     $dscExtensionStatus = $vm.ResourceExtensionStatusList | where { $_.HandlerName -eq 'Microsoft.PowerShell.DSC' } 
     if (-not $dscExtensionStatus) 
     { 
      throw 'Could not find the PowerShell DSC Extension on the VM' 
     } 

     $dscExtensionStatus.ExtensionSettingStatus 
    } 
} 

나는 아직 PowerShell을 매우 능숙하지 않다, 그래서 이것은 아마 조금 더보고 쉽게 읽을 수 있습니다. 아직도, 나는 그것이 나와 같은 상황에있는 누군가에게 유용 할 수 있기를 바란다.

UPDATE 28/11/2014는 :

Microsoft는 버전 1.5.0.0로 DSC 확장을 업데이트하고 내 기능은 그 얼마나 좋은 파산. 그들은 지금 코드를 교환하고 몇 가지 이유를 들어

$DSC_Status = @{ 
    Success = @{ 
     Code = 1 
     Message = 'DSC configuration was applied successfully.' 
    } 
    Initializing = @{ 
     Code = 2 
     Message = 'Initializing DSC extension.' 
    } 
    Enabled = @{ 
     Code = 3 
     Message = 'PowerShell DSC has been enabled.' 
    } 
    RebootingInstall = @{ 
     Code = 4 
     Message = 'Rebooting VM to complete installation.' 
    } 
    RebootingDsc = @{ 
     Code = 5 
     Message = 'Rebooting VM to apply DSC configuration.' 
    } 
    Applying = @{ 
     Code = 6 
     Message = 'Applying DSC configuration to VM.' 
    } 

    # 
    # Errors 
    # 
    GenericError = 1000 # The message for this error is provided by the specific exception 

    InstallError = @{ 
     Code = 1001 
     Message = 'The DSC Extension was not installed correctly, please check the logs on the VM.' 
    } 
    WtrInstallError = @{ 
     Code = 1002 
     Message = 'WTR was not installed correctly, please check the logs on the VM.' 
    } 
    OsVersionNotSupported = @{ 
     Code = 1003 
     Message = 'The current OS version is not supported. The DSC Extension requires Windows Server 2012 or 2012 R2, or Windows 8.1.' 
    } 
} 

: 여기

) 새로운 상태 코드입니다, 나는 응답 코드를 변경하면 같은 주요 변경 또는 아무것도 인 것처럼 그렇지 않은 의미 ... 1은 성공했지만 오류는 100에서 1000으로 올라갔습니다 (그들은이 오류에 많은 오류가있을 것으로 예상합니다).