-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmad.py
145 lines (106 loc) · 3.48 KB
/
mad.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import argparse
import datetime
import cloud_data_types
import xml_operations
import data_structures
import logging
import random
parser = argparse.ArgumentParser(description="MAD Generator, simulator of Cloud life.")
parser.add_argument(
"--output-type",
choices=["opennebulaxml", "storagerecords"],
required=True,
help="Output type of MAD Generator. opennebulaxml (OpenNebula XML) or storagerecords (Storage Records)",
)
parser.add_argument(
"--count", type=int, required=True, help="The number of events to generate"
)
parser.add_argument(
"--start-time",
type=datetime.datetime.fromisoformat,
default=datetime.datetime.today(),
help="First TimeStamp of whole simulation - format YYYY-MM-DD",
)
parser.add_argument(
"--max-objects",
type=int,
required=True,
help="Max number of available existing objects",
)
# TODO: add average-filling (density)
parser.add_argument(
"--average-occupancy",
type=int,
default=50,
help="The percantage number of objects out of the maximum, which should exist on average",
)
# parser.add_argument(
# '--cron-interval',
# # type=datetime.time.fromisoformat,
# # default=datetime.datetime.now(),
# #TODO: add time filter
# help='Intreval of "cron-triggered" events'
# )
# TODO: know about interval and finish it
parser.add_argument(
"--users-count", type=int, default=20, help="Users using simulated cloud"
)
parser.add_argument(
"--groups-count", type=int, default=7, help="Groups in simulated cloud"
)
parser.add_argument(
"--cloud-name", type=str, default="MADCLOUD", help="name of the cloud"
)
# TODO: use name
parser.add_argument(
"--mode",
choices=["vm", "network", "storage"],
required=True,
help="In which mode will MAD Generator run",
)
parser.add_argument(
"-f", "--flood", action="store_true", default=False, help="Flood mode"
)
parser.add_argument(
"-d",
"--debug",
action="store_false",
default=True,
help="Enable debug mode with logs",
)
CONF = parser.parse_args()
logging.basicConfig(
level=logging.DEBUG,
format="%(asctime)s - %(filename)s:%(lineno)d - #%(process)d %(levelname)s: %(message)s",
)
if CONF.debug:
logging.disable(logging.CRITICAL)
logging.debug("Arguments parsed:")
logging.debug(CONF)
xml_operator = xml_operations.XmlOperator()
cloud_datastores = data_structures.Datastores()
for x in range(CONF.users_count):
user = cloud_data_types.User(CONF)
xml_operator.output(user)
if CONF.flood:
for x in range(random.randint(1, CONF.max_objects)):
vm = cloud_data_types.Vm(CONF)
vm.uname = cloud_data_types.User.users_dict[vm.uid]["uname"]
vm.gid = cloud_data_types.User.users_dict[vm.uid]["gid"]
vm.gname = cloud_data_types.User.users_dict[vm.uid]["gname"]
xml_operator.output(vm)
for z in range(10):
image = cloud_data_types.Image(CONF)
image.uname = cloud_data_types.User.users_dict[image.uid]["uname"]
image.gid = cloud_data_types.User.users_dict[image.uid]["gid"]
image.gname = cloud_data_types.User.users_dict[image.uid]["gname"]
datastore = cloud_datastores.getNewDatastore()
image.datastore_id = datastore["datastore_id"]
image.datastore = datastore["datastore"]
xml_operator.output(image)
for z in range(10):
host = cloud_data_types.Host()
xml_operator.output(host)
for z in range(10):
cluster = cloud_data_types.Cluster()
xml_operator.output(cluster)