1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-23 17:33:56 +03:00

Feature #1739: Add messages when extra VMs are detected

This commit is contained in:
Carlos Martín 2013-02-13 18:06:20 +01:00
parent ce565ac542
commit e37c4d1665
3 changed files with 82 additions and 23 deletions

View File

@ -397,12 +397,20 @@ public:
}
/**
* Sets an error message for the VM in the template
* @param message
* Sets an error message with timestamp in the template
* @param message Message string
* @return 0 on success
*/
void set_template_error_message(const string& message);
/**
* Sets a message with timestamp in the template
* @param att_name Name for the attribute
* @param message Message string
* @return 0 on success
*/
void set_template_message(const string& att_name, const string& message);
/**
* Factory method for templates, it should be implemented
* by classes that uses templates

View File

@ -138,7 +138,7 @@ void InformationManagerDriver::protocol(
goto error_common_info;
}
// TODO The hinfo string is parsed again because HostTemplate has
// The hinfo string is parsed again because HostTemplate has
// replace_mode set to true, but we expect several VM vector attributes
Template* tmpl = new Template();
tmpl->parse(*hinfo, &error_msg);
@ -159,6 +159,9 @@ void InformationManagerDriver::protocol(
host->unlock();
vector<string> external_vms;
map<int,string> rogue_vms;
for (it=vm_att.begin(); it != vm_att.end(); it++)
{
vatt = dynamic_cast<VectorAttribute*>(*it);
@ -171,7 +174,7 @@ void InformationManagerDriver::protocol(
rc = vatt->vector_value("ID", vmid);
if (rc == 0)
if (rc == 0 && vmid != -1)
{
if (vm_ids.erase(vmid) == 1)
{
@ -181,12 +184,12 @@ void InformationManagerDriver::protocol(
}
else
{
// TODO: This VM shoulnd't be running on this host
rogue_vms[vmid] = vatt->vector_value("DEPLOY_ID");
}
}
else
else if (rc == 0)
{
// TODO: unknown VM found running on this host
external_vms.push_back( vatt->vector_value("DEPLOY_ID") );
}
delete *it;
@ -201,6 +204,57 @@ void InformationManagerDriver::protocol(
VirtualMachineManagerDriver::process_failed_poll(*it);
}
}
if (!rogue_vms.empty())
{
map<int,string>::iterator it;
oss.str("");
oss << "Manual intervention required, these VMs should"
<< " not be running on Host " << id << ":";
for(it = rogue_vms.begin(); it != rogue_vms.end(); it++)
{
oss << " VM " << it->first << " (hypervisor name '" << it->second << "')";
}
host = hpool->get(id,true);
if ( host != 0 )
{
host->set_template_error_message(oss.str());
hpool->update(host);
host->unlock();
}
NebulaLog::log("InM",Log::ERROR,oss);
}
if (!external_vms.empty())
{
vector<string>::iterator it;
oss.str("");
oss << "External VMs found:";
for(it = external_vms.begin(); it != external_vms.end(); it++)
{
oss << " " << *it;
}
host = hpool->get(id,true);
if ( host != 0 )
{
host->set_template_message("INFO_MESSAGE", oss.str());
hpool->update(host);
host->unlock();
}
}
}
else if (action == "LOG")
{

View File

@ -137,30 +137,27 @@ int PoolObjectSQL::drop(SqlDB *db)
const char * PoolObjectSQL::error_attribute_name = "ERROR";
void PoolObjectSQL::set_template_error_message(const string& message)
{
set_template_message(error_attribute_name, message);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void PoolObjectSQL::set_template_message(
const string& att_name,
const string& message)
{
SingleAttribute * attr;
ostringstream error_value;
char str[26];
time_t the_time;
the_time = time(NULL);
#ifdef SOLARIS
ctime_r(&(the_time),str,sizeof(char)*26);
#else
ctime_r(&(the_time),str);
#endif
str[24] = '\0'; // Get rid of final enter character
error_value << str << " : " << message;
error_value << one_util::log_time() << " : " << message;
//Replace previous error message and insert the new one
attr = new SingleAttribute(error_attribute_name, error_value.str());
attr = new SingleAttribute(att_name, error_value.str());
obj_template->erase(error_attribute_name);
obj_template->erase(att_name);
obj_template->set(attr);
}