Skip to content

Commit ac99919

Browse files
author
Joanna Grycz
committed
feat: compute_reservation_get
1 parent 1c349f1 commit ac99919

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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_reservation_get]
21+
// Import the Compute library
22+
const computeLib = require('@google-cloud/compute');
23+
24+
// Instantiate a reservationsClient
25+
const reservationsClient = new computeLib.ReservationsClient();
26+
27+
/**
28+
* TODO(developer): Update these variables before running the sample.
29+
*/
30+
// The ID of the project where you want to reserve resources and where the instance template exists.
31+
const projectId = await reservationsClient.getProjectId();
32+
// The zone in which to reserve resources.
33+
const zone = 'us-central1-a';
34+
// The name of the reservation to return.
35+
const reservationName = 'reservation-01';
36+
37+
async function callGetReservation() {
38+
const requestedReservation = (
39+
await reservationsClient.get({
40+
project: projectId,
41+
zone,
42+
reservation: reservationName,
43+
})
44+
)[0];
45+
46+
console.log(JSON.stringify(requestedReservation));
47+
}
48+
49+
await callGetReservation();
50+
// [END compute_reservation_get]
51+
}
52+
53+
main().catch(err => {
54+
console.error(err);
55+
process.exitCode = 1;
56+
});
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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('node:assert/strict');
21+
const {after, before, describe, it} = require('mocha');
22+
const cp = require('child_process');
23+
24+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
25+
const cwd = path.join(__dirname, '..');
26+
27+
describe('Get reservation', async () => {
28+
let insertedReservation;
29+
30+
before(async () => {
31+
// Add reservation
32+
insertedReservation = JSON.parse(
33+
execSync('node ./reservations/createReservationFromProperties.js', {
34+
cwd,
35+
})
36+
);
37+
});
38+
39+
after(async () => {
40+
// Delete reservation
41+
execSync('node ./reservations/deleteReservation.js', {
42+
cwd,
43+
});
44+
});
45+
46+
it('should return requested reservation', () => {
47+
const response = JSON.parse(
48+
execSync('node ./reservations/getReservation.js', {
49+
cwd,
50+
})
51+
);
52+
53+
assert.deepEqual(response, insertedReservation);
54+
});
55+
});

0 commit comments

Comments
 (0)