1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-16 22:50:10 +03:00

Merge branch 'feature-4658'

This commit is contained in:
Jaime Melis 2016-08-30 12:34:46 +02:00
commit 2f70d56268

View File

@ -46,7 +46,7 @@ public:
if (!reserved.empty())
{
one_util::split_unique(reserved, ',', reserved_bit);
set_reserved_bit(reserved);
}
};
@ -326,6 +326,66 @@ private:
return rc;
}
/**
* The reserved bit string is separated by ',' for each element
* and by ':' for ranges.
* @param string with reserved bits
*/
void set_reserved_bit(std::string& reserved)
{
std::vector<std::string> strings;
std::vector<std::string> range;
std::vector<std::string>::const_iterator it;
std::istringstream iss;
unsigned int bit, bit_start, bit_end;
strings = one_util::split(reserved, ',', true);
for (it = strings.begin(); it != strings.end(); it++)
{
// Try to split it by ':'
range = one_util::split(*it, ':', true);
iss.clear();
iss.str(range[0]);
iss >> bit_start;
if ( iss.fail() )
{
continue;
}
if (range.size() == 1)
{
bit_end = bit_start;
}
else if (range.size() == 2)
{
iss.clear();
iss.str(range[1]);
iss >> bit_end;
if ( iss.fail() )
{
continue;
}
}
else
{
continue;
}
for (bit = bit_start; bit <= bit_end; bit++)
{
reserved_bit.insert(bit);
}
}
}
};
#endif /*BITMAP_H_*/