@@ -451,8 +451,28 @@ std::vector<mp::NetworkInterface> validate_extra_interfaces(const mp::LaunchRequ
451
451
return interfaces;
452
452
}
453
453
454
- auto validate_create_arguments (const mp::LaunchRequest* request, const mp::VirtualMachineFactory& factory)
454
+ void validate_image (const mp::LaunchRequest* request, const mp::VMImageVault& vault,
455
+ mp::VMWorkflowProvider& workflow_provider)
455
456
{
457
+ // TODO: Refactor this in such a way that we can use info returned here instead of ignoring it to avoid calls
458
+ // later that accomplish the same thing.
459
+ try
460
+ {
461
+ workflow_provider.info_for (request->image ());
462
+ }
463
+ catch (const std::out_of_range&)
464
+ {
465
+ auto image_query = query_from (request, " " );
466
+ if (image_query.query_type == mp::Query::Type::Alias)
467
+ vault.all_info_for (image_query);
468
+ }
469
+ }
470
+
471
+ auto validate_create_arguments (const mp::LaunchRequest* request, const mp::DaemonConfig* config)
472
+ {
473
+ assert (config && config->factory && config->workflow_provider && config->vault && " null ptr somewhere..." );
474
+ validate_image (request, *config->vault , *config->workflow_provider );
475
+
456
476
static const auto min_mem = try_mem_size (mp::min_memory_size);
457
477
static const auto min_disk = try_mem_size (mp::min_disk_size);
458
478
assert (min_mem && min_disk);
@@ -490,7 +510,7 @@ auto validate_create_arguments(const mp::LaunchRequest* request, const mp::Virtu
490
510
option_errors.add_error_codes (mp::LaunchError::INVALID_HOSTNAME);
491
511
492
512
std::vector<std::string> nets_need_bridging;
493
- auto extra_interfaces = validate_extra_interfaces (request, factory, nets_need_bridging, option_errors);
513
+ auto extra_interfaces = validate_extra_interfaces (request, *config-> factory , nets_need_bridging, option_errors);
494
514
495
515
struct CheckedArguments
496
516
{
@@ -2159,13 +2179,7 @@ std::string mp::Daemon::check_instance_exists(const std::string& instance_name)
2159
2179
void mp::Daemon::create_vm (const CreateRequest* request, grpc::ServerWriter<CreateReply>* server,
2160
2180
std::promise<grpc::Status>* status_promise, bool start)
2161
2181
{
2162
- // Try to get info for the requested image. This will throw out if the requested image is not found. This check
2163
- // needs to be done before the other checks.
2164
- auto image_query = query_from (request, " " );
2165
- if (image_query.query_type == Query::Type::Alias)
2166
- config->vault ->all_info_for (image_query);
2167
-
2168
- auto checked_args = validate_create_arguments (request, *config->factory );
2182
+ auto checked_args = validate_create_arguments (request, config.get ());
2169
2183
2170
2184
if (!checked_args.option_errors .error_codes ().empty ())
2171
2185
{
0 commit comments