Skip to content

Commit 562d92c

Browse files
authored
Merge branch 'main' into build/renovate-all
2 parents 3b7558d + 960fee3 commit 562d92c

File tree

5 files changed

+464
-0
lines changed

5 files changed

+464
-0
lines changed
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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_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 resourcePoliciesClient
26+
const resourcePoliciesClient = new computeLib.ResourcePoliciesClient();
27+
// Instantiate a regionOperationsClient
28+
const regionOperationsClient = new computeLib.RegionOperationsClient();
29+
30+
/**
31+
* TODO(developer): Update/uncomment these variables before running the sample.
32+
*/
33+
// The project name.
34+
const projectId = await resourcePoliciesClient.getProjectId();
35+
36+
// The location of the snapshot schedule resource policy.
37+
// region = 'us-central1';
38+
39+
// The name of the snapshot schedule.
40+
// snapshotScheduleName = 'snapshot-schedule-name';
41+
42+
// The description of the snapshot schedule.
43+
const snapshotScheduleDescription = 'snapshot schedule description...';
44+
45+
async function callCreateSnapshotSchedule() {
46+
const [response] = await resourcePoliciesClient.insert({
47+
project: projectId,
48+
region,
49+
resourcePolicyResource: new compute.ResourcePolicy({
50+
name: snapshotScheduleName,
51+
description: snapshotScheduleDescription,
52+
snapshotSchedulePolicy:
53+
new compute.ResourcePolicyInstanceSchedulePolicySchedule({
54+
retentionPolicy:
55+
new compute.ResourcePolicySnapshotSchedulePolicyRetentionPolicy({
56+
maxRetentionDays: 5,
57+
}),
58+
schedule: new compute.ResourcePolicySnapshotSchedulePolicySchedule({
59+
// Similarly, you can create a weekly or monthly schedule.
60+
// Review the resourcePolicies.insert method for details specific to setting a weekly or monthly schedule.
61+
// To see more details, open: `https://cloud.google.com/compute/docs/disks/scheduled-snapshots?authuser=0#create_snapshot_schedule`
62+
dailySchedule: new compute.ResourcePolicyDailyCycle({
63+
startTime: '12:00',
64+
daysInCycle: 1,
65+
}),
66+
}),
67+
snapshotProperties:
68+
new compute.ResourcePolicySnapshotSchedulePolicySnapshotProperties(
69+
{
70+
guestFlush: false,
71+
labels: {
72+
env: 'dev',
73+
media: 'images',
74+
},
75+
// OPTIONAL: the storage location. If you omit this flag, the default storage location is used.
76+
// storageLocations: 'storage-location',
77+
}
78+
),
79+
}),
80+
}),
81+
});
82+
83+
let operation = response.latestResponse;
84+
85+
// Wait for the create operation to complete.
86+
while (operation.status !== 'DONE') {
87+
[operation] = await regionOperationsClient.wait({
88+
operation: operation.name,
89+
project: projectId,
90+
region,
91+
});
92+
}
93+
94+
console.log(`Snapshot schedule: ${snapshotScheduleName} created.`);
95+
}
96+
97+
await callCreateSnapshotSchedule();
98+
// [END compute_snapshot_schedule_create]
99+
}
100+
101+
main(...process.argv.slice(2)).catch(err => {
102+
console.error(err);
103+
process.exitCode = 1;
104+
});
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
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_delete]
21+
// Import the Compute library
22+
const computeLib = require('@google-cloud/compute');
23+
24+
// Instantiate a resourcePoliciesClient
25+
const resourcePoliciesClient = new computeLib.ResourcePoliciesClient();
26+
// Instantiate a regionOperationsClient
27+
const regionOperationsClient = new computeLib.RegionOperationsClient();
28+
29+
/**
30+
* TODO(developer): Update/uncomment these variables before running the sample.
31+
*/
32+
// The project name.
33+
const projectId = await resourcePoliciesClient.getProjectId();
34+
35+
// The location of the snapshot schedule resource policy.
36+
// region = 'us-central1';
37+
38+
// The name of the snapshot schedule.
39+
// snapshotScheduleName = 'snapshot-schedule-name'
40+
41+
async function callDeleteSnapshotSchedule() {
42+
// If the snapshot schedule is already attached to a disk, you will receive an error.
43+
const [response] = await resourcePoliciesClient.delete({
44+
project: projectId,
45+
region,
46+
resourcePolicy: snapshotScheduleName,
47+
});
48+
49+
let operation = response.latestResponse;
50+
51+
// Wait for the delete operation to complete.
52+
while (operation.status !== 'DONE') {
53+
[operation] = await regionOperationsClient.wait({
54+
operation: operation.name,
55+
project: projectId,
56+
region,
57+
});
58+
}
59+
60+
console.log(`Snapshot schedule: ${snapshotScheduleName} deleted.`);
61+
}
62+
63+
await callDeleteSnapshotSchedule();
64+
// [END compute_snapshot_schedule_delete]
65+
}
66+
67+
main(...process.argv.slice(2)).catch(err => {
68+
console.error(err);
69+
process.exitCode = 1;
70+
});
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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_edit]
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 resourcePoliciesClient
26+
const resourcePoliciesClient = new computeLib.ResourcePoliciesClient();
27+
// Instantiate a regionOperationsClient
28+
const regionOperationsClient = new computeLib.RegionOperationsClient();
29+
30+
/**
31+
* TODO(developer): Update/uncomment these variables before running the sample.
32+
*/
33+
// The project name.
34+
const projectId = await resourcePoliciesClient.getProjectId();
35+
36+
// The location of the snapshot schedule resource policy.
37+
// region = 'us-central1';
38+
39+
// The name of the snapshot schedule.
40+
// snapshotScheduleName = 'snapshot-schedule-name';
41+
42+
async function callEditSnapshotSchedule() {
43+
const [response] = await resourcePoliciesClient.patch({
44+
project: projectId,
45+
region,
46+
resourcePolicy: snapshotScheduleName,
47+
resourcePolicyResource: compute.ResourcePolicy({
48+
snapshotSchedulePolicy:
49+
compute.ResourcePolicyInstanceSchedulePolicySchedule({
50+
schedule: compute.ResourcePolicySnapshotSchedulePolicySchedule({
51+
weeklySchedule: compute.ResourcePolicyWeeklyCycle({
52+
dayOfWeeks: [
53+
compute.ResourcePolicyWeeklyCycleDayOfWeek({
54+
day: 'Tuesday',
55+
startTime: '9:00',
56+
}),
57+
],
58+
}),
59+
}),
60+
}),
61+
}),
62+
});
63+
64+
let operation = response.latestResponse;
65+
66+
// Wait for the edit operation to complete.
67+
while (operation.status !== 'DONE') {
68+
[operation] = await regionOperationsClient.wait({
69+
operation: operation.name,
70+
project: projectId,
71+
region,
72+
});
73+
}
74+
75+
console.log(`Snapshot schedule: ${snapshotScheduleName} edited.`);
76+
}
77+
78+
await callEditSnapshotSchedule();
79+
// [END compute_snapshot_schedule_edit]
80+
}
81+
82+
main(...process.argv.slice(2)).catch(err => {
83+
console.error(err);
84+
process.exitCode = 1;
85+
});
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 = 'us-central1';
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(JSON.stringify(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+
});

0 commit comments

Comments
 (0)