diff --git a/src/lib/cloud-instance-metadata/index.test.ts b/src/lib/cloud-instance-metadata/index.test.ts index 5fd712cfc..e1b365bb4 100644 --- a/src/lib/cloud-instance-metadata/index.test.ts +++ b/src/lib/cloud-instance-metadata/index.test.ts @@ -1,10 +1,29 @@ import {describe, expect, jest, test} from '@jest/globals'; import {CloudInstanceMetadataModel} from './index'; + jest.setTimeout(30000); describe('ccf:configure test', () => { test('initialize and test', async () => { const model = await new CloudInstanceMetadataModel().configure('ccf', {}); expect(model).toBeInstanceOf(CloudInstanceMetadataModel); + await expect( + model.calculate([ + { + 'cloud-instance-type': 't2.micro', + 'cloud-vendor': 'aws', + }, + ]) + ).resolves.toStrictEqual( + expect.arrayContaining([ + { + 'cloud-instance-type': 't2.micro', + 'cloud-vendor': 'aws', + 'physical-processor': 'Intel Xeon E5-2676 v3', + 'vcpus-allocated': '1', + 'vcpus-total': '48', + }, + ]) + ); }); }); diff --git a/src/lib/cloud-instance-metadata/index.ts b/src/lib/cloud-instance-metadata/index.ts index 4080bcf30..9a491e96d 100644 --- a/src/lib/cloud-instance-metadata/index.ts +++ b/src/lib/cloud-instance-metadata/index.ts @@ -49,6 +49,28 @@ export class CloudInstanceMetadataModel implements IImpactModelInterface { 'Each observation must contain a cloud-instance-type key' ); } + + const instance = AWS_INSTANCES.find( + instance => instance['Instance type'] === instance_type + ); + if (instance) { + console.log(instance); + console.log(vendor); + observation['vcpus-allocated'] = instance['Instance vCPU']; + observation['vcpus-total'] = instance['Platform Total Number of vCPU']; + const cpuType = instance['Platform CPU Name']; + let platform = ''; + if (cpuType.startsWith('EPYC')) { + platform = 'AMD'; + } else if (cpuType.startsWith('Xeon')) { + platform = 'Intel'; + } else if (cpuType.startsWith('Graviton')) { + platform = 'AWS'; + } else if (cpuType.startsWith('Core')) { + platform = 'Intel'; + } + observation['physical-processor'] = `${platform} ${cpuType}`; + } return observation; }); }