Skip to content

Commit a25a842

Browse files
author
Joanna Grycz
committed
feat: compute_snapshot_schedule_get
1 parent 7a34d18 commit a25a842

File tree

2 files changed

+84
-0
lines changed

2 files changed

+84
-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(snapshotScheduleName, region) {
20+
// [START compute_snapshot_schedule_get]
21+
// Import the Compute library
22+
const computeLib = require('@google-cloud/compute');
23+
24+
// Instantiate a resourcePoliciesClient
25+
const resourcePoliciesClient = new computeLib.ResourcePoliciesClient();
26+
27+
/**
28+
* TODO(developer): Update/uncomment these variables before running the sample.
29+
*/
30+
// The project name.
31+
const projectId = await resourcePoliciesClient.getProjectId();
32+
33+
// The location of the snapshot schedule resource policy.
34+
// region = 'europe-central2';
35+
36+
// The name of the snapshot schedule.
37+
// snapshotScheduleName = 'snapshot-schedule-name';
38+
39+
async function callGetSnapshotSchedule() {
40+
const [response] = await resourcePoliciesClient.get({
41+
project: projectId,
42+
region,
43+
resourcePolicy: snapshotScheduleName,
44+
});
45+
46+
console.log(response);
47+
}
48+
49+
await callGetSnapshotSchedule();
50+
// [END compute_snapshot_schedule_get]
51+
}
52+
53+
main(...process.argv.slice(2)).catch(err => {
54+
console.error(err);
55+
process.exitCode = 1;
56+
});

compute/test/snapshotSchedule.test.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,34 @@ describe('Snapshot schedule', async () => {
5151
);
5252
});
5353

54+
it('should return snapshot schedule', () => {
55+
const snapshotScheduleName = `snapshot-schedule-name-${uuid.v4()}`;
56+
// Create snapshot
57+
execSync(
58+
`node ./snapshotSchedule/createSnapshotSchedule.js ${snapshotScheduleName} ${region}`,
59+
{
60+
cwd,
61+
}
62+
);
63+
64+
const response = execSync(
65+
`node ./snapshotSchedule/getSnapshotSchedule.js ${snapshotScheduleName} ${region}`,
66+
{
67+
cwd,
68+
}
69+
);
70+
71+
assert(response.includes(snapshotScheduleName));
72+
73+
// Delete resource
74+
execSync(
75+
`node ./snapshotSchedule/deleteSnapshotSchedule.js ${snapshotScheduleName} ${region}`,
76+
{
77+
cwd,
78+
}
79+
);
80+
});
81+
5482
it('should delete snapshot schedule', () => {
5583
const snapshotScheduleName = `snapshot-schedule-name-${uuid.v4()}`;
5684
// Create snapshot

0 commit comments

Comments
 (0)