1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

B #2544: Set LN_TARGET and CLONE_TARGET after pick the datastore

This commit is contained in:
juanmont 2018-11-05 16:46:23 +01:00 committed by Ruben S. Montero
parent 4e5ac9f761
commit 807000a59c
7 changed files with 142 additions and 1 deletions

View File

@ -260,6 +260,12 @@ public:
one_util::split_unique(compatible_sys_ds_str, ',', compatible_sys_ds);
}
/**
* Verify the proper definition of the TM_MAD by checking the attributes
* related to the TM defined in TM_MAD_CONF
*/
int get_tm_mad_targets(const string &tm_mad, string& ln_target, string& clone_target);
private:
// -------------------------------------------------------------------------

View File

@ -1274,7 +1274,8 @@ public:
* @param uid for template owner
* @param ar the AuthRequest object
* @param tmpl the virtual machine template
* @param check_lock for check if the resource is lock or not
* @param
* lock for check if the resource is lock or not
*/
static void set_auth_request(int uid, AuthRequest& ar,
VirtualMachineTemplate *tmpl, bool check_lock);
@ -1640,6 +1641,13 @@ public:
*/
int get_auto_network_leases(VirtualMachineTemplate * tmpl, string &estr);
/**
* Check if a tm_mad is valid for the Virtual Machine Disks and set
* clone_target and ln_target
* @param tm_mad is the tm_mad for system datastore chosen
*/
int check_tm_mad_disks(const string& tm_mad);
private:
// -------------------------------------------------------------------------

View File

@ -357,6 +357,12 @@ public:
*/
void to_xml_short(std::ostringstream& oss) const;
/**
* Check if a tm_mad is valid and set clone_target and ln_target
* @param tm_mad is the tm_mad for system datastore chosen
*/
int check_tm_mad(const string& tm_mad);
private:
Snapshots * snapshots;
@ -782,6 +788,13 @@ public:
*/
std::string& to_xml_short(std::string& xml);
/**
* Check if a tm_mad is valid for each Virtual Machine Disk and set
* clone_target and ln_target
* @param tm_mad is the tm_mad for system datastore chosen
*/
int check_tm_mad(const string& tm_mad);
protected:
VirtualMachineAttribute * attribute_factory(VectorAttribute * va,

View File

@ -1094,3 +1094,31 @@ bool Datastore::is_persistent_only()
return persistent_only;
};
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int Datastore::get_tm_mad_targets(const string &tm_mad, string& ln_target, string& clone_target)
{
if (!tm_mad.empty())
{
string tm_mad_t = one_util::trim(tm_mad);
one_util::toupper(tm_mad_t);
get_template_attribute("CLONE_TARGET_" + tm_mad_t, clone_target);
if (clone_target.empty())
{
return -1;
}
get_template_attribute("LN_TARGET_" + tm_mad_t, ln_target);
if (ln_target.empty())
{
return -1;
}
}
return 0;
}

View File

@ -763,6 +763,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
PoolObjectAuth * auth_ds_perms;
string tm_mad;
string ln_target, clone_target;
string error_str;
bool auth = false;
@ -984,6 +985,15 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
if ( vm->check_tm_mad_disks(tm_mad) != 0)
{
att.resp_msg = error_str;
failure_response(ACTION, att);
vm->unlock();
return;
}
static_cast<VirtualMachinePool *>(pool)->update(vm);
// ------------------------------------------------------------------------

View File

@ -3471,3 +3471,25 @@ int VirtualMachine::parse_sched_action(string& error_str)
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
int VirtualMachine::check_tm_mad_disks(const string& tm_mad)
{
string tm_mad_sys;
obj_template->get("TM_MAD_SYSTEM", tm_mad_sys);
if ( tm_mad_sys != "" ) // VM has TM_MAD_SYSTEM already defined
{
return 0;
}
if ( disks.check_tm_mad(tm_mad) != 0 )
{
return -1;
}
obj_template->add("TM_MAD_SYSTEM", tm_mad);
return 0;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */

View File

@ -1614,3 +1614,57 @@ std::string& VirtualMachineDisks::to_xml_short(std::string& xml)
return xml;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachineDisks::check_tm_mad(const string& tm_mad)
{
DatastorePool * dspool = Nebula::instance().get_dspool();
for (disk_iterator it = begin(); it != end() ; ++it)
{
int ds_img_id;
Datastore * ds_img;
string ln_target, clone_target;
string tm_mad_disk, tm_mad_sys, _tm_mad;
_tm_mad = tm_mad;
one_util::toupper(_tm_mad);
(*it)->vector_value("TM_MAD", tm_mad_disk);
one_util::toupper(tm_mad_disk);
if ( _tm_mad == tm_mad_disk)
{
continue;
}
if ( (*it)->vector_value("DATASTORE_ID", ds_img_id) == 0 )
{
ds_img = dspool->get_ro(ds_img_id);
if ( ds_img == 0 )
{
return -1;
}
if ( ds_img->get_tm_mad_targets(tm_mad, ln_target, clone_target) != 0 )
{
return -1;
}
tm_mad_sys = tm_mad;
(*it)->replace("CLONE_TARGET", clone_target);
(*it)->replace("LN_TARGET", ln_target);
(*it)->replace("TM_MAD_SYSTEM", one_util::tolower(tm_mad_sys));
}
else
{
return -1;
}
}
return 0;
}