def schedule_run_instance(self, context, instance_id, *_args, **_kwargs): """Picks a host that is up and has the fewest running instances.""" instance_ref = db.instance_get(context, instance_id) if (instance_ref['availability_zone'] and ':' in instance_ref['availability_zone'] and context.is_admin): zone, _x, host = instance_ref['availability_zone'].partition(':') service = db.service_get_by_args(context.elevated(), host, 'nova-compute') if not self.service_is_up(service): raise driver.WillNotSchedule(_("Host %s is not alive") % host) # TODO(vish): this probably belongs in the manager, if we # can generalize this somehow now = datetime.datetime.utcnow() db.instance_update(context, instance_id, { 'host': host, 'scheduled_at': now }) return host results = db.service_get_all_compute_sorted(context) for result in results: (service, instance_cores) = result if instance_cores + instance_ref['vcpus'] > FLAGS.max_cores: raise driver.NoValidHost(_("All hosts have too many cores")) if self.service_is_up(service): # NOTE(vish): this probably belongs in the manager, if we # can generalize this somehow now = datetime.datetime.utcnow() db.instance_update(context, instance_id, { 'host': service['host'], 'scheduled_at': now }) return service['host'] raise driver.NoValidHost(_("No hosts found"))
def schedule_run_instance(self, context, instance_id, *_args, **_kwargs): """Picks a host that is up and has the fewest running instances.""" instance_ref = db.instance_get(context, instance_id) if (instance_ref['availability_zone'] and ':' in instance_ref['availability_zone'] and context.is_admin): zone, _x, host = instance_ref['availability_zone'].partition(':') service = db.service_get_by_args(context.elevated(), host, 'nova-compute') if not self.service_is_up(service): raise driver.WillNotSchedule(_("Host %s is not alive") % host) # TODO(vish): this probably belongs in the manager, if we # can generalize this somehow now = datetime.datetime.utcnow() db.instance_update(context, instance_id, {'host': host, 'scheduled_at': now}) return host results = db.service_get_all_compute_sorted(context) for result in results: (service, instance_cores) = result if instance_cores + instance_ref['vcpus'] > FLAGS.max_cores: raise driver.NoValidHost(_("All hosts have too many cores")) if self.service_is_up(service): # NOTE(vish): this probably belongs in the manager, if we # can generalize this somehow now = datetime.datetime.utcnow() db.instance_update(context, instance_id, {'host': service['host'], 'scheduled_at': now}) return service['host'] raise driver.NoValidHost(_("No hosts found"))
def _schedule_instance(self, context, instance_opts, *_args, **_kwargs): """Picks a host that is up and has the fewest running instances.""" elevated = context.elevated() availability_zone = instance_opts.get('availability_zone') zone, host = FLAGS.default_schedule_zone, None if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: service = db.service_get_by_args(elevated, host, 'nova-compute') if not self.service_is_up(service): raise exception.WillNotSchedule(host=host) return host results = db.service_get_all_compute_sorted(elevated) if zone: results = [(service, cores) for (service, cores) in results if service['availability_zone'] == zone] for result in results: (service, instance_cores) = result if instance_cores + instance_opts['vcpus'] > FLAGS.max_cores: msg = _("Not enough allocatable CPU cores remaining") raise exception.NoValidHost(reason=msg) if self.service_is_up(service): return service['host'] msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)
def schedule_run_instance(self, context, instance_id, *_args, **_kwargs): """Picks a host that is up and has the fewest running instances.""" instance_ref = db.instance_get(context, instance_id) if (instance_ref['availability_zone'] and ':' in instance_ref['availability_zone'] and context.is_admin): zone, _x, host = instance_ref['availability_zone'].partition(':') service = db.service_get_by_args(context.elevated(), host, 'nova-compute') if not self.service_is_up(service): raise driver.WillNotSchedule(_("Host %s is not alive") % host) # TODO(vish): this probably belongs in the manager, if we # can generalize this somehow now = datetime.datetime.utcnow() db.instance_update(context, instance_id, { 'host': host, 'scheduled_at': now }) return host results = db.service_get_all_compute_sorted(context) for result in results: (service, instance_cores) = result compute_ref = db.service_get_all_compute_by_host( context, service['host'])[0] compute_node_ref = compute_ref['compute_node'][0] if (instance_ref['vcpus'] + instance_cores > compute_node_ref['vcpus'] * FLAGS.max_cores): raise driver.NoValidHost(_("All hosts have too many cores")) LOG.debug( _("requested instance cores = %s + used compute node cores = %s < total compute node cores = %s * max cores = %s" ) % (instance_ref['vcpus'], instance_cores, compute_node_ref['vcpus'], FLAGS.max_cores)) if self.service_is_up(service): # NOTE(vish): this probably belongs in the manager, if we # can generalize this somehow now = datetime.datetime.utcnow() db.instance_update(context, instance_id, { 'host': service['host'], 'scheduled_at': now }) LOG.debug( _("instance = %s scheduled to host = %s") % (instance_id, service['host'])) return service['host'] raise driver.NoValidHost( _("Scheduler was unable to locate a host" " for this request. Is the appropriate" " service running?"))
def trigger_provider_fw_rules_refresh(self, context): """Called when a rule is added to or removed from a security_group""" hosts = [x['host'] for (x, idx) in db.service_get_all_compute_sorted(context)] for host in hosts: rpc.cast(context, self.db.queue_get_for(context, FLAGS.compute_topic, host), {'method': 'refresh_provider_fw_rules', 'args': {}})
def schedule_run_instance(self, context, instance_id, *_args, **_kwargs): """Picks a host that is up and has the fewest running instances.""" instance_ref = db.instance_get(context, instance_id) if (instance_ref['availability_zone'] and ':' in instance_ref['availability_zone'] and context.is_admin): zone, _x, host = instance_ref['availability_zone'].partition(':') service = db.service_get_by_args(context.elevated(), host, 'nova-compute') if not self.service_is_up(service): raise driver.WillNotSchedule(_("Host %s is not alive") % host) # TODO(vish): this probably belongs in the manager, if we # can generalize this somehow now = datetime.datetime.utcnow() db.instance_update(context, instance_id, {'host': host, 'scheduled_at': now}) return host results = db.service_get_all_compute_sorted(context) for result in results: (service, instance_cores) = result compute_ref = db.service_get_all_compute_by_host(context, service['host'])[0] compute_node_ref = compute_ref['compute_node'][0] if (instance_ref['vcpus'] + instance_cores > compute_node_ref['vcpus'] * FLAGS.max_cores): raise driver.NoValidHost(_("All hosts have too many cores")) LOG.debug(_("requested instance cores = %s + used compute node cores = %s < total compute node cores = %s * max cores = %s") % (instance_ref['vcpus'], instance_cores, compute_node_ref['vcpus'], FLAGS.max_cores)) if self.service_is_up(service): # NOTE(vish): this probably belongs in the manager, if we # can generalize this somehow now = datetime.datetime.utcnow() db.instance_update(context, instance_id, {'host': service['host'], 'scheduled_at': now}) LOG.debug(_("instance = %s scheduled to host = %s") % (instance_id, service['host'])) return service['host'] raise driver.NoValidHost(_("Scheduler was unable to locate a host" " for this request. Is the appropriate" " service running?"))
def _schedule_instance(self, context, instance_id, *_args, **_kwargs): """Picks a host that is up and has the fewest running instances.""" elevated = context.elevated() instance_ref = db.instance_get(context, instance_id) if (instance_ref['availability_zone'] and ':' in instance_ref['availability_zone'] and context.is_admin): zone, _x, host = instance_ref['availability_zone'].partition(':') service = db.service_get_by_args(elevated, host, 'nova-compute') if not self.service_is_up(service): raise driver.WillNotSchedule(_("Host %s is not alive") % host) # TODO(vish): this probably belongs in the manager, if we # can generalize this somehow self.assert_compute_node_has_enough_memory(context, instance_ref, service['host']) now = utils.utcnow() db.instance_update(context, instance_id, {'host': host, 'scheduled_at': now}) return host results = db.service_get_all_compute_sorted(elevated) for result in results: (service, instance_cores) = result if instance_cores + instance_ref['vcpus'] > FLAGS.max_cores: raise driver.NoValidHost(_("Not enough allocatable CPU cores" "remaining")) try: self.assert_compute_node_has_enough_memory(context, instance_ref, service['host']) except exception.InsufficientFreeMemory: break if self.service_is_up(service): # NOTE(vish): this probably belongs in the manager, if we # can generalize this somehow now = utils.utcnow() db.instance_update(context, instance_id, {'host': service['host'], 'scheduled_at': now}) return service['host'] raise driver.NoValidHost(_("Scheduler was unable to locate a host" " for this request. Is the appropriate" " service running?"))
def _schedule_instance(self, context, instance_opts, *_args, **_kwargs): """Picks a host that is up and has the fewest running instances.""" availability_zone = instance_opts.get("availability_zone") if availability_zone and context.is_admin and (":" in availability_zone): zone, host = availability_zone.split(":", 1) service = db.service_get_by_args(context.elevated(), host, "nova-compute") if not self.service_is_up(service): raise driver.WillNotSchedule(_("Host %s is not alive") % host) return host results = db.service_get_all_compute_sorted(context) for result in results: (service, instance_cores) = result if instance_cores + instance_opts["vcpus"] > FLAGS.max_cores: raise driver.NoValidHost(_("All hosts have too many cores")) if self.service_is_up(service): return service["host"] raise driver.NoValidHost( _("Scheduler was unable to locate a host" " for this request. Is the appropriate" " service running?") )
def _schedule_instance(self, context, instance_opts, *_args, **_kwargs): """Picks a host that is up and has the fewest running instances.""" elevated = context.elevated() availability_zone = instance_opts.get('availability_zone') zone, host = FLAGS.default_schedule_zone, None if availability_zone: zone, _x, host = availability_zone.partition(':') if host and context.is_admin: service = db.service_get_by_args(elevated, host, 'nova-compute') if not utils.service_is_up(service): raise exception.WillNotSchedule(host=host) return host results = db.service_get_all_compute_sorted(elevated) in_isolation = instance_opts['image_ref'] in FLAGS.isolated_images check_cores = not in_isolation or not FLAGS.skip_isolated_core_check if zone: results = [(service, cores) for (service, cores) in results if service['availability_zone'] == zone] for result in results: (service, instance_cores) = result if in_isolation and service['host'] not in FLAGS.isolated_hosts: # isloated images run on isolated hosts continue if service['host'] in FLAGS.isolated_hosts and not in_isolation: # images that aren't isolated only run on general hosts continue if (check_cores and instance_cores + instance_opts['vcpus'] > FLAGS.max_cores): msg = _("Not enough allocatable CPU cores remaining") raise exception.NoValidHost(reason=msg) if utils.service_is_up(service) and not service['disabled']: return service['host'] msg = _("Is the appropriate service running?") raise exception.NoValidHost(reason=msg)