-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver-resources.js
53 lines (42 loc) · 1.28 KB
/
server-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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { vmDetails } from "./vm-details.js";
import { serverDetails } from "./server-details.js";
export const findUsedResources = async (uri) => {
try {
const vms = await vmDetails(uri);
let usedResources = 0;
for (let x in vms.data.vms) {
usedResources += vms.data.vms[x]['vmMips'];
}
return usedResources;
}
catch (error) {
return error;
}
}
export const findRemainingResources = async (uri) =>{
try{
const serverDetail = await serverDetails(uri);
let usedResources = await findUsedResources(uri);
return serverDetail.data.server_details.total_mips-usedResources;
}
catch(error){
return error;
}
}
export const findWeight = async (uri) => {
try {
const serverDetail = await serverDetails(uri);
let usedResources = await findUsedResources(uri);
if (usedResources == 0)
usedResources = 1;
const weightOfServer = usedResources * serverDetail.data.server_details.unit_power_cost;
return weightOfServer;
}
catch (error) {
return error;
}
}
const uri = 'http://localhost:4000';
console.log(await findWeight(uri));
console.log(await findRemainingResources(uri));
console.log(await findUsedResources(uri));