-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm-resources.js
34 lines (29 loc) · 1.04 KB
/
vm-resources.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { vmDetails } from "./vm-details.js";
import { serverDetails } from "./server-details.js";
// import { findWeight } from "./server-resources.js";
export const findExecutionTime = (task, vmMips) => {
return task['taskLength'] / vmMips + task['communicationCost'];
}
export const populateVMWeights = async (uri) => {
try {
const vmsData = await vmDetails(uri);
let vms = vmsData.data.vms;
const serverDetail = await serverDetails(uri);
let res = [];
let unit_power_cost = serverDetail.data.server_details.unit_power_cost;
for (let vm of vms) {
let sumOfExecTime = 0;
let vmMips = vm['vmMips'];
for (let task of vm['task']) {
sumOfExecTime += findExecutionTime(task, vmMips);
}
let weight = sumOfExecTime*unit_power_cost;
res.push({weight,...vm});
}
return {vms:res};
}
catch (error) {
return error;
}
}
// console.log(await populateVMWeights('http://localhost:4000'));