Skip to content

Commit 28d8e41

Browse files
authored
Merge branch 'main' into compute_disk_regional_replicated
2 parents 580e8ea + 21322df commit 28d8e41

File tree

17 files changed

+464
-545
lines changed

17 files changed

+464
-545
lines changed

.github/workflows/monitoring-opencensus.yaml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/opencensus.yaml

Lines changed: 0 additions & 52 deletions
This file was deleted.

.github/workflows/utils/workflows.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,8 @@
7878
"media/transcoder",
7979
"media/video-stitcher",
8080
"mediatranslation",
81-
"monitoring/opencensus",
8281
"monitoring/prometheus",
8382
"monitoring/snippets",
84-
"opencensus",
8583
"retail",
8684
"run/filesystem",
8785
"scheduler",

CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ storagetransfer @GoogleCloudPlatform/cloud-storage-dpes @GoogleCloudPlatform/nod
3434

3535
# One-offs
3636
composer @GoogleCloudPlatform/cloud-dpes-composer @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
37-
monitoring/opencensus @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
3837

3938
# Data & AI
4039
document-ai @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/document-ai-samples-contributors @GoogleCloudPlatform/cloud-samples-reviewers
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+
});

0 commit comments

Comments
 (0)