-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvm_table.py
executable file
·46 lines (40 loc) · 1.5 KB
/
vm_table.py
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
#! /bin/bash
import csv
import gzip
import sys
from collections import defaultdict
def map_vm_to_cpu(fname):
max_cpu_count = 0
min_cpu_count = 100
vm_to_cpu = defaultdict(list);
cpu_pop = []
if fname.endswith('.csv.gz'):
with gzip.open(fname, "r") as csvDataFile:
vm_table = csv.reader(csvDataFile)
for vm in vm_table:
n_cpu = int(vm[9])
vm_to_cpu[vm[0]].append(n_cpu);
if max_cpu_count < n_cpu:
max_cpu_count = n_cpu
if n_cpu < min_cpu_count:
min_cpu_count = n_cpu;
cpu_pop.append(n_cpu)
return vm_to_cpu, max_cpu_count, min_cpu_count, cpu_pop;
if fname.endswith('.csv'):
with open(fname, "r") as csvDataFile:
vm_table = csv.reader(csvDataFile)
return vm_to_cpu;
print ("incorrect file formate: expect csv.gz or csv. file name: " + fname);
#def workload_generate(fname):
# if fname.endswith('.csv.gz'):
# with gzip.open(fname, "r") as csvDataFile:
# #open a csv writer
# vm_table = csv.reader(csvDataFile)
# for vm in vm_table:
#
#
# if fname.endswith('.csv'):
# with open(fname, "r") as csvDataFile:
# vm_table = csv.reader(csvDataFile)
# return vm_to_cpu;
# print ("incorrect file formate: expect csv.gz or csv. file name: " + fname);