-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into renovate/all
- Loading branch information
Showing
33 changed files
with
2,197 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
compute/disks/consistencyGroups/consistencyGroupAddDisk.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
72
compute/disks/consistencyGroups/consistencyGroupDisksList.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}); |
Oops, something went wrong.