def rpc_call_wrapper(context, topic, msg, timeout=None): """Stub out the scheduler creating the instance entry""" if (topic == FLAGS.scheduler_topic and msg['method'] == 'run_instance'): scheduler = scheduler_driver.Scheduler instance = scheduler().create_instance_db_entry( context, msg['args']['request_spec']) return [scheduler_driver.encode_instance(instance)] else: return orig_rpc_call(context, topic, msg)
def schedule_run_instance(self, context, request_spec, *_args, **kwargs): """Create and run an instance or instances""" num_instances = request_spec.get('num_instances', 1) instances = [] for num in xrange(num_instances): host = self._schedule(context, 'compute', request_spec, **kwargs) request_spec['instance_properties']['launch_index'] = num instance = self.create_instance_db_entry(context, request_spec) driver.cast_to_compute_host(context, host, 'run_instance', instance_uuid=instance['uuid'], **kwargs) instances.append(driver.encode_instance(instance)) # So if we loop around, create_instance_db_entry will actually # create a new entry, instead of assume it's been created # already del request_spec['instance_properties']['uuid'] return instances