1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

feature #2858: Update ARs. Core, OCA and CLI. Needs to implement attribute removal

This commit is contained in:
Ruben S. Montero 2014-05-23 00:24:14 +02:00
parent f440b6b1a5
commit 20a3c25843
11 changed files with 162 additions and 4 deletions

View File

@ -203,6 +203,14 @@ public:
return attr->vector_value(name); return attr->vector_value(name);
} }
/**
* Updates the Address Range with the attributes provided. The following
* CANNOT be updated: TYPE, SIZE, IP, MAC (plus the internal AR_ID and
* ALLOCATED)
* @param vup the new vector attributes for the address range
*/
void update_attributes(VectorAttribute *vup);
private: private:
/* ---------------------------------------------------------------------- */ /* ---------------------------------------------------------------------- */
/* String to binary conversion functions for different address types */ /* String to binary conversion functions for different address types */

View File

@ -62,6 +62,13 @@ public:
*/ */
int rm_ar(unsigned int ar_id, string& error_msg); int rm_ar(unsigned int ar_id, string& error_msg);
/**
* Updates the given address ranges
* @param ars vector of address ranges as VectorAttributes obtined from
* template in the form AR = [...]
*/
void update_ar(vector<Attribute *> ars);
/** /**
* Generate a XML representation of the Address Range Pool * Generate a XML representation of the Address Range Pool
* @param sstream where the ARPool is written * @param sstream where the ARPool is written

View File

@ -99,6 +99,29 @@ public:
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */ /* ------------------------------------------------------------------------- */
class VirtualNetworkUpdateAddressRange: public RequestManagerVirtualNetwork
{
public:
VirtualNetworkUpdateAddressRange():
RequestManagerVirtualNetwork("VirtualNetworkUpdateAddressRange",
"Updates address ranges to a virtual network"){};
~VirtualNetworkUpdateAddressRange(){};
int leases_action(VirtualNetwork * vn,
VirtualNetworkTemplate * tmpl,
string& error_str)
{
error_str.clear();
vn->update_ar(tmpl);
return 0;
};
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class VirtualNetworkHold : public RequestManagerVirtualNetwork class VirtualNetworkHold : public RequestManagerVirtualNetwork
{ {
public: public:

View File

@ -72,6 +72,13 @@ public:
*/ */
int rm_ar(unsigned int ar_id, string& error_msg); int rm_ar(unsigned int ar_id, string& error_msg);
/**
* Update an address range to the virtual network
* @param ars_tmpl template in the form AR = [AR_ID=...]. The address range
* is specified by the AR_ID attribute.
*/
void update_ar(VirtualNetworkTemplate * ars_tmpl);
/** /**
* Holds a Lease, marking it as used * Holds a Lease, marking it as used
* @param leases template in the form LEASES = [IP=XX]. * @param leases template in the form LEASES = [IP=XX].

View File

@ -251,6 +251,25 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end end
end end
update_ar_desc = <<-EOT.unindent
Update Address Range variables. SIZE, IP, MAC and TYPE cannot be updated
EOT
command :updatear, update_ar_desc, :vnetid, :ar_id, [:file, nil] do
helper.perform_action(args[0],options,"modified") do |obj|
str = OpenNebulaHelper.update_template(args[0], obj, args[2],
"AR_POOL/AR[AR_ID=#{args[1]}]")
str[-1]=''
str.gsub!(/AR_ID="\d+"\n/,'')
str.gsub!(/^\s*(#|$)/,'')
str.gsub!(/\n/,',')
obj.update_ar("AR = [AR_ID=#{args[1]},#{str}]")
end
end
rename_desc = <<-EOT.unindent rename_desc = <<-EOT.unindent
Renames the Virtual Network Renames the Virtual Network
EOT EOT

View File

@ -23,13 +23,13 @@ module OpenNebula
# Constants and Class Methods # Constants and Class Methods
####################################################################### #######################################################################
VN_METHODS = { VN_METHODS = {
:info => "vn.info", :info => "vn.info",
:allocate => "vn.allocate", :allocate => "vn.allocate",
:delete => "vn.delete", :delete => "vn.delete",
:add_ar => "vn.add_ar", :add_ar => "vn.add_ar",
:rm_ar => "vn.rm_ar", :rm_ar => "vn.rm_ar",
:update_ar => "vn.update_ar",
:chown => "vn.chown", :chown => "vn.chown",
:chmod => "vn.chmod", :chmod => "vn.chmod",
:update => "vn.update", :update => "vn.update",
@ -109,7 +109,7 @@ module OpenNebula
super(VN_METHODS[:delete]) super(VN_METHODS[:delete])
end end
# Adds a lease to the VirtualNetwork # Adds Address Ranges to the VirtualNetwork
def add_ar(ar_template) def add_ar(ar_template)
return Error.new('ID not defined') if !@pe_id return Error.new('ID not defined') if !@pe_id
@ -119,7 +119,7 @@ module OpenNebula
return rc return rc
end end
# Removes a lease from the VirtualNetwork # Removes an Address Range from the VirtualNetwork
def rm_ar(ar_id) def rm_ar(ar_id)
return Error.new('ID not defined') if !@pe_id return Error.new('ID not defined') if !@pe_id
@ -129,6 +129,16 @@ module OpenNebula
return rc return rc
end end
# Updates Address Ranges from the VirtualNetwork
def update_ar(ar_template)
return Error.new('ID not defined') if !@pe_id
rc = @client.call(VN_METHODS[:update_ar], @pe_id, ar_template)
rc = nil if !OpenNebula.is_error?(rc)
return rc
end
# Holds a virtual network address # Holds a virtual network address
# @param ip [String] address to hold, if contains ":" a MAC address is assumed # @param ip [String] address to hold, if contains ":" a MAC address is assumed
# @param ar_id [Integer] The address range to hold the lease. If not set # @param ar_id [Integer] The address range to hold the lease. If not set

View File

@ -278,6 +278,7 @@ void RequestManager::register_xml_methods()
// VirtualNetwork Methods // VirtualNetwork Methods
xmlrpc_c::methodPtr vn_add_ar(new VirtualNetworkAddAddressRange()); xmlrpc_c::methodPtr vn_add_ar(new VirtualNetworkAddAddressRange());
xmlrpc_c::methodPtr vn_rm_ar(new VirtualNetworkRmAddressRange()); xmlrpc_c::methodPtr vn_rm_ar(new VirtualNetworkRmAddressRange());
xmlrpc_c::methodPtr vn_update_ar(new VirtualNetworkUpdateAddressRange());
xmlrpc_c::methodPtr vn_hold(new VirtualNetworkHold()); xmlrpc_c::methodPtr vn_hold(new VirtualNetworkHold());
xmlrpc_c::methodPtr vn_release(new VirtualNetworkRelease()); xmlrpc_c::methodPtr vn_release(new VirtualNetworkRelease());
@ -487,6 +488,7 @@ void RequestManager::register_xml_methods()
/* Network related methods*/ /* Network related methods*/
RequestManagerRegistry.addMethod("one.vn.add_ar", vn_add_ar); RequestManagerRegistry.addMethod("one.vn.add_ar", vn_add_ar);
RequestManagerRegistry.addMethod("one.vn.rm_ar", vn_rm_ar); RequestManagerRegistry.addMethod("one.vn.rm_ar", vn_rm_ar);
RequestManagerRegistry.addMethod("one.vn.update_ar", vn_update_ar);
RequestManagerRegistry.addMethod("one.vn.hold", vn_hold); RequestManagerRegistry.addMethod("one.vn.hold", vn_hold);
RequestManagerRegistry.addMethod("one.vn.release", vn_release); RequestManagerRegistry.addMethod("one.vn.release", vn_release);
RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate); RequestManagerRegistry.addMethod("one.vn.allocate", vn_allocate);

View File

@ -96,7 +96,6 @@ void VirtualNetworkRmAddressRange::
VirtualNetwork * vn; VirtualNetwork * vn;
string error_str; string error_str;
int rc;
if ( basic_authorization(id, att) == false ) if ( basic_authorization(id, att) == false )
{ {

View File

@ -178,6 +178,42 @@ int AddressRange::from_vattr(VectorAttribute *vattr, string& error_msg)
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void AddressRange::update_attributes(VectorAttribute *vup)
{
/* Remove non-update attributes */
vup->remove("TYPE");
vup->remove("SIZE");
vup->remove("MAC");
vup->remove("IP");
/* Remove internal attributes */
vup->remove("AR_ID");
vup->remove("ALLOCATED");
vup->remove("USED_LEASES");
vup->remove("LEASES");
/* Copy the rest attributes to the address range */
const map<string,string> new_attrs = vup->value();
map <string,string>::const_iterator it;
for (it = new_attrs.begin(); it != new_attrs.end(); it++)
{
attr->replace(it->first, it->second);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int AddressRange::from_vattr_db(VectorAttribute *vattr) int AddressRange::from_vattr_db(VectorAttribute *vattr)
{ {
string value; string value;

View File

@ -74,6 +74,41 @@ int AddressRangePool::from_vattr(vector<Attribute *> ars, string& error_msg)
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void AddressRangePool::update_ar(vector<Attribute *> ars)
{
vector<Attribute *>::iterator it;
map<unsigned int, AddressRange *>::iterator ar_it;
unsigned int arid;
for (it = ars.begin(); it != ars.end(); it++)
{
VectorAttribute * va = static_cast<VectorAttribute *>(*it);
if (va == 0)
{
continue;
}
if (va->vector_value("AR_ID", arid) != 0)
{
continue;
}
ar_it = ar_pool.find(arid);
if (ar_it == ar_pool.end())
{
continue;
}
ar_it->second->update_attributes(va);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int AddressRangePool::from_xml_node(const xmlNodePtr node) int AddressRangePool::from_xml_node(const xmlNodePtr node)
{ {
int rc = ar_template.from_xml_node(node); int rc = ar_template.from_xml_node(node);

View File

@ -608,6 +608,18 @@ int VirtualNetwork::add_ar(VirtualNetworkTemplate * ars_tmpl, string& error_msg)
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */ /* -------------------------------------------------------------------------- */
void VirtualNetwork::update_ar(VirtualNetworkTemplate * ars_tmpl)
{
vector<Attribute *> tmp_ars;
ars_tmpl->get("AR", tmp_ars);
ar_pool.update_ar(tmp_ars);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualNetwork::rm_ar(unsigned int ar_id, string& error_msg) int VirtualNetwork::rm_ar(unsigned int ar_id, string& error_msg)
{ {
return ar_pool.rm_ar(ar_id, error_msg); return ar_pool.rm_ar(ar_id, error_msg);