mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
F #2347: Add/del methods for VMGroup
This commit is contained in:
parent
8b3abfab09
commit
1b4c543712
@ -96,6 +96,30 @@ private:
|
||||
*/
|
||||
int check_affinity(const std::string& aname, std::string& error_str);
|
||||
|
||||
/**
|
||||
* Adds a VM to a role
|
||||
* @param role_name
|
||||
* @param vmid
|
||||
*
|
||||
* @return 0 if VM was successfully added, -1 otherwise
|
||||
*/
|
||||
int add_vm(const std::string& role_name, int vmid)
|
||||
{
|
||||
return roles.add_vm(role_name, vmid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes a VM from a role
|
||||
* @param role_name
|
||||
* @param vmid
|
||||
*
|
||||
* @return 0 if VM was successfully added, -1 otherwise
|
||||
*/
|
||||
int del_vm(const std::string& role_name, int vmid)
|
||||
{
|
||||
return roles.del_vm(role_name, vmid);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// DataBase implementation
|
||||
// -------------------------------------------------------------------------
|
||||
|
@ -118,6 +118,24 @@ public:
|
||||
return by_name.in_map(key_str);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a VM to a role
|
||||
* @param role_name
|
||||
* @param vmid
|
||||
*
|
||||
* @return 0 if VM was successfully added, -1 otherwise
|
||||
*/
|
||||
int add_vm(const std::string& role_name, int vmid);
|
||||
|
||||
/**
|
||||
* Deletes a VM from a role
|
||||
* @param role_name
|
||||
* @param vmid
|
||||
*
|
||||
* @return 0 if VM was successfully added, -1 otherwise
|
||||
*/
|
||||
int del_vm(const std::string& role_name, int vmid);
|
||||
|
||||
private:
|
||||
/**
|
||||
* A role map indexed by different key types
|
||||
@ -155,6 +173,20 @@ private:
|
||||
clear();
|
||||
}
|
||||
|
||||
VMGroupRole * get(T k)
|
||||
{
|
||||
typename std::map<T, VMGroupRole *>::iterator it;
|
||||
|
||||
it = roles.find(k);
|
||||
|
||||
if ( it == roles.end() )
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
return it->second;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clears the contents of the map
|
||||
*/
|
||||
|
@ -164,6 +164,44 @@ int VMGroupRoles::add_role(VectorAttribute * vrole, string& error)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VMGroupRoles::add_vm(const std::string& role_name, int vmid)
|
||||
{
|
||||
VMGroupRole * role;
|
||||
|
||||
role = by_name.get(role_name);
|
||||
|
||||
if ( role == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
role->add_vm(vmid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int VMGroupRoles::del_vm(const std::string& role_name, int vmid)
|
||||
{
|
||||
VMGroupRole * role;
|
||||
|
||||
role = by_name.get(role_name);
|
||||
|
||||
if ( role == 0 )
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
role->del_vm(vmid);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* VMGroup */
|
||||
@ -471,3 +509,4 @@ int VMGroup::post_update_template(string& error)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user