1
0
mirror of https://github.com/OpenNebula/one.git synced 2024-12-22 13:33:52 +03:00

Feature #2613: Extend zonepool with endpoint + update

Done for CLI and Sunstone
This commit is contained in:
Tino Vazquez 2014-01-13 18:26:21 +01:00
parent 8e4467e0e5
commit 461bda9f82
9 changed files with 102 additions and 6 deletions

View File

@ -221,6 +221,24 @@ public:
~ClusterUpdateTemplate(){};
};
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
class ZoneUpdateTemplate : public RequestManagerUpdateTemplate
{
public:
ZoneUpdateTemplate():
RequestManagerUpdateTemplate("ZoneUpdateTemplate",
"Updates a zone template")
{
Nebula& nd = Nebula::instance();
pool = nd.get_zonepool();
auth_object = PoolObjectSQL::ZONE;
};
~ZoneUpdateTemplate(){};
};
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -18,6 +18,7 @@
#define ZONE_H_
#include "PoolObjectSQL.h"
#include "NebulaLog.h"
using namespace std;
@ -59,6 +60,16 @@ private:
~Zone();
// -------------------------------------------------------------------------
// Zone Description
// -------------------------------------------------------------------------
/**
* Endpoint of the zone
*/
string endpoint;
// *************************************************************************
// DataBase implementation (Private)
// *************************************************************************
@ -106,6 +117,14 @@ private:
string error_str;
return insert_replace(db, true, error_str);
}
/**
* Factory method for Zone templates
*/
Template * get_new_template() const
{
return new Template;
}
};
#endif /*ZONE_H_*/

View File

@ -38,7 +38,11 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper
d["NAME"]
end
default :ID, :NAME
column :ENDPOINT, "Endpoint of the Zone", :left, :size=>50 do |d|
d["TEMPLATE"]['ENDPOINT']
end
default :ID, :NAME, :ENDPOINT
end
table

View File

@ -81,6 +81,24 @@ cmd=CommandParser::CmdParser.new(ARGV) do
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.
EOT
command :update, update_desc, :zoneid, [:file, nil],
:options=>OpenNebulaHelper::APPEND do
helper.perform_action(args[0],options,"modified") do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
end
obj.update(str, options[:append])
end
end
delete_desc = <<-EOT.unindent
Deletes the given Zone
EOT

View File

@ -26,6 +26,7 @@ module OpenNebula
ZONE_METHODS = {
:info => "zone.info",
:allocate => "zone.allocate",
:update => "zone.update",
:delete => "zone.delete"
}
@ -73,6 +74,18 @@ module OpenNebula
super(ZONE_METHODS[:allocate], description)
end
# Replaces the template contents
#
# @param new_template [String] New template contents
# @param append [true, false] True to append new attributes instead of
# replace the whole template
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def update(new_template=nil, append=false)
super(ZONE_METHODS[:update], new_template, append ? 1 : 0)
end
# Deletes the Zone
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise

View File

@ -300,6 +300,7 @@ void RequestManager::register_xml_methods()
xmlrpc_c::methodPtr datastore_update(new DatastoreUpdateTemplate());
xmlrpc_c::methodPtr doc_update(new DocumentUpdateTemplate());
xmlrpc_c::methodPtr cluster_update(new ClusterUpdateTemplate());
xmlrpc_c::methodPtr zone_update(new ZoneUpdateTemplate());
// Allocate Methods
xmlrpc_c::methodPtr vm_allocate(new VirtualMachineAllocate());
@ -574,6 +575,7 @@ void RequestManager::register_xml_methods()
/* Zone related methods */
RequestManagerRegistry.addMethod("one.zone.allocate",zone_allocate);
RequestManagerRegistry.addMethod("one.zone.update", zone_update);
RequestManagerRegistry.addMethod("one.zone.delete", zone_delete);
RequestManagerRegistry.addMethod("one.zone.info", zone_info);

View File

@ -35,11 +35,17 @@ module OpenNebulaJSON
return action_hash
end
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
rc = case action_hash['perform']
when "update" then self.update(action_hash['params'])
else
error_msg = "#{action_hash['perform']} action not " <<
" available for this resource"
OpenNebula::Error.new(error_msg)
end
end
rc = OpenNebula::Error.new(error_msg)
def update(params=Hash.new)
super(params['template_raw'])
end
end
end

View File

@ -182,7 +182,8 @@ var zone_actions = {
call: OpenNebula.Zone.update,
callback: function(request,response){
notifyMessage(tr("Zone updated correctly"));
Sunstone.runAction('Zone.show',response.ZONE.ID);
Sunstone.runAction('Zone.show',request.request.data[0][0]);
Sunstone.runAction('Zone.showinfo',request.request.data[0][0]);
},
error: onError
},

View File

@ -73,6 +73,13 @@ int Zone::insert(SqlDB *db, string& error_str)
name = oss.str();
}
get_template_attribute("ENDPOINT", endpoint);
if ( endpoint.empty() )
{
goto error_endpoint;
}
// ------------------------------------------------------------------------
// Insert the Zone
// ------------------------------------------------------------------------
@ -80,6 +87,14 @@ int Zone::insert(SqlDB *db, string& error_str)
rc = insert_replace(db, false, error_str);
return rc;
error_endpoint:
error_str = "ENDPOINT not present in template.";
goto error_common;
error_common:
NebulaLog::log("ZONE", Log::ERROR, error_str);
return -1;
}
/* -------------------------------------------------------------------------- */