1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-24 21:34:01 +03:00

feature #1617: Transfer Manager actions to clone kernels and initrds

This commit is contained in:
Ruben S. Montero 2012-11-19 00:47:02 +01:00
parent dd914b687c
commit 5364c22b4b
2 changed files with 130 additions and 0 deletions

View File

@ -220,6 +220,50 @@ public:
etime = et; etime = et;
}; };
/**
* Sets the KERNEL OS attribute (path to the kernel file). Used when
* the template is using a FILE Datastore for it
* @param path to the kernel (in the remote host)
*/
void set_kernel(const string& kernel)
{
vector<Attribute *> os_attr;
VectorAttribute * os;
int num = obj_template->get("OS", os_attr);
if ( num == 0 )
{
return;
}
os = dynamic_cast<VectorAttribute *>(os_attr[0]);
os->replace("KERNEL", kernel);
};
/**
* Sets the INITRD OS attribute (path to the initrd file). Used when
* the template is using a FILE Datastore for it
* @param path to the initrd (in the remote host)
*/
void set_initrd(const string& initrd)
{
vector<Attribute *> os_attr;
VectorAttribute * os;
int num = obj_template->get("OS", os_attr);
if ( num == 0 )
{
return;
}
os = dynamic_cast<VectorAttribute *>(os_attr[0]);
os->replace("INITRD", initrd);
};
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------
// Access to VM locations // Access to VM locations
// ------------------------------------------------------------------------ // ------------------------------------------------------------------------

View File

@ -348,6 +348,55 @@ error_attributes:
return -1; return -1;
} }
/* -------------------------------------------------------------------------- */
static string prolog_os_transfer_commands(
VirtualMachine * vm,
const VectorAttribute * os_attr,
const string& base,
string& opennebula_hostname,
ostream& xfr)
{
string base_ds = base + "_DS";
string name_ds = os_attr->vector_value(base_ds.c_str());
if ( name_ds.empty() )
{
return "";
}
string base_source = base + "_DS_SOURCE";
string base_ds_id = base + "_DS_DSID";
string base_tm = base + "_DS_TM";
string source = os_attr->vector_value(base_source.c_str());
string ds_id = os_attr->vector_value(base_ds_id.c_str());
string tm_mad = os_attr->vector_value(base_tm.c_str());
if ( source.empty() || ds_id.empty() || tm_mad.empty() )
{
return "";
}
ostringstream base_dst;
string name = base;
transform(name.begin(), name.end(), name.begin(), (int(*)(int))tolower);
base_dst << vm->get_remote_system_dir() << "/" << name;
xfr << "CLONE " << tm_mad << " "
<< opennebula_hostname << ":" << source << " "
<< vm->get_hostname() << ":"
<< base_dst.str() << " "
<< vm->get_oid() << " "
<< ds_id
<< endl;
return base_dst.str();
}
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
@ -435,9 +484,46 @@ void TransferManager::prolog_action(int vid)
} }
} }
// -------------------------------------------------------------------------
// Transfers for kernel and initrd files
// -------------------------------------------------------------------------
attrs.clear();
num = vm->get_template_attribute("OS",attrs);
if ( num > 0 )
{
const VectorAttribute * os_attr;
os_attr = dynamic_cast<const VectorAttribute *>(attrs[0]);
string kernel = prolog_os_transfer_commands(vm,
os_attr,
"KERNEL",
opennebula_hostname,
xfr);
if ( !kernel.empty() )
{
vm->set_kernel(kernel);
vmpool->update(vm);
}
string initrd = prolog_os_transfer_commands(vm,
os_attr,
"initrd",
opennebula_hostname,
xfr);
if ( !initrd.empty() )
{
vm->set_initrd(initrd);
vmpool->update(vm);
}
}
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
// Generate context file // Generate context file
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
context_result = vm->generate_context(files, disk_id); context_result = vm->generate_context(files, disk_id);
if ( context_result == -1 ) if ( context_result == -1 )