Skip to content

Commit 111148a

Browse files
authored
Merge branch 'main' into generativeaionvertexai_embedding_batch
2 parents 32eb6c9 + 04a1f0d commit 111148a

6 files changed

+556
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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(
20+
consistencyGroupName,
21+
consistencyGroupLocation,
22+
diskName,
23+
diskLocation
24+
) {
25+
// [START compute_consistency_group_add_disk]
26+
// Import the Compute library
27+
const computeLib = require('@google-cloud/compute');
28+
const compute = computeLib.protos.google.cloud.compute.v1;
29+
30+
// If you want to add regional disk,
31+
// you should use: RegionDisksClient and RegionOperationsClient.
32+
// Instantiate a disksClient
33+
const disksClient = new computeLib.DisksClient();
34+
// Instantiate a zone
35+
const zoneOperationsClient = new computeLib.ZoneOperationsClient();
36+
37+
/**
38+
* TODO(developer): Update/uncomment these variables before running the sample.
39+
*/
40+
// The project that contains the disk.
41+
const projectId = await disksClient.getProjectId();
42+
43+
// The name of the disk.
44+
// diskName = 'disk-name';
45+
46+
// If you use RegionDisksClient- define region, if DisksClient- define zone.
47+
// The zone or region of the disk.
48+
// diskLocation = 'europe-central2-a';
49+
50+
// The name of the consistency group.
51+
// consistencyGroupName = 'consistency-group-name';
52+
53+
// The region of the consistency group.
54+
// consistencyGroupLocation = 'europe-central2';
55+
56+
async function callAddDiskToConsistencyGroup() {
57+
const [response] = await disksClient.addResourcePolicies({
58+
disk: diskName,
59+
project: projectId,
60+
// If you use RegionDisksClient, pass region as an argument instead of zone.
61+
zone: diskLocation,
62+
disksAddResourcePoliciesRequestResource:
63+
new compute.DisksAddResourcePoliciesRequest({
64+
resourcePolicies: [
65+
`https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${consistencyGroupLocation}/resourcePolicies/${consistencyGroupName}`,
66+
],
67+
}),
68+
});
69+
70+
let operation = response.latestResponse;
71+
72+
// Wait for the add disk operation to complete.
73+
while (operation.status !== 'DONE') {
74+
[operation] = await zoneOperationsClient.wait({
75+
operation: operation.name,
76+
project: projectId,
77+
// If you use RegionDisksClient, pass region as an argument instead of zone.
78+
zone: operation.zone.split('/').pop(),
79+
});
80+
}
81+
82+
console.log(
83+
`Disk: ${diskName} added to consistency group: ${consistencyGroupName}.`
84+
);
85+
}
86+
87+
await callAddDiskToConsistencyGroup();
88+
// [END compute_consistency_group_add_disk]
89+
}
90+
91+
main(...process.argv.slice(2)).catch(err => {
92+
console.error(err);
93+
process.exitCode = 1;
94+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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(
20+
consistencyGroupName,
21+
consistencyGroupLocation,
22+
disksLocation
23+
) {
24+
// [START compute_consistency_group_disks_list]
25+
// Import the Compute library
26+
const computeLib = require('@google-cloud/compute');
27+
28+
// If you want to get regional disks, you should use: RegionDisksClient.
29+
// Instantiate a disksClient
30+
const disksClient = new computeLib.DisksClient();
31+
32+
/**
33+
* TODO(developer): Update/uncomment these variables before running the sample.
34+
*/
35+
// The project that contains the disks.
36+
const projectId = await disksClient.getProjectId();
37+
38+
// If you use RegionDisksClient- define region, if DisksClient- define zone.
39+
// The zone or region of the disks.
40+
// disksLocation = 'europe-central2-a';
41+
42+
// The name of the consistency group.
43+
// consistencyGroupName = 'consistency-group-name';
44+
45+
// The region of the consistency group.
46+
// consistencyGroupLocation = 'europe-central2';
47+
48+
async function callConsistencyGroupDisksList() {
49+
const filter = `https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${consistencyGroupLocation}/resourcePolicies/${consistencyGroupName}`;
50+
51+
const [response] = await disksClient.list({
52+
project: projectId,
53+
// If you use RegionDisksClient, pass region as an argument instead of zone.
54+
zone: disksLocation,
55+
});
56+
57+
// Filtering must be done manually for now, since list filtering inside disksClient.list is not supported yet.
58+
const filteredDisks = response.filter(disk =>
59+
disk.resourcePolicies.includes(filter)
60+
);
61+
62+
console.log(JSON.stringify(filteredDisks));
63+
}
64+
65+
await callConsistencyGroupDisksList();
66+
// [END compute_consistency_group_disks_list]
67+
}
68+
69+
main(...process.argv.slice(2)).catch(err => {
70+
console.error(err);
71+
process.exitCode = 1;
72+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
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(
20+
consistencyGroupName,
21+
consistencyGroupLocation,
22+
diskName,
23+
diskLocation
24+
) {
25+
// [START compute_consistency_group_remove_disk]
26+
// Import the Compute library
27+
const computeLib = require('@google-cloud/compute');
28+
const compute = computeLib.protos.google.cloud.compute.v1;
29+
30+
// If you want to remove regional disk,
31+
// you should use: RegionDisksClient and RegionOperationsClient.
32+
// Instantiate a disksClient
33+
const disksClient = new computeLib.DisksClient();
34+
// Instantiate a zone
35+
const zoneOperationsClient = new computeLib.ZoneOperationsClient();
36+
37+
/**
38+
* TODO(developer): Update/uncomment these variables before running the sample.
39+
*/
40+
// The project that contains the disk.
41+
const projectId = await disksClient.getProjectId();
42+
43+
// The name of the disk.
44+
// diskName = 'disk-name';
45+
46+
// If you use RegionDisksClient- define region, if DisksClient- define zone.
47+
// The zone or region of the disk.
48+
// diskLocation = 'europe-central2-a';
49+
50+
// The name of the consistency group.
51+
// consistencyGroupName = 'consistency-group-name';
52+
53+
// The region of the consistency group.
54+
// consistencyGroupLocation = 'europe-central2';
55+
56+
async function callDeleteDiskFromConsistencyGroup() {
57+
const [response] = await disksClient.removeResourcePolicies({
58+
disk: diskName,
59+
project: projectId,
60+
// If you use RegionDisksClient, pass region as an argument instead of zone.
61+
zone: diskLocation,
62+
disksRemoveResourcePoliciesRequestResource:
63+
new compute.DisksRemoveResourcePoliciesRequest({
64+
resourcePolicies: [
65+
`https://www.googleapis.com/compute/v1/projects/${projectId}/regions/${consistencyGroupLocation}/resourcePolicies/${consistencyGroupName}`,
66+
],
67+
}),
68+
});
69+
70+
let operation = response.latestResponse;
71+
72+
// Wait for the delete disk operation to complete.
73+
while (operation.status !== 'DONE') {
74+
[operation] = await zoneOperationsClient.wait({
75+
operation: operation.name,
76+
project: projectId,
77+
// If you use RegionDisksClient, pass region as an argument instead of zone.
78+
zone: operation.zone.split('/').pop(),
79+
});
80+
}
81+
82+
console.log(
83+
`Disk: ${diskName} deleted from consistency group: ${consistencyGroupName}.`
84+
);
85+
}
86+
87+
await callDeleteDiskFromConsistencyGroup();
88+
// [END compute_consistency_group_remove_disk]
89+
}
90+
91+
main(...process.argv.slice(2)).catch(err => {
92+
console.error(err);
93+
process.exitCode = 1;
94+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
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(consistencyGroupName, region) {
20+
// [START compute_consistency_group_create]
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 that contains the consistency group.
34+
const projectId = await resourcePoliciesClient.getProjectId();
35+
36+
// The region for the consistency group.
37+
// If you want to add primary disks to consistency group, use the same region as the primary disks.
38+
// If you want to add secondary disks to the consistency group, use the same region as the secondary disks.
39+
// region = 'europe-central2';
40+
41+
// The name for consistency group.
42+
// consistencyGroupName = 'consistency-group-name';
43+
44+
async function callCreateConsistencyGroup() {
45+
// Create a resourcePolicyResource
46+
const resourcePolicyResource = new compute.ResourcePolicy({
47+
diskConsistencyGroupPolicy:
48+
new compute.ResourcePolicyDiskConsistencyGroupPolicy({}),
49+
name: consistencyGroupName,
50+
});
51+
52+
const [response] = await resourcePoliciesClient.insert({
53+
project: projectId,
54+
region,
55+
resourcePolicyResource,
56+
});
57+
58+
let operation = response.latestResponse;
59+
60+
// Wait for the create group operation to complete.
61+
while (operation.status !== 'DONE') {
62+
[operation] = await regionOperationsClient.wait({
63+
operation: operation.name,
64+
project: projectId,
65+
region,
66+
});
67+
}
68+
69+
console.log(`Consistency group: ${consistencyGroupName} created.`);
70+
}
71+
72+
await callCreateConsistencyGroup();
73+
// [END compute_consistency_group_create]
74+
}
75+
76+
main(...process.argv.slice(2)).catch(err => {
77+
console.error(err);
78+
process.exitCode = 1;
79+
});

0 commit comments

Comments
 (0)