Skip to content

Commit

Permalink
Add mocks to sharedReservation, revert changes in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gryczj committed Sep 26, 2024
1 parent 8b5586d commit a5a85e1
Show file tree
Hide file tree
Showing 16 changed files with 331 additions and 184 deletions.
18 changes: 13 additions & 5 deletions compute/disks/createComputeHyperdisk.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'use strict';

async function main(diskName) {
async function main() {
// [START compute_hyperdisk_create]
// Import the Compute library
const computeLib = require('@google-cloud/compute');
Expand All @@ -28,14 +28,14 @@ async function main(diskName) {
const zoneOperationsClient = new computeLib.ZoneOperationsClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
* TODO(developer): Update these variables before running the sample.
*/
// Project ID or project number of the Google Cloud project you want to use.
const projectId = await disksClient.getProjectId();
// The zone where your VM and new disk are located.
const zone = 'europe-central2-b';
// The name of the new disk
// const diskName = 'disk-name';
const diskName = 'disk-name';
// The type of disk. This value uses the following format:
// "zones/{zone}/diskTypes/(hyperdisk-balanced|hyperdisk-extreme|hyperdisk-ml|hyperdisk-throughput)".
// For example: "zones/us-west3-b/diskTypes/hyperdisk-balanced"
Expand Down Expand Up @@ -78,14 +78,22 @@ async function main(diskName) {
});
}

console.log(`Disk: ${diskName} created.`);
const hyperdisk = (
await disksClient.get({
project: projectId,
zone,
disk: diskName,
})
)[0];

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

await callCreateComputeHyperdisk();
// [END compute_hyperdisk_create]
}

main(...process.argv.slice(2)).catch(err => {
main().catch(err => {
console.error(err);
process.exitCode = 1;
});
20 changes: 14 additions & 6 deletions compute/disks/createComputeHyperdiskFromPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'use strict';

async function main(diskName, storagePoolName) {
async function main() {
// [START compute_hyperdisk_create_from_pool]
// Import the Compute library
const computeLib = require('@google-cloud/compute');
Expand All @@ -28,16 +28,16 @@ async function main(diskName, storagePoolName) {
const zoneOperationsClient = new computeLib.ZoneOperationsClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
* TODO(developer): Update these variables before running the sample.
*/
// Project ID or project number of the Google Cloud project you want to use.
const projectId = await disksClient.getProjectId();
// The zone where your VM and new disk are located.
const zone = 'us-central1-a';
// The name of the new disk
// const diskName = 'disk-from-pool-name';
const diskName = 'disk-from-pool-name';
// The name of the storage pool
// const storagePoolName = 'storage-pool-name';
const storagePoolName = 'storage-pool-name';
// Link to the storagePool you want to use. Use format:
// https://www.googleapis.com/compute/v1/projects/{projectId}/zones/{zone}/storagePools/{storagePoolName}
const storagePool = `https://www.googleapis.com/compute/v1/projects/${projectId}/zones/${zone}/storagePools/${storagePoolName}`;
Expand Down Expand Up @@ -84,14 +84,22 @@ async function main(diskName, storagePoolName) {
});
}

console.log(`Disk: ${diskName} created.`);
const hyperdisk = (
await disksClient.get({
project: projectId,
zone,
disk: diskName,
})
)[0];

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

await callCreateComputeHyperdiskFromPool();
// [END compute_hyperdisk_create_from_pool]
}

main(...process.argv.slice(2)).catch(err => {
main().catch(err => {
console.error(err);
process.exitCode = 1;
});
18 changes: 13 additions & 5 deletions compute/disks/createComputeHyperdiskPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'use strict';

async function main(storagePoolName) {
async function main() {
// [START compute_hyperdisk_pool_create]
// Import the Compute library
const computeLib = require('@google-cloud/compute');
Expand All @@ -28,14 +28,14 @@ async function main(storagePoolName) {
const zoneOperationsClient = new computeLib.ZoneOperationsClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
* TODO(developer): Update these variables before running the sample.
*/
// Project ID or project number of the Google Cloud project you want to use.
const projectId = await storagePoolClient.getProjectId();
// Name of the zone in which you want to create the storagePool.
const zone = 'us-central1-a';
// Name of the storagePool you want to create.
// const storagePoolName = 'storage-pool-name';
const storagePoolName = 'storage-pool-name';
// The type of disk you want to create. This value uses the following format:
// "projects/{projectId}/zones/{zone}/storagePoolTypes/(hyperdisk-throughput|hyperdisk-balanced)"
const storagePoolType = `projects/${projectId}/zones/${zone}/storagePoolTypes/hyperdisk-balanced`;
Expand Down Expand Up @@ -79,14 +79,22 @@ async function main(storagePoolName) {
});
}

console.log(`Storage pool: ${storagePoolName} created.`);
const createdStoragePool = (
await storagePoolClient.get({
project: projectId,
zone,
storagePool: storagePoolName,
})
)[0];

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

await callCreateComputeHyperdiskPool();
// [END compute_hyperdisk_pool_create]
}

main(...process.argv.slice(2)).catch(err => {
main().catch(err => {
console.error(err);
process.exitCode = 1;
});
18 changes: 13 additions & 5 deletions compute/reservations/createReservationFromProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'use strict';

async function main(reservationName) {
async function main() {
// [START compute_reservation_create]
// Import the Compute library
const computeLib = require('@google-cloud/compute');
Expand All @@ -28,14 +28,14 @@ async function main(reservationName) {
const zoneOperationsClient = new computeLib.ZoneOperationsClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
* TODO(developer): Update these variables before running the sample.
*/
// The ID of the project where you want to reserve resources.
const projectId = await reservationsClient.getProjectId();
// The zone in which to reserve resources.
const zone = 'us-central1-a';
// The name of the reservation to create.
// const reservationName = 'reservation-01';
const reservationName = 'reservation-01';
// The number of VMs to reserve.
const vmsNumber = 3;
// Machine type to use for each VM.
Expand Down Expand Up @@ -96,14 +96,22 @@ async function main(reservationName) {
});
}

console.log(`Reservation: ${reservationName} created.`);
const createdReservation = (
await reservationsClient.get({
project: projectId,
zone,
reservation: reservationName,
})
)[0];

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

await callCreateComputeReservationFromProperties();
// [END compute_reservation_create]
}

main(...process.argv.slice(2)).catch(err => {
main().catch(err => {
console.error(err);
process.exitCode = 1;
});
16 changes: 12 additions & 4 deletions compute/reservations/createReservationInstanceTemplate.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'use strict';

async function main(reservationName, location, instanceTemplateName) {
async function main(location, instanceTemplateName) {
// [START compute_reservation_create_template]
// Import the Compute library
const computeLib = require('@google-cloud/compute');
Expand All @@ -28,14 +28,14 @@ async function main(reservationName, location, instanceTemplateName) {
const zoneOperationsClient = new computeLib.ZoneOperationsClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
* TODO(developer): Update these variables before running the sample.
*/
// The ID of the project where you want to reserve resources and where the instance template exists.
const projectId = await reservationsClient.getProjectId();
// The zone in which to reserve resources.
const zone = 'us-central1-a';
// The name of the reservation to create.
// const reservationName = 'reservation-01';
const reservationName = 'reservation-01';
// The number of VMs to reserve.
const vmsNumber = 3;

Expand Down Expand Up @@ -87,7 +87,15 @@ async function main(reservationName, location, instanceTemplateName) {
});
}

console.log(`Reservation: ${reservationName} created.`);
const createdReservation = (
await reservationsClient.get({
project: projectId,
zone,
reservation: reservationName,
})
)[0];

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

await callCreateComputeReservationInstanceTemplate();
Expand Down
34 changes: 20 additions & 14 deletions compute/reservations/createSharedReservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,33 @@

'use strict';

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

/**
* TODO(developer): Uncomment reservationsClient and zoneOperationsClient before running the sample.
*/
// Instantiate a reservationsClient
const reservationsClient = new computeLib.ReservationsClient();
// reservationsClient = new computeLib.ReservationsClient();
// Instantiate a zoneOperationsClient
const zoneOperationsClient = new computeLib.ZoneOperationsClient();
// zoneOperationsClient = new computeLib.ZoneOperationsClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
* TODO(developer): Update these variables before running the sample.
*/
// The ID of the project where you want to reserve resources and where the instance template exists.
const projectId = await reservationsClient.getProjectId();
// The zone in which to reserve resources.
const zone = 'us-central1-a';
// The name of the reservation to create.
// const reservationName = 'reservation-01';
const reservationName = 'reservation-01';
// The number of VMs to reserve.
const vmsNumber = 3;
// The name of an existing instance template.
// const instanceTemplateName = 'global-instance-template-name';
const instanceTemplateName = 'global-instance-template-name';
// The location of the instance template.
const location = 'global';

Expand All @@ -56,10 +60,9 @@ async function main(reservationName, instanceTemplateName) {
// The IDs of projects that can consume this reservation. You can include up to 100 consumer projects.
// These projects must be in the same organization as the owner project.
// Don't include the owner project. By default, it is already allowed to consume the reservation.
// TODO(developer): Uncomment and update with your consumerId before running the sample.
// consumerId: {
// projectId: 'consumerId',
// },
consumer_project_id: {
projectId: 'consumer_project_id',
},
},
});

Expand Down Expand Up @@ -95,7 +98,10 @@ async function main(reservationName, instanceTemplateName) {
// [END compute_reservation_create_shared]
}

main(...process.argv.slice(2)).catch(err => {
console.error(err);
process.exitCode = 1;
});
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;
// });
10 changes: 4 additions & 6 deletions compute/reservations/deleteReservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
'use strict';
async function main(reservationName) {
async function main() {
// [START compute_reservation_delete]
// Import the Compute library
const computeLib = require('@google-cloud/compute');
Expand All @@ -23,14 +23,14 @@ async function main(reservationName) {
// Instantiate a zoneOperationsClient
const zoneOperationsClient = new computeLib.ZoneOperationsClient();
/**
* TODO(developer): Update/uncomment these variables before running the sample.
* TODO(developer): Update these variables before running the sample.
*/
// The ID of the project where your reservation is located.
const projectId = await reservationsClient.getProjectId();
// The zone where your reservation is located.
const zone = 'us-central1-a';
// The name of the reservation to delete.
// const reservationName = 'reservation-01';
const reservationName = 'reservation-01';

async function callDeleteReservation() {
// Delete the reservation
Expand All @@ -50,13 +50,11 @@ async function main(reservationName) {
zone: operation.zone.split('/').pop(),
});
}

console.log(`Reservation: ${reservationName} deleted.`);
}
await callDeleteReservation();
// [END compute_reservation_delete]
}
main(...process.argv.slice(2)).catch(err => {
main().catch(err => {
console.error(err);
process.exitCode = 1;
});
8 changes: 4 additions & 4 deletions compute/reservations/getReservation.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

'use strict';

async function main(reservationName) {
async function main() {
// [START compute_reservation_get]
// Import the Compute library
const computeLib = require('@google-cloud/compute');
Expand All @@ -25,14 +25,14 @@ async function main(reservationName) {
const reservationsClient = new computeLib.ReservationsClient();

/**
* TODO(developer): Update/uncomment these variables before running the sample.
* TODO(developer): Update these variables before running the sample.
*/
// The ID of the project where your reservation is located.
const projectId = await reservationsClient.getProjectId();
// The zone where your reservation is located.
const zone = 'us-central1-a';
// The name of the reservation to return.
// const reservationName = 'reservation-01';
const reservationName = 'reservation-01';

async function callGetReservation() {
const requestedReservation = (
Expand All @@ -50,7 +50,7 @@ async function main(reservationName) {
// [END compute_reservation_get]
}

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

0 comments on commit a5a85e1

Please sign in to comment.