Пример #1
0
    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?"))
Пример #2
0
    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"))
Пример #3
0
    def schedule_create_volume(self, context, volume_id, *_args, **_kwargs):
        """Picks a host that is up and has the fewest volumes."""
        volume_ref = db.volume_get(context, volume_id)
        if (volume_ref['availability_zone']
                and ':' in volume_ref['availability_zone']
                and context.is_admin):
            zone, _x, host = volume_ref['availability_zone'].partition(':')
            service = db.service_get_by_args(context.elevated(), host,
                                             'nova-volume')
            if not self.service_is_up(service):
                raise driver.WillNotSchedule(_("Host %s not available") % host)

            # TODO(vish): this probably belongs in the manager, if we
            #             can generalize this somehow
            now = datetime.datetime.utcnow()
            db.volume_update(context, volume_id, {
                'host': host,
                'scheduled_at': now
            })
            return host

        results = db.service_get_all_volume_sorted(context)

        for result in results:
            (service, volume_gigabytes) = result

            compute_ref = db.service_get_all_compute_by_host(
                context, service['host'])[0]
            compute_node_ref = compute_ref['compute_node'][0]

            if volume_ref['size'] + volume_gigabytes > compute_node_ref[
                    'local_gb']:
                raise driver.NoValidHost(
                    _("All hosts have too many "
                      "gigabytes"))

            LOG.debug(
                _("requested volume GBs = %s + used compute node GBs = %s < total compute node GBs = %s"
                  ) % (volume_ref['size'], volume_gigabytes,
                       compute_node_ref['local_gb']))

            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.volume_update(context, volume_id, {
                    'host': service['host'],
                    'scheduled_at': now
                })

                LOG.debug(
                    _("volume = %s scheduled to host = %s") %
                    (volume_id, service['host']))

                return service['host']
        raise driver.NoValidHost(
            _("Scheduler was unable to locate a host"
              " for this request. Is the appropriate"
              " service running?"))
Пример #4
0
    def schedule_set_network_host(self, context, *_args, **_kwargs):
        """Picks a host that is up and has the fewest networks."""

        results = db.service_get_all_network_sorted(context)
        for result in results:
            (service, instance_count) = result
            if instance_count >= FLAGS.max_networks:
                raise driver.NoValidHost(_("All hosts have too many networks"))
            if self.service_is_up(service):
                return service['host']
        raise driver.NoValidHost(_("No hosts found"))
Пример #5
0
    def schedule_set_network_host(self, context, *_args, **_kwargs):
        """Picks a host that is up and has the fewest networks."""

        results = db.service_get_all_network_sorted(context)
        for result in results:
            (service, instance_count) = result
            if instance_count >= FLAGS.max_networks:
                raise driver.NoValidHost(_("All hosts have too many networks"))
            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?"))
Пример #6
0
    def schedule(self, context, topic, *args, **kwargs):
        """Gets the host name from the Quantum service"""
        instance_id = kwargs['instance_id']
        user_id = \
                kwargs['request_spec']['instance_properties']['user_id']
        project_id = \
                kwargs['request_spec']['instance_properties']['project_id']

        instance_data_dict = \
                {'novatenant': \
                 {'instance_id': instance_id,
                  'instance_desc': \
                  {'user_id': user_id,
                   'project_id': project_id}}}

        client = Client(HOST,
                        PORT,
                        USE_SSL,
                        format='json',
                        tenant=TENANT_ID,
                        action_prefix=ACTION_PREFIX_CSCO)
        request_url = "/novatenants/" + project_id + ACTION
        data = client.do_request('PUT', request_url, body=instance_data_dict)

        hostname = data["host_list"]["host_1"]
        if not hostname:
            raise driver.NoValidHost(
                _("Scheduler was unable to locate a host"
                  " for this request. Is the appropriate"
                  " service running?"))

        LOG.debug(_("Quantum service returned host: %s") % hostname)
        return hostname
Пример #7
0
    def schedule(self, context, topic, *_args, **_kwargs):
        """Picks a host that is up at random."""

        hosts = self.hosts_up(context, topic)
        if not hosts:
            raise driver.NoValidHost(_("No hosts found"))
        return hosts[int(random.random() * len(hosts))]
Пример #8
0
 def schedule(self, context, topic, request_spec, *args, **kwargs):
     """The schedule() contract requires we return the one
     best-suited host for this request.
     """
     # TODO(sandy): We're only focused on compute instances right now,
     # so we don't implement the default "schedule()" method required
     # of Schedulers.
     msg = _("No host selection for %s defined." % topic)
     raise driver.NoValidHost(msg)
Пример #9
0
    def schedule(self, context, topic, *_args, **_kwargs):
        """Picks a host that is up at random in selected
        availability zone (if defined).
        """

        zone = _kwargs.get('availability_zone')
        hosts = self.hosts_up_with_zone(context, topic, zone)
        if not hosts:
            raise driver.NoValidHost(_("No hosts found"))
        return hosts[int(random.random() * len(hosts))]
Пример #10
0
    def schedule(self, context, topic, *_args, **_kwargs):
        """Picks a host that is up at random."""

        hosts = self.hosts_up(context, topic)
        if not hosts:
            raise driver.NoValidHost(
                _("Scheduler was unable to locate a host"
                  " for this request. Is the appropriate"
                  " service running?"))
        return hosts[int(random.random() * len(hosts))]
Пример #11
0
    def schedule(self, context, topic, *_args, **_kwargs):
        """Picks a host that is up at random in selected
        availability zone (if defined).
        """

        zone = _kwargs.get('availability_zone')
        hosts = self.hosts_up_with_zone(context, topic, zone)
        if not hosts:
            raise driver.NoValidHost(
                _("Scheduler was unable to locate a host"
                  " for this request. Is the appropriate"
                  " service running?"))

        return hosts[int(random.random() * len(hosts))]
Пример #12
0
    def schedule_run_instance(self, context, instance_id, request_spec, *args,
                              **kwargs):
        """This method is called from nova.compute.api to provision
        an instance. However we need to look at the parameters being
        passed in to see if this is a request to:
        1. Create a Build Plan and then provision, or
        2. Use the Build Plan information in the request parameters
           to simply create the instance (either in this zone or
           a child zone).
        """

        # TODO(sandy): We'll have to look for richer specs at some point.

        blob = request_spec.get('blob')
        if blob:
            self._provision_resource(context, request_spec, instance_id,
                                     request_spec, kwargs)
            return None

        num_instances = request_spec.get('num_instances', 1)
        LOG.debug(
            _("Attempting to build %(num_instances)d instance(s)") % locals())

        # Create build plan and provision ...
        build_plan = self.select(context, request_spec)
        if not build_plan:
            raise driver.NoValidHost(_('No hosts were available'))

        for num in xrange(num_instances):
            if not build_plan:
                break

            build_plan_item = build_plan.pop(0)
            self._provision_resource(context, build_plan_item, instance_id,
                                     request_spec, kwargs)

        # Returning None short-circuits the routing to Compute (since
        # we've already done it here)
        return None
Пример #13
0
 def schedule(self, context, topic, request_spec, *args, **kwargs):
     """The schedule() contract requires we return the one
     best-suited host for this request.
     """
     raise driver.NoValidHost(_('No hosts were available'))