@@ -73,6 +73,44 @@ mp::LXDVMImageVault::LXDVMImageVault(std::vector<VMImageHost*> image_hosts, cons
73
73
mp::VMImage mp::LXDVMImageVault::fetch_image (const FetchType& fetch_type, const Query& query,
74
74
const PrepareAction& prepare, const ProgressMonitor& monitor)
75
75
{
76
+ // Look for an already existing instance and get its image info
77
+ try
78
+ {
79
+ auto instance_info = lxd_request (
80
+ manager.get (), " GET" ,
81
+ QUrl (QString (" %1/virtual_machines/%2" ).arg (base_url.toString ()).arg (QString::fromStdString (query.name ))));
82
+
83
+ auto id = instance_info[" metadata" ].toObject ()[" config" ].toObject ()[" volatile.base_image" ].toString ();
84
+
85
+ for (const auto & image_host : image_hosts)
86
+ {
87
+ try
88
+ {
89
+ auto info = image_host->info_for_full_hash (id.toStdString ());
90
+
91
+ VMImage source_image;
92
+
93
+ source_image.id = id.toStdString ();
94
+ source_image.stream_location = info.stream_location .toStdString ();
95
+ source_image.original_release = info.release_title .toStdString ();
96
+ source_image.release_date = info.version .toStdString ();
97
+
98
+ for (const auto & alias : info.aliases )
99
+ {
100
+ source_image.aliases .push_back (alias.toStdString ());
101
+ }
102
+ }
103
+ catch (const std::exception&)
104
+ {
105
+ // Nothing to do, just move on
106
+ }
107
+ }
108
+ }
109
+ catch (const std::exception&)
110
+ {
111
+ // Instance doesn't exist so move on
112
+ }
113
+
76
114
// TODO: Remove once we do support these types of images
77
115
if (query.query_type != Query::Type::Alias && !mp::platform::is_image_url_supported ())
78
116
throw std::runtime_error (fmt::format (" http and file based images are not supported" ));
0 commit comments