mirror of
https://github.com/OpenNebula/one.git
synced 2025-03-28 14:50:08 +03:00
F #4809: Add Server to Zone API call
This commit is contained in:
parent
d03ed15889
commit
ebc810f499
70
include/RequestManagerZone.h
Normal file
70
include/RequestManagerZone.h
Normal file
@ -0,0 +1,70 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#ifndef REQUEST_MANAGER_ZONE_H
|
||||
#define REQUEST_MANAGER_ZONE_H
|
||||
|
||||
#include "Request.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class RequestManagerZone: public Request
|
||||
{
|
||||
protected:
|
||||
RequestManagerZone(const string& method_name,
|
||||
const string& help,
|
||||
const string& params)
|
||||
:Request(method_name,params,help)
|
||||
{
|
||||
Nebula& nd = Nebula::instance();
|
||||
pool = nd.get_zonepool();
|
||||
|
||||
auth_object = PoolObjectSQL::ZONE;
|
||||
auth_op = AuthRequest::ADMIN;
|
||||
};
|
||||
|
||||
~RequestManagerZone(){};
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
|
||||
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att) = 0;
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------------------- */
|
||||
/* ------------------------------------------------------------------------- */
|
||||
|
||||
class ZoneAddServer : public RequestManagerZone
|
||||
{
|
||||
public:
|
||||
ZoneAddServer():
|
||||
RequestManagerZone("ZoneAddServer", "Add a server to zone", "A:sis"){};
|
||||
|
||||
~ZoneAddServer(){};
|
||||
|
||||
void request_execute(xmlrpc_c::paramList const& _paramList,
|
||||
RequestAttributes& att);
|
||||
};
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#endif
|
@ -46,6 +46,15 @@ public:
|
||||
*/
|
||||
int from_xml(const string &xml_str);
|
||||
|
||||
/**
|
||||
* Add servers to this zone
|
||||
* @param tmpl with SERVER definitions
|
||||
* @param error
|
||||
*
|
||||
* @return 0 on success, -1 otherwise
|
||||
*/
|
||||
int add_servers(Template& tmpl, string& error);
|
||||
|
||||
private:
|
||||
// -------------------------------------------------------------------------
|
||||
// Friends
|
||||
|
@ -34,6 +34,18 @@ public:
|
||||
|
||||
int init(string& error)
|
||||
{
|
||||
if ( vector_value("NAME").empty() )
|
||||
{
|
||||
error = "Missing NAME in SERVER";
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ( vector_value("ENDPOINT").empty() )
|
||||
{
|
||||
error = "Missing ENDPOINT in SERVER";
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -147,6 +159,8 @@ public:
|
||||
return -1;
|
||||
}
|
||||
|
||||
va->replace(SERVER_ID_NAME, next_id);
|
||||
|
||||
add_attribute(server, next_id);
|
||||
|
||||
next_id += 1;
|
||||
@ -154,15 +168,14 @@ public:
|
||||
return 0;
|
||||
};
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
ExtendedAttribute * attribute_factory(VectorAttribute * va, int id) const
|
||||
{
|
||||
return new ZoneServer(va, id);
|
||||
};
|
||||
|
||||
private:
|
||||
friend class Zone;
|
||||
|
||||
static const char * SERVER_NAME; //"SERVER"
|
||||
|
||||
|
@ -18,6 +18,22 @@ require 'one_helper'
|
||||
|
||||
class OneZoneHelper < OpenNebulaHelper::OneHelper
|
||||
|
||||
SERVER_NAME={
|
||||
:name => "server_name",
|
||||
:short => "-n server_name",
|
||||
:large => "--name",
|
||||
:format => String,
|
||||
:description => "Zone server name"
|
||||
}
|
||||
|
||||
SERVER_ENDPOINT={
|
||||
:name => "server_rpc",
|
||||
:short => "-r rpc endpoint",
|
||||
:large => "--rpc",
|
||||
:format => String,
|
||||
:description => "Zone server RPC endpoint"
|
||||
}
|
||||
|
||||
def self.rname
|
||||
"ZONE"
|
||||
end
|
||||
@ -98,6 +114,31 @@ class OneZoneHelper < OpenNebulaHelper::OneHelper
|
||||
puts str % ["NAME", zone.name]
|
||||
puts
|
||||
|
||||
zone_hash=zone.to_hash
|
||||
|
||||
if zone.has_elements?("/ZONE/SERVER_POOL/SERVER")
|
||||
puts
|
||||
CLIHelper.print_header(str_h1 % "SERVERS",false)
|
||||
|
||||
CLIHelper::ShowTable.new(nil, self) do
|
||||
|
||||
column :"ID", "", :size=>2 do |d|
|
||||
d["ID"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"NAME", "", :left, :size=>15 do |d|
|
||||
d["NAME"] if !d.nil?
|
||||
end
|
||||
|
||||
column :"ENDPOINT", "", :left, :size=>30 do |d|
|
||||
d["ENDPOINT"] if !d.nil?
|
||||
end
|
||||
|
||||
end.show([zone_hash['ZONE']['SERVER_POOL']['SERVER']].flatten, {})
|
||||
end
|
||||
|
||||
puts
|
||||
|
||||
CLIHelper.print_header(str_h1 % "ZONE TEMPLATE", false)
|
||||
puts zone.template_str
|
||||
end
|
||||
|
@ -91,6 +91,33 @@ cmd=CommandParser::CmdParser.new(ARGV) do
|
||||
end
|
||||
end
|
||||
|
||||
addserver_desc = <<-EOT.unindent
|
||||
Add an OpenNebula server to this zone.
|
||||
EOT
|
||||
|
||||
command :"server-add", addserver_desc, :zoneid, :options =>
|
||||
[ OneZoneHelper::SERVER_NAME, OneZoneHelper::SERVER_ENDPOINT] do
|
||||
|
||||
if options[:server_name].nil? || options[:server_rpc].nil?
|
||||
STDERR.puts "To add a server set:"
|
||||
STDERR.puts "\t-n <server name>"
|
||||
STDERR.puts "\t-r <RPC endpoint>"
|
||||
exit -1
|
||||
end
|
||||
|
||||
template = <<-EOT
|
||||
SERVER = [
|
||||
NAME="#{options[:server_name]}",
|
||||
ENDPOINT="#{options[:server_rpc]}"
|
||||
]
|
||||
EOT
|
||||
|
||||
helper.perform_action(args[0], options, "server added") do |o|
|
||||
o.add_servers(template)
|
||||
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.
|
||||
|
@ -28,7 +28,8 @@ module OpenNebula
|
||||
:allocate => "zone.allocate",
|
||||
:update => "zone.update",
|
||||
:rename => "zone.rename",
|
||||
:delete => "zone.delete"
|
||||
:delete => "zone.delete",
|
||||
:addserver => "zone.addserver"
|
||||
}
|
||||
|
||||
# Creates a Zone description with just its identifier
|
||||
@ -103,5 +104,16 @@ module OpenNebula
|
||||
def rename(name)
|
||||
return call(ZONE_METHODS[:rename], @pe_id, name)
|
||||
end
|
||||
|
||||
# Adds servers to this Zone
|
||||
#
|
||||
# @param name [String] Template with zone servers
|
||||
# SERVER = [ NAME = "<server_name>", ENDPOINT = "<rpc_ep>" ]
|
||||
#
|
||||
# @return [nil, OpenNebula::Error] nil in case of success, Error
|
||||
# otherwise
|
||||
def add_servers(servers)
|
||||
return call(ZONE_METHODS[:addserver], @pe_id, servers)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -30,6 +30,7 @@
|
||||
#include "RequestManagerChmod.h"
|
||||
#include "RequestManagerClone.h"
|
||||
#include "RequestManagerRename.h"
|
||||
#include "RequestManagerZone.h"
|
||||
#include "RequestManagerLock.h"
|
||||
|
||||
#include "RequestManagerVirtualNetwork.h"
|
||||
@ -779,6 +780,8 @@ 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(new ZoneAddServer());
|
||||
|
||||
xmlrpc_c::methodPtr zone_info(new ZoneInfo());
|
||||
xmlrpc_c::methodPtr zonepool_info(new ZonePoolInfo());
|
||||
|
||||
@ -788,6 +791,8 @@ void RequestManager::register_xml_methods()
|
||||
RequestManagerRegistry.addMethod("one.zone.info", zone_info);
|
||||
RequestManagerRegistry.addMethod("one.zone.rename", zone_rename);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.zone.addserver", zone_addserver);
|
||||
|
||||
RequestManagerRegistry.addMethod("one.zonepool.info",zonepool_info);
|
||||
|
||||
/* Security Group objects related methods*/
|
||||
|
74
src/rm/RequestManagerZone.cc
Normal file
74
src/rm/RequestManagerZone.cc
Normal file
@ -0,0 +1,74 @@
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems */
|
||||
/* */
|
||||
/* Licensed under the Apache License, Version 2.0 (the "License"); you may */
|
||||
/* not use this file except in compliance with the License. You may obtain */
|
||||
/* a copy of the License at */
|
||||
/* */
|
||||
/* http://www.apache.org/licenses/LICENSE-2.0 */
|
||||
/* */
|
||||
/* Unless required by applicable law or agreed to in writing, software */
|
||||
/* distributed under the License is distributed on an "AS IS" BASIS, */
|
||||
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. */
|
||||
/* See the License for the specific language governing permissions and */
|
||||
/* limitations under the License. */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
#include "RequestManagerZone.h"
|
||||
#include "Nebula.h"
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void ZoneAddServer::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
RequestAttributes& att)
|
||||
{
|
||||
int id = xmlrpc_c::value_int(paramList.getInt(1));
|
||||
string zs_str = xmlrpc_c::value_string(paramList.getString(2));
|
||||
|
||||
string error_str;
|
||||
|
||||
if ( basic_authorization(id, att) == false )
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Template zs_tmpl;
|
||||
|
||||
int rc = zs_tmpl.parse_str_or_xml(zs_str, error_str);
|
||||
|
||||
if ( rc != 0 )
|
||||
{
|
||||
att.resp_msg = error_str;
|
||||
failure_response(ACTION, att);
|
||||
|
||||
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->add_servers(zs_tmpl, att.resp_msg) == -1 )
|
||||
{
|
||||
failure_response(ACTION, att);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
pool->update(zone);
|
||||
|
||||
zone->unlock();
|
||||
|
||||
success_response(id, att);
|
||||
}
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
@ -45,6 +45,7 @@ source_files=[
|
||||
'RequestManagerRename.cc',
|
||||
'RequestManagerProxy.cc',
|
||||
'RequestManagerVdc.cc',
|
||||
'RequestManagerZone.cc',
|
||||
'RequestManagerDatastore.cc',
|
||||
'RequestManagerLock.cc',
|
||||
'RequestManagerMarketPlaceApp.cc',
|
||||
|
@ -299,3 +299,30 @@ int Zone::post_update_template(string& error)
|
||||
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
int Zone::add_servers(Template& tmpl, string& error)
|
||||
{
|
||||
vector<VectorAttribute *> vs;
|
||||
vector<VectorAttribute *>::iterator it;
|
||||
|
||||
VectorAttribute * server;
|
||||
|
||||
tmpl.get(ZoneServers::SERVER_NAME, vs);
|
||||
|
||||
for ( it = vs.begin() ; it != vs.end() ; ++it )
|
||||
{
|
||||
server = new VectorAttribute(*it);
|
||||
|
||||
if ( servers->add_server(server, error) == -1 )
|
||||
{
|
||||
delete server;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
servers_template.set(server);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user