VMware Cloud Community
nkarandikar
Contributor
Contributor

srm 8.2 api changes? not getting expected results

i had a script working with srm 6.5 using the API, and am having trouble porting it over to 8.2 (new install separate env.)
the script would inject recovery settings per VM (things like post power-on scripting etc.)

pastedImage_7.png

this is the basics of the script with some (not all) output as well, I stop at the point of error, which is listing the recovery settings for 1 VM
notes: there is only 1 protection group, 1 recovery plan, and 1 VM being protected (at the moment), this is vcenter 6.7u2a appliance & srm 8.2 (appliance)

#loading stuff up

PS C:\Windows\system32> Import-Module VMware.VimAutomation.Core
PS C:\Windows\system32> connect-viserver <server ip removed>
PS C:\Windows\system32> $srmconnection = connect-srmserver -port 443
PS C:\Windows\system32> $srmApi = $srmConnection.ExtensionData

#listing protection groups
PS C:\Windows\system32> $srmApi.Protection.ListProtectionGroups().getinfo()

Name   Description Type
----   ----------- ----
TESTPG             vr

#listing the protected VM in the selected protection group [0]
PS C:\Windows\system32> $srmApi.Protection.ListProtectionGroups()[0].listProtectedVms()

VmName             : <hostnameremoved>
Vm                 : VMware.Vim.VirtualMachine
ProtectedVm        : protected-vm-1620
PeerProtectedVm    : protected-vm-1601
State              : Ready
PeerState          : Shadowing
NeedsConfiguration : False
Faults             :

#list recovery plans - there is only 1 protection group so i put in the [0] element to pick that specific one
PS C:\Windows\system32> $srmApi.Protection.ListProtectionGroups()[0].listrecoveryplans()

MoRef
-----
SrmRecoveryPlan-srm-88ed60b2-c8a7-4870-a2e1-e3abf8e4eafe

#list recovery plan - readable
PS C:\Windows\system32> $srmApi.Protection.ListProtectionGroups()[0].listrecoveryplans().getinfo()

Name   Description      State ProtectionGroups
----   -----------      ----- ----------------
testrp             Protecting {VMware.VimAutomation.Srm.Views.SrmProtectionGroup}

#in the past i would need to pass the moref element from the VM, listing and getting that (2nd last item in listing)
PS C:\Windows\system32> get-vm <hostnameremoved> |get-view

Capability           : VMware.Vim.VirtualMachineCapability
Config               : VMware.Vim.VirtualMachineConfigInfo
Layout               : VMware.Vim.VirtualMachineFileLayout
LayoutEx             : VMware.Vim.VirtualMachineFileLayoutEx
Storage              : VMware.Vim.VirtualMachineStorageInfo
EnvironmentBrowser   : EnvironmentBrowser-envbrowser-482
ResourcePool         : ResourcePool-resgroup-20
ParentVApp           :
ResourceConfig       : VMware.Vim.ResourceConfigSpec
Runtime              : VMware.Vim.VirtualMachineRuntimeInfo
Guest                : VMware.Vim.GuestInfo
Summary              : VMware.Vim.VirtualMachineSummary
Datastore            : {Datastore-datastore-489, Datastore-datastore-491, Datastore-datastore-41}
Network              : {DistributedVirtualPortgroup-dvportgroup-40}
Snapshot             : VMware.Vim.VirtualMachineSnapshotInfo
RootSnapshot         : {VirtualMachineSnapshot-snapshot-483}
GuestHeartbeatStatus : green
LinkedView           :
Parent               : Folder-group-v528
CustomValue          : {}
OverallStatus        : green
ConfigStatus         : green
ConfigIssue          : {}
EffectiveRole        : {-1}
Permission           : {}
Name                 : <hostnameremoved>
DisabledMethod       : {Destroy_Task, UnregisterVM, UnmountToolsInstaller, AnswerVM...}
RecentTask           : {}
DeclaredAlarmState   : {alarm-10.vm-482, alarm-113.vm-482, alarm-12.vm-482, alarm-15.vm-482...}
TriggeredAlarmState  : {}
AlarmActionsEnabled  : True
Tag                  : {}
Value                : {}
AvailableField       : {}
MoRef                : VirtualMachine-vm-482
Client               : VMware.Vim.VimClientImpl

#getting and passing moref to a variable
PS C:\Windows\system32> $vmtoconfig = get-vm <hostnameremoved> |get-view
PS C:\Windows\system32> echo $vmtoconfig.moref

Type           Value
----           -----
VirtualMachine vm-482

verifying that this is the same as from what you can extract from protection group VMs

PS C:\Windows\system32> $srmApi.Protection.ListProtectionGroups()[0].listProtectedVms()[0].vm.moref

Type           Value
----           -----
VirtualMachine vm-482

#listing the recovery plan attached to the protection group, noting that this matches the recovery plan listing from above, again since there is only 1 of each so [0] element was used
PS C:\Windows\system32> $srmApi.Protection.ListProtectionGroups()[0].listrecoveryplans()[0]

MoRef
-----
SrmRecoveryPlan-srm-88ed60b2-c8a7-4870-a2e1-e3abf8e4eafe

#looking at what the getrecovery settings element requires (looks same from 6.5)
PS C:\Windows\system32> $srmApi.Protection.ListProtectionGroups()[0].listrecoveryplans()[0].getrecoverysettings

OverloadDefinitions
-------------------
VMware.VimAutomation.Srm.Views.SrmRecoverySettings GetRecoverySettings(VMware.Vim.ManagedObjectReference vm)

#passing the moref of the VM to get listing of the recovery settings for that VM, this worked with 6.5

PS C:\Windows\system32> $srmApi.Protection.ListProtectionGroups()[0].listrecoveryplans()[0].getrecoverysettings($vmtoconfig.moref)

Exception calling "GetRecoverySettings" with "1" argument(s): "Object reference not set to an instance of an object."
At line:1 char:1
+ $srmApi.Protection.ListProtectionGroups()[0].listrecoveryplans()[0].g ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : NullReferenceException

0 Kudos
7 Replies
KlonskyAdam
VMware Employee
VMware Employee

Run into same issue. After investigating, bug report has been submitted to engineering.

The workaround is to completely remove current PowerCLI and install PowerCLI 6.5.0R1

Procedures for uninstalling PowerCLI

  1. Open Powershell as Administrator.
  2. After opening PowerShell do not run any commands.
  3. Run code below several times (2-3) until all the VMware modules are removed.
  4. Get-InstalledModule VMware* | Uninstall-Module -Force
  5. Download PowerCLI 6.5.0R1 VMware-PowerCLI-6.5.0-4624819.exe from https://my.vmware.com/group/vmware/details?downloadGroup=PCLI650R1&productId=859
  6. Install PowerCLI 6.5.0R1 VMware-PowerCLI-6.5.0-4624819.exe
0 Kudos
LucD
Leadership
Leadership

For my information, are you saying that SRM 8.2 requires PowerCLI 6.5R1?
This thread doesn't mention PowerCLI 11.* at all.


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
nkarandikar
Contributor
Contributor

Hi, I lost track of this post (and rereading I was not clear about versions of powercli)

the env where it is NOT working is:
vcenter 6.7u2a (appliance)
srm 8.2 (appliance)

powercli 11.3 on windows 2012r2

pastedImage_2.png

the env that IS working:

vcenter 6.7u2a (windows)
srm 8.2 windows

powercli on windows 2012r2

pastedImage_0.png
pastedImage_1.png

exact same commands work on older powercli and don't work on newer one

0 Kudos
LucD
Leadership
Leadership

So the PowerCLI versions are different, but also how the SRM was installed is different (Windows vs appliance)?


Blog: lucd.info  Twitter: @LucD22  Co-author PowerCLI Reference

0 Kudos
nkarandikar
Contributor
Contributor

you are correct regarding different styles for the SRM servers windows and appliance, but I would hope the API would act the same Smiley Happy

in the original post I can do all the commands on the new env except that last one where I try to list the recovery settings of a specific VM
I did put in an SR to VMware under SRM, but they closed it and said open a new SR under SDK support product (which I don't have/working on seeing if we have it)

this was the tech response to my SRM SR

pastedImage_0.png

0 Kudos
DavidMorgan
Contributor
Contributor

I can update power and tools recovery settings, but I cannot protect VMs. In any case, here's my code for doing what you need to OP.

$SrmApi = $global:DefaultSrmServers.ExtensionData

$RecoveryPlans = $SrmApi.Recovery.ListPlans() | ? { $_.GetInfo().State -eq "Ready" }

$ProtectedVMs = Get-VM -Id $SrmApi.Protection.ListProtectedVms().MoRef

foreach ($RecoveryPlan in $RecoveryPlans) {

  foreach ($VM in $ProtectedVMs) {

    switch ($VM) {

      { $_.PowerState -eq "PoweredOff" } {

        Write-Host "$($RecoveryPlan.GetInfo().Name): Setting $VM placeholder to not power on" -ForegroundColor:Cyan

        try {

          $RecoverySettings = $RecoveryPlan.GetRecoverySettings($VM.ExtensionData.MoRef)

          $RecoverySettings.FinalPowerState = "poweredOff"

          $RecoveryPlan.SetRecoverySettings($VM.ExtensionData.MoRef, $RecoverySettings)

        }

        catch {

          Write-Warning "Not able to set power state for $VM"

        }

      }

      { $_.ExtensionData.Guest.ToolsStatus -match "toolsN" -and $_.PowerState -eq "PoweredOn" } {

        Write-Host "$($RecoveryPlan.GetInfo().Name): Setting $VM placeholder to not wait for VMware Tools" -ForegroundColor:Cyan

        try {

          $RecoverySettings = $RecoveryPlan.GetRecoverySettings($VM.ExtensionData.MoRef)

          $RecoverySettings.PowerOnTimeoutSeconds = 0

          $RecoveryPlan.SetRecoverySettings($VM.ExtensionData.MoRef, $RecoverySettings)

        }

        catch {

          Write-Warning "Not able to set VMware tools state for $VM"

        }

      }

    }

  }

}

PowerCLI Version

----------------

   VMware PowerCLI 12.0.0 build 15947286

---------------

Component Versions

---------------

   VMware Common PowerCLI Component 12.0 build 15939652

   VMware Cis Core PowerCLI Component PowerCLI Component 12.0 build 15939657

   VMware VimAutomation VICore Commands PowerCLI Component PowerCLI Component 12.0 build 15939655

   VMware VimAutomation Srm PowerCLI Component PowerCLI Component 11.5 build 14899557

   VMware VimAutomation Vds Commands PowerCLI Component PowerCLI Component 12.0 build 15940185

$PSVersionTable

Name                           Value

----                           -----

PSVersion                      5.1.18362.752

PSEdition                      Desktop

PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}

BuildVersion                   10.0.18362.752

CLRVersion                     4.0.30319.42000

WSManStackVersion              3.0

PSRemotingProtocolVersion      2.3

SerializationVersion           1.1.0.1

$global:DefaultSrmServers | Select-Object Version,Build

Version Build

------- -----

8.2.0   14761908

8.2.0   14761908

$global:DefaultVIServers | Select-Object Version,Build

Version Build

------- -----

6.7.0   15129973

6.7.0   15129973

vCenter and SRM Photon appliances are being used.

0 Kudos
jordanovi
VMware Employee
VMware Employee

Hi, API acts the same. 

There is one common known issue if you use SRM Virtual Appliance with PowerCLI, Connect-SrmServer command fails if you don’t specify explicitly the port 443 - "Connect-SrmServer -Port 443" (for SRM Windows version this port is 9086)

Here you can see the compatibility between SRM and PowerCLI

http://partnerweb.vmware.com/comp_guide2/sim/interop_matrix.php?#interop&647=3732,2928&299=

  • SRM 8.2 is supported with wide range of PowerCLI versions
  • SRM 8.3 requires PowerCLI 12.1 (requires Windows PowerShell 5.1/ Lunux PowerShell 7 or higher)

Hope this helps

0 Kudos