Skip to content

Commit 1cf0c61

Browse files
authored
feat: create_compute_hyperdisk (#3795)
* feat: create_compute_hyperdisk * refactor: remove chai module * Revert chai module * Downgrade chai module * Fix tests * Revert the changes * Changed debian-10 -> debian-11
1 parent 79969c5 commit 1cf0c61

File tree

13 files changed

+182
-17
lines changed

13 files changed

+182
-17
lines changed

compute/createInstance.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* https://cloud.google.com/sdk/gcloud/reference/compute/machine-types/list
2626
* @param {string} sourceImage - Path the the disk image you want to use for your boot
2727
* disk. This can be one of the public images
28-
* (e.g. "projects/debian-cloud/global/images/family/debian-10")
28+
* (e.g. "projects/debian-cloud/global/images/family/debian-11")
2929
* or a private image you have access to.
3030
* You can check the list of available public images using:
3131
* $ gcloud compute images list
@@ -37,7 +37,7 @@ function main(
3737
zone,
3838
instanceName,
3939
machineType = 'n1-standard-1',
40-
sourceImage = 'projects/debian-cloud/global/images/family/debian-10',
40+
sourceImage = 'projects/debian-cloud/global/images/family/debian-11',
4141
networkName = 'global/networks/default'
4242
) {
4343
// [START compute_instances_create]
@@ -48,7 +48,7 @@ function main(
4848
// const zone = 'europe-central2-b'
4949
// const instanceName = 'YOUR_INSTANCE_NAME'
5050
// const machineType = 'n1-standard-1';
51-
// const sourceImage = 'projects/debian-cloud/global/images/family/debian-10';
51+
// const sourceImage = 'projects/debian-cloud/global/images/family/debian-11';
5252
// const networkName = 'global/networks/default';
5353

5454
const compute = require('@google-cloud/compute');

compute/createInstanceFromTemplateWithOverrides.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* https://cloud.google.com/sdk/gcloud/reference/compute/machine-types/list
2727
* @param {string} newDiskSourceImage - Path the the disk image you want to use for your new
2828
* disk. This can be one of the public images
29-
* (like "projects/debian-cloud/global/images/family/debian-10")
29+
* (like "projects/debian-cloud/global/images/family/debian-11")
3030
* or a private image you have access to.
3131
* For a list of available public images, see the documentation:
3232
* http://cloud.google.com/compute/docs/images
@@ -37,7 +37,7 @@ function main(
3737
instanceName,
3838
instanceTemplateName,
3939
machineType = 'n1-standard-2',
40-
newDiskSourceImage = 'projects/debian-cloud/global/images/family/debian-10'
40+
newDiskSourceImage = 'projects/debian-cloud/global/images/family/debian-11'
4141
) {
4242
// [START compute_instances_create_from_template_with_overrides]
4343
/**
@@ -48,7 +48,7 @@ function main(
4848
// const instanceName = 'YOUR_INSTANCE_NAME';
4949
// const instanceTemplateName = 'YOUR_INSTANCE_TEMPLATE_NAME';
5050
// const machineType = 'n1-standard-1';
51-
// const newDiskSourceImage = 'projects/debian-cloud/global/images/family/debian-10';
51+
// const newDiskSourceImage = 'projects/debian-cloud/global/images/family/debian-11';
5252

5353
const compute = require('@google-cloud/compute');
5454

compute/custom-hostname-instance/createInstanceWithCustomHostname.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function main(
4040
instanceName,
4141
hostname,
4242
machineType = 'n1-standard-1',
43-
sourceImage = 'projects/debian-cloud/global/images/family/debian-10',
43+
sourceImage = 'projects/debian-cloud/global/images/family/debian-11',
4444
networkName = 'global/networks/default'
4545
) {
4646
// [START compute_instances_create_custom_hostname]
@@ -52,7 +52,7 @@ function main(
5252
// const instanceName = 'YOUR_INSTANCE_NAME'
5353
// const hostname = 'host.example.com'
5454
// const machineType = 'n1-standard-1';
55-
// const sourceImage = 'projects/debian-cloud/global/images/family/debian-10';
55+
// const sourceImage = 'projects/debian-cloud/global/images/family/debian-11';
5656
// const networkName = 'global/networks/default';
5757

5858
const compute = require('@google-cloud/compute');
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
async function main() {
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 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+
// The zone where your VM and new disk are located.
36+
const zone = 'europe-central2-b';
37+
// The name of the new disk
38+
const diskName = 'disk-name';
39+
// The type of disk. This value uses the following format:
40+
// "zones/{zone}/diskTypes/(hyperdisk-balanced|hyperdisk-extreme|hyperdisk-ml|hyperdisk-throughput)".
41+
// For example: "zones/us-west3-b/diskTypes/hyperdisk-balanced"
42+
const diskType = `zones/${zone}/diskTypes/hyperdisk-balanced`;
43+
// Size of the new disk in gigabytes.
44+
const diskSizeGb = 10;
45+
// Optional: For Hyperdisk Balanced or Hyperdisk Extreme disks,
46+
// this is the number of I/O operations per second (IOPS) that the disk can handle.
47+
const provisionedIops = 3000;
48+
// Optional: For Hyperdisk Balanced or Hyperdisk Throughput volumes,
49+
// this is an integer that represents the throughput,
50+
// measured in MiB per second, that the disk can handle.
51+
const provisionedThroughput = 140;
52+
53+
async function callCreateComputeHyperdisk() {
54+
// Create a disk
55+
const disk = new compute.Disk({
56+
sizeGb: diskSizeGb,
57+
name: diskName,
58+
zone,
59+
type: diskType,
60+
provisionedIops,
61+
provisionedThroughput,
62+
});
63+
64+
const [response] = await disksClient.insert({
65+
project: projectId,
66+
zone,
67+
diskResource: disk,
68+
});
69+
70+
let operation = response.latestResponse;
71+
72+
// Wait for the create disk operation to complete.
73+
while (operation.status !== 'DONE') {
74+
[operation] = await zoneOperationsClient.wait({
75+
operation: operation.name,
76+
project: projectId,
77+
zone: operation.zone.split('/').pop(),
78+
});
79+
}
80+
81+
const hyperdisk = (
82+
await disksClient.get({
83+
project: projectId,
84+
zone,
85+
disk: diskName,
86+
})
87+
)[0];
88+
89+
console.log(JSON.stringify(hyperdisk));
90+
}
91+
92+
await callCreateComputeHyperdisk();
93+
// [END compute_hyperdisk_create]
94+
}
95+
96+
main().catch(err => {
97+
console.error(err);
98+
process.exitCode = 1;
99+
});

compute/instances/create-start-instance/createInstanceWithAdditionalDisk.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ function main(projectId, zone, instanceName) {
3838
// List of public operating system (OS) images: https://cloud.google.com/compute/docs/images/os-details.
3939
const [newestDebian] = await imagesClient.getFromFamily({
4040
project: 'debian-cloud',
41-
family: 'debian-10',
41+
family: 'debian-11',
4242
});
4343

4444
const [response] = await instancesClient.insert({

compute/instances/create-start-instance/createInstanceWithSubnet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function main(
5252
// List of public operating system (OS) images: https://cloud.google.com/compute/docs/images/os-details.
5353
const [newestDebian] = await imagesClient.getFromFamily({
5454
project: 'debian-cloud',
55-
family: 'debian-10',
55+
family: 'debian-11',
5656
});
5757

5858
const [response] = await instancesClient.insert({

compute/instances/preventing-accidental-vm-deletion/createInstance.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ function main(projectId, zone, instanceName, deleteProtection) {
5151
initializeParams: {
5252
diskSizeGb: '10',
5353
sourceImage:
54-
'projects/debian-cloud/global/images/family/debian-10',
54+
'projects/debian-cloud/global/images/family/debian-11',
5555
},
5656
autoDelete: true,
5757
boot: true,
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright 2024 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const path = require('path');
20+
const {assert} = require('chai');
21+
const {describe, it} = require('mocha');
22+
const cp = require('child_process');
23+
const {DisksClient} = require('@google-cloud/compute').v1;
24+
const {deleteDisk} = require('./util');
25+
26+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
27+
const cwd = path.join(__dirname, '..');
28+
29+
describe('Create compute hyperdisk', async () => {
30+
const diskName = 'disk-name';
31+
const zone = 'europe-central2-b';
32+
const disksClient = new DisksClient();
33+
let projectId;
34+
35+
before(async () => {
36+
projectId = await disksClient.getProjectId();
37+
});
38+
39+
after(async () => {
40+
await deleteDisk(disksClient, projectId, zone, diskName);
41+
});
42+
43+
it('should create a new hyperdisk', () => {
44+
const response = JSON.parse(
45+
execSync('node ./disks/createComputeHyperdisk.js', {
46+
cwd,
47+
})
48+
);
49+
50+
assert.equal(response.name, diskName);
51+
});
52+
});

compute/test/createInstanceTemplates.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const createInstance = async (projectId, zone, instanceName) => {
3434
{
3535
initializeParams: {
3636
diskSizeGb: '250',
37-
sourceImage: 'projects/debian-cloud/global/images/family/debian-10',
37+
sourceImage: 'projects/debian-cloud/global/images/family/debian-11',
3838
},
3939
autoDelete: true,
4040
boot: true,

compute/test/createStartInstance.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ describe('create start instance tests', () => {
132132

133133
const [newestDebian] = await imagesClient.getFromFamily({
134134
project: 'debian-cloud',
135-
family: 'debian-10',
135+
family: 'debian-11',
136136
});
137137

138138
await createDisk(projectId, zone, diskName, newestDebian.selfLink);
@@ -163,7 +163,7 @@ describe('create start instance tests', () => {
163163

164164
const [newestDebian] = await imagesClient.getFromFamily({
165165
project: 'debian-cloud',
166-
family: 'debian-10',
166+
family: 'debian-11',
167167
});
168168

169169
let output;

compute/test/samples.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ describe('samples', () => {
269269
initializeParams: {
270270
diskSizeGb: '10',
271271
sourceImage:
272-
'projects/debian-cloud/global/images/family/debian-10',
272+
'projects/debian-cloud/global/images/family/debian-11',
273273
},
274274
autoDelete: true,
275275
boot: true,
@@ -447,7 +447,7 @@ describe('samples', () => {
447447
initializeParams: {
448448
diskSizeGb: '10',
449449
sourceImage:
450-
'projects/debian-cloud/global/images/family/debian-10',
450+
'projects/debian-cloud/global/images/family/debian-11',
451451
},
452452
autoDelete: true,
453453
boot: true,

compute/test/util.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,22 @@ async function deleteInstance(zone, instanceName) {
8282
}
8383
}
8484

85+
async function deleteDisk(disksClient, projectId, zone, diskName) {
86+
try {
87+
await disksClient.delete({
88+
project: projectId,
89+
disk: diskName,
90+
zone,
91+
});
92+
} catch (err) {
93+
console.error('Deleting disk failed: ', err);
94+
throw new Error(err);
95+
}
96+
}
97+
8598
module.exports = {
8699
generateTestId,
87100
getStaleVMInstances,
88101
deleteInstance,
102+
deleteDisk,
89103
};

functions/v2/autoLabelInstance/test/system.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ describe('functions_label_gce_instance', () => {
4747
initializeParams: {
4848
diskSizeGb: '10',
4949
sourceImage:
50-
'projects/debian-cloud/global/images/family/debian-10',
50+
'projects/debian-cloud/global/images/family/debian-11',
5151
},
5252
boot: true,
5353
autoDelete: true,

0 commit comments

Comments
 (0)