Statistics
| Branch: | Tag: | Revision:

one / include / Nebula.h @ bfaabf35

History | View | Annotate | Download (11 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 NEBULA_H_
18
#define NEBULA_H_
19

    
20
#include "SqlDB.h"
21

    
22
#include "NebulaTemplate.h"
23

    
24
#include "VirtualMachinePool.h"
25
#include "VirtualNetworkPool.h"
26
#include "HostPool.h"
27
#include "UserPool.h"
28
#include "VMTemplatePool.h"
29
#include "GroupPool.h"
30

    
31
#include "VirtualMachineManager.h"
32
#include "LifeCycleManager.h"
33
#include "InformationManager.h"
34
#include "TransferManager.h"
35
#include "DispatchManager.h"
36
#include "RequestManager.h"
37
#include "HookManager.h"
38
#include "AuthManager.h"
39
#include "AclManager.h"
40
#include "ImageManager.h"
41

    
42
#include "Callbackable.h"
43

    
44
class Nebula : public Callbackable
45
{
46
public:
47

    
48
    static Nebula& instance()
49
    {
50
        static Nebula nebulad;
51

    
52
        return nebulad;
53
    };
54

    
55
    // --------------------------------------------------------------
56
    // Pool Accessors
57
    // --------------------------------------------------------------
58

    
59
    VirtualMachinePool * get_vmpool()
60
    {
61
        return vmpool;
62
    };
63

    
64
    HostPool * get_hpool()
65
    {
66
        return hpool;
67
    };
68

    
69
    VirtualNetworkPool * get_vnpool()
70
    {
71
        return vnpool;
72
    };
73

    
74
    UserPool * get_upool()
75
    {
76
        return upool;
77
    };
78

    
79
    ImagePool * get_ipool()
80
    {
81
        return ipool;
82
    };
83

    
84
    GroupPool * get_gpool()
85
    {
86
        return gpool;
87
    };
88

    
89
    VMTemplatePool * get_tpool()
90
    {
91
        return tpool;
92
    };
93

    
94
    // --------------------------------------------------------------
95
    // Manager Accessors
96
    // --------------------------------------------------------------
97

    
98
    VirtualMachineManager * get_vmm()
99
    {
100
        return vmm;
101
    };
102

    
103
    LifeCycleManager * get_lcm()
104
    {
105
        return lcm;
106
    };
107

    
108
        InformationManager * get_im()
109
    {
110
        return im;
111
    };
112

    
113
    TransferManager * get_tm()
114
    {
115
        return tm;
116
    };
117

    
118
    DispatchManager * get_dm()
119
    {
120
        return dm;
121
    };
122

    
123
    HookManager * get_hm()
124
    {
125
        return hm;
126
    };
127

    
128
    AuthManager * get_authm()
129
    {
130
        return authm;
131
    };
132

    
133
    ImageManager * get_imagem()
134
    {
135
        return imagem;
136
    };
137

    
138
    AclManager * get_aclm()
139
    {
140
        return aclm;
141
    };
142

    
143
    // --------------------------------------------------------------
144
    // Environment & Configuration
145
    // --------------------------------------------------------------
146

    
147
    /**
148
     *  Returns the value of ONE_LOCATION env variable. When this variable is
149
     *  not defined the nebula location is "/".
150
     *          @return the nebula location.
151
     */
152
    const string& get_nebula_location()
153
    {
154
        return nebula_location;
155
    };
156

    
157
    /**
158
     *  Returns the path where mad executables are stored, if ONE_LOCATION is
159
     *  defined this path points to $ONE_LOCATION/bin, otherwise it is
160
     *  /usr/lib/one/mads.
161
     *          @return the mad execs location.
162
     */
163
    const string& get_mad_location()
164
    {
165
            return mad_location;
166
    };
167

    
168
    /**
169
     *  Returns the path where defaults for mads are stored, if ONE_LOCATION is
170
     *  defined this path points to $ONE_LOCATION/etc, otherwise it is /etc/one
171
     *          @return the mad defaults location.
172
     */
173
    const string& get_defaults_location()
174
    {
175
            return etc_location;
176
    };
177

    
178
    /**
179
     *  Returns the path where logs (oned.log, schedd.log,...) are generated
180
     *  if ONE_LOCATION is defined this path points to $ONE_LOCATION/var,
181
     *  otherwise it is /var/log/one.
182
     *          @return the log location.
183
     */
184
    const string& get_log_location()
185
    {
186
            return log_location;
187
    };
188

    
189
    /**
190
     *  Returns the path where the OpenNebula DB and the VM local directories
191
     *  are stored. When ONE_LOCATION is defined this path points to
192
     *  $ONE_LOCATION/var, otherwise it is /var/lib/one.
193
     *          @return the log location.
194
     */
195
    const string& get_var_location()
196
    {
197
            return var_location;
198
    };
199

    
200
    /**
201
     *  Returns the path of the log file for a VM, depending where OpenNebula is
202
     *  installed,
203
     *     $ONE_LOCATION/var/$VM_ID/vm.log
204
     *  or
205
     *     /var/log/one/$VM_ID.log
206
     *  @return the log location for the VM.
207
     */
208
    string get_vm_log_filename(int oid)
209
    {
210
            ostringstream oss;
211

    
212
            if (nebula_location == "/")
213
            {
214
                    oss << log_location << oid << ".log";
215
            }
216
            else
217
            {
218
                    oss << nebula_location << "var/" << oid << "/vm.log";
219
            }
220

    
221
            return oss.str();
222
    };
223

    
224
    const string& get_nebula_hostname()
225
    {
226
        return hostname;
227
    };
228

    
229
    static string version()
230
    {
231
        return "OpenNebula 2.3.0";
232
    };
233

    
234
    static int db_version()
235
    {
236
        return 1;
237
    };
238

    
239
    void start();
240

    
241
    void get_configuration_attribute(
242
        const char * name,
243
        string& value) const
244
    {
245
        string _name(name);
246

    
247
        nebula_configuration->Template::get(_name,value);
248
    };
249

    
250
private:
251

    
252
    // -----------------------------------------------------------------------
253
    //Constructors and = are private to only access the class through instance
254
    // -----------------------------------------------------------------------
255

    
256
    Nebula():nebula_configuration(0),db(0),vmpool(0),hpool(0),vnpool(0),
257
        upool(0),ipool(0),gpool(0),tpool(0),lcm(0),vmm(0),im(0),tm(0),
258
        dm(0),rm(0),hm(0),authm(0),aclm(0),imagem(0)
259
    {
260
        const char * nl = getenv("ONE_LOCATION");
261

    
262
        if (nl == 0) //OpenNebula installed under root directory
263
        {
264
            nebula_location = "/";
265

    
266
            mad_location     = "/usr/lib/one/mads/";
267
            etc_location     = "/etc/one/";
268
            log_location     = "/var/log/one/";
269
            var_location     = "/var/lib/one/";
270
            hook_location    = "/usr/share/one/hooks/";
271
            remotes_location = "/var/lib/one/remotes/";
272
        }
273
        else
274
        {
275
            nebula_location = nl;
276

    
277
            if ( nebula_location.at(nebula_location.size()-1) != '/' )
278
            {
279
                nebula_location += "/";
280
            }
281

    
282
            mad_location     = nebula_location + "lib/mads/";
283
            etc_location     = nebula_location + "etc/";
284
            log_location     = nebula_location + "var/";
285
            var_location     = nebula_location + "var/";
286
            hook_location    = nebula_location + "share/hooks/";
287
            remotes_location = nebula_location + "var/remotes/";
288
        }
289
    };
290

    
291
    ~Nebula()
292
    {
293
        if ( vmpool != 0)
294
        {
295
            delete vmpool;
296
        }
297

    
298
        if ( vnpool != 0)
299
        {
300
            delete vnpool;
301
        }
302

    
303
        if ( hpool != 0)
304
        {
305
            delete hpool;
306
        }
307

    
308
        if ( upool != 0)
309
        {
310
            delete upool;
311
        }
312

    
313
        if ( ipool != 0)
314
        {
315
            delete ipool;
316
        }
317

    
318
        if ( gpool != 0)
319
        {
320
            delete gpool;
321
        }
322

    
323
        if ( tpool != 0)
324
        {
325
            delete tpool;
326
        }
327

    
328
        if ( vmm != 0)
329
        {
330
            delete vmm;
331
        }
332

    
333
        if ( lcm != 0)
334
        {
335
            delete lcm;
336
        }
337

    
338
        if ( im != 0)
339
        {
340
            delete im;
341
        }
342

    
343
        if ( tm != 0)
344
        {
345
            delete tm;
346
        }
347

    
348
        if ( dm != 0)
349
        {
350
            delete dm;
351
        }
352

    
353
        if ( rm != 0)
354
        {
355
            delete rm;
356
        }
357

    
358
        if ( hm != 0)
359
        {
360
            delete hm;
361
        }
362

    
363
        if ( authm != 0)
364
        {
365
            delete authm;
366
        }
367

    
368
        if ( aclm != 0)
369
        {
370
            delete aclm;
371
        }
372

    
373
        if ( imagem != 0)
374
        {
375
            delete imagem;
376
        }
377

    
378
        if ( nebula_configuration != 0)
379
        {
380
            delete nebula_configuration;
381
        }
382

    
383
        if ( db != 0 )
384
        {
385
            delete db;
386
        }
387
    };
388

    
389
    Nebula(Nebula const&){};
390

    
391
    Nebula& operator=(Nebula const&){return *this;};
392

    
393
    // ---------------------------------------------------------------
394
    // Environment variables
395
    // ---------------------------------------------------------------
396

    
397
    string  nebula_location;
398

    
399
    string        mad_location;
400
    string        etc_location;
401
    string        log_location;
402
    string        var_location;
403
    string  hook_location;
404
    string  remotes_location;
405

    
406
    string        hostname;
407

    
408
    // ---------------------------------------------------------------
409
    // Configuration
410
    // ---------------------------------------------------------------
411

    
412
    NebulaTemplate *    nebula_configuration;
413

    
414
    // ---------------------------------------------------------------
415
    // Nebula Pools
416
    // ---------------------------------------------------------------
417

    
418
    SqlDB              * db;
419
    VirtualMachinePool * vmpool;
420
    HostPool           * hpool;
421
    VirtualNetworkPool * vnpool;
422
    UserPool           * upool;
423
    ImagePool          * ipool;
424
    GroupPool          * gpool;
425
    VMTemplatePool     * tpool;
426

    
427
    // ---------------------------------------------------------------
428
    // Nebula Managers
429
    // ---------------------------------------------------------------
430

    
431
    LifeCycleManager *      lcm;
432
    VirtualMachineManager * vmm;
433
    InformationManager *    im;
434
    TransferManager *       tm;
435
    DispatchManager *       dm;
436
    RequestManager *        rm;
437
    HookManager *           hm;
438
    AuthManager *           authm;
439
    AclManager *            aclm;
440
    ImageManager *          imagem;
441

    
442
    // ---------------------------------------------------------------
443
    // Implementation functions
444
    // ---------------------------------------------------------------
445

    
446
    friend void nebula_signal_handler (int sig);
447

    
448
    /**
449
     *  Bootstraps the database control tables
450
     */
451
    void bootstrap();
452

    
453
    /**
454
     *  Callback function to TODO
455
     *    @param _loaded_db_version TODO
456
     *    @param num the number of columns read from the DB
457
     *    @param names the column names
458
     *    @param vaues the column values
459
     *    @return 0 on success
460
     */
461
    int select_cb(void *_loaded_db_version, int num, char **values,
462
                  char **names);
463

    
464
    /*
465
     *  TODO
466
     *    @return 0 ok, -1 version mismatch, -2 needs bootstrap
467
     */
468
    int check_db_version();
469
};
470

    
471
#endif /*NEBULA_H_*/