diff --git a/include/DispatchManager.h b/include/DispatchManager.h index 16aeac80c8..f5f58dccd5 100644 --- a/include/DispatchManager.h +++ b/include/DispatchManager.h @@ -53,10 +53,10 @@ public: }; DMAction(Actions a, int v):ActionRequest(ActionRequest::USER), - _action(a), _vm_id(v){}; + _action(a), _vm_id(v){} DMAction(const DMAction& o):ActionRequest(o._type), _action(o._action), - _vm_id(o._vm_id){}; + _vm_id(o._vm_id){} Actions action() const { @@ -89,7 +89,7 @@ public: am.addListener(this); }; - ~DispatchManager(){}; + ~DispatchManager() = default; /** * Initializes internal pointers to other managers. Must be called when @@ -202,7 +202,7 @@ public: * @return 0 on success, -1 if the VM does not exits or -2 if the VM is * in a wrong a state */ - int undeploy (int vid, bool hard, const RequestAttributes& ra, + int undeploy(int vid, bool hard, const RequestAttributes& ra, string& error_str); /** @@ -213,7 +213,7 @@ public: * @return 0 on success, -1 if the VM does not exits or -2 if the VM is * in a wrong a state */ - int poweroff (int vid, bool hard, const RequestAttributes& ra, + int poweroff(int vid, bool hard, const RequestAttributes& ra, string& error_str); /** @@ -492,6 +492,18 @@ public: */ int disk_resize(int vid, int did, long long new_size, const RequestAttributes& ra, string& error_str); + + /** + * Update virtual machine context + * + * @param vid VirtualMachine identification + * @param ra information about the API call request + * @param error_str Error reason, if any + * + * @return 0 on success, -1 otherwise + */ + int live_updateconf(int vid, const RequestAttributes& ra, string& error_str); + private: /** * Thread id for the Dispatch Manager @@ -591,7 +603,7 @@ private: * @param template that will be filled * @param only_running true to not add CPU, MEMORY and VMS counters */ - void get_quota_template(VirtualMachine * vm, + void get_quota_template(VirtualMachine * vm, VirtualMachineTemplate& quota_tmpl, bool only_running); }; diff --git a/include/LifeCycleManager.h b/include/LifeCycleManager.h index 1ef784e71d..327d16ae22 100644 --- a/include/LifeCycleManager.h +++ b/include/LifeCycleManager.h @@ -102,15 +102,17 @@ public: DISK_LOCK_SUCCESS, /**< Sent by IM, image moves from locked to ready */ DISK_LOCK_FAILURE, /**< Sent by IM, image moves from locked to error */ DISK_RESIZE_SUCCESS,/**< Sent by TM/VMM when a disk resize succeeds */ - DISK_RESIZE_FAILURE /**< Sent by TM/VMM when a disk resize fails */ + DISK_RESIZE_FAILURE,/**< Sent by TM/VMM when a disk resize fails */ + UPDATE_CONF_SUCCESS,/**< Sent by TM/VMM when a update conf succeeds */ + UPDATE_CONF_FAILURE /**< Sent by TM/VMM when a update conf fails */ }; LCMAction(Actions a, int v, int u, int g, int r): ActionRequest(ActionRequest::USER), _action(a), _vm_id(v), _uid(u), - _gid(g), _req_id(r){}; + _gid(g), _req_id(r){} LCMAction(const LCMAction& o):ActionRequest(o._type), _action(o._action), - _vm_id(o._vm_id), _uid(o._uid), _gid(o._gid), _req_id(o._req_id){}; + _vm_id(o._vm_id), _uid(o._uid), _gid(o._gid), _req_id(o._req_id){} Actions action() const { @@ -168,7 +170,7 @@ public: am.addListener(this); }; - ~LifeCycleManager(){}; + ~LifeCycleManager() = default; /** * Triggers specific actions to the Life-cycle Manager. This function @@ -304,7 +306,7 @@ private: * @param image_id If the VM is in the middle of a save as operation, an * image may need to be set to error state. */ - void clean_up_vm (VirtualMachine *vm, bool dispose, int& image_id, + void clean_up_vm(VirtualMachine *vm, bool dispose, int& image_id, const LCMAction& la); // ------------------------------------------------------------------------- @@ -369,6 +371,9 @@ private: void disk_resize_success(int vid); void disk_resize_failure(int vid); + void update_conf_success(int vid); + void update_conf_failure(int vid); + // ------------------------------------------------------------------------- // External Actions, triggered by user requests // ------------------------------------------------------------------------- diff --git a/include/TransferManager.h b/include/TransferManager.h index 4460d1f47d..1ca7337f0d 100644 --- a/include/TransferManager.h +++ b/include/TransferManager.h @@ -59,10 +59,10 @@ public: }; TMAction(Actions a, int v):ActionRequest(ActionRequest::USER), - _action(a), _vm_id(v){}; + _action(a), _vm_id(v){} TMAction(const TMAction& o):ActionRequest(o._type), _action(o._action), - _vm_id(o._vm_id){}; + _vm_id(o._vm_id){} Actions action() const { @@ -100,7 +100,7 @@ public: am.addListener(this); }; - ~TransferManager(){}; + ~TransferManager() = default; /** * Triggers specific actions to the Information Manager. This function diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 02ddfdea50..c01dd2a32f 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -294,7 +294,7 @@ public: * Updates VM dynamic information (id). * @param _deploy_id the VMM driver specific id */ - void set_deploy_id (const string& _deploy_id) + void set_deploy_id(const string& _deploy_id) { deploy_id = _deploy_id; }; @@ -709,7 +709,7 @@ public: */ void set_stime(time_t _stime) { - history->stime=_stime; + history->stime = _stime; }; /** @@ -734,7 +734,7 @@ public: */ void set_etime(time_t _etime) { - history->etime=_etime; + history->etime = _etime; }; /** @@ -743,7 +743,7 @@ public: */ void set_previous_etime(time_t _etime) { - previous_history->etime=_etime; + previous_history->etime = _etime; }; /** @@ -752,7 +752,7 @@ public: */ void set_prolog_stime(time_t _stime) { - history->prolog_stime=_stime; + history->prolog_stime = _stime; }; /** @@ -761,7 +761,7 @@ public: */ void set_prolog_etime(time_t _etime) { - history->prolog_etime=_etime; + history->prolog_etime = _etime; }; /** @@ -770,7 +770,7 @@ public: */ void set_running_stime(time_t _stime) { - history->running_stime=_stime; + history->running_stime = _stime; }; /** @@ -787,7 +787,7 @@ public: */ void set_running_etime(time_t _etime) { - history->running_etime=_etime; + history->running_etime = _etime; }; /** @@ -796,7 +796,7 @@ public: */ void set_previous_running_etime(time_t _etime) { - previous_history->running_etime=_etime; + previous_history->running_etime = _etime; }; /** @@ -805,7 +805,7 @@ public: */ void set_epilog_stime(time_t _stime) { - history->epilog_stime=_stime; + history->epilog_stime = _stime; }; /** @@ -814,7 +814,7 @@ public: */ void set_epilog_etime(time_t _etime) { - history->epilog_etime=_etime; + history->epilog_etime = _etime; }; /** @@ -1453,7 +1453,7 @@ public: one_util::split_unique(nic->vector_value("ALIAS_IDS"), ',', a_ids); - for(std::set::iterator it = a_ids.begin(); it != a_ids.end(); it++) + for (std::set::iterator it = a_ids.begin(); it != a_ids.end(); it++) { VirtualMachineNic * nic_a = nics.delete_nic(*it); @@ -2035,11 +2035,11 @@ private: * netowrking updates. * @param context attribute of the VM * @param error string if any - * @param only_auto boolean to generate context only for vnets + * @param only_auto boolean to generate context only for vnets * with NETWORK_MODE = auto * @return 0 on success */ - int generate_network_context(VectorAttribute * context, string& error, + int generate_network_context(VectorAttribute * context, string& error, bool only_auto); /** diff --git a/include/VirtualMachineManager.h b/include/VirtualMachineManager.h index 1a61253d42..1ed0ff2d75 100644 --- a/include/VirtualMachineManager.h +++ b/include/VirtualMachineManager.h @@ -59,7 +59,8 @@ public: SNAPSHOT_REVERT, SNAPSHOT_DELETE, DISK_SNAPSHOT_CREATE, - DISK_RESIZE + DISK_RESIZE, + UPDATE_CONF }; VMMAction(Actions a, int v):ActionRequest(ActionRequest::USER), @@ -501,6 +502,14 @@ private: */ void disk_resize_action( int vid); + + /** + * Update VM context + * + * @param vid the id of the VM. + */ + void update_conf_action( + int vid); }; #endif /*VIRTUAL_MACHINE_MANAGER_H*/ diff --git a/include/VirtualMachineManagerDriver.h b/include/VirtualMachineManagerDriver.h index d6f8de6026..c797b43b20 100644 --- a/include/VirtualMachineManagerDriver.h +++ b/include/VirtualMachineManagerDriver.h @@ -182,7 +182,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void deploy ( + void deploy( const int oid, const string& drv_msg) const { @@ -194,7 +194,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void shutdown ( + void shutdown( const int oid, const string& drv_msg) const { @@ -206,7 +206,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void reset ( + void reset( const int oid, const string& drv_msg) const { @@ -218,7 +218,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void reboot ( + void reboot( const int oid, const string& drv_msg) const { @@ -230,7 +230,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void cancel ( + void cancel( const int oid, const string& drv_msg) const { @@ -242,7 +242,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void cleanup ( + void cleanup( const int oid, const string& drv_msg) const { @@ -254,7 +254,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void checkpoint ( + void checkpoint( const int oid, const string& drv_msg) const { @@ -266,7 +266,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void save ( + void save( const int oid, const string& drv_msg) const { @@ -279,7 +279,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void restore ( + void restore( const int oid, const string& drv_msg) const { @@ -292,7 +292,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void migrate ( + void migrate( const int oid, const string& drv_msg) const { @@ -304,7 +304,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void poll ( + void poll( const int oid, const string& drv_msg) const { @@ -316,7 +316,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void attach ( + void attach( const int oid, const string& drv_msg) const { @@ -328,7 +328,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void detach ( + void detach( const int oid, const string& drv_msg) const { @@ -340,7 +340,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void attach_nic ( + void attach_nic( const int oid, const string& drv_msg) const { @@ -352,7 +352,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void detach_nic ( + void detach_nic( const int oid, const string& drv_msg) const { @@ -365,7 +365,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void snapshot_create ( + void snapshot_create( const int oid, const string& drv_msg) const { @@ -378,7 +378,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void snapshot_revert ( + void snapshot_revert( const int oid, const string& drv_msg) const { @@ -391,7 +391,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void snapshot_delete ( + void snapshot_delete( const int oid, const string& drv_msg) const { @@ -404,7 +404,7 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void disk_snapshot_create ( + void disk_snapshot_create( const int oid, const string& drv_msg) const { @@ -417,20 +417,32 @@ private: * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void disk_resize ( + void disk_resize( const int oid, const string& drv_msg) const { write_drv("RESIZEDISK", oid, drv_msg); } + /** + * Sends an updateconf request to the MAD: "UPDATECONF ID XML_DRV_MSG" + * @param oid the virtual machine id. + * @param drv_msg xml data for the mad operation + */ + void update_conf( + const int oid, + const string& drv_msg) const + { + write_drv("UPDATECONF", oid, drv_msg); + } + /** * Sends a request to update the VM security groups: * "UPDATESG ID XML_DRV_MSG" * @param oid the virtual machine id. * @param drv_msg xml data for the mad operation */ - void updatesg ( + void updatesg( const int oid, const string& drv_msg) const { diff --git a/src/dm/DispatchManagerActions.cc b/src/dm/DispatchManagerActions.cc index f039942e15..5eccfd8467 100644 --- a/src/dm/DispatchManagerActions.cc +++ b/src/dm/DispatchManagerActions.cc @@ -27,7 +27,7 @@ /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int DispatchManager::deploy (VirtualMachine * vm, const RequestAttributes& ra) +int DispatchManager::deploy(VirtualMachine * vm, const RequestAttributes& ra) { ostringstream oss; int vid; @@ -39,7 +39,7 @@ int DispatchManager::deploy (VirtualMachine * vm, const RequestAttributes& ra) VirtualMachineTemplate quota_tmpl; bool do_quotas = false; - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -112,7 +112,7 @@ int DispatchManager::import(VirtualMachine * vm, const RequestAttributes& ra) string error; - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -132,7 +132,7 @@ int DispatchManager::import(VirtualMachine * vm, const RequestAttributes& ra) import_state = vm->get_import_state(); - if(import_state == "POWEROFF") + if (import_state == "POWEROFF") { vm->set_state(VirtualMachine::POWEROFF); vm->set_state(VirtualMachine::LCM_INIT); @@ -186,7 +186,7 @@ int DispatchManager::migrate(VirtualMachine * vm, int poff_migrate, ostringstream oss; int vid; - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -243,7 +243,7 @@ int DispatchManager::live_migrate(VirtualMachine * vm, ostringstream oss; int vid; - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -290,7 +290,7 @@ void DispatchManager::free_vm_resources(VirtualMachine * vm, bool check_images) int vrid = -1; unsigned int port; - quota_tmpl = vm->clone_template(); + quota_tmpl = vm->clone_template(); if ( (vm->get_state() == VirtualMachine::ACTIVE) || (vm->get_state() == VirtualMachine::PENDING) || @@ -322,7 +322,7 @@ void DispatchManager::free_vm_resources(VirtualMachine * vm, bool check_images) VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS"); - if ( graphics != 0 && graphics->vector_value("PORT", port) == 0 + if ( graphics != nullptr && graphics->vector_value("PORT", port) == 0 && vm->hasHistory()) { graphics->remove("PORT"); @@ -365,7 +365,7 @@ void DispatchManager::free_vm_resources(VirtualMachine * vm, bool check_images) { VirtualRouter* vr = vrouterpool->get(vrid); - if (vr != 0) + if (vr != nullptr) { vr->del_vmid(vmid); @@ -387,7 +387,7 @@ int DispatchManager::terminate(int vid, bool hard, const RequestAttributes& ra, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -478,7 +478,7 @@ int DispatchManager::undeploy(int vid, bool hard, const RequestAttributes& ra, VirtualMachine * vm = vmpool->get_ro(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -526,14 +526,14 @@ error: /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int DispatchManager::poweroff (int vid, bool hard, const RequestAttributes& ra, +int DispatchManager::poweroff(int vid, bool hard, const RequestAttributes& ra, string& error_str) { ostringstream oss; VirtualMachine * vm = vmpool->get_ro(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -588,7 +588,7 @@ int DispatchManager::hold(int vid, const RequestAttributes& ra, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -636,7 +636,7 @@ int DispatchManager::release(int vid, const RequestAttributes& ra, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -704,7 +704,7 @@ int DispatchManager::stop(int vid, const RequestAttributes& ra, VirtualMachine * vm = vmpool->get_ro(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -751,7 +751,7 @@ int DispatchManager::suspend(int vid, const RequestAttributes& ra, VirtualMachine * vm = vmpool->get_ro(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -797,7 +797,7 @@ int DispatchManager::resume(int vid, const RequestAttributes& ra, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -876,7 +876,7 @@ int DispatchManager::reboot(int vid, bool hard, const RequestAttributes& ra, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -934,7 +934,7 @@ int DispatchManager::resched(int vid, bool do_resched, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return -1; } @@ -1082,18 +1082,18 @@ int DispatchManager::delete_vm(VirtualMachine * vm, const RequestAttributes& ra, bool is_public_host = false; int host_id = -1; - if(vm->hasHistory()) + if (vm->hasHistory()) { host_id = vm->get_hid(); } int vid = vm->get_oid(); - if(host_id != -1) + if (host_id != -1) { Host * host = hpool->get_ro(host_id); - if ( host == 0 ) + if ( host == nullptr ) { oss << "Error getting host " << host_id; error = oss.str(); @@ -1176,7 +1176,7 @@ int DispatchManager::delete_recreate(VirtualMachine * vm, int rc = 0; - Template * vm_quotas_snp = 0; + Template * vm_quotas_snp = nullptr; VirtualMachineTemplate quota_tmpl; bool do_quotas = false; @@ -1254,7 +1254,7 @@ int DispatchManager::delete_recreate(VirtualMachine * vm, Quotas::ds_del_recreate(vm_uid, vm_gid, ds_quotas_snp); } - if ( vm_quotas_snp != 0 ) + if ( vm_quotas_snp != nullptr ) { Quotas::vm_del(vm_uid, vm_gid, vm_quotas_snp); @@ -1319,10 +1319,10 @@ int DispatchManager::attach(int vid, VirtualMachineTemplate * tmpl, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { oss << "Could not attach a new disk to VM " << vid - << ", VM does not exist" ; + << ", VM does not exist"; err = oss.str(); NebulaLog::log("DiM", Log::ERROR, err); @@ -1424,7 +1424,7 @@ int DispatchManager::detach(int vid, int disk_id, const RequestAttributes& ra, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { oss << "VirtualMachine " << vid << " no longer exists"; error_str = oss.str(); @@ -1519,10 +1519,10 @@ int DispatchManager::snapshot_create(int vid, string& name, int& snap_id, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { oss << "Could not create a new snapshot for VM " << vid - << ", VM does not exist" ; + << ", VM does not exist"; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1570,10 +1570,10 @@ int DispatchManager::snapshot_revert(int vid, int snap_id, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { oss << "Could not revert VM " << vid << " to snapshot " << snap_id - << ", VM does not exist" ; + << ", VM does not exist"; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1633,10 +1633,10 @@ int DispatchManager::snapshot_delete(int vid, int snap_id, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { oss << "Could not delete snapshot " << snap_id << " for VM " << vid - << ", VM does not exist" ; + << ", VM does not exist"; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1703,10 +1703,10 @@ int DispatchManager::attach_nic(int vid, VirtualMachineTemplate* tmpl, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { oss << "Could not add a new NIC to VM " << vid - << ", VM does not exist" ; + << ", VM does not exist"; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1812,7 +1812,7 @@ int DispatchManager::detach_nic(int vid, int nic_id,const RequestAttributes& ra, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { oss << "VirtualMachine " << vid << " no longer exists"; error_str = oss.str(); @@ -1920,10 +1920,10 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { oss << "Could not create a new disk snapshot for VM " << vid - << ", VM does not exist" ; + << ", VM does not exist"; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -1960,7 +1960,7 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name, return -1; } - switch(state) + switch (state) { case VirtualMachine::POWEROFF: vm->set_state(VirtualMachine::ACTIVE); @@ -1980,7 +1980,7 @@ int DispatchManager::disk_snapshot_create(int vid, int did, const string& name, default: break; } - switch(state) + switch (state) { case VirtualMachine::POWEROFF: case VirtualMachine::SUSPENDED: @@ -2034,10 +2034,10 @@ int DispatchManager::disk_snapshot_revert(int vid, int did, int snap_id, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { oss << "Could not revert to disk snapshot for VM " << vid - << ", VM does not exist" ; + << ", VM does not exist"; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -2063,7 +2063,7 @@ int DispatchManager::disk_snapshot_revert(int vid, int did, int snap_id, const Snapshots * snaps = vm->get_disk_snapshots(did, error_str); - if (snaps == 0) + if (snaps == nullptr) { vm->unlock(); return -1; @@ -2075,7 +2075,7 @@ int DispatchManager::disk_snapshot_revert(int vid, int did, int snap_id, return -1; } - switch(state) + switch (state) { case VirtualMachine::POWEROFF: vm->set_state(VirtualMachine::ACTIVE); @@ -2110,10 +2110,10 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { oss << "Could not delete disk snapshot from VM " << vid - << ", VM does not exist" ; + << ", VM does not exist"; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -2140,7 +2140,7 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id, const Snapshots * snaps = vm->get_disk_snapshots(did, error_str); - if (snaps == 0) + if (snaps == nullptr) { vm->unlock(); return -1; @@ -2161,7 +2161,7 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id, // Set the VM info in the history before the snapshot is removed from the VM vm->set_vm_info(); - switch(state) + switch (state) { case VirtualMachine::POWEROFF: vm->set_state(VirtualMachine::ACTIVE); @@ -2181,7 +2181,7 @@ int DispatchManager::disk_snapshot_delete(int vid, int did, int snap_id, default: break; } - switch(state) + switch (state) { case VirtualMachine::ACTIVE: the_time = time(0); @@ -2233,9 +2233,9 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size, VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { - oss << "Could not resize disk for VM " << vid << ", VM does not exist" ; + oss << "Could not resize disk for VM " << vid << ", VM does not exist"; error_str = oss.str(); NebulaLog::log("DiM", Log::ERROR, error_str); @@ -2271,7 +2271,7 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size, return -1; } - switch(state) + switch (state) { case VirtualMachine::POWEROFF: vm->set_state(VirtualMachine::ACTIVE); @@ -2291,7 +2291,7 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size, default: break; } - switch(state) + switch (state) { case VirtualMachine::POWEROFF: case VirtualMachine::UNDEPLOYED: @@ -2338,3 +2338,44 @@ int DispatchManager::disk_resize(int vid, int did, long long new_size, /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ + +int DispatchManager::live_updateconf(int vid, const RequestAttributes& ra, string& error_str) +{ + ostringstream oss; + + VirtualMachine * vm = vmpool->get(vid); + + VirtualMachine::VmState state = vm->get_state(); + VirtualMachine::LcmState lstate = vm->get_lcm_state(); + + // Allowed only for state ACTIVE and RUNNING + if (state != VirtualMachine::ACTIVE || lstate != VirtualMachine::RUNNING) + { + oss << "Could not perform live updateconf for " << vid << ", wrong state " + << vm->state_str() << "."; + error_str = oss.str(); + + NebulaLog::log("DiM", Log::ERROR, error_str); + + vm->unlock(); + + return -1; + } + + // Set VM state + vm->set_state(VirtualMachine::HOTPLUG); + vm->set_resched(false); + + // Trigger UPDATE CONF action + vmm->trigger(VMMAction::UPDATE_CONF, vid); + + vmpool->update(vm); + vmpool->update_search(vm); + + vm->unlock(); + + return 0; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ diff --git a/src/lcm/LifeCycleManager.cc b/src/lcm/LifeCycleManager.cc index d40bcbf830..dee51aae3f 100644 --- a/src/lcm/LifeCycleManager.cc +++ b/src/lcm/LifeCycleManager.cc @@ -49,8 +49,8 @@ int LifeCycleManager::start() int rc; pthread_attr_t pattr; - pthread_attr_init (&pattr); - pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE); + pthread_attr_init(&pattr); + pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE); NebulaLog::log("LCM",Log::INFO,"Starting Life-cycle Manager..."); @@ -229,6 +229,12 @@ void LifeCycleManager::user_action(const ActionRequest& ar) case LCMAction::DISK_RESIZE_FAILURE: disk_resize_failure(vid); break; + case LCMAction::UPDATE_CONF_SUCCESS: + update_conf_success(vid); + break; + case LCMAction::UPDATE_CONF_FAILURE: + update_conf_failure(vid); + break; // ------------------------------------------------------------------------- // External Actions, triggered by user requests // ------------------------------------------------------------------------- diff --git a/src/lcm/LifeCycleStates.cc b/src/lcm/LifeCycleStates.cc index 17d2bdb104..f1911b5a54 100644 --- a/src/lcm/LifeCycleStates.cc +++ b/src/lcm/LifeCycleStates.cc @@ -132,7 +132,7 @@ void LifeCycleManager::save_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -216,7 +216,7 @@ void LifeCycleManager::save_failure_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -264,7 +264,7 @@ void LifeCycleManager::deploy_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -344,7 +344,7 @@ void LifeCycleManager::deploy_failure_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -476,7 +476,7 @@ void LifeCycleManager::shutdown_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -582,7 +582,7 @@ void LifeCycleManager::shutdown_failure_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -635,7 +635,7 @@ void LifeCycleManager::prolog_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -768,12 +768,12 @@ void LifeCycleManager::prolog_failure_action(int vid) VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } - switch(vm->get_lcm_state()) + switch (vm->get_lcm_state()) { case VirtualMachine::PROLOG: vm->set_state(VirtualMachine::PROLOG_FAILURE); @@ -894,7 +894,7 @@ void LifeCycleManager::epilog_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -956,7 +956,7 @@ void LifeCycleManager::epilog_success_action(int vid) VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS"); //Do not free VNC ports for STOP as it is stored in checkpoint file - if ( graphics != 0 && (graphics->vector_value("PORT", port) == 0) && + if ( graphics != nullptr && (graphics->vector_value("PORT", port) == 0) && state != VirtualMachine::EPILOG_STOP ) { graphics->remove("PORT"); @@ -991,7 +991,7 @@ void LifeCycleManager::cleanup_callback_action(int vid) vm = vmpool->get_ro(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1024,7 +1024,7 @@ void LifeCycleManager::epilog_failure_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1074,7 +1074,7 @@ void LifeCycleManager::monitor_suspend_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1132,7 +1132,7 @@ void LifeCycleManager::monitor_done_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1165,7 +1165,7 @@ void LifeCycleManager::monitor_poweroff_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1208,7 +1208,8 @@ void LifeCycleManager::monitor_poweroff_action(int vid) dm->trigger(DMAction::POWEROFF_SUCCESS,vid); - } else if ( vm->get_lcm_state() == VirtualMachine::SHUTDOWN || + } + else if ( vm->get_lcm_state() == VirtualMachine::SHUTDOWN || vm->get_lcm_state() == VirtualMachine::SHUTDOWN_POWEROFF || vm->get_lcm_state() == VirtualMachine::SHUTDOWN_UNDEPLOY ) { @@ -1229,7 +1230,7 @@ void LifeCycleManager::monitor_poweron_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1299,7 +1300,7 @@ void LifeCycleManager::attach_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1340,7 +1341,7 @@ void LifeCycleManager::attach_failure_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1354,7 +1355,7 @@ void LifeCycleManager::attach_failure_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1390,7 +1391,7 @@ void LifeCycleManager::detach_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1404,7 +1405,7 @@ void LifeCycleManager::detach_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1441,7 +1442,7 @@ void LifeCycleManager::detach_failure_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1480,7 +1481,7 @@ void LifeCycleManager::snapshot_create_success(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1510,7 +1511,7 @@ void LifeCycleManager::snapshot_create_failure(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1543,7 +1544,7 @@ void LifeCycleManager::snapshot_revert_success(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1581,7 +1582,7 @@ void LifeCycleManager::snapshot_delete_success(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1611,7 +1612,7 @@ void LifeCycleManager::snapshot_delete_failure(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1641,7 +1642,7 @@ void LifeCycleManager::attach_nic_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1672,7 +1673,7 @@ void LifeCycleManager::attach_nic_failure_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1685,7 +1686,7 @@ void LifeCycleManager::attach_nic_failure_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1712,7 +1713,7 @@ void LifeCycleManager::detach_nic_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1725,7 +1726,7 @@ void LifeCycleManager::detach_nic_success_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1753,7 +1754,7 @@ void LifeCycleManager::detach_nic_failure_action(int vid) vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1788,7 +1789,7 @@ void LifeCycleManager::saveas_success_action(int vid) VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1819,7 +1820,7 @@ void LifeCycleManager::saveas_success_action(int vid) Image * image = ipool->get(image_id); - if (image == 0) + if (image == nullptr) { return; } @@ -1845,7 +1846,7 @@ void LifeCycleManager::saveas_failure_action(int vid) VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1876,7 +1877,7 @@ void LifeCycleManager::saveas_failure_action(int vid) Image * image = ipool->get(image_id); - if (image == 0) + if (image == nullptr) { return; } @@ -1897,8 +1898,8 @@ void LifeCycleManager::disk_snapshot_success(int vid) int disk_id, ds_id, snap_id; int img_id = -1; - Template *ds_quotas = 0; - Template *vm_quotas = 0; + Template *ds_quotas = nullptr; + Template *vm_quotas = nullptr; bool img_owner, vm_owner; @@ -1909,7 +1910,7 @@ void LifeCycleManager::disk_snapshot_success(int vid) VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -1962,7 +1963,7 @@ void LifeCycleManager::disk_snapshot_success(int vid) vm->clear_snapshot_disk(); tmp_snaps = vm->get_disk_snapshots(disk_id, error_str); - if (tmp_snaps != 0) + if (tmp_snaps != nullptr) { snaps = *tmp_snaps; } @@ -1978,13 +1979,13 @@ void LifeCycleManager::disk_snapshot_success(int vid) vm->unlock(); - if ( ds_quotas != 0 ) + if ( ds_quotas != nullptr ) { if ( img_owner ) { Image* img = ipool->get_ro(img_id); - if(img != 0) + if (img != nullptr) { int img_uid = img->get_uid(); int img_gid = img->get_gid(); @@ -2003,7 +2004,7 @@ void LifeCycleManager::disk_snapshot_success(int vid) delete ds_quotas; } - if ( vm_quotas != 0 ) + if ( vm_quotas != nullptr ) { Quotas::vm_del(vm_uid, vm_gid, vm_quotas); @@ -2046,8 +2047,8 @@ void LifeCycleManager::disk_snapshot_failure(int vid) int disk_id, ds_id, snap_id; int img_id = -1; - Template *ds_quotas = 0; - Template *vm_quotas = 0; + Template *ds_quotas = nullptr; + Template *vm_quotas = nullptr; const VirtualMachineDisk* disk; Snapshots snaps(-1, Snapshots::DENY); @@ -2058,7 +2059,7 @@ void LifeCycleManager::disk_snapshot_failure(int vid) VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -2106,7 +2107,7 @@ void LifeCycleManager::disk_snapshot_failure(int vid) vm->clear_snapshot_disk(); tmp_snaps = vm->get_disk_snapshots(disk_id, error_str); - if (tmp_snaps != 0) + if (tmp_snaps != nullptr) { snaps = *tmp_snaps; } @@ -2122,13 +2123,13 @@ void LifeCycleManager::disk_snapshot_failure(int vid) vm->unlock(); - if ( ds_quotas != 0 ) + if ( ds_quotas != nullptr ) { if ( img_owner ) { Image* img = ipool->get_ro(img_id); - if(img != 0) + if (img != nullptr) { int img_uid = img->get_uid(); int img_gid = img->get_gid(); @@ -2147,7 +2148,7 @@ void LifeCycleManager::disk_snapshot_failure(int vid) delete ds_quotas; } - if ( vm_quotas != 0 ) + if ( vm_quotas != nullptr ) { Quotas::vm_del(vm_uid, vm_gid, vm_quotas); @@ -2188,7 +2189,7 @@ void LifeCycleManager::disk_lock_success(int vid) VirtualMachine * vm = vmpool->get_ro(vid); Image * image; - if ( vm == 0 ) + if ( vm == nullptr ) { return; } @@ -2215,12 +2216,12 @@ void LifeCycleManager::disk_lock_success(int vid) { image = ipool->get_ro(*id); - if (image != 0) + if (image != nullptr) { switch (image->get_state()) { case Image::USED: case Image::USED_PERS: - ready.push_back( make_pair(*id, image->get_source()) ); + ready.push_back(make_pair(*id, image->get_source())); break; case Image::ERROR: @@ -2244,7 +2245,7 @@ void LifeCycleManager::disk_lock_success(int vid) vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -2260,7 +2261,7 @@ void LifeCycleManager::disk_lock_success(int vid) vm->get_template_attribute("SUBMIT_ON_HOLD", on_hold); - if(on_hold) + if (on_hold) { vm->set_state(VirtualMachine::HOLD); } @@ -2303,14 +2304,14 @@ void LifeCycleManager::disk_resize_success(int vid) VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } VirtualMachineDisk * disk = vm->get_resize_disk(); - if ( disk == 0 ) + if ( disk == nullptr ) { vm->unlock(); return; @@ -2370,6 +2371,7 @@ void LifeCycleManager::disk_resize_success(int vid) return; } +/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ void LifeCycleManager::disk_resize_failure(int vid) @@ -2382,14 +2384,14 @@ void LifeCycleManager::disk_resize_failure(int vid) VirtualMachine * vm = vmpool->get(vid); - if ( vm == 0 ) + if ( vm == nullptr ) { return; } VirtualMachineDisk * disk = vm->get_resize_disk(); - if ( disk == 0 ) + if ( disk == nullptr ) { vm->unlock(); return; @@ -2435,7 +2437,7 @@ void LifeCycleManager::disk_resize_failure(int vid) { Image* img = ipool->get_ro(img_id); - if(img != 0) + if (img != nullptr) { int img_uid = img->get_uid(); int img_gid = img->get_gid(); @@ -2473,5 +2475,57 @@ void LifeCycleManager::disk_resize_failure(int vid) return; } +/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ +void LifeCycleManager::update_conf_success(int vid) +{ + VirtualMachine * vm = vmpool->get(vid); + + if ( vm == nullptr ) + { + return; + } + + if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG ) + { + vm->set_state(VirtualMachine::RUNNING); + + vmpool->update(vm); + } + else + { + vm->log("LCM",Log::ERROR,"update_conf_success, VM in a wrong state"); + } + + vm->unlock(); +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void LifeCycleManager::update_conf_failure(int vid) +{ + VirtualMachine * vm = vmpool->get(vid); + + if ( vm == nullptr ) + { + return; + } + + if ( vm->get_lcm_state() == VirtualMachine::HOTPLUG ) + { + vm->set_state(VirtualMachine::RUNNING); + + vmpool->update(vm); + + vm->unlock(); + } + else + { + vm->log("LCM",Log::ERROR,"update_conf_failure, VM in a wrong state"); + vm->unlock(); + } +} + +/* -------------------------------------------------------------------------- */ diff --git a/src/mad/ruby/VirtualMachineDriver.rb b/src/mad/ruby/VirtualMachineDriver.rb index e78a8867ae..896272cbe3 100644 --- a/src/mad/ruby/VirtualMachineDriver.rb +++ b/src/mad/ruby/VirtualMachineDriver.rb @@ -51,7 +51,8 @@ class VirtualMachineDriver < OpenNebulaDriver :detach_nic => "DETACHNIC", :disk_snapshot_create => "DISKSNAPSHOTCREATE", :resize_disk => "RESIZEDISK", - :update_sg => "UPDATESG" + :update_sg => "UPDATESG", + :update_conf => "UPDATECONF" } POLL_ATTRIBUTE = OpenNebula::VirtualMachine::Driver::POLL_ATTRIBUTE @@ -96,6 +97,7 @@ class VirtualMachineDriver < OpenNebulaDriver register_action(ACTION[:disk_snapshot_create].to_sym, method("disk_snapshot_create")) register_action(ACTION[:resize_disk].to_sym, method("resize_disk")) register_action(ACTION[:update_sg].to_sym, method("update_sg")) + register_action(ACTION[:update_conf].to_sym, method("update_conf")) end # Decodes the encoded XML driver message received from the core @@ -220,6 +222,11 @@ class VirtualMachineDriver < OpenNebulaDriver send_message(ACTION[:cleanup],RESULT[:failure],id,error) end + def update_conf(id, drv_message) + error = "Action not implemented by driver #{self.class}" + send_message(ACTION[:update_conf],RESULT[:failure],id,error) + end + private # Interface to handle the pending events from the ActionManager Interface diff --git a/src/rm/RequestManagerVirtualMachine.cc b/src/rm/RequestManagerVirtualMachine.cc index 02c45b3a60..6a7db31b32 100644 --- a/src/rm/RequestManagerVirtualMachine.cc +++ b/src/rm/RequestManagerVirtualMachine.cc @@ -38,7 +38,7 @@ bool RequestManagerVirtualMachine::vm_authorization( object = pool->get(oid); - if ( object == 0 ) + if ( object == nullptr ) { att.resp_id = oid; failure_response(NO_EXISTS, att); @@ -54,12 +54,12 @@ bool RequestManagerVirtualMachine::vm_authorization( ar.add_auth(op, vm_perms); - if (host_perm != 0) + if (host_perm != nullptr) { ar.add_auth(AuthRequest::MANAGE, *host_perm); } - if (tmpl != 0) + if (tmpl != nullptr) { string t_xml; @@ -67,17 +67,17 @@ bool RequestManagerVirtualMachine::vm_authorization( tmpl->to_xml(t_xml)); } - if ( vtmpl != 0 ) + if ( vtmpl != nullptr ) { VirtualMachine::set_auth_request(att.uid, ar, vtmpl, true); } - if ( ds_perm != 0 ) + if ( ds_perm != nullptr ) { ar.add_auth(AuthRequest::USE, *ds_perm); } - if ( img_perm != 0 ) + if ( img_perm != nullptr ) { ar.add_auth(AuthRequest::MANAGE, *img_perm); } @@ -104,7 +104,7 @@ bool RequestManagerVirtualMachine::quota_resize_authorization( PoolObjectAuth vm_perms; VirtualMachine * vm = Nebula::instance().get_vmpool()->get_ro(oid); - if (vm == 0) + if (vm == nullptr) { att.resp_obj = PoolObjectSQL::VM; att.resp_id = oid; @@ -140,7 +140,7 @@ bool RequestManagerVirtualMachine::quota_resize_authorization( { User * user = upool->get(vm_perms.uid); - if ( user != 0 ) + if ( user != nullptr ) { rc = user->quota.quota_update(Quotas::VM, deltas, user_dquotas, att.resp_msg); @@ -170,7 +170,7 @@ bool RequestManagerVirtualMachine::quota_resize_authorization( { Group * group = gpool->get(vm_perms.gid); - if ( group != 0 ) + if ( group != nullptr ) { rc = group->quota.quota_update(Quotas::VM, deltas, group_dquotas, att.resp_msg); @@ -222,7 +222,7 @@ int RequestManagerVirtualMachine::get_default_ds_information( cluster = clpool->get_ro(cluster_id); - if (cluster == 0) + if (cluster == nullptr) { att.resp_obj = PoolObjectSQL::CLUSTER; att.resp_id = cluster_id; @@ -273,7 +273,7 @@ int RequestManagerVirtualMachine::get_ds_information(int ds_id, ds_cluster_ids.clear(); - if ( ds == 0 ) + if ( ds == nullptr ) { att.resp_obj = PoolObjectSQL::DATASTORE; att.resp_id = ds_id; @@ -329,7 +329,7 @@ int RequestManagerVirtualMachine::get_host_information( Host * host = hpool->get_ro(hid); - if ( host == 0 ) + if ( host == nullptr ) { att.resp_obj = PoolObjectSQL::HOST; att.resp_id = hid; @@ -378,7 +378,7 @@ bool RequestManagerVirtualMachine::check_host( Host * host = hpool->get_ro(hid); - if (host == 0) + if (host == nullptr) { error = "Host no longer exists"; return false; @@ -415,7 +415,7 @@ VirtualMachine * RequestManagerVirtualMachine::get_vm(int id, vm = static_cast(pool)->get(id); - if ( vm == 0 ) + if ( vm == nullptr ) { att.resp_id = id; failure_response(NO_EXISTS, att); @@ -432,7 +432,7 @@ VirtualMachine * RequestManagerVirtualMachine::get_vm_ro(int id, vm = static_cast(pool)->get_ro(id); - if ( vm == 0 ) + if ( vm == nullptr ) { att.resp_id = id; failure_response(NO_EXISTS, att); @@ -522,7 +522,7 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, return; } - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } @@ -555,8 +555,8 @@ void VirtualMachineAction::request_execute(xmlrpc_c::paramList const& paramList, vm->unlock(); - if ( action == History::RESUME_ACTION && - !quota_authorization("a_tmpl, Quotas::VIRTUALMACHINE, att_aux, + if ( action == History::RESUME_ACTION && + !quota_authorization("a_tmpl, Quotas::VIRTUALMACHINE, att_aux, att.resp_msg) ) { failure_response(ACTION, att); @@ -698,7 +698,7 @@ int set_vnc_port(VirtualMachine *vm, int cluster_id, RequestAttributes& att) unsigned int port; int rc; - if (graphics == 0) + if (graphics == nullptr) { return 0; } @@ -809,7 +809,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, // ------------------------------------------------------------------------ // Get information about the system DS to use (tm_mad & permissions) // ------------------------------------------------------------------------ - if ((vm = get_vm_ro(id, att)) == 0) + if ((vm = get_vm_ro(id, att)) == nullptr) { return; } @@ -882,7 +882,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, { Datastore * ds = dspool->get_ro(ds_id); - if (ds == 0 ) + if (ds == nullptr ) { att.resp_obj = PoolObjectSQL::DATASTORE; att.resp_id = ds_id; @@ -943,7 +943,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList, // - VM States are right // - Host capacity if required // ------------------------------------------------------------------------ - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } @@ -1115,7 +1115,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList { Datastore * ds = dspool->get_ro(ds_id); - if (ds == 0 ) + if (ds == nullptr ) { att.resp_obj = PoolObjectSQL::DATASTORE; att.resp_id = ds_id; @@ -1152,12 +1152,12 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList // - New or old host are not public cloud // ------------------------------------------------------------------------ - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } - if( vm->is_previous_history_open() || + if (vm->is_previous_history_open() || (vm->get_state() != VirtualMachine::POWEROFF && vm->get_state() != VirtualMachine::SUSPENDED && (vm->get_state() != VirtualMachine::ACTIVE || @@ -1268,7 +1268,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList // Check we are migrating to a compatible cluster Host * host = nd.get_hpool()->get_ro(c_hid); - if (host == 0) + if (host == nullptr) { att.resp_obj = PoolObjectSQL::HOST; att.resp_id = c_hid; @@ -1306,7 +1306,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList VirtualMachineManager * vmm = Nebula::instance().get_vmm(); const VirtualMachineManagerDriver * vmmd = vmm->get(vmm_mad); - if ( vmmd == 0 ) + if ( vmmd == nullptr ) { att.resp_msg = "Cannot find vmm driver: " + vmm_mad; failure_response(ACTION, att); @@ -1369,7 +1369,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList // Add a new history record and update volatile DISK attributes // ------------------------------------------------------------------------ - if ( (vm = get_vm(id, att)) == 0 ) + if ( (vm = get_vm(id, att)) == nullptr ) { return; } @@ -1463,7 +1463,7 @@ void VirtualMachineDiskSaveas::request_execute( // ------------------------------------------------------------------------- // Prepare and check the VM/DISK to be saved as // ------------------------------------------------------------------------- - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } @@ -1489,7 +1489,7 @@ void VirtualMachineDiskSaveas::request_execute( // ------------------------------------------------------------------------- img = ipool->get_ro(iid_orig); - if ( img == 0 ) + if ( img == nullptr ) { goto error_image; } @@ -1524,7 +1524,7 @@ void VirtualMachineDiskSaveas::request_execute( // ------------------------------------------------------------------------- // Get the data of the DataStore for the new image & size // ------------------------------------------------------------------------- - if ((ds = dspool->get_ro(ds_id)) == 0 ) + if ((ds = dspool->get_ro(ds_id)) == nullptr ) { goto error_ds; } @@ -1628,7 +1628,7 @@ void VirtualMachineDiskSaveas::request_execute( ds = dspool->get(ds_id); - if (ds == 0) + if (ds == nullptr) { goto error_ds_removed; } @@ -1694,7 +1694,7 @@ error_allocate: goto error_common; error_common: - if ((vm = vmpool->get(id)) != 0) + if ((vm = vmpool->get(id)) != nullptr) { vm->clear_saveas_state(); @@ -1759,7 +1759,7 @@ void VirtualMachineAttach::request_execute( // ------------------------------------------------------------------------- // Check if the VM is a Virtual Router // ------------------------------------------------------------------------- - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } @@ -1846,7 +1846,7 @@ Request::ErrorCode VirtualMachineAttach::request_execute(int id, } } - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return NO_EXISTS; } @@ -1920,7 +1920,7 @@ void VirtualMachineDetach::request_execute(xmlrpc_c::paramList const& paramList, return; } - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } @@ -1966,7 +1966,7 @@ static int test_set_capacity(VirtualMachine * vm, float cpu, long mem, int vcpu, Host * host = hpool->get(vm->get_hid()); - if ( host == 0 ) + if ( host == nullptr ) { error = "Could not update host"; return -1; @@ -2094,7 +2094,7 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, /* ---------------------------------------------------------------------- */ VirtualMachine * vm = vmpool->get_ro(id); - if (vm == 0) + if (vm == nullptr) { att.resp_id = id; failure_response(NO_EXISTS, att); @@ -2148,7 +2148,7 @@ void VirtualMachineResize::request_execute(xmlrpc_c::paramList const& paramList, /* ---------------------------------------------------------------------- */ vm = vmpool->get(id); - if (vm == 0) + if (vm == nullptr) { att.resp_msg = id; failure_response(NO_EXISTS, att); @@ -2331,7 +2331,7 @@ void VirtualMachineAttachNic::request_execute( // ------------------------------------------------------------------------- // Check if the VM is a Virtual Router // ------------------------------------------------------------------------- - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } @@ -2394,7 +2394,7 @@ Request::ErrorCode VirtualMachineAttachNic::request_execute(int id, // ------------------------------------------------------------------------- vm = vmpool->get_ro(id); - if ( vm == 0 ) + if ( vm == nullptr ) { att.resp_id = id; att.resp_obj = PoolObjectSQL::VM; @@ -2466,7 +2466,7 @@ void VirtualMachineDetachNic::request_execute( // Check if the VM is a Virtual Router // ------------------------------------------------------------------------- - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } @@ -2515,7 +2515,7 @@ Request::ErrorCode VirtualMachineDetachNic::request_execute(int id, int nic_id, // ------------------------------------------------------------------------- vm = vmpool->get_ro(id); - if ( vm == 0 ) + if ( vm == nullptr ) { return NO_EXISTS; } @@ -2590,9 +2590,9 @@ void VirtualMachineRecover::request_execute( return; } - VirtualMachine * vm=(static_cast(pool))->get(id); + VirtualMachine * vm = (static_cast(pool))->get(id); - if (vm == 0) + if (vm == nullptr) { att.resp_id = id; failure_response(NO_EXISTS, att); @@ -2705,14 +2705,14 @@ void VirtualMachineDiskSnapshotCreate::request_execute( // ------------------------------------------------------------------------ // Check request consistency (VM & disk exists, no volatile) // ------------------------------------------------------------------------ - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } disk = (const_cast(vm))->get_disk(did); - if (disk == 0) + if (disk == nullptr) { att.resp_msg = "VM disk does not exist"; failure_response(ACTION, att); @@ -2761,7 +2761,7 @@ void VirtualMachineDiskSnapshotCreate::request_execute( Image* img = ipool->get_ro(img_id); - if (img == 0) + if (img == nullptr) { att.resp_obj = PoolObjectSQL::IMAGE; att.resp_id = img_id; @@ -2912,14 +2912,14 @@ void VirtualMachineDiskSnapshotDelete::request_execute( int did = xmlrpc_c::value_int(paramList.getInt(2)); int snap_id = xmlrpc_c::value_int(paramList.getInt(3)); - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } disk = (const_cast(vm))->get_disk(did); - if (disk == 0) + if (disk == nullptr) { att.resp_msg = "VM disk does not exist"; failure_response(ACTION, att); @@ -2942,7 +2942,7 @@ void VirtualMachineDiskSnapshotDelete::request_execute( Image* img = ipool->get_ro(img_id); - if (img == 0) + if (img == nullptr) { att.resp_obj = PoolObjectSQL::IMAGE; att.resp_id = img_id; @@ -3003,7 +3003,7 @@ void VirtualMachineDiskSnapshotRename::request_execute(xmlrpc_c::paramList const return; } - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { oss << "Could not rename the snapshot for VM " << id << ", VM does not exist"; @@ -3015,7 +3015,7 @@ void VirtualMachineDiskSnapshotRename::request_execute(xmlrpc_c::paramList const disk = (const_cast(vm))->get_disk(did); - if (disk == 0) + if (disk == nullptr) { att.resp_msg = "VM disk does not exist"; failure_response(ACTION, att); @@ -3056,6 +3056,7 @@ void VirtualMachineUpdateConf::request_execute( VirtualMachine * vm; VirtualMachineTemplate tmpl; + VirtualMachinePool * vmpool = static_cast(pool); // ------------------------------------------------------------------------- // Parse template @@ -3079,9 +3080,9 @@ void VirtualMachineUpdateConf::request_execute( /* ---------------------------------------------------------------------- */ /* Update VirtualMachine Configuration */ /* ---------------------------------------------------------------------- */ - vm = static_cast(pool)->get(id); + vm = vmpool->get(id); - if (vm == 0) + if (vm == nullptr) { att.resp_id = id; failure_response(NO_EXISTS, att); @@ -3122,9 +3123,11 @@ void VirtualMachineUpdateConf::request_execute( VectorAttribute * graphics = vm->get_template_attribute("GRAPHICS"); unsigned int port; - VirtualMachine::VmState state = vm->get_state(); - if (graphics != 0 && graphics->vector_value("PORT", port) == -1 && + VirtualMachine::VmState state = vm->get_state(); + VirtualMachine::LcmState lcm_state = vm->get_lcm_state(); + + if (graphics != nullptr && graphics->vector_value("PORT", port) == -1 && (state == VirtualMachine::ACTIVE || state == VirtualMachine::POWEROFF || state == VirtualMachine::SUSPENDED)) { @@ -3144,11 +3147,25 @@ void VirtualMachineUpdateConf::request_execute( graphics->replace("PORT", port); } - static_cast(pool)->update(vm); - static_cast(pool)->update_search(vm); + vmpool->update(vm); + vmpool->update_search(vm); vm->unlock(); + // Apply the change for running VM + if (state == VirtualMachine::VmState::ACTIVE && + lcm_state == VirtualMachine::LcmState::RUNNING) + { + auto dm = Nebula::instance().get_dm(); + + if (dm->live_updateconf(id, att, att.resp_msg) != 0) + { + failure_response(INTERNAL, att); + + return; + } + } + success_response(id, att); } @@ -3156,8 +3173,7 @@ void VirtualMachineUpdateConf::request_execute( /* -------------------------------------------------------------------------- */ void VirtualMachineDiskResize::request_execute( - xmlrpc_c::paramList const& paramList, - RequestAttributes& att) + xmlrpc_c::paramList const& paramList, RequestAttributes& att) { Nebula& nd = Nebula::instance(); DispatchManager * dm = nd.get_dm(); @@ -3173,31 +3189,31 @@ void VirtualMachineDiskResize::request_execute( int did = xmlrpc_c::value_int(paramList.getInt(2)); string size_s = xmlrpc_c::value_string(paramList.getString(3)); - long long size , current_size; + long long size , current_size; // ------------------------------------------------------------------------ // Check request consistency (VM & disk exists, size, and no snapshots) // ------------------------------------------------------------------------ - istringstream iss(size_s); + istringstream iss(size_s); - iss >> size; + iss >> size; - if (iss.fail() || !iss.eof()) - { - att.resp_msg = "Disk SIZE is not a valid integer"; + if (iss.fail() || !iss.eof()) + { + att.resp_msg = "Disk SIZE is not a valid integer"; failure_response(ACTION, att); - return; - } + return; + } - if ((vm = get_vm(id, att)) == 0) + if ((vm = get_vm(id, att)) == nullptr) { return; } - VirtualMachineDisk * disk =vm->get_disk(did); + VirtualMachineDisk * disk = vm->get_disk(did); - if (disk == 0) + if (disk == nullptr) { att.resp_msg = "VM disk does not exist"; failure_response(ACTION, att); @@ -3205,29 +3221,29 @@ void VirtualMachineDiskResize::request_execute( vm->unlock(); return; - } + } - disk->vector_value("SIZE", current_size); + disk->vector_value("SIZE", current_size); - if ( size <= current_size ) - { + if ( size <= current_size ) + { att.resp_msg = "New disk size has to be greater than current one"; failure_response(ACTION, att); vm->unlock(); return; - } + } - if ( disk->has_snapshots() ) - { + if ( disk->has_snapshots() ) + { att.resp_msg = "Cannot resize a disk with snapshots"; failure_response(ACTION, att); vm->unlock(); return; - } + } /* ------------- Get information about the disk and image --------------- */ bool img_ds_quota, vm_ds_quota; @@ -3255,7 +3271,7 @@ void VirtualMachineDiskResize::request_execute( { Image* img = ipool->get_ro(img_id); - if (img == 0) + if (img == nullptr) { att.resp_obj = PoolObjectSQL::IMAGE; att.resp_id = img_id; diff --git a/src/tm/TransferManager.cc b/src/tm/TransferManager.cc index db8d8d369c..1706b356a5 100644 --- a/src/tm/TransferManager.cc +++ b/src/tm/TransferManager.cc @@ -33,7 +33,7 @@ extern "C" void * tm_action_loop(void *arg) { TransferManager * tm; - if ( arg == 0 ) + if ( arg == nullptr ) { return 0; } @@ -65,8 +65,8 @@ int TransferManager::start() NebulaLog::log("TrM",Log::INFO,"Starting Transfer Manager..."); - pthread_attr_init (&pattr); - pthread_attr_setdetachstate (&pattr, PTHREAD_CREATE_JOINABLE); + pthread_attr_init(&pattr); + pthread_attr_setdetachstate(&pattr, PTHREAD_CREATE_JOINABLE); rc = pthread_create(&tm_thread,&pattr,tm_action_loop,(void *) this); @@ -88,7 +88,7 @@ void TransferManager::user_action(const ActionRequest& ar) VirtualMachine * vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -104,7 +104,7 @@ void TransferManager::user_action(const ActionRequest& ar) vm->unlock(); - switch(tm_ar.action()) + switch (tm_ar.action()) { case TMAction::PROLOG: if (host_is_cloud) @@ -576,7 +576,7 @@ void TransferManager::prolog_action(int vid) // ------------------------------------------------------------------------- vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -596,7 +596,7 @@ void TransferManager::prolog_action(int vid) vm_tm_mad = vm->get_tm_mad(); tm_md = get(); - if ( tm_md == 0 || vm_tm_mad.empty() ) + if ( tm_md == nullptr || vm_tm_mad.empty() ) { goto error_drivers; } @@ -631,7 +631,7 @@ void TransferManager::prolog_action(int vid) // ------------------------------------------------------------------------- os_attr = vm->get_template_attribute("OS"); - if ( os_attr != 0 ) + if ( os_attr != nullptr ) { string kernel; string initrd; @@ -671,7 +671,7 @@ void TransferManager::prolog_action(int vid) vm->unlock(); vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { goto error_attributes; } @@ -739,7 +739,7 @@ void TransferManager::prolog_migr_action(int vid) // ------------------------------------------------------------------------- vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -754,7 +754,7 @@ void TransferManager::prolog_migr_action(int vid) vm_tm_mad = vm->get_tm_mad(); tm_md = get(); - if ( tm_md == 0 || vm_tm_mad.empty()) + if ( tm_md == nullptr || vm_tm_mad.empty()) { goto error_drivers; } @@ -870,7 +870,7 @@ void TransferManager::prolog_resume_action(int vid) // ------------------------------------------------------------------------- vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -890,7 +890,7 @@ void TransferManager::prolog_resume_action(int vid) vm_tm_mad = vm->get_tm_mad(); tm_md = get(); - if ( tm_md == 0 || vm_tm_mad.empty()) + if ( tm_md == nullptr || vm_tm_mad.empty()) { goto error_drivers; } @@ -1004,7 +1004,7 @@ void TransferManager::prolog_attach_action(int vid) vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -1017,7 +1017,7 @@ void TransferManager::prolog_attach_action(int vid) vm_tm_mad = vm->get_tm_mad(); tm_md = get(); - if ( tm_md == 0 || vm_tm_mad.empty() ) + if ( tm_md == nullptr || vm_tm_mad.empty() ) { goto error_drivers; } @@ -1037,7 +1037,7 @@ void TransferManager::prolog_attach_action(int vid) // ------------------------------------------------------------------------- disk = vm->get_attach_disk(); - if ( disk == 0 ) + if ( disk == nullptr ) { goto error_disk; } @@ -1140,7 +1140,7 @@ void TransferManager::epilog_transfer_command( if ( disk->is_volatile() == true ) { tm_mad = vm->get_tm_mad(); - ds_id_i= vm->get_ds_id(); + ds_id_i = vm->get_ds_id(); } else { @@ -1186,7 +1186,7 @@ void TransferManager::epilog_action(bool local, int vid) // ------------------------------------------------------------------------ vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -1201,7 +1201,7 @@ void TransferManager::epilog_action(bool local, int vid) vm_tm_mad = vm->get_tm_mad(); tm_md = get(); - if ( tm_md == 0 || vm_tm_mad.empty()) + if ( tm_md == nullptr || vm_tm_mad.empty()) { goto error_drivers; } @@ -1295,7 +1295,7 @@ void TransferManager::epilog_stop_action(int vid) // ------------------------------------------------------------------------ vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -1310,7 +1310,7 @@ void TransferManager::epilog_stop_action(int vid) vm_tm_mad = vm->get_tm_mad(); tm_md = get(); - if (tm_md == 0 || vm_tm_mad.empty()) + if (tm_md == nullptr || vm_tm_mad.empty()) { goto error_drivers; } @@ -1544,14 +1544,14 @@ void TransferManager::epilog_delete_action(bool local, int vid) // ------------------------------------------------------------------------ vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } tm_md = get(); - if ( tm_md == 0 ) + if ( tm_md == nullptr ) { goto error_driver; } @@ -1617,14 +1617,14 @@ void TransferManager::epilog_delete_previous_action(int vid) // ------------------------------------------------------------------------ vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } tm_md = get(); - if (tm_md == 0) + if (tm_md == nullptr) { goto error_driver; } @@ -1690,14 +1690,14 @@ void TransferManager::epilog_delete_both_action(int vid) // ------------------------------------------------------------------------ vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } tm_md = get(); - if (tm_md == 0) + if (tm_md == nullptr) { goto error_driver; } @@ -1765,7 +1765,7 @@ void TransferManager::epilog_detach_action(int vid) // ------------------------------------------------------------------------ vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -1778,7 +1778,7 @@ void TransferManager::epilog_detach_action(int vid) vm_tm_mad = vm->get_tm_mad(); tm_md = get(); - if ( tm_md == 0 || vm_tm_mad.empty()) + if ( tm_md == nullptr || vm_tm_mad.empty()) { goto error_drivers; } @@ -1797,7 +1797,7 @@ void TransferManager::epilog_detach_action(int vid) disk = vm->get_attach_disk(); - if ( disk == 0 ) + if ( disk == nullptr ) { goto error_disk; } @@ -1857,14 +1857,14 @@ void TransferManager::driver_cancel_action(int vid) // ------------------------------------------------------------------------ tm_md = get(); - if ( tm_md == 0 ) + if ( tm_md == nullptr ) { return; } vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -1914,7 +1914,7 @@ void TransferManager::saveas_hot_action(int vid) // ------------------------------------------------------------------------ vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -1931,7 +1931,7 @@ void TransferManager::saveas_hot_action(int vid) tm_md = get(); - if (tm_md == 0) + if (tm_md == nullptr) { goto error_driver; } @@ -2058,14 +2058,14 @@ void TransferManager::do_snapshot_action(int vid, const char * snap_action) tm_md = get(); - if (tm_md == 0) + if (tm_md == nullptr) { goto error_driver; } vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -2182,14 +2182,14 @@ void TransferManager::resize_action(int vid) const TransferManagerDriver * tm_md = get(); - if (tm_md == 0) + if (tm_md == nullptr) { goto error_driver; } vm = vmpool->get(vid); - if (vm == 0) + if (vm == nullptr) { return; } @@ -2209,7 +2209,7 @@ void TransferManager::resize_action(int vid) disk = vm->get_resize_disk(); - if ( disk == 0 ) + if ( disk == nullptr ) { goto error_disk; } @@ -2260,8 +2260,8 @@ int TransferManager::load_mads(int uid) int rc; string name; - const VectorAttribute * vattr = 0; - TransferManagerDriver * tm_driver = 0; + const VectorAttribute * vattr = nullptr; + TransferManagerDriver * tm_driver = nullptr; oss << "Loading Transfer Manager driver."; @@ -2272,7 +2272,7 @@ int TransferManager::load_mads(int uid) vattr = mad_conf[0]; } - if ( vattr == 0 ) + if ( vattr == nullptr ) { NebulaLog::log("TM",Log::ERROR,"Failed to load Transfer Manager driver."); return -1; diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 801f85a04a..866b3d6c58 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -171,127 +171,127 @@ int VirtualMachine::lcm_state_from_str(string& st, LcmState& state) if ( st == "LCM_INIT" ){ state = LCM_INIT; - } else if ( st == "PROLOG") { + } else if ( st == "PROLOG" ) { state = PROLOG; - } else if ( st == "BOOT") { + } else if ( st == "BOOT" ) { state = BOOT; - } else if ( st == "RUNNING") { + } else if ( st == "RUNNING" ) { state = RUNNING; - } else if ( st == "MIGRATE") { + } else if ( st == "MIGRATE" ) { state = MIGRATE; - } else if ( st == "SAVE_STOP") { + } else if ( st == "SAVE_STOP" ) { state = SAVE_STOP; - } else if ( st == "SAVE_SUSPEND") { + } else if ( st == "SAVE_SUSPEND" ) { state = SAVE_SUSPEND; - } else if ( st == "SAVE_MIGRATE") { + } else if ( st == "SAVE_MIGRATE" ) { state = SAVE_MIGRATE; - } else if ( st == "PROLOG_MIGRATE") { + } else if ( st == "PROLOG_MIGRATE" ) { state = PROLOG_MIGRATE; - } else if ( st == "PROLOG_RESUME") { + } else if ( st == "PROLOG_RESUME" ) { state = PROLOG_RESUME; - } else if ( st == "EPILOG_STOP") { + } else if ( st == "EPILOG_STOP" ) { state = EPILOG_STOP; - } else if ( st == "EPILOG") { + } else if ( st == "EPILOG" ) { state = EPILOG; - } else if ( st == "SHUTDOWN") { + } else if ( st == "SHUTDOWN" ) { state = SHUTDOWN; - } else if ( st == "CLEANUP_RESUBMIT") { + } else if ( st == "CLEANUP_RESUBMIT" ) { state = CLEANUP_RESUBMIT; - } else if ( st == "UNKNOWN") { + } else if ( st == "UNKNOWN" ) { state = UNKNOWN; - } else if ( st == "HOTPLUG") { + } else if ( st == "HOTPLUG" ) { state = HOTPLUG; - } else if ( st == "SHUTDOWN_POWEROFF") { + } else if ( st == "SHUTDOWN_POWEROFF" ) { state = SHUTDOWN_POWEROFF; - } else if ( st == "BOOT_UNKNOWN") { + } else if ( st == "BOOT_UNKNOWN" ) { state = BOOT_UNKNOWN; - } else if ( st == "BOOT_POWEROFF") { + } else if ( st == "BOOT_POWEROFF" ) { state = BOOT_POWEROFF; - } else if ( st == "BOOT_SUSPENDED") { + } else if ( st == "BOOT_SUSPENDED" ) { state = BOOT_SUSPENDED; - } else if ( st == "BOOT_STOPPED") { + } else if ( st == "BOOT_STOPPED" ) { state = BOOT_STOPPED; - } else if ( st == "CLEANUP_DELETE") { + } else if ( st == "CLEANUP_DELETE" ) { state = CLEANUP_DELETE; - } else if ( st == "HOTPLUG_SNAPSHOT") { + } else if ( st == "HOTPLUG_SNAPSHOT" ) { state = HOTPLUG_SNAPSHOT; - } else if ( st == "HOTPLUG_NIC") { + } else if ( st == "HOTPLUG_NIC" ) { state = HOTPLUG_NIC; - } else if ( st == "HOTPLUG_SAVEAS") { + } else if ( st == "HOTPLUG_SAVEAS" ) { state = HOTPLUG_SAVEAS; - } else if ( st == "HOTPLUG_SAVEAS_POWEROFF") { + } else if ( st == "HOTPLUG_SAVEAS_POWEROFF" ) { state = HOTPLUG_SAVEAS_POWEROFF; - } else if ( st == "HOTPLUG_SAVEAS_SUSPENDED") { + } else if ( st == "HOTPLUG_SAVEAS_SUSPENDED" ) { state = HOTPLUG_SAVEAS_SUSPENDED; - } else if ( st == "SHUTDOWN_UNDEPLOY") { + } else if ( st == "SHUTDOWN_UNDEPLOY" ) { state = SHUTDOWN_UNDEPLOY; - } else if ( st == "EPILOG_UNDEPLOY") { + } else if ( st == "EPILOG_UNDEPLOY" ) { state = EPILOG_UNDEPLOY; - } else if ( st == "PROLOG_UNDEPLOY") { + } else if ( st == "PROLOG_UNDEPLOY" ) { state = PROLOG_UNDEPLOY; - } else if ( st == "BOOT_UNDEPLOY") { + } else if ( st == "BOOT_UNDEPLOY" ) { state = BOOT_UNDEPLOY; - } else if ( st == "HOTPLUG_PROLOG_POWEROFF") { + } else if ( st == "HOTPLUG_PROLOG_POWEROFF" ) { state = HOTPLUG_PROLOG_POWEROFF; - } else if ( st == "HOTPLUG_EPILOG_POWEROFF") { + } else if ( st == "HOTPLUG_EPILOG_POWEROFF" ) { state = HOTPLUG_EPILOG_POWEROFF; - } else if ( st == "BOOT_MIGRATE") { + } else if ( st == "BOOT_MIGRATE" ) { state = BOOT_MIGRATE; - } else if ( st == "BOOT_FAILURE") { + } else if ( st == "BOOT_FAILURE" ) { state = BOOT_FAILURE; - } else if ( st == "BOOT_MIGRATE_FAILURE") { + } else if ( st == "BOOT_MIGRATE_FAILURE" ) { state = BOOT_MIGRATE_FAILURE; - } else if ( st == "PROLOG_MIGRATE_FAILURE") { + } else if ( st == "PROLOG_MIGRATE_FAILURE" ) { state = PROLOG_MIGRATE_FAILURE; - } else if ( st == "PROLOG_FAILURE") { + } else if ( st == "PROLOG_FAILURE" ) { state = PROLOG_FAILURE; - } else if ( st == "EPILOG_FAILURE") { + } else if ( st == "EPILOG_FAILURE" ) { state = EPILOG_FAILURE; - } else if ( st == "EPILOG_STOP_FAILURE") { + } else if ( st == "EPILOG_STOP_FAILURE" ) { state = EPILOG_STOP_FAILURE; - } else if ( st == "EPILOG_UNDEPLOY_FAILURE") { + } else if ( st == "EPILOG_UNDEPLOY_FAILURE" ) { state = EPILOG_UNDEPLOY_FAILURE; - } else if ( st == "PROLOG_MIGRATE_POWEROFF") { + } else if ( st == "PROLOG_MIGRATE_POWEROFF" ) { state = PROLOG_MIGRATE_POWEROFF; - } else if ( st == "PROLOG_MIGRATE_POWEROFF_FAILURE") { + } else if ( st == "PROLOG_MIGRATE_POWEROFF_FAILURE" ) { state = PROLOG_MIGRATE_POWEROFF_FAILURE; - } else if ( st == "PROLOG_MIGRATE_SUSPEND") { + } else if ( st == "PROLOG_MIGRATE_SUSPEND" ) { state = PROLOG_MIGRATE_SUSPEND; - } else if ( st == "PROLOG_MIGRATE_SUSPEND_FAILURE") { + } else if ( st == "PROLOG_MIGRATE_SUSPEND_FAILURE" ) { state = PROLOG_MIGRATE_SUSPEND_FAILURE; - } else if ( st == "BOOT_STOPPED_FAILURE") { + } else if ( st == "BOOT_STOPPED_FAILURE" ) { state = BOOT_STOPPED_FAILURE; - } else if ( st == "BOOT_UNDEPLOY_FAILURE") { + } else if ( st == "BOOT_UNDEPLOY_FAILURE" ) { state = BOOT_UNDEPLOY_FAILURE; - } else if ( st == "PROLOG_RESUME_FAILURE") { + } else if ( st == "PROLOG_RESUME_FAILURE" ) { state = PROLOG_RESUME_FAILURE; - } else if ( st == "PROLOG_UNDEPLOY_FAILURE") { + } else if ( st == "PROLOG_UNDEPLOY_FAILURE" ) { state = PROLOG_UNDEPLOY_FAILURE; - } else if ( st == "DISK_SNAPSHOT_POWEROFF") { + } else if ( st == "DISK_SNAPSHOT_POWEROFF" ) { state = DISK_SNAPSHOT_POWEROFF; - } else if ( st == "DISK_SNAPSHOT_REVERT_POWEROFF") { + } else if ( st == "DISK_SNAPSHOT_REVERT_POWEROFF" ) { state = DISK_SNAPSHOT_REVERT_POWEROFF; - } else if ( st == "DISK_SNAPSHOT_DELETE_POWEROFF") { + } else if ( st == "DISK_SNAPSHOT_DELETE_POWEROFF" ) { state = DISK_SNAPSHOT_DELETE_POWEROFF; - } else if ( st == "DISK_SNAPSHOT_SUSPENDED") { + } else if ( st == "DISK_SNAPSHOT_SUSPENDED" ) { state = DISK_SNAPSHOT_SUSPENDED; - } else if ( st == "DISK_SNAPSHOT_REVERT_SUSPENDED") { + } else if ( st == "DISK_SNAPSHOT_REVERT_SUSPENDED" ) { state = DISK_SNAPSHOT_REVERT_SUSPENDED; - } else if ( st == "DISK_SNAPSHOT_DELETE_SUSPENDED") { + } else if ( st == "DISK_SNAPSHOT_DELETE_SUSPENDED" ) { state = DISK_SNAPSHOT_DELETE_SUSPENDED; - } else if ( st == "DISK_SNAPSHOT") { + } else if ( st == "DISK_SNAPSHOT" ) { state = DISK_SNAPSHOT; - } else if ( st == "DISK_SNAPSHOT_DELETE") { + } else if ( st == "DISK_SNAPSHOT_DELETE" ) { state = DISK_SNAPSHOT_DELETE; - } else if ( st == "PROLOG_MIGRATE_UNKNOWN") { + } else if ( st == "PROLOG_MIGRATE_UNKNOWN" ) { state = PROLOG_MIGRATE_UNKNOWN; - } else if ( st == "PROLOG_MIGRATE_UNKNOWN_FAILURE") { + } else if ( st == "PROLOG_MIGRATE_UNKNOWN_FAILURE" ) { state = PROLOG_MIGRATE_UNKNOWN_FAILURE; - } else if ( st == "DISK_RESIZE") { + } else if ( st == "DISK_RESIZE" ) { state = DISK_RESIZE; - } else if ( st == "DISK_RESIZE_POWEROFF") { + } else if ( st == "DISK_RESIZE_POWEROFF" ) { state = DISK_RESIZE_POWEROFF; - } else if ( st == "DISK_RESIZE_UNDEPLOYED") { + } else if ( st == "DISK_RESIZE_UNDEPLOYED" ) { state = DISK_RESIZE_UNDEPLOYED; } else { return -1; @@ -535,13 +535,13 @@ int VirtualMachine::select(SqlDB * db) // Rebuild the VirtualMachine object rc = PoolObjectSQL::select(db); - if( rc != 0 ) + if ( rc != 0 ) { return rc; } //Get History Records. - if( hasHistory() ) + if ( hasHistory() ) { last_seq = history->seq; @@ -599,7 +599,7 @@ int VirtualMachine::select(SqlDB * db) log_system = nd.get_log_system(); clevel = nd.get_debug_level(); - switch(log_system) + switch (log_system) { case NebulaLog::FILE_TS: case NebulaLog::FILE: @@ -1158,7 +1158,7 @@ error_common: /** * @return -1 for incompatible datastore IDs, -2 for missing datastore IDs */ -static int check_and_set_datastores_id(const set &csystem_ds, +static int check_and_set_datastores_id(const set &csystem_ds, set &ds_ids) { if ( csystem_ds.empty() ) @@ -1339,7 +1339,7 @@ static int get_cluster_requirements(Template *tmpl, set& cluster_ids, // Get cluster id from all DISK vector attributes (IMAGE Datastore) num_vatts = tmpl->get("DISK",vatts); - for(int i=0; i& cluster_ids, // Get cluster id from all NIC vector attributes num_vatts = tmpl->get("NIC", vatts); - for(int i=0; i& cluster_ids, // Get cluster id from all PCI attibutes, TYPE = NIC num_vatts = tmpl->get("PCI", vatts); - for(int i=0; ivector_value("TYPE") != "NIC" ) { @@ -1484,7 +1484,7 @@ error_common: * @param error_str Returns the error reason, if any * @return 0 on success */ -static int get_datastore_requirements(Template *tmpl, set& ds_ids, +static int get_datastore_requirements(Template *tmpl, set& ds_ids, string& error_str) { ostringstream oss; @@ -1499,7 +1499,7 @@ static int get_datastore_requirements(Template *tmpl, set& ds_ids, // Get cluster id from all DISK vector attributes (IMAGE Datastore) int num_vatts = tmpl->get("DISK",vatts); - for(int i=0; i& cluster_ids, oss << " | (PUBLIC_CLOUD = YES & ("; - oss << "HYPERVISOR = " << *it ; + oss << "HYPERVISOR = " << *it; for (++it; it != clouds.end() ; ++it) { @@ -1719,7 +1719,7 @@ int VirtualMachine::insert_replace(SqlDB *db, bool replace, string& error_str) goto error_text; } - if(replace) + if (replace) { oss << "UPDATE " << table << " SET " << "name = '" << sql_name << "', " @@ -2131,7 +2131,7 @@ void VirtualMachine::remove_security_group(int sgid) num_sgs = obj_template->get("SECURITY_GROUP_RULE", sgs); - for(int i=0; ivector_value("SECURITY_GROUP_ID", ssgid); @@ -2177,7 +2177,7 @@ void VirtualMachine::set_auth_request(int uid, VirtualMachineDisks::disk_iterator disk; VirtualMachineDisks tdisks(tmpl, false); - for( disk = tdisks.begin(); disk != tdisks.end(); ++disk) + for (disk = tdisks.begin(); disk != tdisks.end(); ++disk) { (*disk)->authorize(uid, &ar, check_lock); } @@ -2185,7 +2185,7 @@ void VirtualMachine::set_auth_request(int uid, VirtualMachineNics::nic_iterator nic; VirtualMachineNics tnics(tmpl); - for( nic = tnics.begin(); nic != tnics.end(); ++nic) + for (nic = tnics.begin(); nic != tnics.end(); ++nic) { (*nic)->authorize(uid, &ar, check_lock); } @@ -2262,7 +2262,7 @@ string& VirtualMachine::to_xml_extended(string& xml, int n_history) const VirtualMachineDisks::disk_iterator disk; - for ( disk = const_cast(&disks)->begin() ; + for (disk = const_cast(&disks)->begin() ; disk != const_cast(&disks)->end() ; ++disk) { const Snapshots * snapshots = (*disk)->get_snapshots(); @@ -2962,6 +2962,7 @@ int VirtualMachine::updateconf(VirtualMachineTemplate& tmpl, string &err) { case LCM_INIT: case PROLOG: + case RUNNING: case EPILOG: case SHUTDOWN: case CLEANUP_RESUBMIT: @@ -2990,6 +2991,7 @@ int VirtualMachine::updateconf(VirtualMachineTemplate& tmpl, string &err) err = "configuration cannot be updated in state " + state_str(); return -1; }; + break; case INIT: case DONE: @@ -3180,7 +3182,7 @@ int VirtualMachine::get_disk_images(string& error_str) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -void VirtualMachine::release_disk_images(vector