Skip to content

Commit 686d2cd

Browse files
author
Chris Townsend
committed
[image vault/lxd] Find image info for an already existing instance
1 parent d19ccaf commit 686d2cd

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

src/platform/backends/lxd/lxd_vm_image_vault.cpp

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,44 @@ mp::LXDVMImageVault::LXDVMImageVault(std::vector<VMImageHost*> image_hosts, cons
7373
mp::VMImage mp::LXDVMImageVault::fetch_image(const FetchType& fetch_type, const Query& query,
7474
const PrepareAction& prepare, const ProgressMonitor& monitor)
7575
{
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+
76114
// TODO: Remove once we do support these types of images
77115
if (query.query_type != Query::Type::Alias && !mp::platform::is_image_url_supported())
78116
throw std::runtime_error(fmt::format("http and file based images are not supported"));

0 commit comments

Comments
 (0)