diff --git a/include/AddressRange.h b/include/AddressRange.h index 5680b2ed05..a41a3bea67 100644 --- a/include/AddressRange.h +++ b/include/AddressRange.h @@ -405,7 +405,7 @@ public: * rm_ar from AddressRangePool needs to access the internal representation * of the AR to remove it from the ARPool template. */ - friend int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg); + friend int AddressRangePool::rm_ar(unsigned int ar_id, bool force, string& error_msg); /* * rm_ars from AddressRangePool needs to access the internal representation diff --git a/include/AddressRangePool.h b/include/AddressRangePool.h index a03513a918..c054f99fef 100644 --- a/include/AddressRangePool.h +++ b/include/AddressRangePool.h @@ -68,9 +68,10 @@ public: * Removes an address range from the pool if it does not contain any used * leases * @param arid of the address range to be removed + * @param force force remove, even if active leases exists * @return 0 on success, -1 if not exists or has used addresses */ - int rm_ar(unsigned int ar_id, string& error_msg); + int rm_ar(unsigned int ar_id, bool force, string& error_msg); /** * Removes all address ranges from the pool if it does not contain any used diff --git a/include/VirtualNetwork.h b/include/VirtualNetwork.h index 483ef3991b..80f966a516 100644 --- a/include/VirtualNetwork.h +++ b/include/VirtualNetwork.h @@ -234,10 +234,11 @@ public: /** * Removes an address range from the VNET * @param ar_id of the address range + * @param force force remove, even if active leases exists * @param error_msg If the action fails, this message contains the reason. * @return 0 on success */ - int rm_ar(unsigned int ar_id, string& error_msg); + int rm_ar(unsigned int ar_id, bool force, string& error_msg); /** * Removes all address ranges from the VNET diff --git a/src/cli/onevnet b/src/cli/onevnet index 5168aa368f..6c86403ff2 100755 --- a/src/cli/onevnet +++ b/src/cli/onevnet @@ -71,6 +71,12 @@ CommandParser::CmdParser.new(ARGV) do :description => 'lock all actions' } + FORCE = { + :name => 'force', + :large => '--force', + :description => 'Force execution of action, bypass the consistency checks' + } + ######################################################################## # Global Options ######################################################################## @@ -169,9 +175,9 @@ CommandParser::CmdParser.new(ARGV) do Removes an address range from the Virtual Network EOT - command :rmar, rmar_desc, :vnetid, :ar_id do + command :rmar, rmar_desc, :vnetid, :ar_id, :options => FORCE do helper.perform_action(args[0], options, 'address range removed') do |vn| - vn.rm_ar(args[1]) + vn.rm_ar(args[1], options[:force] || false) end end diff --git a/src/oca/ruby/opennebula/virtual_network.rb b/src/oca/ruby/opennebula/virtual_network.rb index beb9206752..f6e7722c93 100644 --- a/src/oca/ruby/opennebula/virtual_network.rb +++ b/src/oca/ruby/opennebula/virtual_network.rb @@ -145,10 +145,10 @@ module OpenNebula end # Removes an Address Range from the VirtualNetwork - def rm_ar(ar_id) + def rm_ar(ar_id, force = false) return Error.new('ID not defined') if !@pe_id - rc = @client.call(VN_METHODS[:rm_ar], @pe_id, ar_id.to_i) + rc = @client.call(VN_METHODS[:rm_ar], @pe_id, ar_id.to_i, force) rc = nil if !OpenNebula.is_error?(rc) return rc diff --git a/src/rm/RequestManagerVirtualNetwork.cc b/src/rm/RequestManagerVirtualNetwork.cc index aac09e9424..821f354d24 100644 --- a/src/rm/RequestManagerVirtualNetwork.cc +++ b/src/rm/RequestManagerVirtualNetwork.cc @@ -94,6 +94,12 @@ void VirtualNetworkRmAddressRange:: return; } + bool force = false; + if (paramList.size() > 3) + { + force = xmlrpc_c::value_boolean(paramList.getBoolean(3)); + } + // ------------------------------------------------------------------------- // Get VNET and data for reservations // ------------------------------------------------------------------------- @@ -119,7 +125,7 @@ void VirtualNetworkRmAddressRange:: vn->get_template_attribute("MAC" , mac , ar_id); - if ( vn->rm_ar(ar_id, att.resp_msg) < 0 ) + if (vn->rm_ar(ar_id, force, att.resp_msg) < 0) { failure_response(INTERNAL, att); diff --git a/src/vnm/AddressRangePool.cc b/src/vnm/AddressRangePool.cc index 9a461ce3d0..42ddb2b7a7 100644 --- a/src/vnm/AddressRangePool.cc +++ b/src/vnm/AddressRangePool.cc @@ -191,7 +191,7 @@ int AddressRangePool::from_xml_node(const xmlNodePtr node) /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg) +int AddressRangePool::rm_ar(unsigned int ar_id, bool force, string& error_msg) { map::iterator it; @@ -203,7 +203,7 @@ int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg) return -1; } - if (it->second->get_used_addr() > 0) + if (!force && it->second->get_used_addr() > 0) { error_msg = "Address Range has leases in use"; return -1; @@ -222,7 +222,7 @@ int AddressRangePool::rm_ar(unsigned int ar_id, string& error_msg) ir.wait(); - if (ir.result != true) + if (!force && ir.result != true) { error_msg = ir.message; return -1; diff --git a/src/vnm/VirtualNetwork.cc b/src/vnm/VirtualNetwork.cc index 7fb58304d9..a4e9fea9c2 100644 --- a/src/vnm/VirtualNetwork.cc +++ b/src/vnm/VirtualNetwork.cc @@ -1065,9 +1065,9 @@ int VirtualNetwork::update_ar( /* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */ -int VirtualNetwork::rm_ar(unsigned int ar_id, string& error_msg) +int VirtualNetwork::rm_ar(unsigned int ar_id, bool force, string& error_msg) { - return ar_pool.rm_ar(ar_id, error_msg); + return ar_pool.rm_ar(ar_id, force, error_msg); } /* -------------------------------------------------------------------------- */