azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Issue with Enable Replication for Azure Site Recovery

Open shubhamgupta514 opened this issue 9 years ago • 13 comments

Please refer old Issue ID #4866

@viverm @shahabhijeet @markcowl

I am having issue with Azure Site Recovery rest api . Authentication header is already added in my script and its working with "GET" API requests . But I have this particular error case in the attached screenshot that I am facing for enabling replication From VMware (on-premise) to Azure in the mobility service installation and preparation step as well as in Unplanned Failover at the Shutdown Source VM step.

I am able to enable the replication from Portal GUI as well. But Rest API calls are not working for this scenario. Is the Current APIs does not support this functionality?

Its a kind request please don't close the issue until there is a satisfactory resolution is available for this issue.This automation is very critical for me. I will be thankful if you guys could provide me your techinical advise and support. If don't have the resolution that's OK.You can close the issue.

Please find the attached script . Enable-ReplicationVMwareToAzure.txt image

shubhamgupta514 avatar Oct 31 '17 14:10 shubhamgupta514

hi @shubhamgupta514
in the attached txt file I am seeing two function ARM-VMInfoAPI and RESTAPI-Auth

looks like ASR-EnableReplicationAPI is not present in file. Can you please add that method too ..

Might be this can help .. Sample Agent-Authentication

{ "NotBeforeTimestamp": "xxxxxxxxxxxxxx", "NotAfterTimestamp": "xxxxxxxxxxxxxxx", "ClientRequestId": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "HashFunction": "HMACSHA256", "Hmac": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "Version": { "Major": 1, "Minor": 2, "Build": -1, "Revision": -1, "MajorRevision": -1, "MinorRevision": -1 }, "PropertyBag": { } }

See the logic of Hmac generation .. and how you can get channel integrity key for onprem operations.

image

Generate Agent authentication header : from https://github.com/Azure/azure-powershell/blob/preview/src/ResourceManager/RecoveryServices.SiteRecovery/Commands.RecoveryServices.SiteRecovery/Common/PSAsrClient.cs

https://msdn.microsoft.com/en-us/library/system.version(v=vs.110).aspx

https://msdn.microsoft.com/en-us/library/xfhwa508(v=vs.110).aspx?cs-save-lang=1&cs-lang=csharp#code-snippet-1

How to get the Channel Integrity key to be used for the hash:-

GET https://management.azure.com/Subscriptions//resourceGroups//providers/Microsoft.RecoveryServices/vaults//extendedinformation/vaultextendedinfo?api-version=2015-11-10

The response body will contain a field called the integrity key. This is your channel integrity key.

viverm avatar Oct 31 '17 14:10 viverm

@shubhamgupta514 any update on this ?

viverm avatar Nov 01 '17 21:11 viverm

@viverm I made the changes in the script as per your recommendations above. But this time I am getting different error while invoking the rest-api .Please look into the attached updated script and let me know if anything is still missing.

Enable-ReplicationVMwareToAzure-v1.1.txt

############################################################### #Error ###############################################################

Invoke-RestMethod : {"error":{"code":"BadRequest","message":"The operation has failed.","details":[{"code":"InvalidChannelIntegrityKeyToken","message":"The operation has failed.","possibleCauses":"An internal server error occurred.","recommendedAction":"Retry the last action. If the issue persists contact support.","clientRequestId":"2e5733ef-b519-449d-bed4-f997b440408b","activityId":"dfd040ad-496d-46da-a515-c6f8becfaa05"}]}} At C:\Users\shubham.k.gupta\Downloads\Enable-ReplicationVMwareToAzure.ps1:64 char:31

  • ... ationInfo = Invoke-RestMethod -Method Put -Headers $requestheader -Ur ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

shubhamgupta514 avatar Nov 02 '17 06:11 shubhamgupta514

@viverm - Is there any update on this? Please help me out to close this ASAP.

shubhamgupta514 avatar Nov 02 '17 19:11 shubhamgupta514

@viverm - Did you take a look at the new error?

shubhamgupta514 avatar Nov 03 '17 10:11 shubhamgupta514

Use javascript serializer

[System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
$ser = New-Object System.Web.Script.Serialization.JavaScriptSerializer
$shaInput = $ser.serialize($global:cikTokenDetails)

$hmacsha = New-Object System.Security.Cryptography.HMACSHA256
$hmacsha.key = [Text.Encoding]::UTF8.GetBytes($integrityKey)
$global:cikTokenDetails.Hmac = [Convert]::ToBase64String($hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($shaInput)))

$global:cikTokenDetails.HashFunction = "HMACSHA256"

viverm avatar Nov 04 '17 12:11 viverm

@viverm

I am getting below error while executing Invoke-Restmethod.

Please find the updated script below:

Enable-ReplicationVMwareToAzure-v1.2.txt

######################################################################## #Error ##########################################################################

Invoke-RestMethod : {"error":{"code":"BadRequest","message":"The operation has failed.","details":[{"code":"InvalidChannelIntegrityKeyToken","message":"The operation has failed.","possibleCauses":"An internal server error occurred.","recommendedAction":"Retry the last action. If the issue persists contact support.","clientRequestId":"38c03514-0374-44a6-aba0-3275a1565d6c","activityId":"c180569e-c132-4b07-a35d-ac4240769ee6"}]}} At line:48 char:31

  • ... ationInfo = Invoke-RestMethod -Method Put -Headers $requestheader -Ur ...
  •             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
    • FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

shubhamgupta514 avatar Nov 04 '17 17:11 shubhamgupta514

@viverm please advise

shubhamgupta514 avatar Nov 07 '17 17:11 shubhamgupta514

@markcowl @viverm could you please advise me on this

shubhamgupta514 avatar Nov 11 '17 10:11 shubhamgupta514

@shubhamgupta514 we have added support for VMware to Azure Site recovery from powershell .

You can use those cmdlet directly .

viverm avatar Nov 13 '17 05:11 viverm

@viverm - Thanks for the update.I have checked new module version and its working for me.

But I am still curious to understand how can I make this work with the help of rest api functionality.

shubhamgupta514 avatar Nov 14 '17 04:11 shubhamgupta514

@shubhamgupta514 I tried some dry on run code added . It is working fine for me .

It just need more investigation what is going wrong. Powershell code is available on git you cake take the reference from it.

viverm avatar Nov 21 '17 04:11 viverm

closing thread . Not active from long time.

viverm avatar Sep 11 '18 14:09 viverm