-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: compute_consistency_group_create/delete/(add/remove)disk/list #3918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
70de528
feat: compute_consistency_group_create/delete
5744f9a
feat: compute_consistency_group_add_disk
76a2e1b
feat: compute_consistency_group_remove_disk
b15eb42
feat: compute_consistency_group_disks_list
fc9e74d
fix(compute): Update compute/disks/consistencyGroups/deleteConsistenc…
iennae f6c314a
fix(compute) : Update compute/disks/consistencyGroups/deleteConsisten…
iennae b1b25ee
fix(compute): Update compute/disks/consistencyGroups/deleteConsistenc…
iennae a9681c4
fix(compute): Update compute/disks/consistencyGroups/deleteConsistenc…
iennae File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
94 changes: 94 additions & 0 deletions
94
compute/disks/consistencyGroups/consistencyGroupAddDisk.js
This file contains hidden or 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; | ||
| }); | ||
72 changes: 72 additions & 0 deletions
72
compute/disks/consistencyGroups/consistencyGroupDisksList.js
This file contains hidden or 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. | ||
| */ | ||
|
Comment on lines
+33
to
+34
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // 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; | ||
| }); | ||
94 changes: 94 additions & 0 deletions
94
compute/disks/consistencyGroups/consistencyGroupRemoveDisk.js
This file contains hidden or 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_remove_disk] | ||
| // Import the Compute library | ||
| const computeLib = require('@google-cloud/compute'); | ||
| const compute = computeLib.protos.google.cloud.compute.v1; | ||
|
|
||
| // If you want to remove 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. | ||
| */ | ||
|
Comment on lines
+38
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // 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 callDeleteDiskFromConsistencyGroup() { | ||
| const [response] = await disksClient.removeResourcePolicies({ | ||
| disk: diskName, | ||
| project: projectId, | ||
| // If you use RegionDisksClient, pass region as an argument instead of zone. | ||
| zone: diskLocation, | ||
| disksRemoveResourcePoliciesRequestResource: | ||
| new compute.DisksRemoveResourcePoliciesRequest({ | ||
| resourcePolicies: [ | ||
| `https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${consistencyGroupLocation}/resourcePolicies/${consistencyGroupName}`, | ||
| ], | ||
| }), | ||
| }); | ||
|
|
||
| let operation = response.latestResponse; | ||
|
|
||
| // Wait for the delete 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} deleted from consistency group: ${consistencyGroupName}.` | ||
| ); | ||
| } | ||
|
|
||
| await callDeleteDiskFromConsistencyGroup(); | ||
| // [END compute_consistency_group_remove_disk] | ||
| } | ||
|
|
||
| main(...process.argv.slice(2)).catch(err => { | ||
| console.error(err); | ||
| process.exitCode = 1; | ||
| }); | ||
This file contains hidden or 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,79 @@ | ||
| /* | ||
| * 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, region) { | ||
| // [START compute_consistency_group_create] | ||
| // Import the Compute library | ||
| const computeLib = require('@google-cloud/compute'); | ||
| const compute = computeLib.protos.google.cloud.compute.v1; | ||
|
|
||
| // Instantiate a resourcePoliciesClient | ||
| const resourcePoliciesClient = new computeLib.ResourcePoliciesClient(); | ||
| // Instantiate a regionOperationsClient | ||
| const regionOperationsClient = new computeLib.RegionOperationsClient(); | ||
|
|
||
| /** | ||
| * TODO(developer): Update/uncomment these variables before running the sample. | ||
| */ | ||
|
Comment on lines
+31
to
+32
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| // The project that contains the consistency group. | ||
| const projectId = await resourcePoliciesClient.getProjectId(); | ||
|
|
||
| // The region for the consistency group. | ||
| // If you want to add primary disks to consistency group, use the same region as the primary disks. | ||
| // If you want to add secondary disks to the consistency group, use the same region as the secondary disks. | ||
| // region = 'europe-central2'; | ||
|
|
||
| // The name for consistency group. | ||
| // consistencyGroupName = 'consistency-group-name'; | ||
|
|
||
| async function callCreateConsistencyGroup() { | ||
| // Create a resourcePolicyResource | ||
| const resourcePolicyResource = new compute.ResourcePolicy({ | ||
| diskConsistencyGroupPolicy: | ||
| new compute.ResourcePolicyDiskConsistencyGroupPolicy({}), | ||
| name: consistencyGroupName, | ||
| }); | ||
|
|
||
| const [response] = await resourcePoliciesClient.insert({ | ||
| project: projectId, | ||
| region, | ||
| resourcePolicyResource, | ||
| }); | ||
|
|
||
| let operation = response.latestResponse; | ||
|
|
||
| // Wait for the create group operation to complete. | ||
| while (operation.status !== 'DONE') { | ||
| [operation] = await regionOperationsClient.wait({ | ||
| operation: operation.name, | ||
| project: projectId, | ||
| region, | ||
| }); | ||
| } | ||
|
|
||
| console.log(`Consistency group: ${consistencyGroupName} created.`); | ||
| } | ||
|
|
||
| await callCreateConsistencyGroup(); | ||
| // [END compute_consistency_group_create] | ||
| } | ||
|
|
||
| main(...process.argv.slice(2)).catch(err => { | ||
| console.error(err); | ||
| process.exitCode = 1; | ||
| }); | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide example values for these variables to guide the user. For instance:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
but they already have defined example values- simmilarly to your proposal, the same situation for other samples
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies, I overlooked the existing example values. Given that similar examples are present in other samples, it's likely consistent with the project's style. No further action needed on my part.