-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathgcp.js
More file actions
98 lines (89 loc) · 2.44 KB
/
gcp.js
File metadata and controls
98 lines (89 loc) · 2.44 KB
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const {
binary2si,
reservedKubeletMemory,
reservedFromCores,
GB2MB,
hash,
} = require("./helpers");
const cmd = require("node-cmd");
const region = "us-east1";
const cloudProvider = "gcp";
const memType = "si";
const maxPodCount = 110;
const provisioningTimeScript = "./scripts/azure.launcher.sh";
//get the input data which generate by gcloud compute machine-types list --filter="zone:us-east1-b" > gcp.txt
const convertStrToArray = (str) => str.split(" ").filter((word) => word);
module.exports = function getGCPInstances(
inputFile,
pricingInput,
includeTime
) {
const input = getData(inputFile);
const instances = [];
for (let i = 0; i < input.length; i++) {
const totalMemory = GB2MB(parseInt(input[i].memory_gb, 10));
const totalCpuCores = parseInt(input[i].cpus, 10);
if (totalMemory <= 2000) {
continue;
}
const costPerHour =
pricingInput[`CP-COMPUTEENGINE-VMIMAGE-${input[i].name.toUpperCase()}`]?.[
region
];
const provisioningTime = includeTime
? parseInt(
cmd
.runSync(`bash ${provisioningTimeScript} ${input[i].name}`)
.data?.trim(),
10
)
: undefined;
instances.push({
id: hash(input[i].name),
name: input[i].name,
os: { memory: { value: 100, type: memType }, cpu: 100 },
kubelet: {
memory: {
value: Math.round(
binary2si(
reservedKubeletMemory({ value: totalMemory, type: memType })
)
),
type: "si",
},
cpu: reservedFromCores(totalCpuCores),
},
evictionThreshold: {
memory: { value: 100, type: "si" },
cpu: 0,
},
totalMemory: { value: totalMemory, type: memType },
totalCpu: totalCpuCores * 1000,
costPerHour,
maxPodCount,
provisioningTime,
cloudProvider,
});
}
return instances;
};
function getData(inputFile) {
const textToArray = inputFile
.split("\n")
.filter((it) => it.trim().length > 0);
const headers = convertStrToArray(textToArray[0]).map((header) =>
header.toLowerCase()
);
const output = [];
for (const data of textToArray.slice(1)) {
const dataToArray = convertStrToArray(data);
output.push(
headers.reduce(
(all, header, index) =>
(all = { ...all, [header]: dataToArray[index] || "" }),
{}
)
);
}
return output.filter((it) => it.deprecated === "");
}