From fa73142e7db7dfe3be423bd71763365cf2f7a412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Czern=C3=BD?= Date: Thu, 21 Nov 2024 17:31:47 +0100 Subject: [PATCH] F #6723: Remove `onehost importvm` (#3231) * Remove vm_import table from DB * Remove imported vms actions * Fix fsck for image and network * onedb fsck fix running_vms only for non-backup images --- include/DispatchManager.h | 10 - include/OneDB.h | 10 - include/VirtualMachine.h | 20 -- include/VirtualMachineManager.h | 18 -- include/VirtualMachineManagerDriver.h | 19 -- include/VirtualMachinePool.h | 37 +-- install.sh | 1 - share/doc/xsd/opennebula_configuration.xsd | 1 - share/etc/oned.conf | 64 +---- share/shell/bash_completion | 4 +- src/cli/one_helper/onehost_helper.rb | 7 +- src/cli/onehost | 17 -- src/cli/onevcenter | 2 +- src/dm/DispatchManagerActions.cc | 86 ------- src/host/Host.cc | 7 - src/im/InformationManager.cc | 12 - src/im_mad/remotes/lib/probe_db.rb | 7 +- src/monitor/include/HostMonitorManager.h | 8 - src/monitor/include/VMRPCPool.h | 7 - src/monitor/src/data_model/VMRPCPool.cc | 28 --- src/monitor/src/monitor/HostMonitorManager.cc | 23 -- .../src/monitor/MonitorDriverProtocol.cc | 22 +- src/oca/ruby/opennebula/host.rb | 59 ----- src/onedb/fsck/image.rb | 43 ++-- src/onedb/fsck/network.rb | 23 +- src/rm/RequestManagerUpdateTemplate.cc | 9 - src/rm/RequestManagerVirtualMachine.cc | 237 +----------------- src/sql/OneDB.cc | 8 - .../models/OpenNebulaJSON/HostJSON.rb | 10 - src/sunstone/public/app/opennebula/host.js | 4 - .../public/app/tabs/hosts-tab/panels/info.js | 6 +- .../public/app/tabs/hosts-tab/panels/wilds.js | 115 --------- .../app/tabs/hosts-tab/panels/wilds/html.hbs | 3 - .../tabs/hosts-tab/utils/can-import-wilds.js | 49 ---- src/sunstone/routes/vcenter.rb | 18 -- src/vm/VirtualMachine.cc | 43 ---- src/vm/VirtualMachinePool.cc | 106 -------- src/vmm/VirtualMachineManagerDriver.cc | 59 ----- .../lib/vcenter_driver/vmm_importer.rb | 165 ------------ src/vmm_mad/remotes/vcenter/vcenter_driver.rb | 1 - 40 files changed, 68 insertions(+), 1300 deletions(-) delete mode 100644 src/sunstone/public/app/tabs/hosts-tab/utils/can-import-wilds.js delete mode 100644 src/vmm_mad/remotes/lib/vcenter_driver/vmm_importer.rb diff --git a/include/DispatchManager.h b/include/DispatchManager.h index 08dbd101de2..0a9bd4cb858 100644 --- a/include/DispatchManager.h +++ b/include/DispatchManager.h @@ -76,16 +76,6 @@ class DispatchManager : public Listener int deploy(std::unique_ptr vm, const RequestAttributes& request); - /** - * Sets an imported VM to RUNNING state, a history record MUST be added, - * and the VM MUST be locked. - * @param vm pointer to a VirtualMachine with its mutex locked. - * @param ra information about the API call request - * @return 0 on success - */ - int import(std::unique_ptr vm, - const RequestAttributes& ra); - /** * Migrates a VM. The following actions must be performed before calling * this function: diff --git a/include/OneDB.h b/include/OneDB.h index 98d0405978e..16e2db8f36f 100644 --- a/include/OneDB.h +++ b/include/OneDB.h @@ -70,16 +70,6 @@ namespace one_db extern const char * vm_template_table; - // ------------------------------------------------------------------------- - // Virtual Machine ID - Deploy ID index for imported VMs - // The index is managed by the VirtualMachinePool - // ------------------------------------------------------------------------- - extern const char * vm_import_table; - - extern const char * vm_import_db_names; - - extern const char * vm_import_db_bootstrap; - /* ---------------------------------------------------------------------- */ /* Cluster tables */ /* ---------------------------------------------------------------------- */ diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index eaa0a814a30..5750d447793 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1191,26 +1191,6 @@ class VirtualMachine : public PoolObjectSQL */ void release_vmgroup(); - // ------------------------------------------------------------------------ - // Imported VM interface - // ------------------------------------------------------------------------ - /** - * Check if the VM is imported - */ - bool is_imported() const; - - /** - * Return state of the VM right before import - */ - std::string get_import_state() const; - - /** - * Checks if the current VM MAD supports the given action for imported VMs - * @param action VM action to check - * @return true if the current VM MAD supports the given action for imported VMs - */ - bool is_imported_action_supported(VMActions::Action action) const; - // ------------------------------------------------------------------------ // Virtual Router related functions // ------------------------------------------------------------------------ diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 5eeef166592..df188650aa3 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -54,24 +54,6 @@ class VirtualMachineManager : */ int load_drivers(const std::vector& _mads); - /** - * Check if action is supported for imported VMs - * @param mad name of the driver - * @param action - * @return True if it is supported - */ - bool is_imported_action_supported(const std::string& mad, VMActions::Action action) - { - const VirtualMachineManagerDriver * vmd = get(mad); - - if ( vmd == nullptr ) - { - return false; - } - - return vmd->is_imported_action_supported(action); - } - /** * Updates firewall rules of a VM * @param vm pointer to VM, needs to be locked diff --git a/include/VirtualMachineManagerDriver.h b/include/VirtualMachineManagerDriver.h index 582e718a07b..74e5947c891 100644 --- a/include/VirtualMachineManagerDriver.h +++ b/include/VirtualMachineManagerDriver.h @@ -80,16 +80,6 @@ class VirtualMachineManagerDriver : public Driver return 0; } - /** - * Check if action is supported for imported VMs - * @param action - * @return True if it is supported - */ - bool is_imported_action_supported(VMActions::Action action) const - { - return imported_actions.is_set(action); - } - /** * @return true if system snapshots are preserved */ @@ -264,20 +254,11 @@ class VirtualMachineManagerDriver : public Driver private: friend class VirtualMachineManager; - static const std::string imported_actions_default; - static const std::string imported_actions_default_public; - /** * Configuration file for the driver */ Template driver_conf; - /** - * List of available actions for imported VMs. Each bit is an action - * as defined in History.h, 1=supported and 0=not supported - */ - ActionSet imported_actions; - /** * Set to true if the hypervisor can keep system snapshots across * create/delete cycles and live migrations. diff --git a/include/VirtualMachinePool.h b/include/VirtualMachinePool.h index eeb70af656d..3b696df2b45 100644 --- a/include/VirtualMachinePool.h +++ b/include/VirtualMachinePool.h @@ -135,15 +135,6 @@ class VirtualMachinePool : public PoolSQL */ int update(PoolObjectSQL * objsql) override; - /** - * Gets a VM ID by its deploy_id, the dedploy_id - VM id mapping is keep - * in the import_table. - * @param deploy_id to search the id for - * @return -1 if not found or VMID - * - */ - int get_vmid(const std::string& deploy_id); - /** * Function to get the IDs of running VMs * @param oids a vector that contains the IDs @@ -237,13 +228,7 @@ class VirtualMachinePool : public PoolSQL */ static int bootstrap(SqlDB * _db) { - int rc; - std::ostringstream oss_import(one_db::vm_import_db_bootstrap); - - rc = VirtualMachine::bootstrap(_db); - rc += _db->exec_local_wr(oss_import); - - return rc; + return VirtualMachine::bootstrap(_db); }; /** @@ -421,12 +406,6 @@ class VirtualMachinePool : public PoolSQL */ void delete_attach_nic(std::unique_ptr vm); - /** - * Deletes an entry in the HV-2-vmid mapping table for imported VMs - * @param deploy_id of the VM - */ - void drop_index(const std::string& deploy_id); - private: /** * Factory method to produce VM objects @@ -457,20 +436,6 @@ class VirtualMachinePool : public PoolSQL * note: datastore cost is always counted in poweroff and suspended state */ bool _showback_only_running; - - /** - * Callback used to get an int in the DB it is used by VM Pool in: - * - calculate_showback (min_stime) - * - get_vmid (vmid) - */ - int db_int_cb(void * _min_stime, int num, char **values, char **names); - - /** - * Insert deploy_id - vmid index. - * @param replace will replace and not insert - * @return 0 on success - */ - int insert_index(const std::string& deploy_id, int vm_id, bool replace); }; #endif /*VIRTUAL_MACHINE_POOL_H_*/ diff --git a/install.sh b/install.sh index ae6c66fdcdb..859af3f8373 100755 --- a/install.sh +++ b/install.sh @@ -1091,7 +1091,6 @@ VMM_EXEC_LIB_VCENTER_FILES="src/vmm_mad/remotes/lib/vcenter_driver/datastore.rb src/vmm_mad/remotes/lib/vcenter_driver/vm_template.rb \ src/vmm_mad/remotes/lib/vcenter_driver/network.rb \ src/vmm_mad/remotes/lib/vcenter_driver/vm_folder.rb \ - src/vmm_mad/remotes/lib/vcenter_driver/vmm_importer.rb \ src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine_device/vm_device.rb \ src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine_device/vm_disk.rb \ src/vmm_mad/remotes/lib/vcenter_driver/virtual_machine_device/vm_nic.rb \ diff --git a/share/doc/xsd/opennebula_configuration.xsd b/share/doc/xsd/opennebula_configuration.xsd index bab543bd8e3..28aa070ad1d 100644 --- a/share/doc/xsd/opennebula_configuration.xsd +++ b/share/doc/xsd/opennebula_configuration.xsd @@ -329,7 +329,6 @@ - diff --git a/share/etc/oned.conf b/share/etc/oned.conf index be02d646a89..0aba95dc300 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -418,46 +418,6 @@ IM_MAD = [ # live_resize: [yes|no] Hypervisor supports hotplug VCPU and memory # # support_shareable: [yes|no] Hypervisor supports shareable disks -# -# imported_vms_actions : comma-separated list of actions supported -# for imported vms. The available actions are: -# migrate -# live-migrate -# terminate -# terminate-hard -# undeploy -# undeploy-hard -# hold -# release -# stop -# suspend -# resume -# delete -# delete-recreate -# reboot -# reboot-hard -# resched -# unresched -# poweroff -# poweroff-hard -# disk-attach -# disk-detach -# nic-attach -# nic-detach -# disk-snapshot-create -# disk-snapshot-delete -# disk-snapshot-rename -# disk-snapshot-revert -# disk-resize -# disk-saveas -# resize -# update -# updateconf -# snapshot-create -# snapshot-delete -# snapshot-revert -# recover -# retry #******************************************************************************* #------------------------------------------------------------------------------- @@ -486,11 +446,7 @@ VM_MAD = [ TYPE = "kvm", KEEP_SNAPSHOTS = "yes", LIVE_RESIZE = "yes", - SUPPORT_SHAREABLE = "yes", - IMPORTED_VMS_ACTIONS = "terminate, terminate-hard, hold, release, suspend, - resume, delete, reboot, reboot-hard, resched, unresched, disk-attach, - disk-detach, nic-attach, nic-detach, snapshot-create, snapshot-delete, - resize, updateconf, update" + SUPPORT_SHAREABLE = "yes" ] # This variant should be used for nested virtualization @@ -503,11 +459,7 @@ VM_MAD = [ TYPE = "qemu", KEEP_SNAPSHOTS = "yes", LIVE_RESIZE = "yes", - SUPPORT_SHAREABLE = "yes", - IMPORTED_VMS_ACTIONS = "terminate, terminate-hard, hold, release, suspend, - resume, delete, reboot, reboot-hard, resched, unresched, disk-attach, - disk-detach, nic-attach, nic-detach, snapshot-create, snapshot-delete, - resize, updateconf, update" + SUPPORT_SHAREABLE = "yes" ] #------------------------------------------------------------------------------- @@ -533,10 +485,7 @@ VM_MAD = [ ARGUMENTS = "-t 15 -r 0 lxc", # DEFAULT = "vmm_exec/vmm_exec_lxc.conf", TYPE = "xml", - KEEP_SNAPSHOTS = "no", - IMPORTED_VMS_ACTIONS = "terminate, terminate-hard, reboot, reboot-hard, - poweroff, poweroff-hard, suspend, resume, stop, delete, nic-attach, - nic-detach, resize, updateconf, update" + KEEP_SNAPSHOTS = "no" ] #------------------------------------------------------------------------------- @@ -557,12 +506,7 @@ VM_MAD = [ # KEEP_SNAPSHOTS = "yes", # DS_LIVE_MIGRATION = "yes", # COLD_NIC_ATTACH = "yes", -# LIVE_RESIZE = "yes", -# IMPORTED_VMS_ACTIONS = "terminate, terminate-hard, hold, release, suspend, -# resume, delete, reboot, reboot-hard, resched, unresched, poweroff, -# poweroff-hard, disk-attach, disk-detach, disk-resize, nic-attach, -# nic-detach, snapshot-create, snapshot-delete, snapshot-revert, migrate, -# live-migrate, resize, updateconf, update, recover" +# LIVE_RESIZE = "yes" #] #------------------------------------------------------------------------------- diff --git a/share/shell/bash_completion b/share/shell/bash_completion index dfc63061029..221bb71aa80 100755 --- a/share/shell/bash_completion +++ b/share/shell/bash_completion @@ -398,14 +398,14 @@ _onehost() { pprev="${COMP_WORDS[COMP_CWORD-2]}" fi opts="create delete enable disable offline update sync list show top flush - rename importvm forceupdate monitoring" + rename forceupdate monitoring" cmd=onehost if [ "$COMP_CWORD" == 1 ]; then COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) return 0 elif [ "$COMP_CWORD" == 2 ]; then case "$prev" in - delete|disable|offline|update|sync|show|flush|rename|importvm| \ + delete|disable|offline|update|sync|show|flush|rename| \ forceupdate|monitoring) _complete $cmd ;; diff --git a/src/cli/one_helper/onehost_helper.rb b/src/cli/one_helper/onehost_helper.rb index 6445915bae0..b2d2464c8c4 100644 --- a/src/cli/one_helper/onehost_helper.rb +++ b/src/cli/one_helper/onehost_helper.rb @@ -700,7 +700,7 @@ def format_resource(host, _options = {}) format = '%-30.30s %36s %4s %10s' CLIHelper.print_header(format(format, 'NAME', - 'IMPORT_ID', 'CPU', 'MEMORY'), + 'DEPLOY_ID', 'CPU', 'MEMORY'), true) wilds.each do |wild| @@ -718,8 +718,9 @@ def format_resource(host, _options = {}) line[/CPU/] end[0].split('=')[1].tr('"', ' ').strip else - name = wild['DEPLOY_ID'] - import = memory = cpu = '-' + name = wild['VM_NAME'] + import = wild['DEPLOY_ID'] + memory = cpu = '-' end puts format(format, name, import, cpu, memory) diff --git a/src/cli/onehost b/src/cli/onehost index 669e8d7ca18..ed08dc68119 100755 --- a/src/cli/onehost +++ b/src/cli/onehost @@ -354,23 +354,6 @@ CommandParser::CmdParser.new(ARGV) do end end - importvm_desc = <<-EOT.unindent - Import VM to OpenNebula - EOT - - command :importvm, - importvm_desc, - :hostid, - :name, - :options => [IPV4, IPV6] do - helper.perform_action(args[0], options, 'imported') do |o| - rc = o.info - next rc if OpenNebula.is_error?(rc) - - o.import_wild(args[1], options[:ipv4], options[:ipv6]) - end - end - forceupdate_desc = <<-EOT.unindent Forces host monitoring update Examples: diff --git a/src/cli/onevcenter b/src/cli/onevcenter index 3f23fd6c9ab..273525f932e 100755 --- a/src/cli/onevcenter +++ b/src/cli/onevcenter @@ -403,7 +403,7 @@ CommandParser::CmdParser.new(ARGV) do vmid = args[0] remove_str = "\n onevm recover --delete-db #{vmid}" \ "\n\nAfter a monitoring cycle, the VM will appear "\ - 'as a Wild VM for reimport.' + 'as a Wild VM.' print 'Extracting information from VM ' + vmid diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index 18bcabb1359..8ad5aa1c7e0 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -108,82 +108,6 @@ int DispatchManager::deploy(unique_ptr vm, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int DispatchManager::import(unique_ptr vm, const RequestAttributes& ra) -{ - string import_state; - - int uid; - int gid; - - VirtualMachineTemplate quota_tmpl; - bool do_quotas = false; - - string error; - - if ( vm == nullptr ) - { - return -1; - } - - if ( vm->get_state() != VirtualMachine::PENDING && - vm->get_state() != VirtualMachine::HOLD ) - { - return -1; - } - - time_t the_time = time(0); - HostShareCapacity sr; - - vm->get_capacity(sr); - - hpool->add_capacity(vm->get_hid(), sr); - - import_state = vm->get_import_state(); - - if (import_state == "POWEROFF") - { - vm->set_state(VirtualMachine::POWEROFF); - vm->set_state(VirtualMachine::LCM_INIT); - } - else - { - vm->set_state(VirtualMachine::ACTIVE); - vm->set_state(VirtualMachine::RUNNING); - - uid = vm->get_uid(); - gid = vm->get_gid(); - - vm->get_quota_template(quota_tmpl, false, true); - - do_quotas = true; - } - - vm->set_stime(the_time); - - vm->set_prolog_stime(the_time); - vm->set_prolog_etime(the_time); - - vm->set_running_stime(the_time); - - vm->set_vm_info(); - - vmpool->update_history(vm.get()); - - vmpool->update(vm.get()); - - vm.reset(); //force unlock of vm mutex - - if ( do_quotas ) - { - Quotas::vm_check(uid, gid, "a_tmpl, error); - } - - return 0; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - int DispatchManager::migrate(VirtualMachine * vm, int poff_migrate, const RequestAttributes& ra) { @@ -340,11 +264,6 @@ void DispatchManager::free_vm_resources(unique_ptr vm, uid = vm->get_uid(); gid = vm->get_gid(); - if (vm->is_imported()) - { - deploy_id = vm->get_deploy_id(); - } - if (vm->is_vrouter()) { vrid = vm->get_vrouter_id(); @@ -361,11 +280,6 @@ void DispatchManager::free_vm_resources(unique_ptr vm, Quotas::ds_del(uid, gid, ds_quotas); } - if (!deploy_id.empty()) - { - vmpool->drop_index(deploy_id); - } - if (vrid != -1) { if (auto vr = vrouterpool->get(vrid)) diff --git a/src/host/Host.cc b/src/host/Host.cc index 99f49756057..09d95ea96b0 100644 --- a/src/host/Host.cc +++ b/src/host/Host.cc @@ -273,13 +273,6 @@ void Host::update_wilds() continue; } - if (vmid == -1) //Check if it is an imported - { - VirtualMachinePool * vmpool = Nebula::instance().get_vmpool(); - - vmid = vmpool->get_vmid(vatt->vector_value("DEPLOY_ID")); - } - if (vmid == -1) { if (num_wilds++ > 0) diff --git a/src/im/InformationManager.cc b/src/im/InformationManager.cc index e2c42ca5496..4699fa96204 100644 --- a/src/im/InformationManager.cc +++ b/src/im/InformationManager.cc @@ -443,18 +443,6 @@ void InformationManager::_vm_state(unique_ptr msg) vm_tmpl->vector_value("DEPLOY_ID", deploy_id); vm_tmpl->vector_value("STATE", state_str); - if (id < 0) - { - // Check wild VMs - id = vmpool->get_vmid(deploy_id); - - if (id < 0) - { - // Not imported wild, ignore VM state - continue; - } - } - hv_ids.insert(id); NebulaLog::debug("InM", "VM_STATE update from host: " + diff --git a/src/im_mad/remotes/lib/probe_db.rb b/src/im_mad/remotes/lib/probe_db.rb index 7603e020cf4..8805e95dd51 100644 --- a/src/im_mad/remotes/lib/probe_db.rb +++ b/src/im_mad/remotes/lib/probe_db.rb @@ -87,7 +87,7 @@ def to_status if sync_state then status_str = "SYNC_STATE=yes\nMISSING_STATE=#{@conf[:missing_state]}\n" - + @db.execute("REPLACE INTO #{@settings} VALUES ('LAST_SYNC', #{time.to_s})") end @@ -98,6 +98,7 @@ def to_status # ---------------------------------------------------------------------- vms.each do |uuid, vm| next if vm[:ignore] == true + next if vm[:id].to_i < 0 # Skip wild VMs if vm[:id] == -1 filter = "WHERE uuid = '#{uuid}'" @@ -124,7 +125,7 @@ def to_status ) status_str << vm_to_status(vm) - + next end @@ -165,7 +166,7 @@ def to_status @db.execute("DELETE FROM #{@dataset} WHERE uuid = \"#{uuid}\"") else status_str << vm_db_to_status(vm_db) if sync_state - + @db.execute( "UPDATE #{@dataset} SET " \ "timestamp = #{time}, " \ diff --git a/src/monitor/include/HostMonitorManager.h b/src/monitor/include/HostMonitorManager.h index 0d60bf0954d..bfd500c92da 100644 --- a/src/monitor/include/HostMonitorManager.h +++ b/src/monitor/include/HostMonitorManager.h @@ -133,14 +133,6 @@ class HostMonitorManager void monitor_vm(int oid, const Template &tmpl); - /** - * Sets the monitor information of the VM. - * @param deploy_id Wild VM deploy_id - * @param tmpl monitoring template - */ - void monitor_wild_vm(const std::string &deploy_id, - const Template &tmpl); - /** * Receive start monitor failure/success from driver * @param oid host id diff --git a/src/monitor/include/VMRPCPool.h b/src/monitor/include/VMRPCPool.h index 3ca97b9a1a7..5aaddf734f7 100644 --- a/src/monitor/include/VMRPCPool.h +++ b/src/monitor/include/VMRPCPool.h @@ -58,13 +58,6 @@ class VMRPCPool : public RPCPool */ bool get_monitoring(int vmid, VirtualMachineMonitorInfo& vm); - /** - * Gets a VM ID by its deploy_id - * @param deploy_id to search the id for - * @return -1 if not found or VMID - */ - int get_vmid(const std::string& deploy_id); - protected: void add_object(xmlNodePtr node) override { diff --git a/src/monitor/src/data_model/VMRPCPool.cc b/src/monitor/src/data_model/VMRPCPool.cc index b31de2d368c..1ca318bbb43 100644 --- a/src/monitor/src/data_model/VMRPCPool.cc +++ b/src/monitor/src/data_model/VMRPCPool.cc @@ -101,34 +101,6 @@ bool VMRPCPool::get_monitoring(int vmid, VirtualMachineMonitorInfo& vm) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VMRPCPool::get_vmid(const string& deploy_id) -{ - int rc; - int vmid = -1; - ostringstream oss; - - single_cb cb; - - cb.set_callback(&vmid); - - oss << "SELECT vmid FROM " << one_db::vm_import_table - << " WHERE deploy_id = '" << db->escape_str(deploy_id) << "'"; - - rc = db->exec_rd(oss, &cb); - - cb.unset_callback(); - - if (rc != 0 ) - { - return -1; - } - - return vmid; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - int VMRPCPool::clean_expired_monitoring() { if (monitor_expiration <= 0) diff --git a/src/monitor/src/monitor/HostMonitorManager.cc b/src/monitor/src/monitor/HostMonitorManager.cc index 732be3d310c..dd1e7ca64b3 100644 --- a/src/monitor/src/monitor/HostMonitorManager.cc +++ b/src/monitor/src/monitor/HostMonitorManager.cc @@ -352,29 +352,6 @@ void HostMonitorManager::monitor_vm(int oid, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void HostMonitorManager::monitor_wild_vm(const string& deploy_id, - const Template &tmpl) -{ - if (!is_leader) - { - return; - } - - // Wild VM, check if it is imported to OpenNebula - int oid = vmpool->get_vmid(deploy_id); - - if (oid < 0) - { - // Not imported VM, ignore monitoring - return; - } - - monitor_vm(oid, tmpl); -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - void HostMonitorManager::start_monitor_failure(int oid) { if (!is_leader) diff --git a/src/monitor/src/monitor/MonitorDriverProtocol.cc b/src/monitor/src/monitor/MonitorDriverProtocol.cc index 772ba906677..7fb59b75598 100644 --- a/src/monitor/src/monitor/MonitorDriverProtocol.cc +++ b/src/monitor/src/monitor/MonitorDriverProtocol.cc @@ -110,7 +110,7 @@ void MonitorDriverProtocol::_monitor_vm(unique_ptr msg) string monitor_b64; string deploy_id; - if (vm->vector_value("ID", id) != 0) + if (vm->vector_value("ID", id) != 0 || id < 0) { continue; } @@ -135,24 +135,16 @@ void MonitorDriverProtocol::_monitor_vm(unique_ptr msg) continue; } - if (id < 0) + // OpenNebula VM, merge templates with same ID + auto it = vms_templ.find(id); + + if (it == vms_templ.end()) { - // Wild VM, no need to merge storage monitor data - hm->monitor_wild_vm(deploy_id, mon_tmpl); + vms_templ[id] = move(mon_tmpl); } else { - // OpenNebula VM, merge templates with same ID - auto it = vms_templ.find(id); - - if (it == vms_templ.end()) - { - vms_templ[id] = move(mon_tmpl); - } - else - { - it->second.merge(&mon_tmpl); - } + it->second.merge(&mon_tmpl); } } diff --git a/src/oca/ruby/opennebula/host.rb b/src/oca/ruby/opennebula/host.rb index ae315168d94..c0a873a86e3 100644 --- a/src/oca/ruby/opennebula/host.rb +++ b/src/oca/ruby/opennebula/host.rb @@ -213,60 +213,6 @@ def rename(name) return call(HOST_METHODS[:rename], @pe_id, name) end - # Imports a wild VM from the host and puts it in running state - # - # @param name [String] Name of the VM to import - # @param ipv4 [Array] Array with IP4s to set - # @param ipv6 [Array] Array with IP6s to set - # - # @return [nil, OpenNebula::Error] nil in case of success, Error - # otherwise - def import_wild(name, ipv4 = nil, ipv6 = nil) - vms = importable_wilds.select {|vm| vm['VM_NAME'] == name } - - if vms.length == 0 - return OpenNebula::Error.new("No importable wilds with name " << - "'#{name}' found.") - elsif vms.length > 1 - return OpenNebula::Error.new("More than one importable wild " << - "with name '#{name}' found.") - end - - wild = vms.first - - template = Base64.decode64(wild['IMPORT_TEMPLATE']) - - xml = OpenNebula::VirtualMachine.build_xml - vm = OpenNebula::VirtualMachine.new(xml, @client) - - # vCenter wild VMs has a different process - # image and vnets objects representing existing nics and disks - # must be created and referenced - vcenter_wild_vm = wild.key? "VCENTER_TEMPLATE" - if vcenter_wild_vm - require 'vcenter_driver' - vi_client = VCenterDriver::VIClient.new_from_host(self["ID"]) - importer = VCenterDriver::VmmImporter.new(@client, vi_client) - - return importer.import( - { :wild => wild, - :template => template, - :one_item => vm, - :host => self['ID'], - :ipv4 => ipv4, - :ipv6 => ipv6 - } - ) - else - rc = vm.allocate(template) - - return rc if OpenNebula.is_error?(rc) - - vm.deploy(id, false) - return vm.id - end - end - ####################################################################### # Helpers to get Host information ####################################################################### @@ -297,11 +243,6 @@ def wilds [self.to_hash['HOST']['TEMPLATE']['VM']].flatten.compact end - # Get importable wild VMs in the host - def importable_wilds - wilds.select {|w| Hash === w && w['IMPORT_TEMPLATE'] } - end - private def set_status(status) return Error.new('ID not defined') if !@pe_id diff --git a/src/onedb/fsck/image.rb b/src/onedb/fsck/image.rb index 85c80737dd2..306de82f4e2 100644 --- a/src/onedb/fsck/image.rb +++ b/src/onedb/fsck/image.rb @@ -49,19 +49,19 @@ def check_image rvms = counters_img[:vms].size n_cloning_ops = counters_img[:clones].size + counters_img[:app_clones].size - # DATA: CHECK: running vm counter with this image - # rewrite running_vms - doc.root.xpath("RUNNING_VMS") {|e| - if e.text != rvms.to_s - log_error("Image #{oid} RUNNING_VMS has #{e.text} \tis\t#{rvms}") - e.text = rvms - error = true - end - } - # For non-backup Images check VM references image_type = doc.root.xpath('TYPE').text.to_i if image_type != 6 + # DATA: CHECK: running vm counter with this image + # rewrite running_vms + old_rvms = doc.root.at_xpath("RUNNING_VMS") + + if !old_rvms.nil? && old_rvms.text != rvms.to_s + log_error("Image #{oid} RUNNING_VMS has #{old_rvms.text} \tis\t#{rvms}") + old_rvms.content = rvms + error = true + end + # re-do list of VM IDs vms_elem = doc.root.xpath("VMS").remove @@ -87,7 +87,6 @@ def check_image end end - if ( persistent && rvms > 0 ) n_cloning_ops = 0 counters_img[:clones] = Set.new @@ -95,7 +94,7 @@ def check_image end # DATA: CHECK: Check number of clones - doc.root.xpath("CLONING_OPS") { |e| + doc.root.xpath("CLONING_OPS").each { |e| if e.text != n_cloning_ops.to_s log_error("Image #{oid} CLONING_OPS has #{e.text} \tis\t#{n_cloning_ops}") e.text = n_cloning_ops @@ -180,15 +179,17 @@ def check_image end end - doc.root.xpath("STATE") { |e| - if e.text != state.to_s - log_error("Image #{oid} has STATE " << - OpenNebula::Image::IMAGE_STATES[e.text.to_i] << - " \tis\t#{OpenNebula::Image::IMAGE_STATES[state]}") - e.text = state - error = true - end - } + # Update state if needed + old_state = doc.root.at_xpath("STATE") + + if !old_state.nil? && old_state.text.to_i != state + log_error("Image #{oid} has STATE " << + OpenNebula::Image::IMAGE_STATES[old_state.text.to_i] << + " \tis\t#{OpenNebula::Image::IMAGE_STATES[state]}") + old_state.content = state + error = true + end + @fixes_image[oid] = doc.root.to_s if error end diff --git a/src/onedb/fsck/network.rb b/src/onedb/fsck/network.rb index 73e2aa31a4e..ce74bf8f24f 100644 --- a/src/onedb/fsck/network.rb +++ b/src/onedb/fsck/network.rb @@ -383,11 +383,11 @@ def check_ar_leases(oid, doc, ar_leases, counter_no_ar) addrs = { :mac => first_mac, :ip => first_ip, :ipv6 => ipv6 } counters = { :ar => counter_ar, :no_ar => counter_no_ar } - error, new_leases = calculate_new_leases(leases, - ids, - addrs, - counters, - error) + error, new_leases, removed_leases = calculate_new_leases(leases, + ids, + addrs, + counters, + error) counter_ar.each do |mac, counter_lease| next if mac.nil? @@ -415,6 +415,14 @@ def check_ar_leases(oid, doc, ar_leases, counter_no_ar) unless new_leases.empty? add_cdata(net_ar, 'ALLOCATED', " #{new_leases.join(' ')}") end + + next if removed_leases.empty? + + removed = removed_leases.join(',') + doc.xpath("VNET/UPDATED_VMS/ID[contains('#{removed}',.)]").remove + doc.xpath("VNET/OUTDATED_VMS/ID[contains('#{removed}',.)]").remove + doc.xpath("VNET/UPDATING_VMS/ID[contains('#{removed}',.)]").remove + doc.xpath("VNET/ERROR_VMS/ID[contains('#{removed}',.)]").remove end [error, new_used_leases] @@ -462,6 +470,7 @@ def fix_parameters(counter_lease) # @return [Boolean/Leases] The current value of error and new leases def calculate_new_leases(leases, ids, addrs, counters, error) new_leases = [] + removed_leases = [] leases.each do |lease_str| index = lease_str[0].to_i @@ -494,6 +503,8 @@ def calculate_new_leases(leases, ids, addrs, counters, error) if counter_lease.nil? if lease[:vm] != HOLD + removed_leases << lease_oid + log_error("VNet #{ids[:o]} AR #{ids[:ar]} has " \ "leased #{lease_to_s(lease)} to #{lease_obj} " \ "#{lease_oid}, but it is actually free") @@ -545,7 +556,7 @@ def calculate_new_leases(leases, ids, addrs, counters, error) end end - [error, new_leases] + [error, new_leases, removed_leases] end end diff --git a/src/rm/RequestManagerUpdateTemplate.cc b/src/rm/RequestManagerUpdateTemplate.cc index e7212b0cc11..cb9dca34fb3 100644 --- a/src/rm/RequestManagerUpdateTemplate.cc +++ b/src/rm/RequestManagerUpdateTemplate.cc @@ -151,15 +151,6 @@ void VirtualMachineUpdateTemplate::request_execute(int oid, return; } - // Check if the action is supported for imported VMs - if (vm->is_imported() && !vm->is_imported_action_supported(VMActions::UPDATE_ACTION)) - { - att.resp_msg = "Action \"update\" is not supported for imported VMs"; - failure_response(ACTION, att); - - return; - } - // Apply generic quota deltas auto new_tmpl = make_unique(false, '=', "USER_TEMPLATE"); diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index c6326536d25..026c86edfc8 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -487,15 +487,6 @@ Request::ErrorCode VirtualMachineAction::request_execute(RequestAttributes& att, return NO_EXISTS; } - // Check if the action is supported for imported VMs - if (vm->is_imported() && !vm->is_imported_action_supported(action)) - { - att.resp_msg = "Action \"" + action_str + "\" is not supported for " - "imported VMs"; - - return ACTION; - } - switch (action) { case VMActions::TERMINATE_ACTION: @@ -1033,17 +1024,10 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, } // ------------------------------------------------------------------------ - // deploy the VM (import/deploy unlocks the vm object) + // deploy the VM (unlocks the vm object) // ------------------------------------------------------------------------ - if (vm->is_imported()) - { - dm->import(std::move(vm), att); - } - else - { - dm->deploy(std::move(vm), att); - } + dm->deploy(std::move(vm), att); success_response(id, att); } @@ -1078,8 +1062,6 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList bool auth = false; bool ds_migr; - VMActions::Action action; - // ------------------------------------------------------------------------ // Get request parameters and information about the target host // ------------------------------------------------------------------------ @@ -1178,26 +1160,9 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList return; } - if (live) - { - action = VMActions::LIVE_MIGRATE_ACTION; - - if ( vm->is_pinned() ) - { - att.resp_msg = "VM with a pinned NUMA topology cannot be live-migrated"; - failure_response(ACTION, att); - - return; - } - } - else - { - action = VMActions::MIGRATE_ACTION; - } - - if (vm->is_imported() && !vm->is_imported_action_supported(action)) + if (live && vm->is_pinned()) { - att.resp_msg = "Migration is not supported for imported VMs"; + att.resp_msg = "VM with a pinned NUMA topology cannot be live-migrated"; failure_response(ACTION, att); return; @@ -1755,17 +1720,6 @@ void VirtualMachineAttach::request_execute( return; } - - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::DISK_ATTACH_ACTION)) - { - att.resp_msg = "Action \"disk-attach\" is not supported for " - "imported VMs"; - failure_response(ACTION, att); - - return; - } } else { @@ -1951,17 +1905,6 @@ void VirtualMachineDetach::request_execute(xmlrpc_c::paramList const& paramList, return; } - - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::DISK_DETACH_ACTION)) - { - att.resp_msg = "Action \"disk-detach\" is not supported for " - "imported VMs"; - failure_response(ACTION, att); - - return; - } } else { @@ -2073,17 +2016,6 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, /* ---------------------------------------------------------------------- */ if ( auto vm = vmpool->get_ro(id) ) { - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::RESIZE_ACTION)) - { - att.resp_msg = "Action \"resize\" is not supported for " - "imported VMs"; - failure_response(ACTION, att); - - return; - } - vm->get_permissions(vm_perms); vm->get_template_attribute("MEMORY", omemory); @@ -2187,15 +2119,6 @@ Request::ErrorCode VirtualMachineSnapshotCreate::request_execute(RequestAttribut // Check if the action is supported for imported VMs if (auto vm = pool->get_ro(vid)) { - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::SNAPSHOT_CREATE_ACTION)) - { - att.resp_msg = "Action \"snapshot-create\" is not supported for " - "imported VMs"; - - return ACTION; - } - auto vm_bck = vm->backups(); if ( vm_bck.configured() && vm_bck.mode() == Backups::INCREMENT ) @@ -2284,25 +2207,6 @@ Request::ErrorCode VirtualMachineSnapshotRevert::request_execute( return auth; } - // Check if the action is supported for imported VMs - if (auto vm = pool->get_ro(vid)) - { - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::SNAPSHOT_REVERT_ACTION)) - { - att.resp_msg = "Action \"snapshot-revert\" is not supported for " - "imported VMs"; - - return ACTION; - } - } - else - { - att.resp_id = vid; - return NO_EXISTS; - } - rc = dm->snapshot_revert(vid, snap_id, att, att.resp_msg); if ( rc != 0 ) @@ -2355,24 +2259,6 @@ Request::ErrorCode VirtualMachineSnapshotDelete::request_execute( return auth; } - // Check if the action is supported for imported VMs - if (auto vm = pool->get_ro(vid)) - { - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::SNAPSHOT_DELETE_ACTION)) - { - att.resp_msg = "Action \"snapshot-delete\" is not supported for " - "imported VMs"; - - return ACTION; - } - } - else - { - att.resp_id = vid; - return NO_EXISTS; - } - rc = dm->snapshot_delete(vid, snap_id, att, att.resp_msg); if ( rc != 0 ) @@ -2431,17 +2317,6 @@ void VirtualMachineAttachNic::request_execute( return; } - - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::NIC_ATTACH_ACTION)) - { - att.resp_msg = "Action \"nic-attach\" is not supported for " - "imported VMs"; - failure_response(ACTION, att); - - return; - } } else { @@ -2633,17 +2508,6 @@ void VirtualMachineDetachNic::request_execute( failure_response(Request::ACTION, att); return; } - - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::NIC_DETACH_ACTION)) - { - att.resp_msg = "Action \"nic-detach\" is not supported for " - "imported VMs"; - failure_response(ACTION, att); - - return; - } } else { @@ -2745,17 +2609,6 @@ void VirtualMachineUpdateNic::request_execute( return; } - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::NIC_UPDATE_ACTION)) - { - att.resp_msg = "Action \"nic-update\" is not supported for " - "imported VMs"; - failure_response(ACTION, att); - - return; - } - vm->get_permissions(vm_perms); auto nic = vm->get_nic(nic_id); @@ -2891,17 +2744,6 @@ void VirtualMachineRecover::request_execute( return; } - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(action)) - { - att.resp_msg = "Action \"" + VMActions::action_to_str(action) + - "\" is not supported for imported VMs"; - failure_response(ACTION, att); - - return; - } - switch (op) { case 0: //recover-failure @@ -3004,16 +2846,6 @@ Request::ErrorCode VirtualMachineDiskSnapshotCreate::request_execute( if (auto vm = pool->get_ro(vid)) { - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::DISK_SNAPSHOT_CREATE_ACTION)) - { - att.resp_msg = "Action \"disk-snapshot-create\" is not supported for " - "imported VMs"; - - return ACTION; - } - auto vm_bck = vm->backups(); if ( vm_bck.configured() && vm_bck.mode() == Backups::INCREMENT ) @@ -3208,24 +3040,6 @@ Request::ErrorCode VirtualMachineDiskSnapshotRevert::request_execute( return auth; } - if (auto vm = pool->get_ro(vid)) - { - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::DISK_SNAPSHOT_REVERT_ACTION)) - { - att.resp_msg = "Action \"disk-snapshot-revert\" is not supported for " - "imported VMs"; - - return ACTION; - } - } - else - { - att.resp_id = vid; - return NO_EXISTS; - } - rc = dm->disk_snapshot_revert(vid, disk_id, snap_id, att, att.resp_msg); if ( rc != 0 ) @@ -3278,16 +3092,6 @@ Request::ErrorCode VirtualMachineDiskSnapshotDelete::request_execute( if (auto vm = pool->get_ro(vid)) { - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::DISK_SNAPSHOT_DELETE_ACTION)) - { - att.resp_msg = "Action \"disk-snapshot-delete\" is not supported for " - "imported VMs"; - - return ACTION; - } - disk = vm->get_disk(disk_id); if (disk == nullptr) @@ -3407,17 +3211,6 @@ void VirtualMachineDiskSnapshotRename::request_execute(xmlrpc_c::paramList const return; } - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::DISK_SNAPSHOT_RENAME_ACTION)) - { - att.resp_msg = "Action \"disk-snapshot-rename\" is not supported for " - "imported VMs"; - failure_response(ACTION, att); - - return; - } - disk = vm->get_disk(did); if (disk == nullptr) @@ -3501,17 +3294,6 @@ void VirtualMachineUpdateConf::request_execute( return; } - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::UPDATECONF_ACTION)) - { - att.resp_msg = "Action \"updateconf\" is not supported for " - "imported VMs"; - failure_response(ACTION, att); - - return; - } - if (!att.is_admin()) { string aname; @@ -3628,17 +3410,6 @@ void VirtualMachineDiskResize::request_execute( if ( auto vm = get_vm(id, att) ) { - // Check if the action is supported for imported VMs - if (vm->is_imported() && - !vm->is_imported_action_supported(VMActions::DISK_RESIZE_ACTION)) - { - att.resp_msg = "Action \"disk-resize\" is not supported for " - "imported VMs"; - failure_response(ACTION, att); - - return; - } - VirtualMachineDisk * disk = vm->get_disk(did); if (disk == nullptr) diff --git a/src/sql/OneDB.cc b/src/sql/OneDB.cc index 8c7779ed2d9..2d0e1d4bc8b 100644 --- a/src/sql/OneDB.cc +++ b/src/sql/OneDB.cc @@ -84,14 +84,6 @@ namespace one_db "(vmid INTEGER, year INTEGER, month INTEGER, body MEDIUMTEXT, " "PRIMARY KEY(vmid, year, month))"; - const char * vm_import_table = "vm_import"; - - const char * vm_import_db_names = "deploy_id, vmid"; - - const char * vm_import_db_bootstrap = - "CREATE TABLE IF NOT EXISTS vm_import " - "(deploy_id VARCHAR(128), vmid INTEGER, PRIMARY KEY(deploy_id))"; - const char * vm_group_table = "vmgroup_pool"; diff --git a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb index af06dd7bbc9..7715a3455c7 100644 --- a/src/sunstone/models/OpenNebulaJSON/HostJSON.rb +++ b/src/sunstone/models/OpenNebulaJSON/HostJSON.rb @@ -61,7 +61,6 @@ def perform_action(template_json) when "offline" then self.offline when "update" then self.update(action_hash['params']) when "rename" then self.rename(action_hash['params']) - when "import_wild" then self.import_wild(action_hash['params']) else error_msg = "#{action_hash['perform']} action not " << " available for this resource" @@ -80,14 +79,5 @@ def update(params=Hash.new) def rename(params=Hash.new) super(params['name']) end - - def import_wild(params=Hash.new) - rc = super(params['name']) - if OpenNebula.is_error?(rc) - return rc - else - return VirtualMachineJSON.new_with_id(rc, @client) - end - end end end diff --git a/src/sunstone/public/app/opennebula/host.js b/src/sunstone/public/app/opennebula/host.js index f5e573117cf..12fa4220afc 100644 --- a/src/sunstone/public/app/opennebula/host.js +++ b/src/sunstone/public/app/opennebula/host.js @@ -129,10 +129,6 @@ define(function(require) { var action_obj = params.data.extra_param; OpenNebulaAction.simple_action(params, RESOURCE, "rename", action_obj); }, - "import_wild" : function(params) { - var action_obj = params.data.extra_param; - OpenNebulaAction.simple_action(params, RESOURCE, "import_wild", action_obj); - }, "getName": function(id){ return OpenNebulaAction.getName(id, RESOURCE); }, diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js index 0fe7c6aac8e..0258ce32976 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/info.js +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/info.js @@ -19,7 +19,6 @@ define(function(require) { */ require("foundation"); - var CanImportWilds = require("../utils/can-import-wilds"); var CapacityTable = require("utils/custom-tags-table"); var ClusterTr = require("utils/panel/cluster-tr"); var CPUBars = require("../utils/cpu-bars"); @@ -65,7 +64,6 @@ define(function(require) { this.icon = "fa-info-circle"; this.element = info[XML_ROOT]; - this.canImportWilds = CanImportWilds(this.element); return this; }; @@ -87,7 +85,7 @@ define(function(require) { Sunstone.runAction("Cluster.list"); cache = OpenNebulaAction.cache("CLUSTER"); } - + var elementAux = Reserved.updateHostTemplate(cache, this.element); var attributes = TemplateTable.getTemplatesAttributes(this.element.TEMPLATE, { regexVCenter: REGEX_VCENTER_ATTRS, @@ -180,7 +178,7 @@ define(function(require) { RenameTr.setup(TAB_ID, RESOURCE, this.element.ID, context); ClusterTr.setup(RESOURCE, this.element.ID, this.element.CLUSTER_ID, context); - PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context); + PermissionsTable.setup(TAB_ID, RESOURCE, this.element, context); var attributes = TemplateTable.getTemplatesAttributes(this.element.TEMPLATE, { regexVCenter: REGEX_VCENTER_ATTRS, diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js index 2b7f9584220..570cdc1ba50 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds.js @@ -22,7 +22,6 @@ define(function(require) { require("datatables.net"); require("datatables.foundation"); var Locale = require("utils/locale"); - var CanImportWilds = require("../utils/can-import-wilds"); var OpenNebulaHost = require("opennebula/host"); var OpenNebulaAction = require("opennebula/action"); var Notifier = require("utils/notifier"); @@ -72,10 +71,6 @@ define(function(require) { function _setup(context) { var that = this; - // Hide the import button if the Wilds cannot be imported - if (!CanImportWilds(this.element)) { - $("#import_wilds").hide(); - } that.dataTableWildHosts = $("#datatable_host_wilds", context).dataTable({ "bSortClasses" : false, @@ -121,117 +116,7 @@ define(function(require) { return false; }) - // Enable the import button when at least a VM is selected - $("#import_wilds", context).attr("disabled", "disabled").on("click.disable", function(e) { return false; }); - - context.off("change", ".import_wild_checker"); - context.on("change", ".import_wild_checker", function(){ - if ($(".import_wild_checker:checked", context).length == 0){ - $("#import_wilds", context).attr("disabled", "disabled").on("click.disable", function(e) { return false; }); - } else { - $("#import_wilds", context).removeAttr("disabled").off("click.disable"); - } - }); - - // Add event listener for importing WILDS - context.off("click", "#import_wilds"); - context.on("click", "#import_wilds", function () { - $("#import_wilds", context).attr("disabled", "disabled").on("click.disable", function(e) { return false; }); - $("#import_wilds", context).html(""); - - if (that.element.TEMPLATE.HYPERVISOR === "vcenter"){ - var path = "/vcenter/wild"; - var resource = "Wild"; - var vcenter_refs = []; - var opts = {}; - $(".import_wild_checker:checked", "#datatable_host_wilds").each(function() { - var wild_obj = $(this).attr("import_data"); - try{ - var wild_data = JSON.parse(wild_obj); - if(wild_data && wild_data.DEPLOY_ID){ - var ref = wild_data.DEPLOY_ID; - vcenter_refs.push(ref); - opts[ref] = wild_data; - } - }catch(error){ - Notifier.notifyError("Empty data Vm Wild"); - } - }); - - $.ajax({ - url: path, - type: "POST", - data: { - wilds: vcenter_refs.join(","), - opts: opts, - host: that.element.ID, - timeout: false - }, - dataType: "json", - success: function(response){ - $.each(response.success, function(key, value){ - Notifier.notifyCustom(Locale.tr("VM imported"), - Navigation.link(" ID: " + value, "vms-tab", value), false); - }); - VCenterCommon.jGrowlFailure({error : response.error, resource : resource}); - }, - error: function (request, error_json) { - if (request.responseJSON === undefined){ - Notifier.notifyError("Empty response received from server. Check your setup to avoid timeouts"); - } else { - Notifier.notifyError(request.responseJSON.error.message); - } - }, - complete: function (data) { - $("#import_wilds", context).removeAttr("disabled").off("click.disable"); - $("#import_wilds", context).html(Locale.tr("Import Wilds")); - } - }); - } else { - $(".import_wild_checker:checked", "#datatable_host_wilds").each(function() { - var wild_row = $(this).closest("tr"); - var aData = that.dataTableWildHosts.fnGetData(wild_row); - - var dataJSON = { - "id": that.element.ID, - "extra_param": { - "name": aData[1] - } - }; - - // Create the VM in OpenNebula - OpenNebulaHost.import_wild({ - timeout: true, - data: dataJSON, - success: function(request, response) { - OpenNebulaAction.clear_cache("VM"); - Notifier.notifyCustom(Locale.tr("VM imported"), - Navigation.link(" ID: " + response.VM.ID, "vms-tab", response.VM.ID), false); - // Delete row (shouldn't be there in next monitorization) - that.dataTableWildHosts.fnDeleteRow(wild_row); - }, - error: function (request, error_json) { - wildsError(error_json, context); - }, - complete: function (data) { - $("#import_wilds", context).removeAttr("disabled").off("click.disable"); - $("#import_wilds", context).html(Locale.tr("Import Wilds")); - } - }); - }); - } - }); - return false; } - function wildsError(error_json, context){ - var msg; - if (error_json.error.message){ - msg = error_json.error.message; - } else { - msg = Locale.tr("Cannot contact server: is it running and reachable?"); - } - Notifier.notifyError(msg); - } }); diff --git a/src/sunstone/public/app/tabs/hosts-tab/panels/wilds/html.hbs b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds/html.hbs index 1173ea5f681..dd53b08ad11 100644 --- a/src/sunstone/public/app/tabs/hosts-tab/panels/wilds/html.hbs +++ b/src/sunstone/public/app/tabs/hosts-tab/panels/wilds/html.hbs @@ -15,9 +15,6 @@ {{! -------------------------------------------------------------------------- }}
-
- -
diff --git a/src/sunstone/public/app/tabs/hosts-tab/utils/can-import-wilds.js b/src/sunstone/public/app/tabs/hosts-tab/utils/can-import-wilds.js deleted file mode 100644 index 10f3efea3d2..00000000000 --- a/src/sunstone/public/app/tabs/hosts-tab/utils/can-import-wilds.js +++ /dev/null @@ -1,49 +0,0 @@ -/* -------------------------------------------------------------------------- */ -/* Copyright 2002-2024, OpenNebula Project, OpenNebula Systems */ -/* */ -/* Licensed under the Apache License, Version 2.0 (the "License"); you may */ -/* not use this file except in compliance with the License. You may obtain */ -/* a copy of the License at */ -/* */ -/* http://www.apache.org/licenses/LICENSE-2.0 */ -/* */ -/* Unless required by applicable law or agreed to in writing, software */ -/* distributed under the License is distributed on an "AS IS" BASIS, */ -/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */ -/* See the License for the specific language governing permissions and */ -/* limitations under the License. */ -/* -------------------------------------------------------------------------- */ - -define(function(require){ - /* - CONSTRUCTOR - */ - - return _canImportWilds; - - /* - FUNCTION DEFINITIONS - */ - - /* Check if any of the existing VMs in the Host define the IMPORT_TEMPLATE - attribute to be imported into OpenNebula. - @param {Object} element Host element as returned by OpenNebula - @result {Boolean} - */ - function _canImportWilds(element) { - var canImportWilds = false; - if (element.TEMPLATE.VM) { - var vms = element.TEMPLATE.VM; - if (!Array.isArray(vms)) { // If only 1 VM convert to array - vms = [vms]; - } - $.each(vms, function() { - if (this.IMPORT_TEMPLATE) { - canImportWilds = true; - return false; - } - }); - } - return canImportWilds; - } -}); diff --git a/src/sunstone/routes/vcenter.rb b/src/sunstone/routes/vcenter.rb index 6198fcc820c..9089ee13b87 100644 --- a/src/sunstone/routes/vcenter.rb +++ b/src/sunstone/routes/vcenter.rb @@ -270,24 +270,6 @@ def new_vcenter_importer(type, client=nil) end end -post '/vcenter/wild' do - begin - client = one_client - vi_client = viclient_from_host(client) - importer = VCenterDriver::VmmImporter.new(client, vi_client).tap do |im| - im.list(params["host"], params["opts"]) - end - - importer.process_import(params["wilds"]) - - [200, importer.output.to_json] - rescue Exception => e - logger.error("[vCenter] " + e.message) - error = Error.new(e.message) - error 403, error.to_json - end -end - post '/vcenter/register_hooks' do VCenterDriver::VcImporter.register_hooks end diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 0e9f46c3ab8..4d9fd04ec25 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -2249,49 +2249,6 @@ static int parse_memory_mode(string& mem_mode, string& error) } -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -bool VirtualMachine::is_imported() const -{ - bool imported = false; - - get_template_attribute("IMPORTED", imported); - - return imported; -} - -string VirtualMachine::get_import_state() const -{ - string import_state; - - user_obj_template->get("IMPORT_STATE", import_state); - user_obj_template->erase("IMPORT_STATE"); - - return import_state; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -bool VirtualMachine::is_imported_action_supported(VMActions::Action action) const -{ - string vmm_mad; - - if (hasHistory()) - { - vmm_mad = get_vmm_mad(); - } - else - { - user_obj_template->get("HYPERVISOR", vmm_mad); - } - - VirtualMachineManager * vmm = Nebula::instance().get_vmm(); - - return vmm->is_imported_action_supported(vmm_mad, action); -} - /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ diff --git a/src/vm/VirtualMachinePool.cc b/src/vm/VirtualMachinePool.cc index 3e177336af4..6a58d85f65a 100644 --- a/src/vm/VirtualMachinePool.cc +++ b/src/vm/VirtualMachinePool.cc @@ -76,56 +76,8 @@ int VirtualMachinePool::update(PoolObjectSQL * objsql) return vm->update(db); }; -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - -int VirtualMachinePool::insert_index(const string& deploy_id, int vmid, - bool replace) -{ - ostringstream oss; - char * deploy_name = db->escape_str(deploy_id); - - if (deploy_name == 0) - { - return -1; - } - - if (replace) - { - oss << "REPLACE "; - } - else - { - oss << "INSERT "; - } - - oss << "INTO " << one_db::vm_import_table - << " (" << one_db::vm_import_db_names << ") " - << " VALUES ('" << deploy_name << "'," << vmid << ")"; - - db->free_str(deploy_name); - - return db->exec_wr(oss); -}; /* -------------------------------------------------------------------------- */ - -void VirtualMachinePool::drop_index(const string& deploy_id) -{ - ostringstream oss; - char * deploy_name = db->escape_str(deploy_id); - - if (deploy_name == 0) - { - return; - } - - oss << "DELETE FROM " << one_db::vm_import_table << " WHERE deploy_id='" - << deploy_name << "'"; - - db->exec_wr(oss); -} - /* -------------------------------------------------------------------------- */ int VirtualMachinePool::allocate( @@ -157,20 +109,6 @@ int VirtualMachinePool::allocate( vm.prev_state = vm.state; - string deploy_id; - vm.user_obj_template->get("DEPLOY_ID", deploy_id); - - if (!deploy_id.empty()) - { - vm.state = VirtualMachine::HOLD; - - if (insert_index(deploy_id, -1, false) == -1) //Set import in progress - { - error_str = "Virtual Machine " + deploy_id + " already imported."; - return -1; - } - } - // ------------------------------------------------------------------------ // Insert the Object in the pool // ------------------------------------------------------------------------ @@ -181,18 +119,6 @@ int VirtualMachinePool::allocate( // Insert the deploy_id - vmid index for imported VMs // ------------------------------------------------------------------------ - if (!deploy_id.empty()) - { - if (*oid >= 0) - { - insert_index(deploy_id, *oid, true); - } - else - { - drop_index(deploy_id); - } - } - if (*oid >= 0) { if (auto vm2 = get_ro(*oid)) @@ -487,38 +413,6 @@ VirtualMachineMonitorInfo VirtualMachinePool::get_monitoring(int vmid) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualMachinePool::get_vmid(const string& deploy_id) -{ - int rc; - int vmid = -1; - ostringstream oss; - - auto sql_id = db->escape_str(deploy_id); - - single_cb cb; - - cb.set_callback(&vmid); - - oss << "SELECT vmid FROM " << one_db::vm_import_table - << " WHERE deploy_id = '" << sql_id << "'"; - - rc = db->exec_rd(oss, &cb); - - cb.unset_callback(); - - db->free_str(sql_id); - - if (rc != 0 ) - { - return -1; - } - - return vmid; -} - -/* -------------------------------------------------------------------------- */ -/* -------------------------------------------------------------------------- */ - #ifdef SBDEBUG #include diff --git a/src/vmm/VirtualMachineManagerDriver.cc b/src/vmm/VirtualMachineManagerDriver.cc index bb6f3bc6ab0..234379ca459 100644 --- a/src/vmm/VirtualMachineManagerDriver.cc +++ b/src/vmm/VirtualMachineManagerDriver.cc @@ -25,16 +25,6 @@ using namespace std; -const string VirtualMachineManagerDriver::imported_actions_default = - "shutdown, shutdown-hard, hold, release, suspend, resume, delete, reboot, " - "reboot-hard, resched, unresched, disk-attach, disk-detach, nic-attach, " - "nic-detach, snap-create, snap-delete"; - -const string VirtualMachineManagerDriver::imported_actions_default_public = - "shutdown, shutdown-hard, hold, release, suspend, resume, delete, reboot, " - "reboot-hard, resched, unresched, disk-attach, disk-detach, nic-attach, " - "nic-detach, snap-create, snap-delete, poweroff, poweroff-hard"; - VirtualMachineManagerDriver::VirtualMachineManagerDriver( const string &mad_location, const map &attrs): @@ -50,7 +40,6 @@ VirtualMachineManagerDriver::VirtualMachineManagerDriver( const char * cfile; string file; int rc; - string action_defaults; auto it = attrs.find("DEFAULT"); @@ -117,54 +106,6 @@ VirtualMachineManagerDriver::VirtualMachineManagerDriver( driver_conf.get("SUPPORT_SHAREABLE", support_shareable_); - // ------------------------------------------------------------------------- - // Parse IMPORTED_VMS_ACTIONS string and init the action set - // ------------------------------------------------------------------------- - it = attrs.find("IMPORTED_VMS_ACTIONS"); - - if (it != attrs.end()) - { - action_defaults = it->second; - } - else - { - NebulaLog::log("VMM", Log::INFO, "\tUsing default imported VMs actions"); - - it = attrs.find("NAME"); - - if (it != attrs.end()) - { - if ( it->second == "kvm" || it->second == "xen" ) - { - action_defaults = imported_actions_default; - } - else if ( it->second == "sl" || it->second == "ec2" || - it->second == "az" || it->second == "vcenter" ) - { - action_defaults = imported_actions_default_public; - } - } - } - - vector actions; - - VMActions::Action id; - - actions = one_util::split(action_defaults, ','); - - for (auto action : actions) - { - action = one_util::trim(action); - - if ( VMActions::action_from_str(action, id) != 0 ) - { - NebulaLog::log("VMM", Log::ERROR, "Wrong action: " + action); - continue; - } - - imported_actions.set(id); - } - string name, exec, args; driver_conf.get("NAME", name); driver_conf.get("EXECUTABLE", exec); diff --git a/src/vmm_mad/remotes/lib/vcenter_driver/vmm_importer.rb b/src/vmm_mad/remotes/lib/vcenter_driver/vmm_importer.rb deleted file mode 100644 index 13c520e677f..00000000000 --- a/src/vmm_mad/remotes/lib/vcenter_driver/vmm_importer.rb +++ /dev/null @@ -1,165 +0,0 @@ -module VCenterDriver - - # Functionality to import vCenter VMs into OpenNebula - class VmmImporter < VCenterDriver::VcImporter - - def initialize(one_client, vi_client) - super(one_client, vi_client) - @one_class = OpenNebula::VirtualMachine - @defaults = {} - end - - def list(key, list) - @list = { key => list } - end - - def request_vnc(vc_vm) - one_vm = vc_vm.one_item - vnc_port = one_vm['TEMPLATE/GRAPHICS/PORT'] - elapsed_seconds = 0 - - # Let's update the info to gather VNC port - until vnc_port || elapsed_seconds > 30 - sleep(1) - one_vm.info - vnc_port = one_vm['TEMPLATE/GRAPHICS/PORT'] - elapsed_seconds += 1 - end - - return unless vnc_port - - extraconfig = [] - extraconfig += vc_vm.extraconfig_vnc - spec_hash = { :extraConfig => extraconfig } - spec = RbVmomi::VIM.VirtualMachineConfigSpec(spec_hash) - vc_vm.item.ReconfigVM_Task(:spec => spec).wait_for_completion - end - - def build - xml = OpenNebula::VirtualMachine.build_xml - OpenNebula::VirtualMachine.new(xml, @one_client) - end - - def import(selected) - import_tmplt = selected['IMPORT_TEMPLATE'] - import_tmplt = Base64.decode64(import_tmplt) if import_tmplt - vm_ref = selected['DEPLOY_ID'] || selected[:wild]['DEPLOY_ID'] - vm = selected[:one_item] || build - template = selected[:template] || import_tmplt - template = "DEPLOY_ID = #{vm_ref}\n" + template - - # Index where start GRAPHICS block - graphics_index = template.index('GRAPHICS = [') - unless graphics_index.nil? - # Index where finish GRAPHICS block - end_of_graphics = template[graphics_index..-1].index(']') + 1 - - # GRAPHICS block - graphics_sub_string = - template[graphics_index, end_of_graphics] - - # GRAPHICS block with PORT removed - # OpenNebula will asing a new not used PORT - graphics_sub_string = - graphics_sub_string.gsub(/PORT(.*?),[\r\n]/, '') - - # Index where graphics block finish - before_graphics = template[0, graphics_index] - - # Block after graphics block - after_graphics = - template[graphics_index..-1][end_of_graphics..-1] - - # Template with out PORT inside GRAPHICS - template = - before_graphics + - graphics_sub_string + - after_graphics - end - - host_id = selected[:host] || @list.keys[0] - - vc_uuid = @vi_client.vim.serviceContent.about.instanceUuid - vc_name = @vi_client.vim.host - dpool, ipool, npool, hpool = create_pools - - vc_vm = VCenterDriver::VirtualMachine.new_without_id(@vi_client, - vm_ref) - - # clear OpenNebula attributes - vc_vm.clear_tags - - # Importing Wild VMs with snapshots is not supported - # https://github.com/OpenNebula/one/issues/1268 - if vc_vm.snapshots? && vc_vm.disk_keys.empty? - raise 'Disk metadata not present and snapshots exist, '\ - 'cannot import this VM' - end - - vname = vc_vm['name'] - - type = { :object => 'VM', :id => vname } - error, template_disks = vc_vm.import_vcenter_disks(vc_uuid, dpool, - ipool, type) - raise error unless error.empty? - - template << template_disks - - opts = { - :vi_client => @vi_client, - :vc_uuid => vc_uuid, - :npool => npool, - :hpool => hpool, - :vcenter => vc_name, - :template_moref => vm_ref, - :vm_object => vc_vm, - :ipv4 => selected[:ipv4], - :ipv6 => selected[:ipv6] - } - - # Create images or get nics information for template - error, template_nics, ar_ids = - vc_vm.import_vcenter_nics(opts) - opts = { :uuid => vc_uuid, :npool => npool, :error => error } - Raction.delete_ars(ar_ids, opts) unless error.empty? - - template << template_nics - template << "VCENTER_ESX_HOST = #{vc_vm['runtime.host.name']}\n" - - # Get DS_ID for the deployment, the wild VM needs a System DS - dc_ref = vc_vm.datacenter.item._ref - ds_ref = template.match(/^VCENTER_DS_REF *= *"(.*)" *$/)[1] - - ds_one = dpool.select do |e| - e['TEMPLATE/TYPE'] == 'SYSTEM_DS' && - e['TEMPLATE/VCENTER_DS_REF'] == ds_ref && - e['TEMPLATE/VCENTER_DC_REF'] == dc_ref && - e['TEMPLATE/VCENTER_INSTANCE_ID'] == vc_uuid - end.first - opts[:error] = "ds with ref #{ds_ref} is not imported, aborting" - Raction.delete_ars(ar_ids, opts) unless ds_one - - rc = vm.allocate(template) - if OpenNebula.is_error?(rc) - Raction.delete_ars(ar_ids, opts.merge(:error => rc.message)) - end - - rc = vm.deploy(host_id, false, ds_one.id) - if OpenNebula.is_error?(rc) - Raction.delete_ars(ar_ids, opts.merge(:error => rc.message)) - end - - # Set reference to template disks and nics in VM template - vc_vm.one_item = vm - - request_vnc(vc_vm) - - # Sync disks with extraConfig - vc_vm.reference_all_disks - - vm.id - end - - end - -end diff --git a/src/vmm_mad/remotes/vcenter/vcenter_driver.rb b/src/vmm_mad/remotes/vcenter/vcenter_driver.rb index 2b3886d4798..d673150400e 100644 --- a/src/vmm_mad/remotes/vcenter/vcenter_driver.rb +++ b/src/vmm_mad/remotes/vcenter/vcenter_driver.rb @@ -115,7 +115,6 @@ def initialize require 'network' require 'file_helper' require 'vm_folder' -require 'vmm_importer' require 'vm_device' require 'vm_disk' require 'vm_nic'