1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-04-01 06:50:25 +03:00

Feature #1796: Add ceph host and secret to kvm deployment files

This commit is contained in:
Carlos Martín 2013-11-15 12:58:53 +01:00
parent b559b3250a
commit 1a2b923825
4 changed files with 94 additions and 9 deletions

View File

@ -18,6 +18,7 @@
#define _NEBULA_UTIL_H_
#include <string>
#include <vector>
namespace one_util
{
@ -66,6 +67,23 @@ namespace one_util
* @return a new random password
*/
std::string random_password();
/**
* Splits a string, using the given delimiter
*
* @param st string to split
* @param delim delimiter character
* @param clean_empty true to clean empty split parts.
* Example for st "a::b:c"
* clean_empty true will return ["a", "b", "c"]
* clean_empty fase will return ["a", "", "b", "c"]
*
* @return a vector containing the resulting substrings
*/
std::vector<std::string> split(
const std::string& st,
char delim,
bool clean_empty=true);
};
#endif /* _NEBULA_UTIL_H_ */

View File

@ -700,3 +700,6 @@ IMAGE_RESTRICTED_ATTR = "SOURCE"
#INHERIT_IMAGE_ATTR = "SECOND_EXAMPLE"
#INHERIT_DATASTORE_ATTR = "COLOR"
#INHERIT_VNET_ATTR = "BANDWIDTH_THROTTLING"
INHERIT_DATASTORE_ATTR = "CEPH_HOST"
INHERIT_DATASTORE_ATTR = "CEPH_SECRET"

View File

@ -217,3 +217,24 @@ string one_util::random_password()
return sha1_digest(sstr.str());
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
vector<string> one_util::split(const string& st, char delim, bool clean_empty)
{
vector<string> parts;
string part;
stringstream ss(st);
while (getline(ss, part, delim))
{
if (!(clean_empty && part.empty()))
{
parts.push_back(part);
}
}
return parts;
}

View File

@ -59,6 +59,8 @@ int LibVirtDriver::deployment_description_kvm(
string disk_io = "";
string source = "";
string clone = "";
string ceph_host = "";
string ceph_secret= "";
int disk_id;
string default_driver = "";
@ -311,14 +313,16 @@ int LibVirtDriver::deployment_description_kvm(
continue;
}
type = disk->vector_value("TYPE");
target = disk->vector_value("TARGET");
ro = disk->vector_value("READONLY");
driver = disk->vector_value("DRIVER");
cache = disk->vector_value("CACHE");
disk_io= disk->vector_value("IO");
source = disk->vector_value("SOURCE");
clone = disk->vector_value("CLONE");
type = disk->vector_value("TYPE");
target = disk->vector_value("TARGET");
ro = disk->vector_value("READONLY");
driver = disk->vector_value("DRIVER");
cache = disk->vector_value("CACHE");
disk_io = disk->vector_value("IO");
source = disk->vector_value("SOURCE");
clone = disk->vector_value("CLONE");
ceph_host = disk->vector_value("CEPH_HOST");
ceph_secret = disk->vector_value("CEPH_SECRET");
disk->vector_value_str("DISK_ID", disk_id);
@ -360,7 +364,46 @@ int LibVirtDriver::deployment_description_kvm(
file << "-" << vm->get_oid() << "-" << disk_id;
}
file << "'/>" << endl;
if ( ceph_host.empty() )
{
file << "'/>" << endl;
}
else
{
vector<string>::const_iterator it;
vector<string> hosts = one_util::split(ceph_host, ' ');
file << "'>" << endl;
for (it = hosts.begin(); it != hosts.end(); it++)
{
vector<string> parts = one_util::split(*it, ':');
if (parts.empty())
{
continue;
}
file << "\t\t\t\t<host name='" << parts[0];
if (parts.size() > 1)
{
file << "' port='" << parts[1];
}
file << "'/>" << endl;
}
file << "\t\t\t</source>" << endl;
}
if ( !ceph_secret.empty() )
{
file << "\t\t\t<auth username='libvirt'>" << endl
<< "\t\t\t\t<secret type='ceph' uuid='"
<< ceph_secret <<"'/>" << endl
<< "\t\t\t</auth>" << endl;
}
}
else if ( type == "RBD_CDROM" )
{