Skip to content

Commit

Permalink
F OpenNebula#1089 Allow creation of "Empty disk image" for type OS
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian González authored and Ruben S. Montero committed Oct 18, 2018
1 parent 023063b commit a6b8f48
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/image/Image.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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() )
{
Expand Down
38 changes: 28 additions & 10 deletions src/image/ImageManagerActions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -836,21 +836,22 @@ 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);

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
{
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -929,11 +929,29 @@ int ImageManager::stat_image(Template* img_tmpl,
<< one_util::xml_escape(res)
<< "</PATH></IMAGE>";
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;

Expand Down

0 comments on commit a6b8f48

Please sign in to comment.