您可以使用 vSphere Replication REST API 設定從來源站台到目標站台的虛擬機器複寫。

必要條件

設定虛擬機器複寫:
  • 您必須使用 VRMS Appliance Management Interface 或 VRMS 應用裝置組態 REST API 閘道將 vSphere Replication 登錄至 Platform Services Controller (PSC)。
  • 您必須在來源站台和目標站台之間建立站台配對。

程序

  1. 若要登入來源站台,請發出 POST 請求。
    POST BASE_URL/api/rest/vr/API_VERSION/session

    在授權 HTTP 標頭中輸入您的使用者名稱和密碼。使用傳回的工作階段識別碼作為對 REST API 的所有後續呼叫的 x-dr-session HTTP 標頭的值。

  2. 若要取得配對識別碼和本機 vCenter Server 識別碼,請發出 GET 請求。
    GET BASE_URL/api/rest/vr/API_VERSION/pairings/
    回應範例:
    {
       "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
    }

    儲存配對識別碼和本機 vCenter Server 識別碼。

  3. 若要取得每個站台配對的虛擬機器識別碼,請發出 GET 請求。
    GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vcenters/VC_GUID/vms

    儲存要設定複寫的虛擬機器的識別碼。

  4. 取得目標 vSphere Replication 伺服器識別碼:
    1. 發出 POST 請求以登入目標站台。
      POST BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/remote-session

      在授權 HTTP 標頭中輸入您的使用者名稱和密碼。確保 x-dr-session HTTP 標頭仍然存在。

    2. 發出 GET 請求以取得配對中的所有 vSphere Replication Management Server 執行個體。
      GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vrs

      儲存目標 vSphere Replication Management Server 的識別碼。

    3. 發出 GET 請求以取得登錄至目標 vSphere Replication Management Server 的所有 vSphere Replication 伺服器。
      GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vrs/VR_ID/replication-servers

      PAIRING_ID 值取代為配對的識別碼,將 VR_ID 值取代為步驟 4.b 中的目標 vSphere Replication Management Server 識別碼。

      儲存結果中的目標 vSphere Replication 伺服器識別碼。

  5. 若要取得目標資料存放區,請發出 GET 請求。
    GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vcenters/VC_ID/datastores

    VC_ID 值取代為目標 vCenter Server 的識別碼,然後儲存回應。

  6. 若要取得慣用的儲存區原則識別碼,請發出 GET 請求。
    GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vcenters/VC_ID/storage-policies

    VC_ID 值取代為目標 vCenter Server 的識別碼,並儲存慣用的目標儲存區原則識別碼。

  7. 若要取得虛擬機器磁碟的相關資訊,請發出 GET 請求。
    GET BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/vcenters/VC_ID/vms/VM_ID/disks

    VC_ID 值取代為來源 vCenter Server 的識別碼,將 VM_ID 值取代為您在步驟 3 中取得的虛擬機器識別碼,然後儲存回應。

  8. 若要設定複寫,請發出 POST 請求。
    POST BASE_URL/api/rest/vr/API_VERSION/pairings/PAIRING_ID/replications
    設定複寫要求本文範例:
    [
       {
          "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
                }
             }
          ]
       }
    ]