2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2012-01-12 15:29:18 +04:00
/* Copyright 2002-2012, OpenNebula Project Leads (OpenNebula.org) */
2008-06-17 20:27:32 +04:00
/* */
/* 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 NEBULA_H_
# define NEBULA_H_
2010-04-11 00:19:49 +04:00
# include "SqlDB.h"
2008-06-17 20:27:32 +04:00
# include "NebulaTemplate.h"
# include "VirtualMachinePool.h"
2008-11-13 19:21:17 +03:00
# include "VirtualNetworkPool.h"
2008-06-17 20:27:32 +04:00
# include "HostPool.h"
2009-07-09 18:34:34 +04:00
# include "UserPool.h"
2011-03-30 21:03:49 +04:00
# include "VMTemplatePool.h"
2011-05-10 20:45:15 +04:00
# include "GroupPool.h"
2012-02-09 20:56:47 +04:00
# include "DatastorePool.h"
2012-02-24 18:53:53 +04:00
# include "ClusterPool.h"
2008-06-17 20:27:32 +04:00
# include "VirtualMachineManager.h"
# include "LifeCycleManager.h"
# include "InformationManager.h"
# include "TransferManager.h"
# include "DispatchManager.h"
# include "RequestManager.h"
2009-04-04 03:34:33 +04:00
# include "HookManager.h"
2010-07-08 21:28:10 +04:00
# include "AuthManager.h"
2011-06-22 21:22:52 +04:00
# include "AclManager.h"
2011-03-22 20:21:09 +03:00
# include "ImageManager.h"
2008-06-17 20:27:32 +04:00
2011-04-29 20:59:39 +04:00
# include "Callbackable.h"
class Nebula : public Callbackable
2008-06-17 20:27:32 +04:00
{
public :
2010-04-11 00:19:49 +04:00
static Nebula & instance ( )
2008-06-17 20:27:32 +04:00
{
static Nebula nebulad ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
return nebulad ;
} ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
// --------------------------------------------------------------
// Pool Accessors
2010-04-11 00:19:49 +04:00
// --------------------------------------------------------------
2008-06-17 20:27:32 +04:00
VirtualMachinePool * get_vmpool ( )
{
return vmpool ;
2010-04-11 00:19:49 +04:00
} ;
2008-06-17 20:27:32 +04:00
HostPool * get_hpool ( )
{
return hpool ;
2010-04-11 00:19:49 +04:00
} ;
2008-11-13 19:21:17 +03:00
VirtualNetworkPool * get_vnpool ( )
{
return vnpool ;
} ;
2010-04-11 00:19:49 +04:00
2009-07-09 18:34:34 +04:00
UserPool * get_upool ( )
{
return upool ;
} ;
2008-06-17 20:27:32 +04:00
2010-06-25 15:24:54 +04:00
ImagePool * get_ipool ( )
{
return ipool ;
} ;
2011-05-10 20:45:15 +04:00
GroupPool * get_gpool ( )
{
return gpool ;
} ;
2011-03-30 21:03:49 +04:00
VMTemplatePool * get_tpool ( )
{
return tpool ;
} ;
2012-02-09 20:56:47 +04:00
DatastorePool * get_dspool ( )
{
return dspool ;
} ;
2012-02-24 18:53:53 +04:00
ClusterPool * get_clpool ( )
{
return clpool ;
} ;
2008-06-17 20:27:32 +04:00
// --------------------------------------------------------------
// Manager Accessors
2010-04-11 00:19:49 +04:00
// --------------------------------------------------------------
2008-06-17 20:27:32 +04:00
VirtualMachineManager * get_vmm ( )
{
return vmm ;
} ;
LifeCycleManager * get_lcm ( )
{
return lcm ;
} ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
InformationManager * get_im ( )
{
return im ;
} ;
TransferManager * get_tm ( )
{
return tm ;
} ;
DispatchManager * get_dm ( )
{
return dm ;
} ;
2010-04-11 00:19:49 +04:00
2009-04-04 03:34:33 +04:00
HookManager * get_hm ( )
{
return hm ;
} ;
2010-04-11 00:19:49 +04:00
2010-07-08 21:28:10 +04:00
AuthManager * get_authm ( )
{
return authm ;
} ;
2011-03-22 20:21:09 +03:00
ImageManager * get_imagem ( )
{
return imagem ;
} ;
2011-06-22 21:22:52 +04:00
AclManager * get_aclm ( )
{
return aclm ;
} ;
2008-06-17 20:27:32 +04:00
// --------------------------------------------------------------
// Environment & Configuration
2009-01-02 17:58:51 +03:00
// --------------------------------------------------------------
2010-04-11 00:19:49 +04:00
2009-01-02 17:58:51 +03:00
/**
2010-04-11 00:19:49 +04:00
* Returns the value of ONE_LOCATION env variable . When this variable is
2009-01-02 17:58:51 +03:00
* not defined the nebula location is " / " .
* @ return the nebula location .
2010-04-11 00:19:49 +04:00
*/
2008-11-13 19:21:17 +03:00
const string & get_nebula_location ( )
2008-06-17 20:27:32 +04:00
{
return nebula_location ;
} ;
2009-01-02 17:58:51 +03:00
/**
2010-04-11 00:19:49 +04:00
* Returns the path where mad executables are stored , if ONE_LOCATION is
* defined this path points to $ ONE_LOCATION / bin , otherwise it is
2009-01-02 17:58:51 +03:00
* / usr / lib / one / mads .
* @ return the mad execs location .
*/
const string & get_mad_location ( )
{
return mad_location ;
} ;
/**
2010-04-11 00:19:49 +04:00
* Returns the path where defaults for mads are stored , if ONE_LOCATION is
2009-01-02 17:58:51 +03:00
* defined this path points to $ ONE_LOCATION / etc , otherwise it is / etc / one
* @ return the mad defaults location .
*/
const string & get_defaults_location ( )
{
return etc_location ;
} ;
2010-04-11 00:19:49 +04:00
2009-01-02 17:58:51 +03:00
/**
* Returns the path where logs ( oned . log , schedd . log , . . . ) are generated
2010-04-11 00:19:49 +04:00
* if ONE_LOCATION is defined this path points to $ ONE_LOCATION / var ,
2009-01-02 17:58:51 +03:00
* otherwise it is / var / log / one .
* @ return the log location .
*/
const string & get_log_location ( )
{
return log_location ;
} ;
/**
2012-02-25 02:13:22 +04:00
* Returns the default var location . When ONE_LOCATION is defined this path
* points to $ ONE_LOCATION / var , otherwise it is / var / lib / one .
2009-01-02 17:58:51 +03:00
* @ return the log location .
*/
const string & get_var_location ( )
{
return var_location ;
} ;
2010-04-11 00:19:49 +04:00
2012-02-25 02:13:22 +04:00
/**
* Returns the base for the system datastore ( for tmp VM images ) . When
* ONE_LOCATION is defined this path points to $ ONE_LOCATION / var / system_ds ,
* otherwise it is / var / lib / one / system_ds .
2012-02-26 02:31:44 +04:00
* @ return the system datastore pa location .
2012-02-25 02:13:22 +04:00
*/
string get_system_ds_path ( )
{
Datastore * ds ;
string system_ds_path ;
ds = dspool - > get ( DatastorePool : : SYSTEM_DS_ID , true ) ;
system_ds_path = ds - > get_base_path ( ) ;
ds - > unlock ( ) ;
return system_ds_path ;
} ;
2012-02-25 04:25:59 +04:00
/**
* Returns the Transfer Manager for the system datastore
2012-02-26 02:31:44 +04:00
* @ return the tm name .
2012-02-25 04:25:59 +04:00
*/
string get_system_ds_tm_mad ( )
{
Datastore * ds ;
string tm_mad ;
ds = dspool - > get ( DatastorePool : : SYSTEM_DS_ID , true ) ;
tm_mad = ds - > get_tm_mad ( ) ;
ds - > unlock ( ) ;
return tm_mad ;
} ;
2012-02-26 02:31:44 +04:00
/**
* Returns the name for the system datastore
* @ return the datastore name .
*/
string get_system_ds_name ( )
{
Datastore * ds ;
string name ;
ds = dspool - > get ( DatastorePool : : SYSTEM_DS_ID , true ) ;
name = ds - > get_name ( ) ;
ds - > unlock ( ) ;
return name ;
} ;
2009-01-02 17:58:51 +03:00
/**
* Returns the path of the log file for a VM , depending where OpenNebula is
* installed ,
* $ ONE_LOCATION / var / $ VM_ID / vm . log
* or
* / var / log / one / $ VM_ID . log
* @ return the log location for the VM .
*/
string get_vm_log_filename ( int oid )
{
ostringstream oss ;
2010-04-11 00:19:49 +04:00
2009-01-02 17:58:51 +03:00
if ( nebula_location = = " / " )
{
2010-04-11 00:19:49 +04:00
oss < < log_location < < oid < < " .log " ;
2009-01-02 17:58:51 +03:00
}
else
{
2010-04-11 00:19:49 +04:00
oss < < nebula_location < < " var/ " < < oid < < " /vm.log " ;
2009-01-02 17:58:51 +03:00
}
2010-04-11 00:19:49 +04:00
2009-01-02 17:58:51 +03:00
return oss . str ( ) ;
} ;
2010-04-11 00:19:49 +04:00
2008-11-13 19:21:17 +03:00
const string & get_nebula_hostname ( )
{
return hostname ;
} ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
static string version ( )
{
2012-01-12 15:29:18 +04:00
return " OpenNebula 3.2.0 " ;
2008-06-17 20:27:32 +04:00
} ;
2010-04-11 00:19:49 +04:00
2011-07-12 15:54:53 +04:00
static string db_version ( )
2011-04-29 20:59:39 +04:00
{
2012-01-12 15:29:18 +04:00
return " 3.2.0 " ;
2011-07-12 15:54:53 +04:00
}
2011-04-29 20:59:39 +04:00
2008-06-17 20:27:32 +04:00
void start ( ) ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
void get_configuration_attribute (
2010-04-11 00:19:49 +04:00
const char * name ,
2008-06-17 20:27:32 +04:00
string & value ) const
{
string _name ( name ) ;
2010-04-11 00:19:49 +04:00
nebula_configuration - > Template : : get ( _name , value ) ;
2008-06-17 20:27:32 +04:00
} ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
private :
2010-04-11 00:19:49 +04:00
// -----------------------------------------------------------------------
2008-06-17 20:27:32 +04:00
//Constructors and = are private to only access the class through instance
// -----------------------------------------------------------------------
2010-04-11 00:19:49 +04:00
2011-03-30 21:03:49 +04:00
Nebula ( ) : nebula_configuration ( 0 ) , db ( 0 ) , vmpool ( 0 ) , hpool ( 0 ) , vnpool ( 0 ) ,
2012-02-24 18:53:53 +04:00
upool ( 0 ) , ipool ( 0 ) , gpool ( 0 ) , tpool ( 0 ) , dspool ( 0 ) , clpool ( 0 ) ,
lcm ( 0 ) , vmm ( 0 ) , im ( 0 ) , tm ( 0 ) , dm ( 0 ) , rm ( 0 ) , hm ( 0 ) , authm ( 0 ) , aclm ( 0 ) , imagem ( 0 )
2009-01-02 17:58:51 +03:00
{
2010-06-25 15:24:54 +04:00
const char * nl = getenv ( " ONE_LOCATION " ) ;
2009-01-02 17:58:51 +03:00
if ( nl = = 0 ) //OpenNebula installed under root directory
{
2010-06-25 15:24:54 +04:00
nebula_location = " / " ;
2010-04-11 00:19:49 +04:00
2010-08-17 02:28:48 +04:00
mad_location = " /usr/lib/one/mads/ " ;
etc_location = " /etc/one/ " ;
log_location = " /var/log/one/ " ;
var_location = " /var/lib/one/ " ;
2010-11-16 14:29:14 +03:00
remotes_location = " /var/lib/one/remotes/ " ;
2009-01-02 17:58:51 +03:00
}
else
{
2010-06-25 15:24:54 +04:00
nebula_location = nl ;
2010-04-11 00:19:49 +04:00
2010-06-25 15:24:54 +04:00
if ( nebula_location . at ( nebula_location . size ( ) - 1 ) ! = ' / ' )
{
nebula_location + = " / " ;
}
2010-04-11 00:19:49 +04:00
2010-08-17 02:28:48 +04:00
mad_location = nebula_location + " lib/mads/ " ;
etc_location = nebula_location + " etc/ " ;
log_location = nebula_location + " var/ " ;
var_location = nebula_location + " var/ " ;
2010-11-16 14:29:14 +03:00
remotes_location = nebula_location + " var/remotes/ " ;
2010-04-11 00:19:49 +04:00
}
2009-01-02 17:58:51 +03:00
} ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
~ Nebula ( )
{
if ( vmpool ! = 0 )
{
delete vmpool ;
}
2008-11-13 23:12:52 +03:00
if ( vnpool ! = 0 )
{
delete vnpool ;
}
2008-06-17 20:27:32 +04:00
if ( hpool ! = 0 )
{
delete hpool ;
}
2009-07-09 18:34:34 +04:00
if ( upool ! = 0 )
{
delete upool ;
}
2010-06-25 15:24:54 +04:00
if ( ipool ! = 0 )
{
delete ipool ;
}
2011-05-10 20:45:15 +04:00
if ( gpool ! = 0 )
{
delete gpool ;
}
2011-03-30 21:03:49 +04:00
if ( tpool ! = 0 )
{
delete tpool ;
}
2012-02-10 04:18:46 +04:00
if ( dspool ! = 0 )
{
2012-02-10 16:24:52 +04:00
delete dspool ;
2012-02-10 04:18:46 +04:00
}
2012-02-24 18:53:53 +04:00
if ( clpool ! = 0 )
{
delete clpool ;
}
2012-02-10 04:18:46 +04:00
2008-06-17 20:27:32 +04:00
if ( vmm ! = 0 )
{
delete vmm ;
}
if ( lcm ! = 0 )
{
delete lcm ;
}
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
if ( im ! = 0 )
{
delete im ;
}
if ( tm ! = 0 )
{
delete tm ;
}
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
if ( dm ! = 0 )
{
delete dm ;
}
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
if ( rm ! = 0 )
{
delete rm ;
}
2010-04-11 00:19:49 +04:00
2009-04-05 02:07:06 +04:00
if ( hm ! = 0 )
{
delete hm ;
}
2010-04-11 00:19:49 +04:00
2010-07-08 21:28:10 +04:00
if ( authm ! = 0 )
{
delete authm ;
}
2011-06-22 21:22:52 +04:00
if ( aclm ! = 0 )
{
delete aclm ;
}
2011-03-22 20:21:09 +03:00
if ( imagem ! = 0 )
{
delete imagem ;
}
2008-06-17 20:27:32 +04:00
if ( nebula_configuration ! = 0 )
{
delete nebula_configuration ;
}
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
if ( db ! = 0 )
{
delete db ;
}
} ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
Nebula ( Nebula const & ) { } ;
2010-04-11 00:19:49 +04:00
Nebula & operator = ( Nebula const & ) { return * this ; } ;
2008-06-17 20:27:32 +04:00
// ---------------------------------------------------------------
// Environment variables
// ---------------------------------------------------------------
2010-04-11 00:19:49 +04:00
2009-01-02 17:58:51 +03:00
string nebula_location ;
2010-04-11 00:19:49 +04:00
2009-01-02 17:58:51 +03:00
string mad_location ;
string etc_location ;
string log_location ;
string var_location ;
2010-08-02 13:24:01 +04:00
string hook_location ;
2010-08-17 02:28:48 +04:00
string remotes_location ;
2009-01-02 17:58:51 +03:00
string hostname ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
// ---------------------------------------------------------------
// Configuration
// ---------------------------------------------------------------
2011-12-14 02:57:56 +04:00
OpenNebulaTemplate * nebula_configuration ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
// ---------------------------------------------------------------
// Nebula Pools
// ---------------------------------------------------------------
2010-04-11 00:19:49 +04:00
SqlDB * db ;
2008-06-17 20:27:32 +04:00
VirtualMachinePool * vmpool ;
2008-11-13 19:21:17 +03:00
HostPool * hpool ;
VirtualNetworkPool * vnpool ;
2009-07-09 18:34:34 +04:00
UserPool * upool ;
2010-06-01 20:00:44 +04:00
ImagePool * ipool ;
2011-05-10 20:45:15 +04:00
GroupPool * gpool ;
2011-03-30 21:03:49 +04:00
VMTemplatePool * tpool ;
2012-02-09 20:56:47 +04:00
DatastorePool * dspool ;
2012-02-24 18:53:53 +04:00
ClusterPool * clpool ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
// ---------------------------------------------------------------
// Nebula Managers
// ---------------------------------------------------------------
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
LifeCycleManager * lcm ;
VirtualMachineManager * vmm ;
InformationManager * im ;
TransferManager * tm ;
DispatchManager * dm ;
RequestManager * rm ;
2009-04-04 03:34:33 +04:00
HookManager * hm ;
2010-07-08 21:28:10 +04:00
AuthManager * authm ;
2011-06-22 21:22:52 +04:00
AclManager * aclm ;
2011-03-22 20:21:09 +03:00
ImageManager * imagem ;
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
// ---------------------------------------------------------------
// Implementation functions
// ---------------------------------------------------------------
2010-04-11 00:19:49 +04:00
2008-06-17 20:27:32 +04:00
friend void nebula_signal_handler ( int sig ) ;
2011-04-29 20:59:39 +04:00
/**
* Bootstraps the database control tables
2011-10-10 17:14:46 +04:00
*
* @ return 0 on success
2011-04-29 20:59:39 +04:00
*/
2011-10-10 17:14:46 +04:00
int bootstrap ( ) ;
2011-04-29 20:59:39 +04:00
/**
2011-09-21 18:13:04 +04:00
* Callback function for the check_db_version method . Stores the read
* version in loaded_db_version
* @ param _loaded_db_version returned columns
2011-04-29 20:59:39 +04:00
* @ param num the number of columns read from the DB
* @ param names the column names
* @ param vaues the column values
* @ return 0 on success
*/
int select_cb ( void * _loaded_db_version , int num , char * * values ,
char * * names ) ;
2011-09-21 18:13:04 +04:00
/**
* Reads the current DB version .
*
* @ return 0 on success ,
* - 1 if there is a version mismatch ,
* - 2 if the DB needs a bootstrap
2011-04-29 20:59:39 +04:00
*/
int check_db_version ( ) ;
2008-06-17 20:27:32 +04:00
} ;
# endif /*NEBULA_H_*/