-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfleet_classes.py
More file actions
172 lines (147 loc) · 6.16 KB
/
Copy pathfleet_classes.py
File metadata and controls
172 lines (147 loc) · 6.16 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
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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
"""This script contains the data classes that are used in the fleet offer search."""
import copy
# from external_functions import calculate_group_score, calculate_offer_score
class Component(object):
"""Component class."""
def __init__(self, app_index, app_name, component_specs):
"""Initialize class."""
self.memory = float(component_specs["memory"])
self.vCPUs = float(component_specs["vCPUs"])
self.network = (
float(component_specs["network"]) if "network" in component_specs else 0.0
)
self.affinity = self.affinity_list(component_specs)
self.anti_affinity = self.anti_affinity_list(component_specs)
self.behavior = (
component_specs["behavior"]
if "behavior" in component_specs
else "terminate"
)
self.interruption_frequency = (
int(component_specs["frequency"]) if "frequency" in component_specs else 4
)
self.storage_size = (
float(component_specs["size"]) if "size" in component_specs else 0
)
self.iops = (
float(component_specs["iops"])
if "iops" in component_specs and component_specs["iops"] is not None
else 0
)
self.throughput = (
float(component_specs["throughput"])
if "throughput" in component_specs
and component_specs["throughput"] is not None
else 0
)
self.storage_type = (
component_specs["storageType"]
if "storageType" in component_specs
and component_specs["storageType"] is not None
else "all"
)
self.burstable = True
if self.network > 0:
self.burstable = (
component_specs["burstable"] is True
if "burstable" in component_specs
else False
)
self.app_index = app_index
self.app_name = app_name
self.component_name = component_specs["name"]
self.storage_offer = None
def get_component_name(self):
"""Get Component name function."""
return self.component_name
def affinity_list(self,component_specs):
afl = component_specs["affinity"].split(",") if "affinity" in component_specs else None
afl.append(component_specs["name"]) if afl is not None else None
return afl
def anti_affinity_list(self,component_specs):
if "antiaffinity" in component_specs:
component_specs["anti-affinity"] = component_specs.pop("antiaffinity")
afl = component_specs["anti-affinity"].split(",") if "anti-affinity" in component_specs else None
afl.append(component_specs["name"]) if afl is not None else None
return afl
class GroupedParam(object):
"""Group (sum) all the parameters values together."""
def __init__(self, params, app_sizes):
"""Initialize class."""
self.params = params
self.total_vcpus = 0
self.total_memory = 0
for p in params:
self.total_vcpus += p.vCPUs
self.total_memory += p.memory
self.network = sum(map(lambda p: p.network, params))
behaviors = map(lambda p: p.behavior, params)
self.behavior = (
"hibernation"
if "hibernation" in behaviors
else ("stop" if "stop" in behaviors else "terminate")
)
self.interruption_frequency = min(
map(lambda p: p.interruption_frequency, params)
)
# self.score = calculate_group_score(params,app_sizes)
self.burstable = False if False in map(lambda p: p.burstable, params) else True
self.storage_price = (
0 ## intead of 0 = sum(map(lambda p: p.storage_offer.storage_price,params))
)
##in case EBS should be calculated
def get_info(self):
"""Get params function."""
return self.params
class ComponentOffer(object):
"""Component offer Class."""
def __init__(self, app_name, component_name):
"""Initialize class."""
self.app_name = app_name
self.component_name = component_name
# self.ebs_instance = ebs_instance
self.storage_price = 0 ## = storage_price # in case EBS should be calculated
def get_component(self):
"""Get list of components function."""
return [self.component_name]
class GroupedInstance(object):
"""Offer for each combination class."""
def __init__(self, instance, components, pricing):
"""Initialize class."""
self.spot_price = round(float(instance["spot_price"]), 5) if isinstance(instance["spot_price"],float) else 100000
self.discount = instance["discount"]
self.components = components
self.instance = instance
# self.region = instance['region'] ##cross region option
self.onDemand = round(float(instance["onDemandPrice"]), 5)
if pricing == "spot":
self.total_price = self.spot_price * (
1 - (self.discount) / 100
) ##+ sum(map(lambda c: c.storage_price,components)) in case EBS should be calculated
else:
self.total_price = self.onDemand * (
1 - (self.discount) / 100
) ##+ sum(map(lambda c: c.storage_price,components)) in case EBS should be calculated
def get_info(self):
"""Get Component function."""
return self.components
class Offer(object):
"""Offer Class."""
def __init__(self, partitions, app_sizes):
"""Initialize class."""
self.remaining_partitions = list(
map(lambda p: GroupedParam(p, app_sizes), partitions)
)
# self.onDemand = sum(map(lambda p: p.storage_price,self.remaining_partitions))
self.total_price = sum(
map(lambda p: p.storage_price, self.remaining_partitions)
)
self.instance_groups = []
self.region = ""
# self.score = calculate_offer_score(self.remaining_partitions) ## currently not relevant
def get_info(self):
"""Get remaining partitions function."""
return self.remaining_partitions
def copy_group(self):
"""Copy group function."""
return copy.deepcopy(self)