+
+ def _write_log(self, d, path, action):
+ """
+ Helper to log RM info for experiments.
+ :param d: container
+ :param path: log path
+ :param action: allocate or free
+ :return:
+ """
+ if path is None:
+ return
+ # we have a path: write out RM info
+ l = dict()
+ l["t"] = time.time()
+ l["container_state"] = d.getStatus()
+ l["action"] = action
+ l["rm_state"] = self.get_state_dict()
+ # append to logfile
+ with open(path, "a") as f:
+ f.write("%s\n" % json.dumps(l))
+
+
+class UpbOverprovisioningCloudDcRM(UpbSimpleCloudDcRM):
+ """
+ This will be an example resource model that limits the overall
+ resources that can be deployed per data center.
+ Allows over provisioning. Might result in reducing resources of single
+ containers whenever a data-center is over provisioned.
+ """
+ # TODO add parts for memory
+ def __init__(self, *args, **kvargs):
+ super(UpbOverprovisioningCloudDcRM, self).__init__(*args, **kvargs)
+ self.raise_no_cpu_resources_left = False
+
+ def _compute_single_cu(self):
+ """
+ Calculate percentage of CPU time of a singe CU unit.
+ Take scale-down facte for over provisioning into account.
+ :return:
+ """
+ # get cpu time fraction for entire emulation
+ e_cpu = self.registrar.e_cpu
+ # calculate over provisioning scale factor
+ self.cpu_op_factor = float(self.dc_max_cu) / (max(self.dc_max_cu, self.dc_alloc_cu))
+ # calculate
+ return float(e_cpu) / sum([rm.dc_max_cu for rm in list(self.registrar.resource_models)]) * self.cpu_op_factor
+
+
+class UpbDummyRM(UpbSimpleCloudDcRM):
+ """
+ No limits. But log allocations.
+ """
+ def __init__(self, *args, **kvargs):
+ super(UpbDummyRM, self).__init__(*args, **kvargs)
+ self.raise_no_cpu_resources_left = False
+
+ def _apply_limits(self):
+ # do nothing here
+ pass
+