def set_vm_count(self, trace_file, total_vm): self.total_vm = total_vm self.vmm = VMManager(trace_file, total_vm)
class Manager: def __init__(self): self.placement = [] self.total_pm = 0 self.total_vm = 0 self.vmm = None self.pmm = None self.strategy = None def set_vm_count(self, trace_file, total_vm): self.total_vm = total_vm self.vmm = VMManager(trace_file, total_vm) def set_pm_count(self, total_pm): self.total_pm = total_pm self.pmm = PMManager(total_pm) def set_strategy(self, strategy): self.strategy = strategy self.strategy.set_vmm(self.vmm) self.strategy.pmm = self.pmm def place_vms(self, vms, host): i = 0 while i < len(vms): vm = vms[i] host.place_vm(vm) print('{}'.format(host)) i += 1 self.vmm.items_remove(vms) def placed_vms(self): result = 0 for host in self.pmm.items: result += len(host.vms) return result def unplaced_vms(self): return self.total_vm - self.placed_vms() def solve_hosts(self): for host in self.pmm.items: if self.vmm.items != []: solution = self.strategy.solve_host() vms = self.strategy.get_vm_objects(solution) if vms is not None: self.place_vms(vms, host) else: if not isinstance(self.strategy, EnergyUnawareStrategyPlacement): host.suspend() print(host) def calculate_power_consumed(self): result = 0 for host in self.pmm.items: result += host.estimate_consumed_power() return result def calculate_physical_hosts_used(self): result = 0 for host in self.pmm.items: if host.vms != []: result += 1 return result def calculate_physical_hosts_suspended(self): result = 0 for host in self.pmm.items: if host.suspended: result += 1 return result def calculate_physical_hosts_idle(self): result = 0 for host in self.pmm.items: if host.vms == [] and not host.suspended: result += 1 return result
class Manager: def __init__(self): add_physical_hosts_factory = None add_physical_hosts_args = None self.placement = [] self.total_pm = 0 self.total_vm = 0 self.vmm = None self.pmm = None self.strategy = None def set_vm_count(self, trace_file, total_vm): self.total_vm = total_vm self.vmm = VMManager(trace_file, total_vm) def set_pm_count(self, total_pm): self.total_pm = total_pm self.pmm = PMManager(total_pm) def set_strategy(self, strategy): self.strategy = strategy self.strategy.set_vmm(self.vmm) self.strategy.pmm = self.pmm def place_vms(self, vms, host): i = 0 while i < len(vms): vm = vms[i] host.place_vm(vm) print("{}".format(host)) i += 1 self.vmm.items_remove(vms) def placed_vms(self): result = 0 for host in self.pmm.items: result += len(host.vms) return result def unplaced_vms(self): return self.total_vm - self.placed_vms() # def solve_hosts(self): # for host in self.pmm.items: # if self.vmm.items != []: # solution = self.strategy.solve_host() # vms = self.strategy.get_vm_objects(solution) # if vms is not None: # self.place_vms(vms, host) # else: # if not isinstance(self.strategy, EnergyUnawareStrategyPlacement): # host.suspend() # print(host) def calculate_power_consumed(self): result = 0 for host in self.pmm.items: result += host.estimate_consumed_power() return result def calculate_physical_hosts_used(self): result = 0 for host in self.pmm.items: if host.vms != []: result += 1 return result def calculate_physical_hosts_suspended(self): result = 0 for host in self.pmm.items: if host.suspended: result += 1 return result def calculate_physical_hosts_idle(self): result = 0 for host in self.pmm.items: if host.vms == [] and not host.suspended: result += 1 return result def add_physical_host(self, host): print("add_physical_host: {}".format(host)) def add_physical_hosts(self, host=None): if self.add_physical_hosts_factory: result = self.add_physical_hosts_factory(self.add_physical_hosts_args) for host in result: self.add_physical_host(host) else: self.add_physical_host(host) def execute(config, state): print("execute method") def start(self): """ Start the local manager loop. :return: The final state. :rtype: dict(str: *) """ self.config = read_and_validate_config() config = self.config common.init_logging(config["log_directory"], __file__ + ".log", int(config["log_level"])) interval = int(config["clock_tick_interval"]) / 1000.0 if log.isEnabledFor(logging.INFO): log.info("Starting the global manager, " + "iterations every %s seconds", interval) # it auto-starts, no need of rt.start() # rt = RepeatedTimer(interval, hello, "World") import pdb pdb.set_trace() # BREAKPOINT rt = RepeatedTimer(interval, self.execute, config) rt.start() # rt = RepeatedTimer(interval, callback, "") try: # your long-running job goes here... # sleep(5) # state = init_state(config) while True: time.sleep(1) # return common.start( # init_state, # execute, # config, # int(interval)) finally: # better in a try/finally block to make sure the program ends! rt.stop()