def _run_instance(self, message, host_sched_kwargs): """Attempt to schedule instance(s). If we have no cells to try, raise exception.NoCellsAvailable """ ctxt = message.ctxt request_spec = host_sched_kwargs['request_spec'] # The message we might forward to a child cell cells = self._get_possible_cells() if not cells: raise exception.NoCellsAvailable() cells = list(cells) # Random selection for now random.shuffle(cells) target_cell = cells[0] LOG.debug(_("Scheduling with routing_path=%(routing_path)s"), locals()) if target_cell.is_me: # Need to create instance DB entries as the host scheduler # expects that the instance(s) already exists. self._create_instances_here(ctxt, request_spec) # Need to record the create action in the db as the scheduler # expects it to already exist. self._create_action_here(ctxt, request_spec['instance_uuids']) self.scheduler_rpcapi.run_instance(ctxt, **host_sched_kwargs) return self.msg_runner.schedule_run_instance(ctxt, target_cell, host_sched_kwargs)
def _build_instances(self, message, target_cells, instance_uuids, build_inst_kwargs): """Attempt to build instance(s) or send msg to child cell.""" ctxt = message.ctxt instance_properties = build_inst_kwargs['instances'][0] filter_properties = build_inst_kwargs['filter_properties'] instance_type = filter_properties['instance_type'] image = build_inst_kwargs['image'] security_groups = build_inst_kwargs['security_groups'] block_device_mapping = build_inst_kwargs['block_device_mapping'] LOG.debug(_("Building instances with routing_path=%(routing_path)s"), {'routing_path': message.routing_path}) for target_cell in target_cells: try: if target_cell.is_me: # Need to create instance DB entries as the conductor # expects that the instance(s) already exists. self._create_instances_here(ctxt, instance_uuids, instance_properties, instance_type, image, security_groups, block_device_mapping) # Need to record the create action in the db as the # conductor expects it to already exist. self._create_action_here(ctxt, instance_uuids) self.compute_task_api.build_instances( ctxt, **build_inst_kwargs) return self.msg_runner.build_instances(ctxt, target_cell, build_inst_kwargs) return except Exception: LOG.exception( _("Couldn't communicate with cell '%s'") % target_cell.name) # FIXME(comstud): Would be nice to kick this back up so that # the parent cell could retry, if we had a parent. msg = _("Couldn't communicate with any cells") LOG.error(msg) raise exception.NoCellsAvailable()
def _run_instance(self, message, target_cells, instance_uuids, host_sched_kwargs): """Attempt to schedule instance(s).""" ctxt = message.ctxt request_spec = host_sched_kwargs['request_spec'] instance_properties = request_spec['instance_properties'] instance_type = request_spec['instance_type'] image = request_spec['image'] security_groups = request_spec['security_group'] block_device_mapping = request_spec['block_device_mapping'] LOG.debug(_("Scheduling with routing_path=%(routing_path)s"), {'routing_path': message.routing_path}) for target_cell in target_cells: try: if target_cell.is_me: # Need to create instance DB entries as the host scheduler # expects that the instance(s) already exists. self._create_instances_here(ctxt, instance_uuids, instance_properties, instance_type, image, security_groups, block_device_mapping) # Need to record the create action in the db as the # scheduler expects it to already exist. self._create_action_here(ctxt, instance_uuids) self.scheduler_rpcapi.run_instance(ctxt, **host_sched_kwargs) return self.msg_runner.schedule_run_instance(ctxt, target_cell, host_sched_kwargs) return except Exception: LOG.exception( _("Couldn't communicate with cell '%s'") % target_cell.name) # FIXME(comstud): Would be nice to kick this back up so that # the parent cell could retry, if we had a parent. msg = _("Couldn't communicate with any cells") LOG.error(msg) raise exception.NoCellsAvailable()
def _grab_target_cells(self, filter_properties): cells = self._get_possible_cells() cells = self.filter_handler.get_filtered_objects( self.filter_classes, cells, filter_properties) # NOTE(comstud): I know this reads weird, but the 'if's are nested # this way to optimize for the common case where 'cells' is a list # containing at least 1 entry. if not cells: if cells is None: # None means to bypass further scheduling as a filter # took care of everything. return raise exception.NoCellsAvailable() weighted_cells = self.weight_handler.get_weighed_objects( self.weigher_classes, cells, filter_properties) LOG.debug(_("Weighted cells: %(weighted_cells)s"), {'weighted_cells': weighted_cells}) target_cells = [cell.obj for cell in weighted_cells] return target_cells
def fake_grab_target_cells(filter_properties): call_info['num_tries'] += 1 raise exception.NoCellsAvailable()
def _run_instance(self, message, host_sched_kwargs): """Attempt to schedule instance(s). If we have no cells to try, raise exception.NoCellsAvailable """ ctxt = message.ctxt routing_path = message.routing_path request_spec = host_sched_kwargs['request_spec'] LOG.debug(_("Scheduling with routing_path=%(routing_path)s"), {'routing_path': routing_path}) filter_properties = copy.copy(host_sched_kwargs['filter_properties']) filter_properties.update({ 'context': ctxt, 'scheduler': self, 'routing_path': routing_path, 'host_sched_kwargs': host_sched_kwargs, 'request_spec': request_spec }) cells = self._get_possible_cells() cells = self.filter_handler.get_filtered_objects( self.filter_classes, cells, filter_properties) # NOTE(comstud): I know this reads weird, but the 'if's are nested # this way to optimize for the common case where 'cells' is a list # containing at least 1 entry. if not cells: if cells is None: # None means to bypass further scheduling as a filter # took care of everything. return raise exception.NoCellsAvailable() weighted_cells = self.weight_handler.get_weighed_objects( self.weigher_classes, cells, filter_properties) LOG.debug(_("Weighted cells: %(weighted_cells)s"), {'weighted_cells': weighted_cells}) # Keep trying until one works for weighted_cell in weighted_cells: cell = weighted_cell.obj try: if cell.is_me: # Need to create instance DB entry as scheduler # thinks it's already created... At least how things # currently work. self._create_instances_here(ctxt, request_spec) # Need to record the create action in the db as the # scheduler expects it to already exist. self._create_action_here(ctxt, request_spec['instance_uuids']) self.scheduler_rpcapi.run_instance(ctxt, **host_sched_kwargs) return # Forward request to cell self.msg_runner.schedule_run_instance(ctxt, cell, host_sched_kwargs) return except Exception: LOG.exception( _("Couldn't communicate with cell '%s'") % cell.name) # FIXME(comstud): Would be nice to kick this back up so that # the parent cell could retry, if we had a parent. msg = _("Couldn't communicate with any cells") LOG.error(msg) raise exception.NoCellsAvailable()
def fake_run_instance(message, host_sched_kwargs): call_info['num_tries'] += 1 raise exception.NoCellsAvailable()