diff --git a/include/Datastore.h b/include/Datastore.h index 5be4db3a4e..4646581e12 100644 --- a/include/Datastore.h +++ b/include/Datastore.h @@ -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: // ------------------------------------------------------------------------- diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 7842769651..1f02e3514c 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -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: // ------------------------------------------------------------------------- diff --git a/include/VirtualMachineDisk.h b/include/VirtualMachineDisk.h index f8cbc66fd5..2fe7e14d0a 100644 --- a/include/VirtualMachineDisk.h +++ b/include/VirtualMachineDisk.h @@ -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, diff --git a/src/datastore/Datastore.cc b/src/datastore/Datastore.cc index 66cbdc50a7..72b83e6fc2 100644 --- a/src/datastore/Datastore.cc +++ b/src/datastore/Datastore.cc @@ -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; +} diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 0f29951740..a7ecc1dc0d 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -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(pool)->update(vm); // ------------------------------------------------------------------------ diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index e77ee1e73e..c3a9ad0e39 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -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; +} + +/* ------------------------------------------------------------------------ */ +/* ------------------------------------------------------------------------ */ + diff --git a/src/vm/VirtualMachineDisk.cc b/src/vm/VirtualMachineDisk.cc index d9b66075b8..034324ad4c 100644 --- a/src/vm/VirtualMachineDisk.cc +++ b/src/vm/VirtualMachineDisk.cc @@ -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; +} +