|
| 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(region) { |
| 20 | + // [START compute_snapshot_schedule_list] |
| 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 region of the snapshot schedules. |
| 34 | + // region = 'us-central1'; |
| 35 | + |
| 36 | + async function callSnapshotScheduleList() { |
| 37 | + const aggListRequest = resourcePoliciesClient.aggregatedListAsync({ |
| 38 | + project: projectId, |
| 39 | + filter: `region = "https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${region}"`, |
| 40 | + }); |
| 41 | + const result = []; |
| 42 | + |
| 43 | + for await (const [, listObject] of aggListRequest) { |
| 44 | + const {resourcePolicies} = listObject; |
| 45 | + if (resourcePolicies.length > 0) { |
| 46 | + result.push(...resourcePolicies); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + console.log(JSON.stringify(result)); |
| 51 | + } |
| 52 | + |
| 53 | + await callSnapshotScheduleList(); |
| 54 | + // [END compute_snapshot_schedule_list] |
| 55 | +} |
| 56 | + |
| 57 | +main(...process.argv.slice(2)).catch(err => { |
| 58 | + console.error(err); |
| 59 | + process.exitCode = 1; |
| 60 | +}); |
0 commit comments