diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index f6abad08e2..f152fa4692 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -664,7 +664,7 @@ class OneHostHelper < OpenNebulaHelper::OneHelper .split("\n") name = wild['VM_NAME'] import = wild_tmplt.select do |line| - line[/DEPLOY_ID/] + line[/IMPORT_VM_ID/] end[0].split('=')[1].tr('"', ' ').strip memory = wild_tmplt.select do |line| line[/MEMORY/] diff --git a/src/host/Host.cc b/src/host/Host.cc index 32f07ad9b7..9d70c0728a 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -183,7 +183,7 @@ int Host::update_info(Template &tmpl) obj_template->get("TOTALCPU", total_cpu); obj_template->get("TOTALMEMORY", total_mem); - + if (host_share.get_total_cpu() == total_cpu && host_share.get_total_mem() == total_mem) { @@ -275,7 +275,7 @@ void Host::update_wilds() { VirtualMachinePool * vmpool = Nebula::instance().get_vmpool(); - vmid = vmpool->get_vmid(vatt->vector_value("DEPLOY_ID")); + vmid = vmpool->get_vmid(vatt->vector_value("UUID")); } if (vmid == -1) @@ -290,7 +290,7 @@ void Host::update_wilds() if (wname.empty()) { - wname = vatt->vector_value("DEPLOY_ID"); + wname = vatt->vector_value("UUID"); } wild << wname; diff --git a/src/im/InformationManager.cc b/src/im/InformationManager.cc index 68ee898e98..f8e64261c7 100644 --- a/src/im/InformationManager.cc +++ b/src/im/InformationManager.cc @@ -198,7 +198,7 @@ void InformationManager::_undefined(unique_ptr> msg) void InformationManager::_host_state(unique_ptr> msg) { - NebulaLog::ddebug("InM", "HOST_STATE update from host: " + + NebulaLog::debug("InM", "HOST_STATE update from host: " + to_string(msg->oid()) + ". Host information: " + msg->payload()); @@ -250,7 +250,7 @@ void InformationManager::_host_state(unique_ptr> msg void InformationManager::_host_system(unique_ptr> msg) { - NebulaLog::ddebug("InM", "HOST_SYSTEM update from host: " + + NebulaLog::debug("InM", "HOST_SYSTEM update from host: " + to_string(msg->oid()) + ". Host information: " + msg->payload()); char * error_msg; @@ -388,6 +388,7 @@ void InformationManager::_vm_state(unique_ptr> msg) int id; string deploy_id; + string uuid; string state_str; string vm_msg; @@ -404,12 +405,13 @@ void InformationManager::_vm_state(unique_ptr> msg) } vm_tmpl->vector_value("DEPLOY_ID", deploy_id); + vm_tmpl->vector_value("UUID", uuid); vm_tmpl->vector_value("STATE", state_str); if (id < 0) { // Check wild VMs - id = vmpool->get_vmid(deploy_id); + id = vmpool->get_vmid(uuid); if (id < 0) { diff --git a/src/im_mad/remotes/lib/kvm.rb b/src/im_mad/remotes/lib/kvm.rb index 5b6647b1f0..04bd16eb81 100644 --- a/src/im_mad/remotes/lib/kvm.rb +++ b/src/im_mad/remotes/lib/kvm.rb @@ -317,7 +317,7 @@ class Domain tmpl << "VCPU=#{vcpu}\n" tmpl << "MEMORY=#{mem}\n" tmpl << "HYPERVISOR=\"kvm\"\n" - tmpl << "DEPLOY_ID=\"#{name}\"\n" + tmpl << "IMPORT_VM_ID=\"#{uuid}\"\n" tmpl << "OS=[ARCH=\"#{arch}\"]\n" tmpl << features_txt << "\n" unless features_txt.empty? tmpl << spice_txt << "\n" unless spice_txt.empty? @@ -516,7 +516,7 @@ module DomainList mon_s = '' @vms.each do |_uuid, vm| - mon_s << "VM = [ ID=\"#{vm[:id]}\", DEPLOY_ID=\"#{vm[:name]}\"," + mon_s << "VM = [ ID=\"#{vm[:id]}\", UUID=\"#{vm[:uuid]}\"," mon_s << " MONITOR=\"#{vm.to_monitor}\"]\n" end @@ -530,7 +530,7 @@ module DomainList @vms.each do |_uuid, vm| next if vm[:id] != -1 || vm[:template].empty? - mon_s << "VM = [ID=\"#{vm[:id]}\", DEPLOY_ID=\"#{vm[:name]}\"," + mon_s << "VM = [ID=\"#{vm[:id]}\", UUID=\"#{vm[:uuid]}\"," mon_s << " VM_NAME=\"#{vm.name}\"," mon_s << " IMPORT_TEMPLATE=\"#{vm[:template]}\"]\n" end diff --git a/src/im_mad/remotes/lib/lxd.rb b/src/im_mad/remotes/lib/lxd.rb index 59bf8ae2c4..9e223646d9 100644 --- a/src/im_mad/remotes/lib/lxd.rb +++ b/src/im_mad/remotes/lib/lxd.rb @@ -36,6 +36,7 @@ module LXD @container = container @deploy_id = @container.name + @uuid = "#{@deploy_id}-#{Socket.gethostname}" if @deploy_id =~ /^one-\d+/ @wild = false @@ -138,7 +139,7 @@ module LXD VCPU = #{vcpu} MEMORY = #{mem} HYPERVISOR = "lxd" - DEPLOY_ID = "#{@deploy_id}" + IMPORT_VM_ID = "#{@deploy_id}" OS = [ ARCH="#{arch}" ] EOT @@ -148,7 +149,7 @@ module LXD private def template_string_header - "VM = [ ID=#{@id}, DEPLOY_ID=#{@deploy_id}, " + "VM = [ ID=#{@id}, UUID=#{@uuid}, " end def parse_memory(memory) diff --git a/src/im_mad/remotes/lib/probe_db.rb b/src/im_mad/remotes/lib/probe_db.rb index 9a09e8483d..633578176e 100644 --- a/src/im_mad/remotes/lib/probe_db.rb +++ b/src/im_mad/remotes/lib/probe_db.rb @@ -227,15 +227,17 @@ class VirtualMachineDB def vm_to_status(vm, state = vm[:state]) "VM = [ ID=\"#{vm[:id]}\", DEPLOY_ID=\"#{vm[:name]}\", " \ - " STATE=\"#{state}\" ]\n" + " UUID=\"#{vm[:uuid]}\", STATE=\"#{state}\" ]\n" end def vm_db_to_status(vm, state = vm[col_name_to_idx('state')]) id = col_name_to_idx('id') name = col_name_to_idx('name') + uuid = col_name_to_idx('uuid') + "VM = [ ID=\"#{vm[id]}\", DEPLOY_ID=\"#{vm[name]}\", " \ - " STATE=\"#{state}\" ]\n" + " UUID=\"#{vm[uuid]}\", STATE=\"#{state}\" ]\n" end # Load configuration file and parse user provided options diff --git a/src/monitor/src/monitor/HostMonitorManager.cc b/src/monitor/src/monitor/HostMonitorManager.cc index aa96f5564d..b4f18a8b25 100644 --- a/src/monitor/src/monitor/HostMonitorManager.cc +++ b/src/monitor/src/monitor/HostMonitorManager.cc @@ -307,13 +307,13 @@ void HostMonitorManager::update_last_monitor(int oid) /* -------------------------------------------------------------------------- */ void HostMonitorManager::monitor_vm(int oid, - const string& deploy_id, + const string& uuid, const Template &tmpl) { if (oid < 0) { // Wild VM, check if it is imported to OpenNebula - oid = vmpool->get_vmid(deploy_id); + oid = vmpool->get_vmid(uuid); if (oid < 0) { diff --git a/src/monitor/src/monitor/MonitorDriverProtocol.cc b/src/monitor/src/monitor/MonitorDriverProtocol.cc index 1fb8ec220b..4736557c79 100644 --- a/src/monitor/src/monitor/MonitorDriverProtocol.cc +++ b/src/monitor/src/monitor/MonitorDriverProtocol.cc @@ -64,7 +64,7 @@ void MonitorDriverProtocol::_monitor_vm(message_t msg) { int id = -1; string monitor_b64; - string deploy_id; + string uuid; if (vm->vector_value("ID", id) != 0) { @@ -72,7 +72,7 @@ void MonitorDriverProtocol::_monitor_vm(message_t msg) } vm->vector_value("MONITOR", monitor_b64); - vm->vector_value("DEPLOY_ID", deploy_id); + vm->vector_value("UUID", uuid); auto monitor_plain = one_util::base64_decode(monitor_b64); @@ -95,11 +95,11 @@ void MonitorDriverProtocol::_monitor_vm(message_t msg) delete monitor_plain; - auto it = vms_templ.find(deploy_id); + auto it = vms_templ.find(uuid); if (it == vms_templ.end()) { - vms_templ.insert(make_pair(std::move(deploy_id), + vms_templ.insert(make_pair(std::move(uuid), make_pair(id, std::move(mon_tmpl)))); } else diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 0e76855199..94fceda8b0 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -998,20 +998,28 @@ int VirtualMachine::insert(SqlDB * db, string& error_str) // ------------------------------------------------------------------------- // Get and set DEPLOY_ID for imported VMs // ------------------------------------------------------------------------- - user_obj_template->get("DEPLOY_ID", deploy_id); - user_obj_template->erase("DEPLOY_ID"); + user_obj_template->get("IMPORT_VM_ID", value); + user_obj_template->erase("IMPORT_VM_ID"); if (!value.empty()) { const char * one_vms = "^one-[[:digit:]]+$"; - if (one_util::regex_match(one_vms, deploy_id.c_str()) == 0) + if (one_util::regex_match(one_vms, value.c_str()) == 0) { goto error_one_vms; } else { obj_template->add("IMPORTED", "YES"); + + user_obj_template->get("DEPLOY_ID", deploy_id); + user_obj_template->erase("DEPLOY_ID"); + + if (deploy_id.empty()) + { + deploy_id = value; + } } } diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 3152b4bf7e..c62ee9b13c 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -159,7 +159,7 @@ int VirtualMachinePool::allocate( vm->prev_state = vm->state; - vm->user_obj_template->get("DEPLOY_ID", deploy_id); + vm->user_obj_template->get("IMPORT_VM_ID", deploy_id); if (!deploy_id.empty()) {