()
| 17 | 'use strict'; |
| 18 | |
| 19 | async function main() { |
| 20 | // [START batch_create_persistent_disk_job] |
| 21 | // Imports the Batch library |
| 22 | const batchLib = require('@google-cloud/batch'); |
| 23 | const batch = batchLib.protos.google.cloud.batch.v1; |
| 24 | |
| 25 | // Instantiates a client |
| 26 | const batchClient = new batchLib.v1.BatchServiceClient(); |
| 27 | |
| 28 | /** |
| 29 | * TODO(developer): Update these variables before running the sample. |
| 30 | */ |
| 31 | // Project ID or project number of the Google Cloud project you want to use. |
| 32 | const projectId = await batchClient.getProjectId(); |
| 33 | // The name of the job that will be created. |
| 34 | // It needs to be unique for each project and region pair. |
| 35 | const jobName = 'batch-create-persistent-disk-job'; |
| 36 | // Name of the region you want to use to run the job. Regions that are |
| 37 | // available for Batch are listed on: https://cloud.google.com/batch/docs/get-started#locations |
| 38 | const region = 'europe-central2'; |
| 39 | // The name of an existing persistent disk. |
| 40 | const existingPersistentDiskName = 'existing-persistent-disk-name'; |
| 41 | // The name of the new persistent disk. |
| 42 | const newPersistentDiskName = 'new-persistent-disk-name'; |
| 43 | // The size of the new persistent disk in GB. |
| 44 | // The allowed sizes depend on the type of persistent disk, |
| 45 | // but the minimum is often 10 GB (10) and the maximum is often 64 TB (64000). |
| 46 | const diskSize = 10; |
| 47 | // The location of an existing persistent disk. For more info : |
| 48 | // https://cloud.google.com/batch/docs/create-run-job-storage#gcloud |
| 49 | const location = 'regions/us-central1'; |
| 50 | // The disk type of the new persistent disk, either pd-standard, |
| 51 | // pd-balanced, pd-ssd, or pd-extreme. For Batch jobs, the default is pd-balanced. |
| 52 | const newDiskType = 'pd-balanced'; |
| 53 | |
| 54 | // Define what will be done as part of the job. |
| 55 | const runnable = new batch.Runnable({ |
| 56 | script: new batch.Runnable.Script({ |
| 57 | commands: [ |
| 58 | '-c', |
| 59 | 'echo Hello world! This is task ${BATCH_TASK_INDEX}.' + |
| 60 | '>> /mnt/disks/NEW_PERSISTENT_DISK_NAME/output_task_${BATCH_TASK_INDEX}.txt', |
| 61 | ], |
| 62 | }), |
| 63 | }); |
| 64 | |
| 65 | // Define volumes and their parameters to be mounted to a VM. |
| 66 | const newVolume = new batch.Volume({ |
| 67 | deviceName: newPersistentDiskName, |
| 68 | mountPath: `/mnt/disks/${newPersistentDiskName}`, |
| 69 | mountOptions: ['rw', 'async'], |
| 70 | }); |
| 71 | |
| 72 | const existingVolume = new batch.Volume({ |
| 73 | deviceName: existingPersistentDiskName, |
| 74 | mountPath: `/mnt/disks/${existingPersistentDiskName}`, |
| 75 | }); |
| 76 |
no test coverage detected