( 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_create_secondary_custom] |
| 26 | // Import the Compute library |
| 27 | const computeLib = require('@google-cloud/compute'); |
| 28 | const compute = computeLib.protos.google.cloud.compute.v1; |
| 29 | |
| 30 | // If you want to create regional disk, you should use: RegionDisksClient and RegionOperationsClient. |
| 31 | // Instantiate a diskClient |
| 32 | const disksClient = new computeLib.DisksClient(); |
| 33 | // Instantiate a zoneOperationsClient |
| 34 | const zoneOperationsClient = new computeLib.ZoneOperationsClient(); |
| 35 | |
| 36 | /** |
| 37 | * TODO(developer): Update/uncomment these variables before running the sample. |
| 38 | */ |
| 39 | // The project for the secondary disk. |
| 40 | const secondaryProjectId = await disksClient.getProjectId(); |
| 41 | |
| 42 | // The zone or region for the secondary disk. The primary and secondary disks must be in different regions. |
| 43 | // If you use RegionDisksClient- define region, if DisksClient- define zone. |
| 44 | // secondaryLocation = 'us-central1-a'; |
| 45 | |
| 46 | // The name of the secondary disk. |
| 47 | // secondaryDiskName = 'secondary-disk-name'; |
| 48 | |
| 49 | // The project that contains the primary disk. |
| 50 | const primaryProjectId = await disksClient.getProjectId(); |
| 51 | |
| 52 | // The zone or region for the primary disk. |
| 53 | // If you use RegionDisksClient- define region, if DisksClient- define zone. |
| 54 | // primaryLocation = 'us-central1-b'; |
| 55 | |
| 56 | // The name of the primary disk that the secondary disk receives data from. |
| 57 | // primaryDiskName = 'primary-disk-name'; |
| 58 | |
| 59 | // The disk type. Must be one of `pd-ssd` or `pd-balanced`. |
| 60 | const diskType = `zones/${secondaryLocation}/diskTypes/pd-balanced`; |
| 61 | |
| 62 | // The size of the secondary disk in gigabytes. |
| 63 | const diskSizeGb = 10; |
| 64 | |
| 65 | // Create a secondary disk identical to the primary disk. |
| 66 | async function callCreateComputeSecondaryDisk() { |
| 67 | // Create a secondary disk |
| 68 | const disk = new compute.Disk({ |
| 69 | sizeGb: diskSizeGb, |
| 70 | name: secondaryDiskName, |
| 71 | // If you use RegionDisksClient, pass region as an argument instead of zone |
| 72 | zone: secondaryLocation, |
| 73 | type: diskType, |
| 74 | asyncPrimaryDisk: new compute.DiskAsyncReplication({ |
| 75 | // Make sure that the primary disk supports asynchronous replication. |
| 76 | // Only certain persistent disk types, like `pd-balanced` and `pd-ssd`, are eligible. |
no test coverage detected