mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-08 21:17:43 +03:00
Feature #2858: Return error for wrong AR update actions. Do not allow to update a reservation SIZE
This commit is contained in:
parent
711419e82a
commit
faa407e0ec
@ -307,8 +307,11 @@ public:
|
||||
* CANNOT be updated: TYPE, SIZE, IP, MAC (plus the internal AR_ID and
|
||||
* ALLOCATED)
|
||||
* @param vup the new vector attributes for the address range
|
||||
* @param error_msg If the action fails, this message contains
|
||||
* the reason.
|
||||
* @return 0 on success
|
||||
*/
|
||||
void update_attributes(VectorAttribute *vup);
|
||||
int update_attributes(VectorAttribute *vup, string& error_msg);
|
||||
|
||||
/*
|
||||
* add_ar from AddressRangePool needs to access the internal representation
|
||||
|
@ -73,10 +73,13 @@ public:
|
||||
|
||||
/**
|
||||
* Updates the given address ranges
|
||||
* @param ars vector of address ranges as VectorAttributes obtined from
|
||||
* template in the form AR = [...]
|
||||
* @param ars vector of address ranges as VectorAttributes obtained from
|
||||
* template in the form AR = [...]. Only one AR is processed.
|
||||
* @param error_msg If the action fails, this message contains
|
||||
* the reason.
|
||||
* @return 0 on success
|
||||
*/
|
||||
void update_ar(vector<Attribute *> ars);
|
||||
int update_ar(vector<Attribute *> ars, string& error_msg);
|
||||
|
||||
/**
|
||||
* Allocates a new *empty* address range. It is not added to the pool as it
|
||||
|
@ -152,11 +152,7 @@ public:
|
||||
RequestAttributes& att,
|
||||
string& error_str)
|
||||
{
|
||||
error_str.clear();
|
||||
|
||||
vn->update_ar(tmpl);
|
||||
|
||||
return 0;
|
||||
return vn->update_ar(tmpl, error_str);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -108,8 +108,11 @@ public:
|
||||
* 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.
|
||||
* @param error_msg If the action fails, this message contains
|
||||
* the reason.
|
||||
* @return 0 on success
|
||||
*/
|
||||
void update_ar(VirtualNetworkTemplate * ars_tmpl);
|
||||
int update_ar(VirtualNetworkTemplate * ars_tmpl, string& error_msg);
|
||||
|
||||
// *************************************************************************
|
||||
// Address hold/release interface
|
||||
|
@ -199,8 +199,13 @@ int AddressRange::from_vattr(VectorAttribute *vattr, string& error_msg)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRange::update_attributes(VectorAttribute *vup)
|
||||
int AddressRange::update_attributes(VectorAttribute *vup, string& error_msg)
|
||||
{
|
||||
/* --------------- Do not allow to modify a reservation ------- */
|
||||
|
||||
int pid;
|
||||
bool is_reservation = (get_attribute("PARENT_NETWORK_AR_ID", pid) == 0);
|
||||
|
||||
/* --------------- Copy non-update attributes ----------------- */
|
||||
|
||||
vup->replace("TYPE", attr->vector_value("TYPE"));
|
||||
@ -220,12 +225,19 @@ void AddressRange::update_attributes(VectorAttribute *vup)
|
||||
|
||||
vup->replace("ALLOCATED", attr->vector_value("ALLOCATED"));
|
||||
|
||||
vup->replace("PARENT_NETWORK_AR_ID", attr->vector_value("PARENT_NETWORK_AR_ID"));
|
||||
|
||||
vup->remove("USED_LEASES");
|
||||
|
||||
vup->remove("LEASES");
|
||||
|
||||
vup->remove("PARENT_NETWORK_AR_ID");
|
||||
|
||||
if (is_reservation)
|
||||
{
|
||||
vup->replace("PARENT_NETWORK_AR_ID",
|
||||
attr->vector_value("PARENT_NETWORK_AR_ID"));
|
||||
}
|
||||
|
||||
|
||||
/* ----------------- update known attributes ----------------- */
|
||||
|
||||
unsigned int new_size;
|
||||
@ -234,31 +246,53 @@ void AddressRange::update_attributes(VectorAttribute *vup)
|
||||
{
|
||||
map<unsigned int, long long> itup;
|
||||
|
||||
if (allocated.upper_bound(new_size-1) == allocated.end())
|
||||
if (is_reservation && new_size != size)
|
||||
{
|
||||
size = new_size;
|
||||
error_msg = "The SIZE of a reservation cannot be changed.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (allocated.upper_bound(new_size-1) != allocated.end())
|
||||
{
|
||||
error_msg = "New SIZE cannot be applied. There are used leases"
|
||||
" that would fall outside the range.";
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
new_size = size;
|
||||
}
|
||||
|
||||
string new_global = vup->vector_value("GLOBAL_PREFIX");
|
||||
|
||||
if (prefix6_to_i(new_global, global6) != 0 )
|
||||
{
|
||||
error_msg = "Wrong format for IP6 global address prefix";
|
||||
return -1;
|
||||
}
|
||||
|
||||
string new_ula = vup->vector_value("ULA_PREFIX");
|
||||
|
||||
if (prefix6_to_i(new_ula, ula6) != 0 )
|
||||
{
|
||||
error_msg = "Wrong format for IP6 unique local address prefix";
|
||||
return -1;
|
||||
}
|
||||
|
||||
size = new_size;
|
||||
|
||||
vup->replace("SIZE", size);
|
||||
|
||||
string value = vup->vector_value("GLOBAL_PREFIX");
|
||||
|
||||
if (prefix6_to_i(value, global6) != 0 )
|
||||
{
|
||||
vup->replace("GLOBAL_PREFIX", attr->vector_value("GLOBAL_PREFIX"));
|
||||
}
|
||||
|
||||
value = vup->vector_value("ULA_PREFIX");
|
||||
|
||||
if (prefix6_to_i(value, ula6) != 0 )
|
||||
{
|
||||
vup->replace("ULA_PREFIX", attr->vector_value("ULA_PREFIX"));
|
||||
}
|
||||
vup->replace("GLOBAL_PREFIX", new_global);
|
||||
vup->replace("ULA_PREFIX", new_ula);
|
||||
|
||||
/* Replace with the new attributes */
|
||||
|
||||
attr->replace(vup->value());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -81,7 +81,7 @@ int AddressRangePool::add_ar(AddressRange * ar)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void AddressRangePool::update_ar(vector<Attribute *> ars)
|
||||
int AddressRangePool::update_ar(vector<Attribute *> ars, string& error_msg)
|
||||
{
|
||||
vector<Attribute *>::iterator it;
|
||||
map<unsigned int, AddressRange *>::iterator ar_it;
|
||||
@ -99,18 +99,27 @@ void AddressRangePool::update_ar(vector<Attribute *> ars)
|
||||
|
||||
if (va->vector_value("AR_ID", arid) != 0)
|
||||
{
|
||||
continue;
|
||||
error_msg = "AR/AR_ID attribute is missing.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
ar_it = ar_pool.find(arid);
|
||||
|
||||
if (ar_it == ar_pool.end())
|
||||
{
|
||||
continue;
|
||||
ostringstream oss;
|
||||
|
||||
oss << "Address Range with ID " << arid << " was not found.";
|
||||
error_msg = oss.str();
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
ar_it->second->update_attributes(va);
|
||||
return ar_it->second->update_attributes(va, error_msg);
|
||||
}
|
||||
|
||||
error_msg = "Wrong AR definition. AR vector attribute is missing.";
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -656,13 +656,18 @@ int VirtualNetwork::add_ar(VirtualNetworkTemplate * ars_tmpl, string& error_msg)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void VirtualNetwork::update_ar(VirtualNetworkTemplate * ars_tmpl)
|
||||
int VirtualNetwork::update_ar(VirtualNetworkTemplate * ars_tmpl, string& error_msg)
|
||||
{
|
||||
vector<Attribute *> tmp_ars;
|
||||
|
||||
ars_tmpl->get("AR", tmp_ars);
|
||||
if(ars_tmpl->get("AR", tmp_ars) == 0)
|
||||
{
|
||||
error_msg = "Wrong AR definition. AR vector attribute is missing.";
|
||||
|
||||
ar_pool.update_ar(tmp_ars);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ar_pool.update_ar(tmp_ars, error_msg);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
Loading…
Reference in New Issue
Block a user