Statistics
| Branch: | Tag: | Revision:

one / include / Nebula.h @ ae53d437

History | View | Annotate | Download (10.3 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 "ImageManager.h"
40

    
41
class Nebula
42
{
43
public:
44

    
45
    static Nebula& instance()
46
    {
47
        static Nebula nebulad;
48

    
49
        return nebulad;
50
    };
51

    
52
    // --------------------------------------------------------------
53
    // Pool Accessors
54
    // --------------------------------------------------------------
55

    
56
    VirtualMachinePool * get_vmpool()
57
    {
58
        return vmpool;
59
    };
60

    
61
    HostPool * get_hpool()
62
    {
63
        return hpool;
64
    };
65

    
66
    VirtualNetworkPool * get_vnpool()
67
    {
68
        return vnpool;
69
    };
70

    
71
    UserPool * get_upool()
72
    {
73
        return upool;
74
    };
75

    
76
    ImagePool * get_ipool()
77
    {
78
        return ipool;
79
    };
80

    
81
    ClusterPool * get_cpool()
82
    {
83
        return cpool;
84
    };
85

    
86
    GroupPool * get_gpool()
87
    {
88
        return gpool;
89
    };
90

    
91
    VMTemplatePool * get_tpool()
92
    {
93
        return tpool;
94
    };
95

    
96
    // --------------------------------------------------------------
97
    // Manager Accessors
98
    // --------------------------------------------------------------
99

    
100
    VirtualMachineManager * get_vmm()
101
    {
102
        return vmm;
103
    };
104

    
105
    LifeCycleManager * get_lcm()
106
    {
107
        return lcm;
108
    };
109

    
110
        InformationManager * get_im()
111
    {
112
        return im;
113
    };
114

    
115
    TransferManager * get_tm()
116
    {
117
        return tm;
118
    };
119

    
120
    DispatchManager * get_dm()
121
    {
122
        return dm;
123
    };
124

    
125
    HookManager * get_hm()
126
    {
127
        return hm;
128
    };
129

    
130
    AuthManager * get_authm()
131
    {
132
        return authm;
133
    };
134

    
135
    ImageManager * get_imagem()
136
    {
137
        return imagem;
138
    };
139

    
140
    // --------------------------------------------------------------
141
    // Environment & Configuration
142
    // --------------------------------------------------------------
143

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

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

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

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

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

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

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

    
218
            return oss.str();
219
    };
220

    
221
    const string& get_nebula_hostname()
222
    {
223
        return hostname;
224
    };
225

    
226
    static string version()
227
    {
228
        return "OpenNebula 2.3.0";
229
    };
230

    
231
    void start();
232

    
233
    void get_configuration_attribute(
234
        const char * name,
235
        string& value) const
236
    {
237
        string _name(name);
238

    
239
        nebula_configuration->Template::get(_name,value);
240
    };
241

    
242
private:
243

    
244
    // -----------------------------------------------------------------------
245
    //Constructors and = are private to only access the class through instance
246
    // -----------------------------------------------------------------------
247

    
248
    Nebula():nebula_configuration(0),db(0),vmpool(0),hpool(0),vnpool(0),
249
        upool(0),ipool(0),cpool(0),gpool(0),tpool(0),lcm(0),vmm(0),im(0),tm(0),
250
        dm(0),rm(0),hm(0),authm(0),imagem(0)
251
    {
252
        const char * nl = getenv("ONE_LOCATION");
253

    
254
        if (nl == 0) //OpenNebula installed under root directory
255
        {
256
            nebula_location = "/";
257

    
258
            mad_location     = "/usr/lib/one/mads/";
259
            etc_location     = "/etc/one/";
260
            log_location     = "/var/log/one/";
261
            var_location     = "/var/lib/one/";
262
            hook_location    = "/usr/share/one/hooks/";
263
            remotes_location = "/var/lib/one/remotes/";
264
        }
265
        else
266
        {
267
            nebula_location = nl;
268

    
269
            if ( nebula_location.at(nebula_location.size()-1) != '/' )
270
            {
271
                nebula_location += "/";
272
            }
273

    
274
            mad_location     = nebula_location + "lib/mads/";
275
            etc_location     = nebula_location + "etc/";
276
            log_location     = nebula_location + "var/";
277
            var_location     = nebula_location + "var/";
278
            hook_location    = nebula_location + "share/hooks/";
279
            remotes_location = nebula_location + "var/remotes/";
280
        }
281
    };
282

    
283
    ~Nebula()
284
    {
285
        if ( vmpool != 0)
286
        {
287
            delete vmpool;
288
        }
289

    
290
        if ( vnpool != 0)
291
        {
292
            delete vnpool;
293
        }
294

    
295
        if ( hpool != 0)
296
        {
297
            delete hpool;
298
        }
299

    
300
        if ( upool != 0)
301
        {
302
            delete upool;
303
        }
304

    
305
        if ( ipool != 0)
306
        {
307
            delete ipool;
308
        }
309

    
310
        if ( cpool != 0)
311
        {
312
            delete cpool;
313
        }
314

    
315
        if ( gpool != 0)
316
        {
317
            delete gpool;
318
        }
319

    
320
        if ( tpool != 0)
321
        {
322
            delete tpool;
323
        }
324

    
325
        if ( vmm != 0)
326
        {
327
            delete vmm;
328
        }
329

    
330
        if ( lcm != 0)
331
        {
332
            delete lcm;
333
        }
334

    
335
        if ( im != 0)
336
        {
337
            delete im;
338
        }
339

    
340
        if ( tm != 0)
341
        {
342
            delete tm;
343
        }
344

    
345
        if ( dm != 0)
346
        {
347
            delete dm;
348
        }
349

    
350
        if ( rm != 0)
351
        {
352
            delete rm;
353
        }
354

    
355
        if ( hm != 0)
356
        {
357
            delete hm;
358
        }
359

    
360
        if ( authm != 0)
361
        {
362
            delete authm;
363
        }
364

    
365
        if ( imagem != 0)
366
        {
367
            delete imagem;
368
        }
369

    
370
        if ( nebula_configuration != 0)
371
        {
372
            delete nebula_configuration;
373
        }
374

    
375
        if ( db != 0 )
376
        {
377
            delete db;
378
        }
379
    };
380

    
381
    Nebula(Nebula const&){};
382

    
383
    Nebula& operator=(Nebula const&){return *this;};
384

    
385
    // ---------------------------------------------------------------
386
    // Environment variables
387
    // ---------------------------------------------------------------
388

    
389
    string  nebula_location;
390

    
391
    string        mad_location;
392
    string        etc_location;
393
    string        log_location;
394
    string        var_location;
395
    string  hook_location;
396
    string  remotes_location;
397

    
398
    string        hostname;
399

    
400
    // ---------------------------------------------------------------
401
    // Configuration
402
    // ---------------------------------------------------------------
403

    
404
    NebulaTemplate *    nebula_configuration;
405

    
406
    // ---------------------------------------------------------------
407
    // Nebula Pools
408
    // ---------------------------------------------------------------
409

    
410
    SqlDB              * db;
411
    VirtualMachinePool * vmpool;
412
    HostPool           * hpool;
413
    VirtualNetworkPool * vnpool;
414
    UserPool           * upool;
415
    ImagePool          * ipool;
416
    ClusterPool        * cpool;
417
    GroupPool          * gpool;
418
    VMTemplatePool     * tpool;
419

    
420
    // ---------------------------------------------------------------
421
    // Nebula Managers
422
    // ---------------------------------------------------------------
423

    
424
    LifeCycleManager *      lcm;
425
    VirtualMachineManager * vmm;
426
    InformationManager *    im;
427
    TransferManager *       tm;
428
    DispatchManager *       dm;
429
    RequestManager *        rm;
430
    HookManager *           hm;
431
    AuthManager *           authm;
432
    ImageManager *          imagem;
433

    
434
    // ---------------------------------------------------------------
435
    // Implementation functions
436
    // ---------------------------------------------------------------
437

    
438
    friend void nebula_signal_handler (int sig);
439
};
440

    
441
#endif /*NEBULA_H_*/