You can configure virtual machines replication from a source site to a target site by using the vSphere Replication REST APIs.

Prerequisites

To configure a virtual machine replication:
  • You must register your vSphere Replication to the Platform Services Controller (PSC) by using the VRMS Appliance Management Interface or the VRMS Appliance Configuration REST API Gateway.
  • You must have a site pair between the source and the target sites.

Procedure

  1. To login to the source site, make a POST request.
    POST BASE_URL/api/rest/vr/API_VERSION/session

    Enter your user name and password in the Аuthorization HTTP header. Use the returned session ID as a value for x-dr-session HTTP header for all subsequent calls to the REST API.

  2. To get the pairing ID and the local vCenter Server ID, make a GET request.
    GET BASE_URL/api/rest/vr/API_VERSION/pairings/
    Example response:
    {
       "pairing_id": "e41c183f-bc55-319b-bf76-8ec83d335074", <----------- Pairing ID
       "local_vc_server": {
          "id": "0a98c22d-a553-47e4-bd56-2844f45d8ef6", <--------------- VC ID
          "url": "https://s2-srm2-219-12.eng.vmware.com:443/sdk",
          "name": "s2-srm2-219-12.eng.vmware.com",
          "server_status": "OK",
          // Other fields are not relevant in this example
    }

    Save the pairing ID and the local vCenter Server ID.

  3. To get the virtual machines IDs per site pair, make a GET request.
    GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vcenters/VC_GUID/vms

    Save the ID of the VM for which you want to configure the replication.

  4. To get the target vSphere Replication Server ID:
    1. Make a POST request to login to the target site.
      POST BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/remote-session

      Enter your user name and password in the Authorization HTTP header. Ensure the x-dr-session HTTP header is still present.

    2. Make a GET request to obtain all vSphere Replication Management Server instances in pairing.
      GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vrs

      Save the ID of the target vSphere Replication Management Server.

    3. Make a GET request to obtain all vSphere Replication Servers registered to the target vSphere Replication Management Server.
      GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vrs/VR_ID/replication-servers

      Replace the PAIRING_ID value with the ID of the pairing, and the VR_ID value with the target vSphere Replication Management Server ID from Step 4.b.

      Save the target vSphere Replication Server ID from the result.

  5. To get the target datastore, make a GET request.
    GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vcenters/VC_ID/datastores

    Replace the VC_ID value with the ID of the target vCenter Server, and save the response.

  6. To get the preferred storage policy ID, make a GET request.
    GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vcenters/VC_ID/storage-policies

    Replace the VC_ID value with the ID of the target vCenter Server, and save the preferred target storage policy ID.

  7. To get information about the disks of a VM, make a GET request.
    GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vcenters/VC_ID/vms/VM_ID/disks

    Replace the VC_ID value with the ID of the source vCenter Server, replace the VM_ID value with the ID of the VM which you got in Step 3., and save the response.

  8. To configure the replication, make a POST request.
    POST BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/replications
    Example Configure Replication request body:
    [
       {
          "auto_replicate_new_disks": true,
          "rpo": 60,
          "lwd_encryption_enabled": false,
          "mpit_days": 0,
          "mpit_enabled": false,
          "mpit_instances": 0,
          "network_compression_enabled": false,
          "quiesce_enabled": false,
          // You get this from Step 3.
          "vm_id": "VirtualMachine:vm-38:fa655d23-b8ac-4eb1-8351-129954807e2c",
          //You get this from Step 4.
          "target_replication_server_id": "HmsRemoteHbrServer:HBRSRV-26c6bd13-1fac-4d04-adcb-2700a258025c:b41aa649-bd9b-45e0-9d41-a7a16c0b0946",
          "target_vc_id": "54d0e5ab-3e9d-4372-9f27-036cf1c24639"
          "disks": [
             {
                //  You get this from Step 5.
                "destination_datastore_id": "Datastore:datastore-18:54d0e5ab-3e9d-4372-9f27-036cf1c24639",
                // Options for destination_disk_format parameter: SAME_AS_SOURCE, SAME_AS_PRIMARY, AS_DEFINED_IN_PROFILE, FLAT, THICK, NATIVE_THICK, THIN, RDM.
                "destination_disk_format": "SAME_AS_SOURCE",
                "enabled_for_replication": true,
                "use_seeds": false,
                "destination_path": "target_folder/test-vm-1",
                // You get this from Step 6.
                "destination_storage_policy_id": "4b97756b-3c50-481a-a105-d6a7b1507f9a",
               //  You got this from Step 7.
                "vm_disk" : {
                    "vm_id": "VirtualMachine:vm-38:fa655d23-b8ac-4eb1-8351-129954807e2c",
                    "device_key": 2000,
                    "is_vm_home": false,
                    "encrypted": false,
                    "capacity": 524288,
                    "source_disk_format": "THIN",
                    "source_path": {
                        "datastore_id": "Datastore:datastore-17:fa655d23-b8ac-4eb1-8351-129954807e2c",
                        "datastore_name": "local",
                        "path": "test-vm-1",
                        "filename": "test-vm-1.vmdk"
                    },
                    "source_storage_policy_name": "Datastore Default",
                    "source_storage_policy_id": null,
                    "label": "Hard disk 1",
                    "controller_key": 1000,
                    "controller_label": "SCSI controller 0",
                    "supported_for_replication": true
                }
             },
             {
                //  You get this from Step 5.
                "destination_datastore_id": "Datastore:datastore-18:54d0e5ab-3e9d-4372-9f27-036cf1c24639",
                "destination_disk_format": "SAME_AS_SOURCE",
                "enabled_for_replication": true,
                "use_seeds": false,
                "destination_path": "target_folder/test-vm-1",
                //  You get this from Step 6.
                "destination_storage_policy_id": "4b97756b-3c50-481a-a105-d6a7b1507f9a",
                // You get this from Step 7.
                "vm_disk" : {
                    "vm_id": "VirtualMachine:vm-38:fa655d23-b8ac-4eb1-8351-129954807e2c",
                    "device_key": 0,
                    "is_vm_home": true,
                    "encrypted": false,
                    "capacity": 0,
                    "source_disk_format": null,
                    "source_path": {
                        "datastore_id": "Datastore:datastore-17:fa655d23-b8ac-4eb1-8351-129954807e2c",
                        "datastore_name": "local",
                        "path": "test-vm-1",
                        "filename": "test-vm-1.vmx"
                    },
                    "source_storage_policy_name": "Datastore Default",
                    "source_storage_policy_id": null,
                    "label": "VM home",
                    "controller_key": 0,
                    "controller_label": null,
                    "supported_for_replication": false
                }
             }
          ]
       }
    ]