1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-29 18:50:08 +03:00

feature #4446: Reservations are handled always by OpenNebula's internal

IPAM. Add consistency check to IPAM results. Log error messages from
IPAM drivers. Remove unused internal AR attribute (ipam_mad)

Signed-off-by: Ruben S. Montero <rsmontero@opennebula.org>
This commit is contained in:
Guillaume Oberlé 2016-08-26 14:31:30 +02:00 committed by Ruben S. Montero
parent 1eb2628dc4
commit f8874bb320
3 changed files with 34 additions and 5 deletions

View File

@ -660,11 +660,6 @@ private:
*/
set<int> security_groups;
/**
* The name of the IPAM driver (internal for OpenNebula built-in)
*/
string ipam_mad;
/**
* The Address Range attributes as a Template VectorAttribute. This is
* used to generate XML or a template representation of the AR.

View File

@ -17,6 +17,7 @@
#include "AddressRange.h"
#include "Attribute.h"
#include "VirtualNetworkPool.h"
#include "NebulaLog.h"
#include "NebulaUtil.h"
#include <arpa/inet.h>
@ -225,6 +226,15 @@ int AddressRange::update_attributes(
vup->replace("MAC", attr->vector_value("MAC"));
string ipam_mad = attr->vector_value("IPAM_MAD");
if ( !ipam_mad.empty() )
{
vup->replace("IPAM_MAD", ipam_mad);
}
vup->replace("MAC", attr->vector_value("MAC"));
vup->remove("IP");
if (type & 0x00000002)
@ -1151,6 +1161,7 @@ int AddressRange::allocate_addr(
if ( get_addr(index, 1, error_msg) != 0 )
{
NebulaLog::log("IPM", Log::ERROR, error_msg);
return -1;
}
@ -1179,6 +1190,7 @@ int AddressRange::allocate_by_mac(
if (allocate_addr(index, 1, error_msg) != 0)
{
NebulaLog::log("IPM", Log::ERROR, error_msg);
return -1;
}
@ -1207,6 +1219,7 @@ int AddressRange::allocate_by_ip(
if (allocate_addr(index, 1, error_msg) != 0)
{
NebulaLog::log("IPM", Log::ERROR, error_msg);
return -1;
}
@ -1235,6 +1248,7 @@ int AddressRange::free_addr(PoolObjectSQL::ObjectType ot, int obid,
if (free_addr(index, error_msg) != 0)
{
NebulaLog::log("IPM", Log::ERROR, error_msg);
return -1;
}
@ -1400,6 +1414,7 @@ int AddressRange::hold_by_ip(const string& ip_s)
if (allocate_addr(index, 1, error_msg) != 0)
{
NebulaLog::log("IPM", Log::ERROR, error_msg);
return -1;
}
@ -1423,6 +1438,7 @@ int AddressRange::hold_by_mac(const string& mac_s)
if (allocate_addr(index, 1, error_msg) != 0)
{
NebulaLog::log("IPM", Log::ERROR, error_msg);
return -1;
}
@ -1446,6 +1462,7 @@ int AddressRange::reserve_addr(int vid, unsigned int rsize, AddressRange *rar)
if ( get_addr(first_index, rsize, error_msg) != 0 )
{
NebulaLog::log("IPM", Log::ERROR, error_msg);
return -1;
}
@ -1466,6 +1483,8 @@ int AddressRange::reserve_addr(int vid, unsigned int rsize, AddressRange *rar)
new_ar->replace("SIZE",rsize);
new_ar->remove("IPAM_MAD");
rar->from_vattr(new_ar, errmsg);
new_ar->replace("PARENT_NETWORK_AR_ID",id);
@ -1493,6 +1512,7 @@ int AddressRange::reserve_addr_by_index(int vid, unsigned int rsize,
if (allocate_addr(sindex, rsize, error_msg) != 0)
{
NebulaLog::log("IPM", Log::ERROR, error_msg);
return -1;
}
@ -1515,6 +1535,8 @@ int AddressRange::reserve_addr_by_index(int vid, unsigned int rsize,
new_ar->replace("SIZE",rsize);
new_ar->remove("IPAM_MAD");
rar->from_vattr(new_ar, errmsg);
new_ar->replace("PARENT_NETWORK_AR_ID",id);

View File

@ -132,9 +132,21 @@ int AddressRangeIPAM::get_addr(unsigned int& index, unsigned int rsize,
if ( !is_valid_ip(index, ip, false) )
{
error_msg = "Address returned by IPAM is not valid: " + ip;
return -1;
}
unsigned int ar_size = get_size();
for (unsigned int j=0, i=index; j<rsize; j++, i++)
{
if ( allocated.count(i) != 0 || i >= ar_size )
{
error_msg = "Address returned by IPAM are not within AR or in use";
return -1;
}
}
return 0;
}