mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
Adds a new attribute (from the POLL string) to the VM template. It replaces the
attribute if it already exists. git-svn-id: http://svn.opennebula.org/trunk@65 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
537a7058d5
commit
a08d1c2d06
@ -85,6 +85,14 @@ protected:
|
||||
* @param db pointer to the database.
|
||||
*/
|
||||
int drop(SqliteDB *db);
|
||||
|
||||
/**
|
||||
* Removes a template attribute from the DB (ONLY SINGLE ATTRIBUTES)
|
||||
* @param db pointer to the database.
|
||||
* @param name of the attribute.
|
||||
* @param value of the new attribute.
|
||||
*/
|
||||
int replace_attribute(SqliteDB * db, string& name, string& value);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -750,6 +750,22 @@ private:
|
||||
return -1;
|
||||
};
|
||||
|
||||
/**
|
||||
* Updates the template of a VM, adding a new attribute (replacing it if
|
||||
* already defined), the vm's mutex SHOULD be locked
|
||||
* @param vm pointer to the virtual machine object
|
||||
* @param name of the new attribute
|
||||
* @param value of the new attribute
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_template_attribute(
|
||||
SqliteDB * db,
|
||||
string& name,
|
||||
string& value)
|
||||
{
|
||||
return vm_template.replace_attribute(db,name,value);
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
//**************************************************************************
|
||||
|
@ -86,6 +86,22 @@ public:
|
||||
// Virtual Machine DB access functions
|
||||
//--------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Updates the template of a VM, adding a new attribute (replacing it if
|
||||
* already defined), the vm's mutex SHOULD be locked
|
||||
* @param vm pointer to the virtual machine object
|
||||
* @param name of the new attribute
|
||||
* @param value of the new attribute
|
||||
* @return 0 on success
|
||||
*/
|
||||
int update_template_attribute(
|
||||
VirtualMachine * vm,
|
||||
string& name,
|
||||
string& value)
|
||||
{
|
||||
return vm->update_template_attribute(db,name,value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the history record of a VM, the vm's mutex SHOULD be locked
|
||||
* @param vm pointer to the virtual machine object
|
||||
|
@ -241,3 +241,64 @@ int TemplateSQL::drop(SqliteDB * db)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int TemplateSQL::replace_attribute(
|
||||
SqliteDB * db,
|
||||
string& name,
|
||||
string& value)
|
||||
{
|
||||
ostringstream oss;
|
||||
int rc;
|
||||
|
||||
multimap<string, Attribute *>::const_iterator i;
|
||||
Attribute * attribute;
|
||||
|
||||
if ( id == -1 || name.empty() || name.empty() )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
i = attributes.find(name);
|
||||
|
||||
if ( i != attributes.end() ) //attribute exists
|
||||
{
|
||||
string * attr = i->second->marshall();
|
||||
|
||||
if ( attr != 0 )
|
||||
{
|
||||
oss << "DELETE FROM " << table << " WHERE id=" << id
|
||||
<< " AND name='" << name << "' AND value='" << *attr << "'";
|
||||
|
||||
delete attr;
|
||||
}
|
||||
else
|
||||
{
|
||||
oss << "DELETE FROM " << table << " WHERE id=" << id
|
||||
<< " AND name='" << name << "'";
|
||||
}
|
||||
|
||||
rc = db->exec(oss);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
return rc;
|
||||
}
|
||||
|
||||
attributes.erase(name);
|
||||
}
|
||||
|
||||
attribute = new SingleAttribute(name,value);
|
||||
|
||||
attributes.insert(make_pair(attribute->name(),attribute));
|
||||
|
||||
oss.str("");
|
||||
|
||||
oss << "INSERT INTO " << table << " " << db_names
|
||||
<< " VALUES (" << id << ",'" << name << "'," <<
|
||||
Attribute::SIMPLE <<",'" << value << "')";
|
||||
|
||||
return db->exec(oss);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -467,10 +467,17 @@ void VirtualMachineManagerDriver::protocol(
|
||||
}
|
||||
else
|
||||
{
|
||||
string val;
|
||||
|
||||
os.str("");
|
||||
os << "Unknown monitoring attribute (ignored): " << tmp;
|
||||
os << "Unknown monitoring attribute (adding/updating"
|
||||
<< " template): " << tmp;
|
||||
|
||||
vm->log("VMM",Log::WARNING,os);
|
||||
|
||||
tiss >> val;
|
||||
|
||||
vmpool->update_template_attribute(vm,var,val);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user