|
| 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 = 'europe-central2'; |
| 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