コード例 #1
0
ファイル: chance.py プロジェクト: windskyer/k_nova
 def schedule_run_instance(self, context, request_spec,
                           admin_password, injected_files,
                           requested_networks, is_first_time,
                           filter_properties, legacy_bdm_in_spec):
     """Create and run an instance or instances."""
     instance_uuids = request_spec.get('instance_uuids')
     for num, instance_uuid in enumerate(instance_uuids):
         request_spec['instance_properties']['launch_index'] = num
         try:
             host = self._schedule(context, CONF.compute_topic,
                                   request_spec, filter_properties)
             updated_instance = driver.instance_update_db(context,
                     instance_uuid)
             self.compute_rpcapi.run_instance(context,
                     instance=updated_instance, host=host,
                     requested_networks=requested_networks,
                     injected_files=injected_files,
                     admin_password=admin_password,
                     is_first_time=is_first_time,
                     request_spec=request_spec,
                     filter_properties=filter_properties,
                     legacy_bdm_in_spec=legacy_bdm_in_spec)
         except Exception as ex:
             # NOTE(vish): we don't reraise the exception here to make sure
             #             that all instances in the request get set to
             #             error properly
             driver.handle_schedule_error(context, ex, instance_uuid,
                                          request_spec)
コード例 #2
0
ファイル: filter_scheduler.py プロジェクト: windskyer/k_nova
    def schedule_run_instance(self, context, request_spec,
                              admin_password, injected_files,
                              requested_networks, is_first_time,
                              filter_properties, legacy_bdm_in_spec):
        """This method is called from nova.compute.api to provision
        an instance.  We first create a build plan (a list of WeightedHosts)
        and then provision.

        Returns a list of the instances created.
        """
        payload = dict(request_spec=request_spec)
        self.notifier.info(context, 'scheduler.run_instance.start', payload)

        instance_uuids = request_spec.get('instance_uuids')
        LOG.info(_("Attempting to build %(num_instances)d instance(s) "
                    "uuids: %(instance_uuids)s"),
                  {'num_instances': len(instance_uuids),
                   'instance_uuids': instance_uuids})
        LOG.debug(_("Request Spec: %s") % request_spec)

        weighed_hosts = self._schedule(context, request_spec,
                                       filter_properties, instance_uuids)

        # NOTE: Pop instance_uuids as individual creates do not need the
        # set of uuids. Do not pop before here as the upper exception
        # handler fo NoValidHost needs the uuid to set error state
        instance_uuids = request_spec.pop('instance_uuids')

        # NOTE(comstud): Make sure we do not pass this through.  It
        # contains an instance of RpcContext that cannot be serialized.
        filter_properties.pop('context', None)

        for num, instance_uuid in enumerate(instance_uuids):
            request_spec['instance_properties']['launch_index'] = num

            try:
                try:
                    weighed_host = weighed_hosts.pop(0)
                    LOG.info(_("Choosing host %(weighed_host)s "
                                "for instance %(instance_uuid)s"),
                              {'weighed_host': weighed_host,
                               'instance_uuid': instance_uuid})
                except IndexError:
                    raise exception.NoValidHost(reason="")

                self._provision_resource(context, weighed_host,
                                         request_spec,
                                         filter_properties,
                                         requested_networks,
                                         injected_files, admin_password,
                                         is_first_time,
                                         instance_uuid=instance_uuid,
                                         legacy_bdm_in_spec=legacy_bdm_in_spec)
            except Exception as ex:
                # NOTE(vish): we don't reraise the exception here to make sure
                #             that all instances in the request get set to
                #             error properly
                driver.handle_schedule_error(context, ex, instance_uuid,
                                             request_spec)
            # scrub retry host list in case we're scheduling multiple
            # instances:
            retry = filter_properties.get('retry', {})
            retry['hosts'] = []

        self.notifier.info(context, 'scheduler.run_instance.end', payload)