Revision ebc810f4

View differences:

include/RequestManagerZone.h
1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

  
17
#ifndef REQUEST_MANAGER_ZONE_H
18
#define REQUEST_MANAGER_ZONE_H
19

  
20
#include "Request.h"
21
#include "Nebula.h"
22

  
23
using namespace std;
24

  
25
/* ------------------------------------------------------------------------- */
26
/* ------------------------------------------------------------------------- */
27
/* ------------------------------------------------------------------------- */
28

  
29
class RequestManagerZone: public Request
30
{
31
protected:
32
    RequestManagerZone(const string& method_name,
33
                       const string& help,
34
                       const string& params)
35
        :Request(method_name,params,help)
36
    {
37
        Nebula& nd = Nebula::instance();
38
        pool       = nd.get_zonepool();
39

  
40
        auth_object = PoolObjectSQL::ZONE;
41
        auth_op     = AuthRequest::ADMIN;
42
    };
43

  
44
    ~RequestManagerZone(){};
45

  
46
    /* -------------------------------------------------------------------- */
47

  
48
    virtual void request_execute(xmlrpc_c::paramList const& _paramList,
49
                                 RequestAttributes& att) = 0;
50
};
51

  
52
/* ------------------------------------------------------------------------- */
53
/* ------------------------------------------------------------------------- */
54

  
55
class ZoneAddServer : public RequestManagerZone
56
{
57
public:
58
    ZoneAddServer():
59
        RequestManagerZone("ZoneAddServer", "Add a server to zone", "A:sis"){};
60

  
61
    ~ZoneAddServer(){};
62

  
63
    void request_execute(xmlrpc_c::paramList const& _paramList,
64
                         RequestAttributes& att);
65
};
66

  
67
/* -------------------------------------------------------------------------- */
68
/* -------------------------------------------------------------------------- */
69

  
70
#endif
include/Zone.h
46 46
     */
47 47
    int from_xml(const string &xml_str);
48 48

  
49
    /**
50
     *  Add servers to this zone
51
     *    @param tmpl with SERVER definitions
52
     *    @param error
53
     *
54
     *    @return 0 on success, -1 otherwise
55
     */
56
    int add_servers(Template& tmpl, string& error);
57

  
49 58
private:
50 59
    // -------------------------------------------------------------------------
51 60
    // Friends
include/ZoneServer.h
34 34

  
35 35
    int init(string& error)
36 36
    {
37
        if ( vector_value("NAME").empty() )
38
        {
39
            error = "Missing NAME in SERVER";
40
            return -1;
41
        }
42

  
43
        if ( vector_value("ENDPOINT").empty() )
44
        {
45
            error = "Missing ENDPOINT in SERVER";
46
            return -1;
47
        }
48

  
37 49
        return 0;
38 50
    }
39 51

  
......
147 159
            return -1;
148 160
        }
149 161

  
162
        va->replace(SERVER_ID_NAME, next_id);
163

  
150 164
        add_attribute(server, next_id);
151 165

  
152 166
        next_id += 1;
......
154 168
        return 0;
155 169
    };
156 170

  
157

  
158 171
protected:
159

  
160 172
    ExtendedAttribute * attribute_factory(VectorAttribute * va, int id) const
161 173
    {
162 174
        return new ZoneServer(va, id);
163 175
    };
164 176

  
165 177
private:
178
    friend class Zone;
166 179

  
167 180
    static const char * SERVER_NAME; //"SERVER"
168 181

  
src/cli/one_helper/onezone_helper.rb
18 18

  
19 19
class OneZoneHelper < OpenNebulaHelper::OneHelper
20 20

  
21
    SERVER_NAME={
22
        :name => "server_name",
23
        :short => "-n server_name",
24
        :large => "--name",
25
        :format => String,
26
        :description => "Zone server name"
27
    }
28

  
29
    SERVER_ENDPOINT={
30
        :name => "server_rpc",
31
        :short => "-r rpc endpoint",
32
        :large => "--rpc",
33
        :format => String,
34
        :description => "Zone server RPC endpoint"
35
    }
36

  
21 37
    def self.rname
22 38
        "ZONE"
23 39
    end
......
98 114
        puts str % ["NAME", zone.name]
99 115
        puts
100 116

  
117
        zone_hash=zone.to_hash
118

  
119
        if zone.has_elements?("/ZONE/SERVER_POOL/SERVER")
120
            puts
121
            CLIHelper.print_header(str_h1 % "SERVERS",false)
122

  
123
            CLIHelper::ShowTable.new(nil, self) do
124

  
125
                column :"ID", "", :size=>2 do |d|
126
                    d["ID"] if !d.nil?
127
                end
128

  
129
                column :"NAME", "", :left, :size=>15 do |d|
130
                    d["NAME"] if !d.nil?
131
                end
132

  
133
                column :"ENDPOINT", "", :left, :size=>30 do |d|
134
                    d["ENDPOINT"] if !d.nil?
135
                end
136

  
137
            end.show([zone_hash['ZONE']['SERVER_POOL']['SERVER']].flatten, {})
138
        end
139

  
140
        puts
141

  
101 142
        CLIHelper.print_header(str_h1 % "ZONE TEMPLATE", false)
102 143
        puts zone.template_str
103 144
    end
src/cli/onezone
91 91
        end
92 92
    end
93 93

  
94
    addserver_desc = <<-EOT.unindent
95
        Add an OpenNebula server to this zone.
96
    EOT
97

  
98
    command :"server-add", addserver_desc, :zoneid, :options =>
99
        [ OneZoneHelper::SERVER_NAME, OneZoneHelper::SERVER_ENDPOINT] do
100

  
101
        if options[:server_name].nil? || options[:server_rpc].nil?
102
            STDERR.puts "To add a server set:"
103
            STDERR.puts "\t-n <server name>"
104
            STDERR.puts "\t-r <RPC endpoint>"
105
            exit -1
106
        end
107

  
108
        template = <<-EOT
109
            SERVER = [
110
              NAME="#{options[:server_name]}",
111
              ENDPOINT="#{options[:server_rpc]}"
112
            ]
113
        EOT
114

  
115
        helper.perform_action(args[0], options, "server added") do |o|
116
            o.add_servers(template)
117
        end
118

  
119
    end
120

  
94 121
    update_desc = <<-EOT.unindent
95 122
        Update the template contents. If a path is not provided the editor will
96 123
        be launched to modify the current content.
src/oca/ruby/opennebula/zone.rb
28 28
            :allocate       => "zone.allocate",
29 29
            :update         => "zone.update",
30 30
            :rename         => "zone.rename",
31
            :delete         => "zone.delete"
31
            :delete         => "zone.delete",
32
            :addserver      => "zone.addserver"
32 33
        }
33 34

  
34 35
        # Creates a Zone description with just its identifier
......
103 104
        def rename(name)
104 105
            return call(ZONE_METHODS[:rename], @pe_id, name)
105 106
        end
107

  
108
        # Adds servers to this Zone
109
        #
110
        # @param name [String] Template with zone servers
111
        #   SERVER = [ NAME = "<server_name>", ENDPOINT = "<rpc_ep>" ]
112
        #
113
        # @return [nil, OpenNebula::Error] nil in case of success, Error
114
        #   otherwise
115
        def add_servers(servers)
116
            return call(ZONE_METHODS[:addserver], @pe_id, servers)
117
        end
106 118
    end
107 119
end
src/rm/RequestManager.cc
30 30
#include "RequestManagerChmod.h"
31 31
#include "RequestManagerClone.h"
32 32
#include "RequestManagerRename.h"
33
#include "RequestManagerZone.h"
33 34
#include "RequestManagerLock.h"
34 35

  
35 36
#include "RequestManagerVirtualNetwork.h"
......
779 780
    xmlrpc_c::methodPtr zone_delete(zone_delete_pt);
780 781
    xmlrpc_c::methodPtr zone_rename(zone_rename_pt);
781 782

  
783
    xmlrpc_c::methodPtr zone_addserver(new ZoneAddServer());
784

  
782 785
    xmlrpc_c::methodPtr zone_info(new ZoneInfo());
783 786
    xmlrpc_c::methodPtr zonepool_info(new ZonePoolInfo());
784 787

  
......
788 791
    RequestManagerRegistry.addMethod("one.zone.info",    zone_info);
789 792
    RequestManagerRegistry.addMethod("one.zone.rename",  zone_rename);
790 793

  
794
    RequestManagerRegistry.addMethod("one.zone.addserver", zone_addserver);
795

  
791 796
    RequestManagerRegistry.addMethod("one.zonepool.info",zonepool_info);
792 797

  
793 798
    /* Security Group objects related methods*/
src/rm/RequestManagerZone.cc
1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems                */
3
/*                                                                            */
4
/* Licensed under the Apache License, Version 2.0 (the "License"); you may    */
5
/* not use this file except in compliance with the License. You may obtain    */
6
/* a copy of the License at                                                   */
7
/*                                                                            */
8
/* http://www.apache.org/licenses/LICENSE-2.0                                 */
9
/*                                                                            */
10
/* Unless required by applicable law or agreed to in writing, software        */
11
/* distributed under the License is distributed on an "AS IS" BASIS,          */
12
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   */
13
/* See the License for the specific language governing permissions and        */
14
/* limitations under the License.                                             */
15
/* -------------------------------------------------------------------------- */
16

  
17
#include "RequestManagerZone.h"
18
#include "Nebula.h"
19

  
20
/* -------------------------------------------------------------------------- */
21
/* -------------------------------------------------------------------------- */
22

  
23
void ZoneAddServer::request_execute(xmlrpc_c::paramList const& paramList,
24
    RequestAttributes& att)
25
{
26
    int    id     = xmlrpc_c::value_int(paramList.getInt(1));
27
    string zs_str = xmlrpc_c::value_string(paramList.getString(2));
28

  
29
    string error_str;
30

  
31
    if ( basic_authorization(id, att) == false )
32
    {
33
        return;
34
    }
35

  
36
    Template zs_tmpl;
37

  
38
    int rc = zs_tmpl.parse_str_or_xml(zs_str, error_str);
39

  
40
    if ( rc != 0 )
41
    {
42
        att.resp_msg = error_str;
43
        failure_response(ACTION, att);
44

  
45
        return;
46
    }
47

  
48
    Zone * zone = (static_cast<ZonePool *>(pool))->get(id, true);
49

  
50
    if ( zone == 0 )
51
    {
52
        att.resp_id = id;
53
        failure_response(NO_EXISTS, att);
54

  
55
        return;
56
    }
57

  
58
    if ( zone->add_servers(zs_tmpl, att.resp_msg) == -1 )
59
    {
60
        failure_response(ACTION, att);
61

  
62
        return;
63
    }
64

  
65
    pool->update(zone);
66

  
67
    zone->unlock();
68

  
69
    success_response(id, att);
70
}
71

  
72
/* -------------------------------------------------------------------------- */
73
/* -------------------------------------------------------------------------- */
74

  
src/rm/SConstruct
45 45
    'RequestManagerRename.cc',
46 46
    'RequestManagerProxy.cc',
47 47
    'RequestManagerVdc.cc',
48
    'RequestManagerZone.cc',
48 49
    'RequestManagerDatastore.cc',
49 50
    'RequestManagerLock.cc',
50 51
    'RequestManagerMarketPlaceApp.cc',
src/zone/Zone.cc
299 299

  
300 300
/* -------------------------------------------------------------------------- */
301 301
/* -------------------------------------------------------------------------- */
302

  
303
int Zone::add_servers(Template& tmpl, string& error)
304
{
305
    vector<VectorAttribute *> vs;
306
    vector<VectorAttribute *>::iterator it;
307

  
308
    VectorAttribute * server;
309

  
310
    tmpl.get(ZoneServers::SERVER_NAME, vs);
311

  
312
    for ( it = vs.begin() ; it != vs.end() ; ++it )
313
    {
314
        server = new VectorAttribute(*it);
315

  
316
        if ( servers->add_server(server, error) == -1 )
317
        {
318
            delete server;
319

  
320
            return -1;
321
        }
322

  
323
        servers_template.set(server);
324
    }
325

  
326
    return 0;
327
}
328

  

Also available in: Unified diff