ProtectVms

This method adds virtual machines to a protection group.
With array-based replication, the protection group is determined by datastore location of the virtual machines. With host-based replication (vSphere replication), you can use the AssociateVms method to place virtual machines into a protection group. With vVol replication, the protection group is determined by replication groups of the virtual machines. To protect a Virtual Machine, its folder, resource pool, and network must be mapped from the protected site to the recovery site. To get a list of currently configured mappings, see ListInventoryMappings. If a few or all the VMs in the list are already protected, then the operation succeeds.

Synopsis

ProtectionTask protectVms(ProtectionGroup.VmProtectionSpec[] vms)
vms[]
is a list of virtual machines to protect. If some of the virtual machines from the list or all of them are already protected, the operation succeeds.
VmProtectionSpec
is a spec describing how a virtual machine to be protected. It has the following properties:
Field
Description
@optional VirtualMachine vm
The virtual machine to be protected
VmRecoverySpec recoverySpec
Information relevant at the recovery site to which the VM will be protected. Allows configuration of protection per VM instead of using global inventory mappings.
VmRecoverySpec
is a spec describing virtual machine recovery locations. It has the following properties:
Field
Description
@optional PlaceholderVmLocation placeholderVmLocation
Location in which to create the placeholder VM.
@optional RecoveryLocationSettings recoveryLocationSettings
Recovery location settings.
PlaceholderVmLocation
is a data object. It contains information about where a placeholder VM should be created. It has the following fields:
Field
Description
folder
Folder in which the placeholder VM should be created. If unset, the inventory mapper will be queried for a suitable location.
hostSystem
Host in which the placeholder VM should be created. If unset, SRM will attempt to pick one based on the resource pool mapping (this works only if the resource pool unambiguously designates a single host, or if it designates a DRS cluster).
resourcePool
Resource pool in which the placeholder VM should be created. If unset, the inventory mapper will be queried for a suitable location.
placeholderDatastore
Datastore in which the placeholder VM should be created. If unset, the placeholder datastore manager will be queried for a suitable location.
RecoveryLocationSettings
is a spec that provides user-editable settings regarding where to find virtual machine components at recovery time. It has the following properties:
Field
Description
@optional DeviceInfo[] protectedDevices
Information about devices for which the user has supplied recovery-time information.
@optional DeviceInfo[] excludedDevices
Information about devices for which the user does not want to be present in the recovered VM. If autoExcludeMediaDevices advance settings is enabled, the list includes the media devices that are auto-excluded by SRM.
@optional String changeVersion
Change version control. When reconfiguring an existing settings this value must be set and must match the most recent value. This means that first
#getRecoveryLocationSettings
should be called. Then its result should be updated and passed to
#reconfigureRecoveryLocationSettings
. For newly protected VMs, leave it unset.
DeviceInfo
is a data object with the following properties:
Field
Description
key
Device key
NetworkDeviceInfo
extends DeviceInfo and has the following properties:
Field
Description
vim.Network network
Reference to a recovery network managed object to which to attach the NIC device.
FileDeviceInfo
extends DeviceInfo and has the following properties:
Field
Description
@optional vim.Datastore datastore
Reference to the datastore the directory is located on. If the directory is not located on a datastore, this is omitted.
path
Directory path.
fileName
Name of the file under the directory.
NetworkDeviceInfo
and
FileDeviceInfo
should be used to construct
RecoveryLocationSettings
.
ProtectionTask
is the task object to monitor the status of requested virtual machines. For more information, see Protection Task.
If a task fails, its error field may contain one of the following:
  • drextapi.fault.ConnectionDownFault
    - if the remote SRM could not be reached.
  • drextapi.fault.CannotProtectFTSecondaryVm
    - if the VM is a fault tolerance secondary VM.
  • drextapi.fault.DeviceBackingConflict
    - if the caller specified a device locator, or explicitly excluded, a device which the provider would like to protect.
  • drextapi.fault.DevicesNotResolved
    - if any of the VM's devices were neither protected by the provider, nor was a backing locator provided by the caller, nor was the device explicitly excluded.
  • drextapi.fault.InsufficientLicensesFault
    - If there were not enough licenses available to protect the VMs.
  • drextapi.InvalidState
    - if the group we are trying to protect into is not in the 'ProtectedVm.State#active active' state.
  • drextapi.fault.ProductionVmDeleted
    - if the VM to be protected did not exist on VC.
  • drextapi.fault.ReplicationProviderFault
    - if the replication provider rejected the operation.
  • drextapi.fault.VmAlreadyProtectedEx
    - if the VM was already protected in another group.
  • vim.fault.ConcurrentAccess
    - if the group was modified during the operation.

Faults

  • InvalidArgument - If the list of virtual machines is empty or null.
  • RuntimeFault
For information about the faults that
Site Recovery Manager
throws, see Faults in Site Recovery Manager API.
Example for ProtectVms
ManagedObjectReference taskRef = srmPortType.protectVms( ManagedObjectReference _this, List < SrmProtectionGroupVmProtectionSpec > vms); Where ManagedObjectReference _this = _protectionGroupRef; where _protectionGroupRef can be taken from: SrmServiceInstanceContent content = _srmPortType.retrieveContent(_svcRef); ManagedObjectReference _protectionRef = content.getProtection(); List < ManagedObjectReference > groups = srmPortType.listProtectionGroups(_protectionRef); _protectionGroupRef = groups.get(0);