F #2837: Add --force option to 'onevnet rmar' (#4511)

This commit is contained in:
Pavel Czerný authored and GitHub committed 2020-04-14 10:49:06 +02:00
1 parent fd4138a9db
commit 36c79d643b
8 files changed
+27 -13

No files matched your search

+8 -2
View File
@@ -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
+2 -2
View File
@@ -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
+7 -1
View File
@@ -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);
+3 -3
View File
@@ -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<unsigned int, AddressRange *>::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;
+2 -2
View File
@@ -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);
}
/* -------------------------------------------------------------------------- */