VMware Cloud Community
jaychinut
Contributor
Contributor
Jump to solution

VMware SDK for SRM - PlanId Query

Dear VMware community

I am currently exploring the VMware.Sdk.srm module to interact with the SRM REST API for a project involving disaster recovery and business continuity. While navigating this process, I have encountered a question regarding the retrieval of the 'PlanId' value and the overall usage of this parameter in my scripting efforts.

To provide context, I have outlined the steps I have taken so far:

1. I initiate my script by obtaining the pairing ID with the command:
```powershell
$pairings = Invoke-SrmGetPairings
```

2. Following this, I compile a list of recovery plans associated with the obtained pairing ID:
```powershell
$plans = Invoke-SrmGetAllRecoveryPlans -pairingId $pairings.List.pairingid.guid
```

3. From the list of recovery plans, I extract relevant information from a plan named 'PlanName1' using the following line of code:
```powershell
$planid = $plans.list | Where-Object { $_.Name -eq "PlanName1" }
```

4. My intention is to use the 'PlanId' I've gathered in the previous step to retrieve recovery steps for this particular plan. However, when executing the following command, I encounter an error:
```powershell
Invoke-SrmGetRecoverySteps -PairingId $pairings.List.pairingid.guid -PlanId $planid.Id -ViewMode test
The error looks like this: Invoke-SrmGetRecoverySteps: Error converting value {null} to type 'System.Int64'. Path 'list[0].start_time', line 1, position 213.
```


To clarify my query further, when I inspect the `$planid` variable, it provides the following details:

```powershell
Status : READYSTATE
Id : DrRecoveryRecoveryPlan:9fzzzzz-23zz-48zz-b2zz-bzzzzzzzzzz:4zzzzzzzz-7zzz-4zzz-9fzz-b7zzzzzzzzz
ProtectedSiteName : vcenter1
RecoverySiteName : vcenter2
ProtectedVcGuid : 80zzzzz-95zz-4zzz-9zzzz-f4zzzzzzzz
RecoveryVcGuid : 89zzzzz-69zz-4bzz-97zz-5zzzzzzzz
Name : RecoveryPlan1
Description :
Location : DrFolder:DrRecoveryRootFolder:442zzzzz-77zz-46zz-9fzz-bzzzzzzzz
LocationName : Recovery Plans
Progress : 0
IsRunning : False
```

In summary, I would greatly appreciate your assistance in clarifying whether the 'Id' property within the `$planid` variable contains the 'PlanId' I should be using in the `Invoke-SrmGetRecoverySteps` command.

Reply
0 Kudos
1 Solution

Accepted Solutions
zivanov
VMware Employee
VMware Employee
Jump to solution

Hey,

The Id is the correct field you should use when need to call object-related APIs (like recovery plans, protection groups, etc).

Here I suspect there is some issue with the PowerCLI cmdlets and the REST API itself.
Until the problem is fixed, you can use PowerShell to communicate with this exact API endpoint. Here is a snippet:

// Authenticate to the local site

$srmConnection = Connect-SrmSdkServer -Server $srmLocalHostName `
 -User $localVcUsername `
 -Password $localVcPassword `
 -RemoteUser $remoteVcUsername `
 -RemotePassword $remoteVcPassword

$pairings = Invoke-SrmGetPairings

$pairingId = $srmConnection.ConnectedPairing.PairingId

// Find the desired plan

$plans = Invoke-SrmGetAllRecoveryPlans -pairingId $pairingId

$plan = $plans.list | Where-Object { $_.Name -eq "PlanName1" }

$planId = $plan.Id

// Get the current API session

$sessionId = $srmConnection.SessionId

// And use it to construct request headers
$global:headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$global:headers.Add("x-dr-session", $sessionId)
$global:headers.Add("Content-Type", "application/json")

// The view mode
$viewMode = "test"

// Construct the recovery steps URL
$recoveryStepsUrl = $srmConnection.ServerUri.AbsoluteUri + "api/rest/srm/v2/pairings/${pairingId}/recovery-management/plans/${planId}/recovery-steps/${viewMode}"

// Make the call
$response = Invoke-RestMethod $recoveryStepsUrl -Method 'GET' -Headers $global:headers

// $response will contain all recovery steps

Some API examples using PowerShell and PowerCLI:
https://github.com/vmware-samples/site-recovery-manager-rest-api-examples/tree/main/power-shell

Hope this helps, 

Zdravko Ivanov

View solution in original post

3 Replies
Nano_JT
Contributor
Contributor
Jump to solution

I ran into a similar issue. Anyone within this community have any advice or insight? 

Reply
0 Kudos
zivanov
VMware Employee
VMware Employee
Jump to solution

Hey,

The Id is the correct field you should use when need to call object-related APIs (like recovery plans, protection groups, etc).

Here I suspect there is some issue with the PowerCLI cmdlets and the REST API itself.
Until the problem is fixed, you can use PowerShell to communicate with this exact API endpoint. Here is a snippet:

// Authenticate to the local site

$srmConnection = Connect-SrmSdkServer -Server $srmLocalHostName `
 -User $localVcUsername `
 -Password $localVcPassword `
 -RemoteUser $remoteVcUsername `
 -RemotePassword $remoteVcPassword

$pairings = Invoke-SrmGetPairings

$pairingId = $srmConnection.ConnectedPairing.PairingId

// Find the desired plan

$plans = Invoke-SrmGetAllRecoveryPlans -pairingId $pairingId

$plan = $plans.list | Where-Object { $_.Name -eq "PlanName1" }

$planId = $plan.Id

// Get the current API session

$sessionId = $srmConnection.SessionId

// And use it to construct request headers
$global:headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
$global:headers.Add("x-dr-session", $sessionId)
$global:headers.Add("Content-Type", "application/json")

// The view mode
$viewMode = "test"

// Construct the recovery steps URL
$recoveryStepsUrl = $srmConnection.ServerUri.AbsoluteUri + "api/rest/srm/v2/pairings/${pairingId}/recovery-management/plans/${planId}/recovery-steps/${viewMode}"

// Make the call
$response = Invoke-RestMethod $recoveryStepsUrl -Method 'GET' -Headers $global:headers

// $response will contain all recovery steps

Some API examples using PowerShell and PowerCLI:
https://github.com/vmware-samples/site-recovery-manager-rest-api-examples/tree/main/power-shell

Hope this helps, 

Zdravko Ivanov

jaychinut
Contributor
Contributor
Jump to solution

Thanks for the awesome response!

I found it easier to get the pairingid like this:

$pairingId = $pairings.List.pairingId.Guid

 

instead of:

$pairingId = $srmConnection.ConnectedPairing.PairingId

After running the sample code you posted, I got a proper response. 

$response = Invoke-RestMethod $recoveryStepsUrl -Method 'GET' -Headers $global:headers -SkipCertificateCheck
PS /Users/username/Documents/VMwareAPI> $response

list
----
{@{plan_callout_position_spec=; vm_callout_position_spec=; title=Synchronize storage; step_number=1.; child_count=6; depth=0; finish_time=; start_time=; expanded=False; id=4254; progress=0; status=INACTIVE; warnings=; errors=; referred_…

I do hope they fix the issue with the PowerCLI cmdlets though.  This is a nice workaround. 

Reply
0 Kudos