srm 8.2 api changes? not getting expected results
nkarandikar Jun 12, 2019 12:23 PMi 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.)
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