mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-23 17:33:56 +03:00
Feature #4215: Add support for %i name replacement in vrouter.instantiate
This commit is contained in:
parent
c41d43f09a
commit
383babc8f7
@ -174,6 +174,29 @@ namespace one_util
|
|||||||
* @return trimed string
|
* @return trimed string
|
||||||
*/
|
*/
|
||||||
std::string trim(const std::string& str);
|
std::string trim(const std::string& str);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a copy of st with the all occurrences of "find" substituted
|
||||||
|
* for "replacement"
|
||||||
|
* @param st string input
|
||||||
|
* @param find string to search for
|
||||||
|
* @param replacement string to replace occurrences with
|
||||||
|
* @return a string copy
|
||||||
|
*/
|
||||||
|
std::string gsub(const std::string& st,
|
||||||
|
const char *find, const char *replacement);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a copy of st with the all occurrences of "find" substituted
|
||||||
|
* for "replacement"
|
||||||
|
* @param st string input
|
||||||
|
* @param find string to search for
|
||||||
|
* @param replacement string to replace occurrences with
|
||||||
|
* @return a string copy
|
||||||
|
*/
|
||||||
|
std::string gsub(const std::string& st,
|
||||||
|
const char *find, const std::string& replacement);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* _NEBULA_UTIL_H_ */
|
#endif /* _NEBULA_UTIL_H_ */
|
||||||
|
@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <cstring>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
@ -306,3 +307,36 @@ std::string one_util::trim(const std::string& str)
|
|||||||
|
|
||||||
return tstr;
|
return tstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
string one_util::gsub(const string& st,
|
||||||
|
const char *find, const string& replacement)
|
||||||
|
{
|
||||||
|
return gsub(st, find, replacement.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
/* -------------------------------------------------------------------------- */
|
||||||
|
|
||||||
|
string one_util::gsub(const string& st,
|
||||||
|
const char *find, const char *replacement)
|
||||||
|
{
|
||||||
|
string result = st;
|
||||||
|
|
||||||
|
string::size_type pos = 0;
|
||||||
|
size_t find_len = strlen(find);
|
||||||
|
size_t replacement_len = strlen(replacement);
|
||||||
|
|
||||||
|
pos = result.find(find, pos);
|
||||||
|
|
||||||
|
while(pos != std::string::npos)
|
||||||
|
{
|
||||||
|
result.replace(pos, find_len, replacement);
|
||||||
|
pos += replacement_len;
|
||||||
|
|
||||||
|
pos = result.find(find, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
@ -68,6 +68,8 @@ void VirtualRouterInstantiate::request_execute(
|
|||||||
Template* extra_attrs;
|
Template* extra_attrs;
|
||||||
bool has_vmids;
|
bool has_vmids;
|
||||||
string errorstr;
|
string errorstr;
|
||||||
|
string vr_name;
|
||||||
|
ostringstream oss;
|
||||||
|
|
||||||
vector<int> vms;
|
vector<int> vms;
|
||||||
vector<int>::iterator vmid;
|
vector<int>::iterator vmid;
|
||||||
@ -93,6 +95,8 @@ void VirtualRouterInstantiate::request_execute(
|
|||||||
|
|
||||||
has_vmids = vr->has_vmids();
|
has_vmids = vr->has_vmids();
|
||||||
|
|
||||||
|
vr_name = vr->get_name();
|
||||||
|
|
||||||
vr->unlock();
|
vr->unlock();
|
||||||
|
|
||||||
if ( att.uid != 0 )
|
if ( att.uid != 0 )
|
||||||
@ -120,9 +124,21 @@ void VirtualRouterInstantiate::request_execute(
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (name.empty())
|
||||||
|
{
|
||||||
|
oss.str("");
|
||||||
|
oss << "vr-" << vr_name << "-%i";
|
||||||
|
name = oss.str();
|
||||||
|
}
|
||||||
|
|
||||||
for (int i=0; i<n_vms; i++)
|
for (int i=0; i<n_vms; i++)
|
||||||
{
|
{
|
||||||
int vid = instantiate(att, tmpl_id, name, true, str_uattrs, extra_attrs);
|
oss.str("");
|
||||||
|
oss << i;
|
||||||
|
|
||||||
|
string tmp_name = one_util::gsub(name, "%i", oss.str());
|
||||||
|
|
||||||
|
int vid = instantiate(att, tmpl_id, tmp_name, true, str_uattrs, extra_attrs);
|
||||||
|
|
||||||
if (vid == -1)
|
if (vid == -1)
|
||||||
{
|
{
|
||||||
|
@ -165,8 +165,6 @@ define(function(require) {
|
|||||||
timeout: true,
|
timeout: true,
|
||||||
success: function (request, response) {
|
success: function (request, response) {
|
||||||
|
|
||||||
//TODO: add support for vm_name.replace(/%i/gi, i), or remove tooltip
|
|
||||||
|
|
||||||
var tmpl = WizardFields.retrieve($(".template_user_inputs", context));
|
var tmpl = WizardFields.retrieve($(".template_user_inputs", context));
|
||||||
|
|
||||||
var extra_info = {
|
var extra_info = {
|
||||||
|
Loading…
Reference in New Issue
Block a user