diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index 5a26d18867..c2b431f4b7 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -786,16 +786,6 @@ void TransferManager::prolog_action(int vid) } } - // ------------------------------------------------------------------------- - // Generate context file - // ------------------------------------------------------------------------- - rc = prolog_context_command(vm, token_password, vm_tm_mad, disk_id, xfr); - - if ( rc == -1 ) - { - goto error_context; - } - xfr.close(); tm_md->transfer(vid,xfr_name); @@ -820,12 +810,6 @@ error_attributes: xfr.close(); goto error_common; -error_context: - os << "could not write context file for VM " << vid; - - xfr.close(); - goto error_common; - error_common: (nd.get_lcm())->trigger(LifeCycleManager::PROLOG_FAILURE,vid); vm->log("TM", Log::ERROR, os); @@ -1083,16 +1067,6 @@ void TransferManager::prolog_resume_action(int vid) << vm->get_oid() << " " << vm->get_ds_id() << endl; - // ------------------------------------------------------------------------- - // Generate context file - // ------------------------------------------------------------------------- - rc = prolog_context_command(vm, token_password, vm_tm_mad, disk_id, xfr); - - if ( rc == -1 ) - { - goto error_context; - } - xfr.close(); tm_md->transfer(vid,xfr_name); @@ -1115,14 +1089,9 @@ error_file: os << "prolog_resume, could not open file: " << xfr_name; goto error_common; -error_context: - os << "prolog_resume, could not write context file for VM " << vid; - - xfr.close(); - goto error_common; - error_common: (nd.get_lcm())->trigger(LifeCycleManager::PROLOG_FAILURE,vid); + vm->log("TM", Log::ERROR, os); vm->unlock(); diff --git a/src/vmm/LibVirtDriverKVM.cc b/src/vmm/LibVirtDriverKVM.cc index 6d7ed16e0b..3f892278e9 100644 --- a/src/vmm/LibVirtDriverKVM.cc +++ b/src/vmm/LibVirtDriverKVM.cc @@ -1153,11 +1153,9 @@ int LibVirtDriver::deployment_description_kvm( file << "\t\n" << "\t\t" << one_util::escape_xml(vm->get_remote_system_dir()) - << "\t\t\n\t\t\n" - << vm->to_xml(vm_xml) - << "\t\t\n"; - - file << "\t\n"; + << "\t\t\n" + // << "\t\t\n" << vm->to_xml(vm_xml) << "\t\t\n" + << "\t\n"; file << "" << endl; diff --git a/src/vmm/VirtualMachineManager.cc b/src/vmm/VirtualMachineManager.cc index 2985867398..37a609cee1 100644 --- a/src/vmm/VirtualMachineManager.cc +++ b/src/vmm/VirtualMachineManager.cc @@ -463,6 +463,45 @@ string * VirtualMachineManager::format_message( return one_util::base64_encode(oss.str()); } +static int do_context_command(VirtualMachine * vm, const string& password, + string& prolog_cmd, string& disk_path) +{ + prolog_cmd = ""; + disk_path = ""; + + if (vm->get_host_is_cloud()) + { + return 0; + } + + ostringstream os; + + Nebula& nd = Nebula::instance(); + TransferManager * tm = nd.get_tm(); + + string vm_tm_mad = vm->get_tm_mad(); + int disk_id; + + int rc = tm->prolog_context_command(vm, password, vm_tm_mad, disk_id, os); + + if ( rc == -1 ) + { + return -1; + } + else if ( rc == 1 ) + { + prolog_cmd = os.str(); + + os.str(""); + + os << vm->get_remote_system_dir() << "/disk." << disk_id; + + disk_path = os.str(); + } //else rc == 0 VM has no context + + return 0; +} + /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ @@ -473,10 +512,31 @@ void VirtualMachineManager::deploy_action(int vid) int rc; ostringstream os; + string password; + string disk_path; + string prolog_cmd; string vm_tmpl; string * drv_msg; - // Get the VM from the pool + vm = vmpool->get(vid,true); + + if (vm == 0) + { + return; + } + + int uid = vm->get_created_by_uid(); + + vm->unlock(); + + User * user = Nebula::instance().get_upool()->get(uid, true); + + if (user != 0) + { + user->get_template_attribute("TOKEN_PASSWORD", password); + user->unlock(); + } + vm = vmpool->get(vid,true); if (vm == 0) @@ -498,11 +558,12 @@ void VirtualMachineManager::deploy_action(int vid) } //Generate VM description file - os.str(""); os << "Generating deployment file: " << vm->get_deployment_file(); vm->log("VMM", Log::INFO, os); + os.str(""); + rc = vmd->deployment_description(vm,vm->get_deployment_file()); if (rc != 0) @@ -510,6 +571,11 @@ void VirtualMachineManager::deploy_action(int vid) goto error_file; } + if ( do_context_command(vm, password, prolog_cmd, disk_path) == -1 ) + { + goto error_no_tm_command; + } + // Invoke driver method drv_msg = format_message( vm->get_hostname(), @@ -520,9 +586,9 @@ void VirtualMachineManager::deploy_action(int vid) vm->get_deployment_file(), vm->get_remote_deployment_file(), "", + prolog_cmd, "", - "", - "", + disk_path, vm->to_xml(vm_tmpl), vm->get_ds_id(), -1); @@ -536,18 +602,20 @@ void VirtualMachineManager::deploy_action(int vid) return; error_history: - os.str(""); os << "deploy_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "deploy_action, error getting driver " << vm->get_vmm_mad(); goto error_common; error_file: - os.str(""); - os << "deploy_action, error generating deployment file: " << vm->get_deployment_file(); + os << "deploy_action, error generating deployment file: " + << vm->get_deployment_file(); + goto error_common; + +error_no_tm_command: + os << "Cannot set context disk to update it for VM " << vm->get_oid(); error_common: Nebula &ne = Nebula::instance(); @@ -644,17 +712,14 @@ void VirtualMachineManager::save_action( return; error_history: - os.str(""); os << "save_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "save_action, error getting driver " << vm->get_vmm_mad(); goto error_common; error_previous_history: - os.str(""); os << "save_action, VM has no previous history"; error_common: @@ -728,12 +793,10 @@ void VirtualMachineManager::shutdown_action( return; error_history: - os.str(""); os << "shutdown_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "shutdown_action, error getting driver " << vm->get_vmm_mad(); error_common: @@ -807,12 +870,10 @@ void VirtualMachineManager::reboot_action( return; error_history: - os.str(""); os << "reboot_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "reboot_action, error getting driver " << vm->get_vmm_mad(); error_common: @@ -881,12 +942,10 @@ void VirtualMachineManager::reset_action( return; error_history: - os.str(""); os << "reset_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "reset_action, error getting driver " << vm->get_vmm_mad(); error_common: @@ -956,12 +1015,10 @@ void VirtualMachineManager::cancel_action( return; error_history: - os.str(""); os << "cancel_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "cancel_action, error getting driver " << vm->get_vmm_mad(); error_common://LifeCycleManager::cancel_failure_action will check state @@ -1036,12 +1093,10 @@ void VirtualMachineManager::cancel_previous_action( return; error_history: - os.str(""); os << "cancel_previous_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "cancel_previous_action, error getting driver " << vm->get_vmm_mad(); error_common: @@ -1061,6 +1116,7 @@ void VirtualMachineManager::cleanup_action( string vm_tmpl; string * drv_msg; + string tm_command = ""; string m_hostname = ""; string m_net_drv = ""; @@ -1098,19 +1154,12 @@ void VirtualMachineManager::cleanup_action( if (!vm->get_host_is_cloud()) { - int rc = nd.get_tm()->epilog_delete_commands(vm, os, false, false); - - if ( rc != 0 ) + if ( nd.get_tm()->epilog_delete_commands(vm, os, false, false) != 0 ) { - os.str(""); - os << "cleanup_action canceled"; - - goto error_common; + goto error_epligo_command; } - } - else - { - os.str(""); + + tm_command = os.str(); } // Invoke driver method @@ -1123,7 +1172,7 @@ void VirtualMachineManager::cleanup_action( "", "", "", - os.str(), + tm_command, "", "", vm->to_xml(vm_tmpl), @@ -1139,13 +1188,15 @@ void VirtualMachineManager::cleanup_action( return; error_history: - os.str(""); os << "cleanup_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "cleanup_action, error getting driver " << vm->get_vmm_mad(); + goto error_common; + +error_epligo_command: + os << "cleanup_action canceled"; error_common: (nd.get_lcm())->trigger(LifeCycleManager::CLEANUP_FAILURE, vid); @@ -1158,16 +1209,14 @@ error_common: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void VirtualMachineManager::cleanup_previous_action( - int vid) +void VirtualMachineManager::cleanup_previous_action(int vid) { - int rc; - VirtualMachine * vm; ostringstream os; string vm_tmpl; string * drv_msg; + string tm_command = ""; const VirtualMachineManagerDriver * vmd; @@ -1194,16 +1243,13 @@ void VirtualMachineManager::cleanup_previous_action( goto error_driver; } - rc = nd.get_tm()->epilog_delete_commands(vm, os, false, true); - - if ( rc != 0 ) + if ( nd.get_tm()->epilog_delete_commands(vm, os, false, true) != 0 ) { - os.str(""); - os << "cleanup_action canceled"; - - goto error_common; + goto error_epilog_command; } + tm_command = os.str(); + // Invoke driver method drv_msg = format_message( vm->get_previous_hostname(), @@ -1214,7 +1260,7 @@ void VirtualMachineManager::cleanup_previous_action( "", "", "", - os.str(), + tm_command, "", "", vm->to_xml(vm_tmpl), @@ -1230,13 +1276,15 @@ void VirtualMachineManager::cleanup_previous_action( return; error_history: - os.str(""); os << "cleanup_previous_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "cleanup_previous_action, error getting driver " << vm->get_vmm_mad(); + goto error_common; + +error_epilog_command: + os << "cleanup_action canceled"; error_common: (nd.get_lcm())->trigger(LifeCycleManager::CLEANUP_FAILURE, vid); @@ -1313,17 +1361,14 @@ void VirtualMachineManager::migrate_action( return; error_history: - os.str(""); os << "migrate_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "migrate_action, error getting driver " << vm->get_vmm_mad(); goto error_common; error_previous_history: - os.str(""); os << "migrate_action, error VM has no previous history"; error_common: @@ -1349,20 +1394,13 @@ void VirtualMachineManager::restore_action( ostringstream os; string vm_tmpl; + string password; string prolog_cmd; - string vm_tm_mad; string disk_path; - string error; string* drv_msg; - int disk_id; - int rc; - - Nebula& nd = Nebula::instance(); - TransferManager * tm = nd.get_tm(); - vm = vmpool->get(vid,true); if (vm == 0) @@ -1401,31 +1439,9 @@ void VirtualMachineManager::restore_action( goto error_driver; } - if (!vm->get_host_is_cloud()) + if ( do_context_command(vm, password, prolog_cmd, disk_path) == -1 ) { - vm_tm_mad = vm->get_tm_mad(); - - rc = tm->prolog_context_command(vm, password, vm_tm_mad, disk_id, os); - - if ( rc == -1 ) - { - goto error_no_tm_command; - } - else if ( rc == 1 ) - { - prolog_cmd = os.str(); - - os.str(""); - - os << vm->get_remote_system_dir() << "/disk." << disk_id; - - disk_path = os.str(); - } - else //rc == 0 VM has no context - { - prolog_cmd = ""; - disk_path = ""; - } + goto error_no_tm_command; } // Invoke driver method @@ -1454,17 +1470,14 @@ void VirtualMachineManager::restore_action( return; error_history: - os.str(""); os << "restore_action, VM has no history"; goto error_common; error_no_tm_command: - os.str(""); os << "Cannot set context disk to update it for VM " << vm->get_oid(); goto error_common; error_driver: - os.str(""); os << "restore_action, error getting driver " << vm->get_vmm_mad(); error_common: @@ -1539,12 +1552,10 @@ void VirtualMachineManager::poll_action( return; error_history: - os.str(""); os << "poll_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "poll_action, error getting driver " << vm->get_vmm_mad(); error_common: @@ -1592,12 +1603,10 @@ void VirtualMachineManager::driver_cancel_action( return; error_history: - os.str(""); os << "driver_cacncel_action, VM has no history"; goto error_common; error_driver: - os.str(""); os << "driver_cancel_action, error getting driver " << vm->get_vmm_mad(); error_common: @@ -2468,18 +2477,11 @@ void VirtualMachineManager::attach_nic_action( string vm_tmpl; string* drv_msg; - string vm_tm_mad; string opennebula_hostname; string prolog_cmd; string disk_path; string password; - int disk_id; - int rc; - - Nebula& nd = Nebula::instance(); - TransferManager * tm = nd.get_tm(); - // Get the VM from the pool vm = vmpool->get(vid,true); @@ -2519,31 +2521,9 @@ void VirtualMachineManager::attach_nic_action( goto error_driver; } - if (!vm->get_host_is_cloud()) + if ( do_context_command(vm, password, prolog_cmd, disk_path) == -1 ) { - vm_tm_mad = vm->get_tm_mad(); - - rc = tm->prolog_context_command(vm, password, vm_tm_mad, disk_id, os); - - if ( rc == -1 ) - { - goto error_no_tm_command; - } - else if ( rc == 1 ) - { - prolog_cmd = os.str(); - - os.str(""); - - os << vm->get_remote_system_dir() << "/disk." << disk_id; - - disk_path = os.str(); - } - else //rc == 0 VM has no context - { - prolog_cmd = ""; - disk_path = ""; - } + goto error_no_tm_command; } // Invoke driver method diff --git a/src/vmm_mad/exec/one_vmm_exec.rb b/src/vmm_mad/exec/one_vmm_exec.rb index fa7cc295d5..4f67016251 100755 --- a/src/vmm_mad/exec/one_vmm_exec.rb +++ b/src/vmm_mad/exec/one_vmm_exec.rb @@ -342,8 +342,22 @@ class ExecDriver < VirtualMachineDriver # ---------------------------------------------------------------------- # Deployment Steps # ---------------------------------------------------------------------- + xml_data = decode(drv_message) - steps=[ + tm_command = xml_data.elements['TM_COMMAND'] + tm_command = tm_command.text if tm_command + + steps = [] + + if tm_command && !tm_command.empty? + steps << { + :driver => :tm, + :action => :tm_context, + :parameters => tm_command.strip.split(' ') + } + end + + steps.concat([ # Execute pre-boot networking setup { :driver => :vnm, @@ -369,7 +383,7 @@ class ExecDriver < VirtualMachineDriver } ] } - ] + ]) action.run(steps) end