( secondaryDiskName, secondaryLocation, primaryDiskName, primaryLocation )
| 17 | 'use strict'; |
| 18 | |
| 19 | async function main( |
| 20 | secondaryDiskName, |
| 21 | secondaryLocation, |
| 22 | primaryDiskName, |
| 23 | primaryLocation |
| 24 | ) { |
| 25 | // [START compute_disk_start_replication] |
| 26 | // Import the Compute library |
| 27 | const computeLib = require('@google-cloud/compute'); |
| 28 | const compute = computeLib.protos.google.cloud.compute.v1; |
| 29 | |
| 30 | // Instantiate a diskClient |
| 31 | const disksClient = new computeLib.DisksClient(); |
| 32 | // Instantiate a zoneOperationsClient |
| 33 | const zoneOperationsClient = new computeLib.ZoneOperationsClient(); |
| 34 | |
| 35 | /** |
| 36 | * TODO(developer): Update/uncomment these variables before running the sample. |
| 37 | */ |
| 38 | // The project of the secondary disk. |
| 39 | const secondaryProjectId = await disksClient.getProjectId(); |
| 40 | |
| 41 | // The zone of the secondary disk. |
| 42 | // secondaryLocation = 'us-central1-a'; |
| 43 | |
| 44 | // The name of the secondary disk. |
| 45 | // secondaryDiskName = 'secondary-disk-name'; |
| 46 | |
| 47 | // The project of the primary disk. |
| 48 | const primaryProjectId = await disksClient.getProjectId(); |
| 49 | |
| 50 | // The zone of the primary disk. |
| 51 | // primaryLocation = 'us-central1-a'; |
| 52 | |
| 53 | // The name of the primary disk. |
| 54 | // primaryDiskName = 'primary-disk-name'; |
| 55 | |
| 56 | // Start replication |
| 57 | async function callStartReplication() { |
| 58 | const [response] = await disksClient.startAsyncReplication({ |
| 59 | project: secondaryProjectId, |
| 60 | zone: primaryLocation, |
| 61 | disk: primaryDiskName, |
| 62 | disksStartAsyncReplicationRequestResource: |
| 63 | new compute.DisksStartAsyncReplicationRequest({ |
| 64 | asyncSecondaryDisk: `projects/${primaryProjectId}/zones/${secondaryLocation}/disks/${secondaryDiskName}`, |
| 65 | }), |
| 66 | }); |
| 67 | |
| 68 | let operation = response.latestResponse; |
| 69 | |
| 70 | // Wait for the operation to complete. |
| 71 | while (operation.status !== 'DONE') { |
| 72 | [operation] = await zoneOperationsClient.wait({ |
| 73 | operation: operation.name, |
| 74 | project: secondaryProjectId, |
| 75 | zone: operation.zone.split('/').pop(), |
| 76 | }); |
no test coverage detected