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

Function main

compute/disks/createComputeHyperdisk.js:19–89  ·  view source on GitHub ↗
(diskName, zone)

Source from the content-addressed store, hash-verified

17'use strict';
18
19async function main(diskName, zone) {
20 // [START compute_hyperdisk_create]
21 // Import the Compute library
22 const computeLib = require('@google-cloud/compute');
23 const compute = computeLib.protos.google.cloud.compute.v1;
24
25 // Instantiate a diskClient
26 const disksClient = new computeLib.DisksClient();
27 // Instantiate a zoneOperationsClient
28 const zoneOperationsClient = new computeLib.ZoneOperationsClient();
29
30 /**
31 * TODO(developer): Update/uncomment these variables before running the sample.
32 */
33 // Project ID or project number of the Google Cloud project you want to use.
34 const projectId = await disksClient.getProjectId();
35
36 // The zone where your VM and new disk are located.
37 // zone = 'europe-central2-b';
38
39 // The name of the new disk
40 // diskName = 'disk-name';
41
42 // The type of disk. This value uses the following format:
43 // "zones/{zone}/diskTypes/(hyperdisk-balanced|hyperdisk-extreme|hyperdisk-ml|hyperdisk-throughput)".
44 // For example: "zones/us-west3-b/diskTypes/hyperdisk-balanced"
45 const diskType = `zones/${zone}/diskTypes/hyperdisk-balanced`;
46 // Size of the new disk in gigabytes.
47 const diskSizeGb = 10;
48 // Optional: For Hyperdisk Balanced or Hyperdisk Extreme disks,
49 // this is the number of I/O operations per second (IOPS) that the disk can handle.
50 const provisionedIops = 3000;
51 // Optional: For Hyperdisk Balanced or Hyperdisk Throughput volumes,
52 // this is an integer that represents the throughput,
53 // measured in MiB per second, that the disk can handle.
54 const provisionedThroughput = 140;
55
56 async function callCreateComputeHyperdisk() {
57 // Create a disk
58 const disk = new compute.Disk({
59 sizeGb: diskSizeGb,
60 name: diskName,
61 zone,
62 type: diskType,
63 provisionedIops,
64 provisionedThroughput,
65 });
66
67 const [response] = await disksClient.insert({
68 project: projectId,
69 zone,
70 diskResource: disk,
71 });
72
73 let operation = response.latestResponse;
74
75 // Wait for the create disk operation to complete.
76 while (operation.status !== 'DONE') {

Callers 1

Calls 2

getProjectIdMethod · 0.80

Tested by

no test coverage detected