1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-28 14:50:08 +03:00

F #4809: Delete servers from zone

This commit is contained in:
Ruben S. Montero 2017-04-13 18:31:14 +02:00
parent c360b015b3
commit cd580714ab
10 changed files with 146 additions and 4 deletions

View File

@ -219,12 +219,21 @@ protected:
/* ---------------------------------------------------------------------- */
/**
* Adds a new VirtualMachine attribute to the set
* @param a the Extended attribute to add
* @param id of the new attribute
*/
void add_attribute(ExtendedAttribute * a, int id)
{
a_set.insert(make_pair(id, a));
}
/**
* Deletes an attribute from the set
* @param id of the attribute
* @return the attribute removed or 0 if not found
*/
ExtendedAttribute * delete_attribute(int id);
/**
* Init the attribute set from a vector
* @param id_name with the ID of the attribute

View File

@ -67,4 +67,20 @@ public:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ZoneDeleteServer : public RequestManagerZone
{
public:
ZoneDeleteServer():
RequestManagerZone("ZoneDeleteServer", "Delete a server from zone",
"A:sii"){};
~ZoneDeleteServer(){};
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
};
#endif

View File

@ -53,7 +53,16 @@ public:
*
* @return 0 on success, -1 otherwise
*/
int add_servers(Template& tmpl, string& error);
int add_server(Template& tmpl, string& error);
/**
* Delete a server from this zone
* @param it of the SERVER
* @param error if any
*
* @return 0 on success, -1 otherwise
*/
int delete_server(int id, string& error);
private:
// -------------------------------------------------------------------------

View File

@ -168,6 +168,12 @@ public:
return 0;
};
ZoneServer * delete_server(int id)
{
return static_cast<ZoneServer *>(delete_attribute(id));
};
protected:
ExtendedAttribute * attribute_factory(VectorAttribute * va, int id) const
{

View File

@ -118,6 +118,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
delserver_desc = <<-EOT.unindent
Delete an OpenNebula server from this zone.
EOT
command :"server-del", delserver_desc, :zoneid, :serverid do
helper.perform_action(args[0], options, "server deleted") do |o|
o.delete_servers(args[1].to_i)
end
end
update_desc = <<-EOT.unindent
Update the template contents. If a path is not provided the editor will
be launched to modify the current content.

View File

@ -75,3 +75,20 @@ void ExtendedAttributeSet::init_attribute_map(const std::string& id_name,
}
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
ExtendedAttribute * ExtendedAttributeSet::delete_attribute(int id)
{
std::map<int, ExtendedAttribute*>::iterator it = a_set.find(id);
if ( it == a_set.end() )
{
return 0;
}
a_set.erase(it);
return it->second;
}

View File

@ -29,7 +29,8 @@ module OpenNebula
:update => "zone.update",
:rename => "zone.rename",
:delete => "zone.delete",
:addserver => "zone.addserver"
:addserver => "zone.addserver",
:delserver => "zone.delserver"
}
# Creates a Zone description with just its identifier
@ -115,5 +116,15 @@ module OpenNebula
def add_servers(servers)
return call(ZONE_METHODS[:addserver], @pe_id, servers)
end
# Delete servers from this Zone
#
# @param id [Int] Server ID
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def delete_servers(server_id)
return call(ZONE_METHODS[:delserver], @pe_id, server_id)
end
end
end

View File

@ -760,6 +760,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::method * zone_delete_pt;
xmlrpc_c::method * zone_rename_pt;
xmlrpc_c::method * zone_addserver_pt;
xmlrpc_c::method * zone_delserver_pt;
if (nebula.is_federation_slave())
{
@ -768,6 +769,7 @@ void RequestManager::register_xml_methods()
zone_delete_pt = new RequestManagerProxy("one.zone.delete");
zone_rename_pt = new RequestManagerProxy("one.zone.rename");
zone_addserver_pt = new RequestManagerProxy("one.zone.addserver");
zone_delserver_pt = new RequestManagerProxy("one.zone.delserver");
}
else
{
@ -776,6 +778,7 @@ void RequestManager::register_xml_methods()
zone_delete_pt = new ZoneDelete();
zone_rename_pt = new ZoneRename();
zone_addserver_pt = new ZoneAddServer();
zone_delserver_pt = new ZoneDeleteServer();
}
xmlrpc_c::methodPtr zone_allocate(zone_allocate_pt);
@ -783,6 +786,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr zone_delete(zone_delete_pt);
xmlrpc_c::methodPtr zone_rename(zone_rename_pt);
xmlrpc_c::methodPtr zone_addserver(zone_addserver_pt);
xmlrpc_c::methodPtr zone_delserver(zone_delserver_pt);
xmlrpc_c::methodPtr zone_info(new ZoneInfo());
xmlrpc_c::methodPtr zonepool_info(new ZonePoolInfo());
@ -794,6 +798,7 @@ void RequestManager::register_xml_methods()
RequestManagerRegistry.addMethod("one.zone.rename", zone_rename);
RequestManagerRegistry.addMethod("one.zone.addserver", zone_addserver);
RequestManagerRegistry.addMethod("one.zone.delserver", zone_delserver);
RequestManagerRegistry.addMethod("one.zonepool.info",zonepool_info);

View File

@ -55,7 +55,7 @@ void ZoneAddServer::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
if ( zone->add_servers(zs_tmpl, att.resp_msg) == -1 )
if ( zone->add_server(zs_tmpl, att.resp_msg) == -1 )
{
failure_response(ACTION, att);
@ -72,3 +72,44 @@ void ZoneAddServer::request_execute(xmlrpc_c::paramList const& paramList,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void ZoneDeleteServer::request_execute(xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
{
int id = xmlrpc_c::value_int(paramList.getInt(1));
int zs_id = xmlrpc_c::value_int(paramList.getInt(2));
string error_str;
if ( basic_authorization(id, att) == false )
{
return;
}
Zone * zone = (static_cast<ZonePool *>(pool))->get(id, true);
if ( zone == 0 )
{
att.resp_id = id;
failure_response(NO_EXISTS, att);
return;
}
if ( zone->delete_server(zs_id, att.resp_msg) == -1 )
{
failure_response(ACTION, att);
zone->unlock();
return;
}
pool->update(zone);
zone->unlock();
success_response(id, att);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -300,7 +300,7 @@ int Zone::post_update_template(string& error)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int Zone::add_servers(Template& tmpl, string& error)
int Zone::add_server(Template& tmpl, string& error)
{
vector<VectorAttribute *> vs;
vector<VectorAttribute *>::iterator it;
@ -326,3 +326,21 @@ int Zone::add_servers(Template& tmpl, string& error)
return 0;
}
int Zone::delete_server(int id, string& error)
{
ZoneServer * zs;
zs = servers->delete_server(id);
if ( zs == 0 )
{
error = "SERVER not found in zone";
return -1;
}
delete servers_template.remove(zs->vector_attribute());
delete zs;
return 0;
}