Statistics
| Branch: | Tag: | Revision:

one / include / RequestManagerAllocate.h @ 0a132883

History | View | Annotate | Download (9.81 KB)

1
/* -------------------------------------------------------------------------- */
2
/* Copyright 2002-2011, OpenNebula Project Leads (OpenNebula.org)             */
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_ALLOCATE_H_
18
#define REQUEST_MANAGER_ALLOCATE_H_
19

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

    
23
#include "VirtualNetworkTemplate.h"
24
#include "ImageTemplate.h"
25
#include "VirtualMachineTemplate.h"
26

    
27
using namespace std;
28

    
29
/* ------------------------------------------------------------------------- */
30
/* ------------------------------------------------------------------------- */
31
/* ------------------------------------------------------------------------- */
32

    
33
class RequestManagerAllocate: public Request
34
{
35
protected:
36
    RequestManagerAllocate(const string& method_name,
37
                           const string& help,
38
                           const string& xml_args,
39
                           bool  dt)
40
        :Request(method_name,xml_args,help), do_template(dt)
41
    {
42
        auth_op = AuthRequest::CREATE;
43
    };
44

    
45
    ~RequestManagerAllocate(){};
46

    
47
    /* -------------------------------------------------------------------- */
48

    
49
    void request_execute(xmlrpc_c::paramList const& _paramList);
50

    
51
    virtual bool allocate_authorization(Template * obj_template);
52

    
53
    string allocate_error (char *error);
54

    
55
    string allocate_error (const string& error);
56

    
57
    /* -------------------------------------------------------------------- */
58

    
59
    virtual Template * get_object_template() { return 0; };
60

    
61
    virtual int pool_allocate(xmlrpc_c::paramList const& _paramList, 
62
                              Template * tmpl,
63
                              int& id, 
64
                              string& error_str) = 0;
65
private:
66

    
67
    bool do_template;
68
};
69

    
70

    
71
/* ------------------------------------------------------------------------- */
72
/* ------------------------------------------------------------------------- */
73

    
74
class VirtualMachineAllocate: public RequestManagerAllocate
75
{
76
public:
77
    VirtualMachineAllocate():
78
        RequestManagerAllocate("VirtualMachineAllocate",
79
                               "Allocates a new virtual machine",
80
                               "A:ss",
81
                               true)
82
    {    
83
        Nebula& nd = Nebula::instance();
84
        pool       = nd.get_vmpool();
85
        auth_object = AuthRequest::VM;
86
    };
87

    
88
    ~VirtualMachineAllocate(){};
89
    /* --------------------------------------------------------------------- */
90

    
91
    Template * get_object_template() 
92
    { 
93
        return new VirtualMachineTemplate; 
94
    };
95

    
96
    int pool_allocate(xmlrpc_c::paramList const& _paramList, 
97
                      Template * tmpl,
98
                      int& id, 
99
                      string& error_str);
100

    
101
    bool allocate_authorization(Template * obj_template);
102
};
103

    
104
/* ------------------------------------------------------------------------- */
105
/* ------------------------------------------------------------------------- */
106

    
107
class VirtualNetworkAllocate: public RequestManagerAllocate
108
{
109
public:
110
    VirtualNetworkAllocate():
111
        RequestManagerAllocate("VirtualNetworkInfo",
112
                               "Allocates a new virtual network",
113
                               "A:ss",
114
                               true)
115
    {    
116
        Nebula& nd  = Nebula::instance();
117
        pool        = nd.get_vnpool();
118
        auth_object = AuthRequest::NET;
119
    };
120

    
121
    ~VirtualNetworkAllocate(){};
122

    
123
    /* --------------------------------------------------------------------- */
124

    
125
    Template * get_object_template() 
126
    { 
127
        return new VirtualNetworkTemplate; 
128
    };
129

    
130
    int pool_allocate(xmlrpc_c::paramList const& _paramList, 
131
                      Template * tmpl,
132
                      int& id, 
133
                      string& error_str);
134
};
135

    
136
/* ------------------------------------------------------------------------- */
137
/* ------------------------------------------------------------------------- */
138

    
139
class ImageAllocate: public RequestManagerAllocate
140
{
141
public:
142
    ImageAllocate():
143
        RequestManagerAllocate("ImageAllocate",
144
                               "Allocates a new image",
145
                               "A:ss",
146
                               true)
147
    {    
148
        Nebula& nd  = Nebula::instance();
149
        pool        = nd.get_ipool();
150
        auth_object = AuthRequest::IMAGE;
151
    };
152

    
153
    ~ImageAllocate(){};
154

    
155
    /* --------------------------------------------------------------------- */
156

    
157
    Template * get_object_template() 
158
    { 
159
        return new ImageTemplate; 
160
    };
161

    
162
    int pool_allocate(xmlrpc_c::paramList const& _paramList, 
163
                      Template * tmpl,
164
                      int& id, 
165
                      string& error_str);
166
};
167

    
168
/* ------------------------------------------------------------------------- */
169
/* ------------------------------------------------------------------------- */
170

    
171
class TemplateAllocate : public RequestManagerAllocate
172
{
173
public:
174
    TemplateAllocate():
175
        RequestManagerAllocate("TemplateAllocate",
176
                               "Allocates a new virtual machine template",
177
                               "A:ss",
178
                               true)
179
    {    
180
        Nebula& nd  = Nebula::instance();
181
        pool        = nd.get_tpool();
182
        auth_object = AuthRequest::TEMPLATE;
183
    };
184

    
185
    ~TemplateAllocate(){};
186

    
187
    /* --------------------------------------------------------------------- */
188

    
189
    Template * get_object_template() 
190
    { 
191
        return new VirtualMachineTemplate; 
192
    };
193

    
194
    int pool_allocate(xmlrpc_c::paramList const& _paramList, 
195
                      Template * tmpl,
196
                      int& id, 
197
                      string& error_str);
198
};
199

    
200
/* ------------------------------------------------------------------------- */
201
/* ------------------------------------------------------------------------- */
202

    
203
class HostAllocate : public RequestManagerAllocate
204
{
205
public:
206
    HostAllocate():
207
        RequestManagerAllocate("HostInfo",
208
                               "Allocates a new host",
209
                               "A:sssss",
210
                               false)
211
    {    
212
        Nebula& nd  = Nebula::instance();
213
        pool        = nd.get_hpool();
214
        auth_object = AuthRequest::HOST;
215
    };
216

    
217
    ~HostAllocate(){};
218

    
219
    int pool_allocate(xmlrpc_c::paramList const& _paramList, 
220
                      Template * tmpl,
221
                      int& id, 
222
                      string& error_str);
223
};
224

    
225
/* ------------------------------------------------------------------------- */
226
/* ------------------------------------------------------------------------- */
227

    
228
class UserAllocate: public RequestManagerAllocate
229
{
230
public:
231
    UserAllocate():
232
        RequestManagerAllocate("UserInfo",
233
                               "Returns user information",
234
                               "A:sss",
235
                               false)
236
    {    
237
        Nebula& nd  = Nebula::instance();
238
        pool        = nd.get_upool();
239
        auth_object = AuthRequest::USER;
240
    };
241

    
242
    ~UserAllocate(){};
243

    
244
    int pool_allocate(xmlrpc_c::paramList const& _paramList, 
245
                      Template * tmpl,
246
                      int& id, 
247
                      string& error_str);
248
};
249

    
250
/* ------------------------------------------------------------------------- */
251
/* ------------------------------------------------------------------------- */
252

    
253
class ClusterAllocate : public RequestManagerAllocate
254
{
255
public:
256
    ClusterAllocate():
257
        RequestManagerAllocate("ClusterInfo",
258
                               "Allocates a new cluster",
259
                               "A:ss",
260
                               false)
261
    {    
262
        Nebula& nd = Nebula::instance();
263
        pool       = nd.get_cpool();
264
        auth_object = AuthRequest::CLUSTER;
265
    };
266

    
267
    ~ClusterAllocate(){};
268

    
269
    int pool_allocate(xmlrpc_c::paramList const& _paramList, 
270
                      Template * tmpl,
271
                      int& id, 
272
                      string& error_str);
273
};
274

    
275
/* ------------------------------------------------------------------------- */
276
/* ------------------------------------------------------------------------- */
277

    
278
class GroupAllocate: public RequestManagerAllocate
279
{
280
public:
281
    GroupAllocate():
282
        RequestManagerAllocate("GroupAllocate",
283
                               "Allocates a new group",
284
                               "A:ss",
285
                               false)
286
    {    
287
        Nebula& nd = Nebula::instance();
288
        pool       = nd.get_gpool();
289
        auth_object = AuthRequest::GROUP;
290
    };
291

    
292
    ~GroupAllocate(){};
293

    
294
    int pool_allocate(xmlrpc_c::paramList const& _paramList, 
295
                      Template * tmpl,
296
                      int& id, 
297
                      string& error_str);
298
};
299

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

    
304
#endif