-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm-mapping.js
45 lines (37 loc) · 1.44 KB
/
vm-mapping.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
// Fetching Servers details
import servers from './servers.json' assert {type: 'json'};
import vm from './test-vm.json' assert {type:"json"};
import { findWeight, findRemainingResources} from './server-resources.js';
import { serverDetails } from './server-details.js';
// console.log(servers)
export const findOptimalServer = async (vm,servers) => {
const Servers = servers.servers;
// console.log(Servers);
let optimalServer = { uri:null, server_id:null,weight:null };
let requiredResources = vm.vmMips;
for(let server of Servers){
let weightOfServer = await findWeight(server);
let remainingResources = await findRemainingResources(server);
if(remainingResources>=requiredResources){
if(!optimalServer['uri']){
optimalServer['uri']=server,
optimalServer['weight']=weightOfServer;
}
else{
if(weightOfServer<optimalServer['weight']){
optimalServer['uri']=server;
optimalServer['weight']=weightOfServer;
}
}
}
}
if(optimalServer['uri']){
let serverDetail = await serverDetails(optimalServer['uri'])
let serverId = serverDetail.data.server_details.server_id ;
optimalServer['server_id'] = serverId;
return optimalServer;
}
else
return {msg :"No Server Found on which we can put out virtual machine"};
}
// Calculating weight