Skip to content

Commit

Permalink
Merge branch 'main' into renovate/all
Browse files Browse the repository at this point in the history
  • Loading branch information
subfuzion authored Dec 4, 2024
2 parents e6d5591 + 68c11ef commit e909827
Show file tree
Hide file tree
Showing 33 changed files with 2,197 additions and 27 deletions.
54 changes: 54 additions & 0 deletions .github/workflows/tpu.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# Copyright 2024 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

name: tpu
on:
push:
branches:
- main
paths:
- 'tpu/**'
- '.github/workflows/tpu.yaml'
- '.github/workflows/test.yaml'
pull_request:
types:
- opened
- reopened
- synchronize
- labeled
paths:
- 'tpu/**'
- '.github/workflows/tpu.yaml'
- '.github/workflows/test.yaml'
schedule:
- cron: '0 0 * * 0'
jobs:
test:
# Ref: https://github.com/google-github-actions/auth#usage
permissions:
contents: 'read'
id-token: 'write'
if: github.event.action != 'labeled' || github.event.label.name == 'actions:force-run'
uses: ./.github/workflows/test.yaml
with:
name: 'tpu'
path: 'tpu'
flakybot:
# Ref: https://github.com/google-github-actions/auth#usage
permissions:
contents: 'read'
id-token: 'write'
if: github.event_name == 'schedule' && always() # always() submits logs even if tests fail
uses: ./.github/workflows/flakybot.yaml
needs: [test]
1 change: 1 addition & 0 deletions .github/workflows/utils/workflows.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
"speech",
"talent",
"texttospeech",
"tpu",
"translate",
"video-intelligence",
"vision/productSearch",
Expand Down
1 change: 1 addition & 0 deletions CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ recaptcha_enterprise @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-
recaptcha_enterprise/demosite @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/recaptcha-customer-obsession-reviewers @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
secret-manager @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers @GoogleCloudPlatform/cloud-secrets-team
service-directory @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
tpu @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers
webrisk @GoogleCloudPlatform/dee-infra @GoogleCloudPlatform/nodejs-samples-reviewers @GoogleCloudPlatform/cloud-samples-reviewers

# SoDa teams
Expand Down
94 changes: 94 additions & 0 deletions compute/disks/consistencyGroups/consistencyGroupAddDisk.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

async function main(
consistencyGroupName,
consistencyGroupLocation,
diskName,
diskLocation
) {
// [START compute_consistency_group_add_disk]
// Import the Compute library
const computeLib = require('@google-cloud/compute');
const compute = computeLib.protos.google.cloud.compute.v1;

// If you want to add regional disk,
// you should use: RegionDisksClient and RegionOperationsClient.
// Instantiate a disksClient
const disksClient = new computeLib.DisksClient();
// Instantiate a zone
const zoneOperationsClient = new computeLib.ZoneOperationsClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
*/
// The project that contains the disk.
const projectId = await disksClient.getProjectId();

// The name of the disk.
// diskName = 'disk-name';

// If you use RegionDisksClient- define region, if DisksClient- define zone.
// The zone or region of the disk.
// diskLocation = 'europe-central2-a';

// The name of the consistency group.
// consistencyGroupName = 'consistency-group-name';

// The region of the consistency group.
// consistencyGroupLocation = 'europe-central2';

async function callAddDiskToConsistencyGroup() {
const [response] = await disksClient.addResourcePolicies({
disk: diskName,
project: projectId,
// If you use RegionDisksClient, pass region as an argument instead of zone.
zone: diskLocation,
disksAddResourcePoliciesRequestResource:
new compute.DisksAddResourcePoliciesRequest({
resourcePolicies: [
`https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${consistencyGroupLocation}/resourcePolicies/${consistencyGroupName}`,
],
}),
});

let operation = response.latestResponse;

// Wait for the add disk operation to complete.
while (operation.status !== 'DONE') {
[operation] = await zoneOperationsClient.wait({
operation: operation.name,
project: projectId,
// If you use RegionDisksClient, pass region as an argument instead of zone.
zone: operation.zone.split('/').pop(),
});
}

console.log(
`Disk: ${diskName} added to consistency group: ${consistencyGroupName}.`
);
}

await callAddDiskToConsistencyGroup();
// [END compute_consistency_group_add_disk]
}

main(...process.argv.slice(2)).catch(err => {
console.error(err);
process.exitCode = 1;
});
90 changes: 90 additions & 0 deletions compute/disks/consistencyGroups/consistencyGroupClone.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

async function main(disksClient, zoneOperationsClient) {
// [START compute_consistency_group_clone]
// Import the Compute library
const computeLib = require('@google-cloud/compute');
const compute = computeLib.protos.google.cloud.compute.v1;

// If you want to clone regional disks,
// you should use: RegionDisksClient and RegionOperationsClient.
// TODO(developer): Uncomment disksClient and zoneOperationsClient before running the sample.
// Instantiate a disksClient
// disksClient = new computeLib.DisksClient();
// Instantiate a zone
// zoneOperationsClient = new computeLib.ZoneOperationsClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
*/
// The project that contains the disks.
const projectId = await disksClient.getProjectId();

// If you use RegionDisksClient- define region, if DisksClient- define zone.
// The zone or region that the disks in the consistency group are located in. The clones are created in this location.
// diskLocation = 'europe-central2-a';
const disksLocation = 'europe-north1-a';

// The name of the consistency group, that contains secondary disks to clone.
// consistencyGroupName = 'consistency-group-name';
const consistencyGroupName = 'consistency-group-1';

// The region of the consistency group.
const consistencyGroupLocation = 'europe-north1';

async function callConsistencyGroupClone() {
const [response] = await disksClient.bulkInsert({
project: projectId,
// If you use RegionDisksClient, pass region as an argument instead of zone.
zone: disksLocation,
bulkInsertDiskResourceResource: new compute.BulkInsertDiskResource({
sourceConsistencyGroupPolicy: [
`https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${consistencyGroupLocation}/resourcePolicies/${consistencyGroupName}`,
],
}),
});

let operation = response.latestResponse;

// Wait for the clone operation to complete.
while (operation.status !== 'DONE') {
[operation] = await zoneOperationsClient.wait({
operation: operation.name,
project: projectId,
// If you use RegionDisksClient, pass region as an argument instead of zone.
zone: operation.zone.split('/').pop(),
});
}

const message = `Disks cloned from consistency group: ${consistencyGroupName}.`;
console.log(message);
return message;
}

return await callConsistencyGroupClone();
// [END compute_consistency_group_clone]
}

module.exports = main;

// TODO(developer): Uncomment below lines before running the sample.
// main(...process.argv.slice(2)).catch(err => {
// console.error(err);
// process.exitCode = 1;
// });
72 changes: 72 additions & 0 deletions compute/disks/consistencyGroups/consistencyGroupDisksList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

async function main(
consistencyGroupName,
consistencyGroupLocation,
disksLocation
) {
// [START compute_consistency_group_disks_list]
// Import the Compute library
const computeLib = require('@google-cloud/compute');

// If you want to get regional disks, you should use: RegionDisksClient.
// Instantiate a disksClient
const disksClient = new computeLib.DisksClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
*/
// The project that contains the disks.
const projectId = await disksClient.getProjectId();

// If you use RegionDisksClient- define region, if DisksClient- define zone.
// The zone or region of the disks.
// disksLocation = 'europe-central2-a';

// The name of the consistency group.
// consistencyGroupName = 'consistency-group-name';

// The region of the consistency group.
// consistencyGroupLocation = 'europe-central2';

async function callConsistencyGroupDisksList() {
const filter = `https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${consistencyGroupLocation}/resourcePolicies/${consistencyGroupName}`;

const [response] = await disksClient.list({
project: projectId,
// If you use RegionDisksClient, pass region as an argument instead of zone.
zone: disksLocation,
});

// Filtering must be done manually for now, since list filtering inside disksClient.list is not supported yet.
const filteredDisks = response.filter(disk =>
disk.resourcePolicies.includes(filter)
);

console.log(JSON.stringify(filteredDisks));
}

await callConsistencyGroupDisksList();
// [END compute_consistency_group_disks_list]
}

main(...process.argv.slice(2)).catch(err => {
console.error(err);
process.exitCode = 1;
});
Loading

0 comments on commit e909827

Please sign in to comment.