MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

compute/disks/createZonalSecondaryDisk.js:19–99  ·  view source on GitHub ↗
(
  secondaryDiskName,
  secondaryLocation,
  primaryDiskName,
  primaryLocation
)

Source from the content-addressed store, hash-verified

17'use strict';
18
19async function main(
20 secondaryDiskName,
21 secondaryLocation,
22 primaryDiskName,
23 primaryLocation
24) {
25 // [START compute_disk_create_secondary]
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 for the secondary disk.
39 const secondaryProjectId = await disksClient.getProjectId();
40
41 // The zone for the secondary disk. The primary and secondary disks must be in different regions.
42 // secondaryLocation = 'us-central1-a';
43
44 // The name of the secondary disk.
45 // secondaryDiskName = 'secondary-disk-name';
46
47 // The project that contains the primary disk.
48 const primaryProjectId = await disksClient.getProjectId();
49
50 // The zone for the primary disk.
51 // primaryLocation = 'us-central1-b';
52
53 // The name of the primary disk that the secondary disk receives data from.
54 // primaryDiskName = 'primary-disk-name';
55
56 // The disk type. Must be one of `pd-ssd` or `pd-balanced`.
57 const diskType = `zones/${secondaryLocation}/diskTypes/pd-balanced`;
58
59 // The size of the secondary disk in gigabytes.
60 const diskSizeGb = 10;
61
62 // Create a secondary disk identical to the primary disk.
63 async function callCreateComputeSecondaryDisk() {
64 // Create a secondary disk
65 const disk = new compute.Disk({
66 sizeGb: diskSizeGb,
67 name: secondaryDiskName,
68 zone: secondaryLocation,
69 type: diskType,
70 asyncPrimaryDisk: new compute.DiskAsyncReplication({
71 // Make sure that the primary disk supports asynchronous replication.
72 // Only certain persistent disk types, like `pd-balanced` and `pd-ssd`, are eligible.
73 disk: `projects/${primaryProjectId}/zones/${primaryLocation}/disks/${primaryDiskName}`,
74 }),
75 });
76

Callers 1

Calls 2

getProjectIdMethod · 0.80

Tested by

no test coverage detected