-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSimulation_large.py
74 lines (64 loc) · 2.43 KB
/
Simulation_large.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
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
import argparse
import os
import errno
import random
import libs.VirtualMachine as vm
import libs.PhysicalMachine as pm
import libs.MigrationManager as mm
def mkdir_p(path):
try:
os.makedirs(path)
except OSError as exc: # Python >2.5
if exc.errno == errno.EEXIST and os.path.isdir(path):
pass
else: raise
def main():
parser = argparse.ArgumentParser( \
description='VM migration simulator', \
formatter_class=argparse.ArgumentDefaultsHelpFormatter)
migrationAlgorithms = ("random load_aware load_aware_woi migration_likelihood migration_likelihood_woi sandpiper").split()
parser.add_argument('--strategy',
help = 'Migration algorithms: ' + ' '.join(migrationAlgorithms),
default = migrationAlgorithms[0])
parser.add_argument('--normalizationperiod',
type = int,
help = 'Load normalization: 0 if inactive, 10 for every ten steps',
default = 0)
parser.add_argument('--outdir',
help = 'Destination folder for results and logs',
default = 'results')
parser.add_argument('--steps',
type = int,
help = 'Simulation steps',
default = 500)
args = parser.parse_args()
strategy = args.strategy
if strategy not in migrationAlgorithms:
print "Unsupported migration algorithm %s"%format(strategy)
parser.print_help()
quit()
mkdir_p(args.outdir)
# ---------------------------------------------------------------------------
# simulation: defining data center
physical_machines = list()
npm = 150
for i in range(0,npm):
physical_machines.append(pm.PhysicalMachine(16))
virtual_machines = list()
for i in range(0,30):
virtual_machines.append(vm.VirtualMachine(physical_machines[random.choice(range(0,npm))],'gold', 2))
for i in range(0,70):
virtual_machines.append(vm.VirtualMachine(physical_machines[random.choice(range(0,npm))],'silver', 1))
for i in range(0,100):
virtual_machines.append(vm.VirtualMachine(physical_machines[random.choice(range(0,npm))],'bronze', 6))
for i in range(0,200):
virtual_machines.append(vm.VirtualMachine(physical_machines[random.choice(range(0,npm))],'basic', 8))
# ---------------------------------------------------------------------------
migration_manager = mm.MigrationManager(args.outdir, args.strategy, physical_machines, \
virtual_machines, args.normalizationperiod)
for i in range(0, args.steps):
# generate actual loads (random number, method defined in VirtualMachine)
[x.execute() for x in virtual_machines]
migration_manager.execute(i)
if __name__ == "__main__":
main()