Skip to content

Commit

Permalink
code refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
gryczj committed Aug 22, 2024
1 parent 5e508c1 commit 88e40e8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 64 deletions.
2 changes: 1 addition & 1 deletion compute/disks/createComputeHyperdiskFromPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async function main() {
// The name of the new disk
const diskName = 'disk-name';
// The name of the storage pool
const storagePoolName = 'storage-pool-hyperdisk';
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
18 changes: 2 additions & 16 deletions compute/test/createComputeHyperdiskFromPool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,39 +20,25 @@ const path = require('path');
const {assert} = require('chai');
const {describe, it} = require('mocha');
const cp = require('child_process');
const {StoragePoolsClient} = require('@google-cloud/compute');
const {DisksClient} = require('@google-cloud/compute').v1;
const {createStoragePool, deleteStoragePool, deleteDisk} = require('./util');
const {deleteDisk} = require('./util');

const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
const cwd = path.join(__dirname, '..');

describe('Create compute hyperdisk from pool', async () => {
const diskName = 'disk-name';
const zone = 'europe-central2-b';
const storagePoolName = 'storage-pool-hyperdisk';
const storagePoolName = 'storage-pool-name';
const disksClient = new DisksClient();
const storagePoolsClient = new StoragePoolsClient();
let projectId;

before(async () => {
projectId = await disksClient.getProjectId();
await createStoragePool(
storagePoolsClient,
projectId,
zone,
storagePoolName
);
});

after(async () => {
await deleteDisk(disksClient, projectId, zone, diskName);
await deleteStoragePool(
storagePoolsClient,
projectId,
zone,
storagePoolName
);
});

it('should create a new hyperdisk from pool', () => {
Expand Down
48 changes: 1 addition & 47 deletions compute/test/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,51 +90,7 @@ async function deleteDisk(disksClient, projectId, zone, diskName) {
zone,
});
} catch (err) {
console.error('Deleting job failed: ', err);
throw new Error(err);
}
}

async function createStoragePool(
storagePoolsClient,
projectId,
zone,
storagePoolName
) {
try {
await storagePoolsClient.insert({
project: projectId,
storagePoolResource: {
name: storagePoolName,
poolProvisionedCapacityGb: 10240,
poolProvisionedIops: 10000,
poolProvisionedThroughput: 1024,
storagePoolType: `projects/${projectId}/zones/${zone}/storagePoolTypes/hyperdisk-balanced`,
capacityProvisioningType: 'advanced',
zone,
},
zone,
});
} catch (err) {
console.error('Creating storage pool failed: ', err);
throw new Error(err);
}
}

async function deleteStoragePool(
storagePoolsClient,
projectId,
zone,
storagePoolName
) {
try {
await storagePoolsClient.delete({
project: projectId,
storagePool: storagePoolName,
zone,
});
} catch (err) {
console.error('Deleting storage pool failed: ', err);
console.error('Deleting disk failed: ', err);
throw new Error(err);
}
}
Expand All @@ -144,6 +100,4 @@ module.exports = {
getStaleVMInstances,
deleteInstance,
deleteDisk,
createStoragePool,
deleteStoragePool,
};

0 comments on commit 88e40e8

Please sign in to comment.