From 09b92cb1ff3cd9f5c9a230a5678b200013ac61e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20Gonz=C3=A1lez?= Date: Thu, 18 Oct 2018 11:18:15 +0200 Subject: [PATCH] F #1089 Allow creation of "Empty disk image" for type OS (cherry picked from commit a6b8f48c4f3fef4801ac021b733248a4fb99ff52) --- src/image/Image.cc | 4 ++-- src/image/ImageManagerActions.cc | 38 +++++++++++++++++++++++--------- 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/src/image/Image.cc b/src/image/Image.cc index aacd2d5305..a2a8f428ea 100644 --- a/src/image/Image.cc +++ b/src/image/Image.cc @@ -185,7 +185,7 @@ int Image::insert(SqlDB *db, string& error_str) if (!is_saving()) { - if ( source.empty() && path.empty() && type != DATABLOCK ) + if ( source.empty() && path.empty() && type != DATABLOCK && type != OS) { goto error_no_path; } @@ -194,7 +194,7 @@ int Image::insert(SqlDB *db, string& error_str) goto error_path_and_source; } - if ( path.empty() && type == Image::DATABLOCK ) + if ( path.empty() && (type == Image::DATABLOCK || type == Image::OS)) { if ( fs_type.empty() ) { diff --git a/src/image/ImageManagerActions.cc b/src/image/ImageManagerActions.cc index 1f71e873f0..4ac6dabe33 100644 --- a/src/image/ImageManagerActions.cc +++ b/src/image/ImageManagerActions.cc @@ -836,14 +836,7 @@ int ImageManager::register_image(int iid, { string source = img->get_source(); - if ( img->is_saving() || img->get_type() == Image::DATABLOCK ) - { - imd->mkfs(img->get_oid(), *drv_msg); - - oss << "Creating disk at " << source << " of "<< img->get_size() - << "Mb (type: " << img->get_fstype() << ")"; - } - else if ( !source.empty() ) //Source in Template + if ( !source.empty() ) //Source in Template { img->set_state_unlock(); ipool->update(img); @@ -851,6 +844,14 @@ int ImageManager::register_image(int iid, oss << "Using source " << source << " from template for image " << img->get_name(); } + else if ( img->is_saving() || img->get_type() == Image::DATABLOCK + || img->get_type() == Image::OS) + { + imd->mkfs(img->get_oid(), *drv_msg); + + oss << "Creating disk at " << source << " of "<< img->get_size() + << "Mb (type: " << img->get_fstype() << ")"; + } } else //PATH -> COPY TO REPOSITORY AS SOURCE { @@ -895,7 +896,6 @@ int ImageManager::stat_image(Template* img_tmpl, switch (Image::str_to_type(type_att)) { - case Image::OS: case Image::CDROM: case Image::KERNEL: case Image::RAMDISK: @@ -929,11 +929,29 @@ int ImageManager::stat_image(Template* img_tmpl, << one_util::xml_escape(res) << ""; break; + + case Image::OS: + img_tmpl->get("SOURCE", res); + + if (!res.empty()) //SOURCE in Image + { + long long size_l; + + if (!img_tmpl->get("SIZE", size_l)) + { + res = "Wrong number or missing SIZE attribute."; + return -1; + } + + img_tmpl->get("SIZE", res); + + return 0; + } case Image::DATABLOCK: img_tmpl->get("PATH", res); - if (res.empty())//no PATH + if (res.empty())//no PATH, created using mkfs { long long size_l;