def run(self): def _print_error(msg): print "! " + msg # Load scheduler tree from yaml file content = open(self.file, 'r').read() tree_config = yaml.load(content) Universe.get_tree().load_schedulers(tree_config, _print_error)
def run(self): self.setup_schedulers() # pprint(self.tree_config) def _print_error(msg): print "! " + msg Universe.get_tree().load_schedulers(self.tree_config, _print_error)
def check_placement(results): for request, response in results: request = request.place_request resource = request.resource request_constraints = resource.vm.resource_constraints if request_constraints: host = Universe.get_tree().get_scheduler(response.agent_id) nw_constraints = [ c.values[0] for c in host.constraints if c.type == RCType.NETWORK ] ds_constraints = [ c.values[0] for c in host.constraints if c.type == RCType.DATASTORE ] for constraint in request_constraints: if constraint.type == RCType.NETWORK: if constraint.values[0] not in nw_constraints: raise ConstraintError(resource.vm.id, constraint.values[0], host.id) if constraint.type == RCType.DATASTORE: if constraint.values[0] not in ds_constraints: raise ConstraintError(resource.vm.id, constraint.values[0], host.id)
def get_child_objects(self): from psim.universe import Universe schedulers = Universe.get_tree().schedulers for cid in self._child_ids: if cid not in schedulers: raise ConfigError("Child '%d' of scheduler '%d' not found" % (cid, self.id)) self.adopt_child(schedulers[cid])
def place(self, request): try: response = Universe.get_tree().root_scheduler.place(request) sys.stdout.write('.') return response except Exception, e: self._logger.error(e) traceback.print_exc(file=sys.stdout) sys.stdout.write('F') return None
def tabulate_hosts(): hosts = [h for h in Universe.get_tree().schedulers.values() if isinstance(h, Host)] rows = [] for h in hosts: rows.append(h.get_info()) header = ["Host Id", "VM Count", "Mem", "Used Mem", "Mem. Consumed", "Disk", "Used Disk", "Constraints"] return tabulate(rows, headers=header, tablefmt="rst")
def run(self): if not Universe.get_tree().root_scheduler: raise PreconditionError("Root scheduler is not configured." + "Please run load_tree first.") self.register_services() requests = Requests(self.requests_file) create_queue = {} results = [] reserve_failures = [] create_failures = [] sys.stdout.write('Running') for index, request in enumerate(requests.requests): self._logger.info("Req #%d: %s", index + 1, request.place_request) response = self.place(request.place_request) if response: results.append((request, response)) # Generate the "iteration" when this place will be created. create_index = min(len(requests.requests) - 1, self.create_interval + index) if create_index not in create_queue: create_queue[create_index] = collections.deque() create_queue[create_index].appendleft((request, response)) # If there are requests to create for this iteration, do so. if index in create_queue: queue = create_queue[index] while queue: request, response = queue.pop() if response.result == PlaceResultCode.OK: agent = Universe.get_tree().get_scheduler( response.agent_id) self.reserve_and_create(request, agent, response, reserve_failures, create_failures) create_queue.pop(index) assert len(create_queue) == 0 Universe.results = Results(results, reserve_failures, create_failures) print "Done"
def run(self): if not Universe.get_tree().root_scheduler: raise PreconditionError("Root scheduler is not configured." + "Please run load_tree first.") self.register_services() requests = Requests(self.requests_file) create_queue = {} results = [] reserve_failures = [] create_failures = [] sys.stdout.write('Running') for index, request in enumerate(requests.requests): self._logger.info("Req #%d: %s", index + 1, request.place_request) response = self.place(request.place_request) if response: results.append((request, response)) # Generate the "iteration" when this place will be created. create_index = min( len(requests.requests) - 1, self.create_interval + index) if create_index not in create_queue: create_queue[create_index] = collections.deque() create_queue[create_index].appendleft((request, response)) # If there are requests to create for this iteration, do so. if index in create_queue: queue = create_queue[index] while queue: request, response = queue.pop() if response.result == PlaceResultCode.OK: agent = Universe.get_tree().get_scheduler( response.agent_id) self.reserve_and_create(request, agent, response, reserve_failures, create_failures) create_queue.pop(index) assert len(create_queue) == 0 Universe.results = Results(results, reserve_failures, create_failures) print "Done"
def tabulate_hosts(): hosts = [ h for h in Universe.get_tree().schedulers.values() if isinstance(h, Host) ] rows = [] for h in hosts: rows.append(h.get_info()) header = [ "Host Id", "VM Count", "Mem", "Used Mem", "Mem. Consumed", "Disk", "Used Disk", "Constraints" ] return tabulate(rows, headers=header, tablefmt="rst")
def tabulate_stats(): hosts = [h for h in Universe.get_tree().schedulers.values() if isinstance(h, Host)] hypervisors = [(h.id, h.hypervisor.hypervisor) for h in hosts] mem_stats = StatsHelper(dict( (id, x.system.memory_info().used) for (id, x) in hypervisors)) disk_stats = StatsHelper(dict( (id, x.total_datastore_info().used) for (id, x) in hypervisors)) vm_stats = StatsHelper(dict( (id, len(x.vm_manager._resources)) for (id, x) in hypervisors)) header = ["Memory Mean (MB)", "Memory Std. Dev. (MB)", "Disk Mean (GB)", "Disk Std. Dev. (GB)", "VM Count Mean", "VM Count Std. Dev."] row = [(mem_stats.mean(), mem_stats.stddev(), disk_stats.mean(), disk_stats.stddev(), vm_stats.mean(), vm_stats.stddev())] return tabulate(row, headers=header, tablefmt="rst")
def check_hosts(self): hosts = [ h for h in Universe.get_tree().schedulers.values() if isinstance(h, Host) ] hypervisors = [(h.id, h.hypervisor.hypervisor) for h in hosts] mem_stats = StatsHelper( dict((id, x.system.memory_info().used) for (id, x) in hypervisors)) disk_stats = StatsHelper( dict((id, x.total_datastore_info().used) for (id, x) in hypervisors)) if self.expected: # We do not do an exact compare of stddev and # mean. We check if it is within 10% of the # expected self.check_stat(mem_stats.stddev(), self.expected['mem_std_dev']) self.check_stat(mem_stats.mean(), self.expected['mem_mean']) self.check_stat(disk_stats.stddev(), self.expected['disk_std_dev']) self.check_stat(disk_stats.mean(), self.expected['disk_mean'])
def check_hosts(self): hosts = [h for h in Universe.get_tree().schedulers.values() if isinstance(h, Host)] hypervisors = [(h.id, h.hypervisor.hypervisor) for h in hosts] mem_stats = StatsHelper(dict( (id, x.system.memory_info().used) for (id, x) in hypervisors)) disk_stats = StatsHelper(dict( (id, x.total_datastore_info().used) for (id, x) in hypervisors)) if self.expected: # We do not do an exact compare of stddev and # mean. We check if it is within 10% of the # expected self.check_stat(mem_stats.stddev(), self.expected['mem_std_dev']) self.check_stat(mem_stats.mean(), self.expected['mem_mean']) self.check_stat(disk_stats.stddev(), self.expected['disk_std_dev']) self.check_stat(disk_stats.mean(), self.expected['disk_mean'])
def tabulate_stats(): hosts = [ h for h in Universe.get_tree().schedulers.values() if isinstance(h, Host) ] hypervisors = [(h.id, h.hypervisor.hypervisor) for h in hosts] mem_stats = StatsHelper( dict((id, x.system.memory_info().used) for (id, x) in hypervisors)) disk_stats = StatsHelper( dict((id, x.total_datastore_info().used) for (id, x) in hypervisors)) vm_stats = StatsHelper( dict( (id, len(x.vm_manager._resources)) for (id, x) in hypervisors)) header = [ "Memory Mean (MB)", "Memory Std. Dev. (MB)", "Disk Mean (GB)", "Disk Std. Dev. (GB)", "VM Count Mean", "VM Count Std. Dev." ] row = [(mem_stats.mean(), mem_stats.stddev(), disk_stats.mean(), disk_stats.stddev(), vm_stats.mean(), vm_stats.stddev())] return tabulate(row, headers=header, tablefmt="rst")
def check_placement(results): for request, response in results: request = request.place_request resource = request.resource request_constraints = resource.vm.resource_constraints if request_constraints: host = Universe.get_tree().get_scheduler( response.agent_id) nw_constraints = [c.values[0] for c in host.constraints if c.type == RCType.NETWORK] ds_constraints = [c.values[0] for c in host.constraints if c.type == RCType.DATASTORE] for constraint in request_constraints: if constraint.type == RCType.NETWORK: if constraint.values[0] not in nw_constraints: raise ConstraintError(resource.vm.id, constraint.values[0], host.id) if constraint.type == RCType.DATASTORE: if constraint.values[0] not in ds_constraints: raise ConstraintError(resource.vm.id, constraint.values[0], host.id)
def run(self): Universe.get_tree().pretty_print()