2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
2016-05-04 13:33:23 +03:00
/* Copyright 2002-2016, OpenNebula Project, OpenNebula Systems */
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 VIRTUAL_MACHINE_H_
# define VIRTUAL_MACHINE_H_
# include "VirtualMachineTemplate.h"
2015-06-23 22:52:10 +03:00
# include "VirtualMachineMonitorInfo.h"
2008-06-17 20:27:32 +04:00
# include "PoolSQL.h"
# include "History.h"
2012-12-05 02:19:08 +04:00
# include "Image.h"
2008-06-17 20:27:32 +04:00
# include "Log.h"
2010-05-25 20:19:22 +04:00
# include "NebulaLog.h"
2013-05-18 03:04:40 +04:00
# include "NebulaUtil.h"
2015-06-17 18:45:37 +03:00
# include "Quotas.h"
2008-06-17 20:27:32 +04:00
# include <time.h>
2012-06-15 14:28:20 +04:00
# include <set>
2008-06-17 20:27:32 +04:00
# include <sstream>
using namespace std ;
2011-06-01 14:41:46 +04:00
class AuthRequest ;
2015-05-19 19:41:23 +03:00
class Snapshots ;
2011-06-01 14:41:46 +04:00
2008-06-17 20:27:32 +04:00
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
/**
* The Virtual Machine class . It represents a VM . . .
*/
class VirtualMachine : public PoolObjectSQL
{
public :
2008-06-22 05:51:49 +04:00
// -------------------------------------------------------------------------
2010-12-31 19:00:26 +03:00
// VM States
2009-03-06 15:10:15 +03:00
// -------------------------------------------------------------------------
2008-06-17 20:27:32 +04:00
/**
* Global Virtual Machine state
*/
enum VmState
{
2016-04-22 17:06:43 +03:00
INIT = 0 ,
PENDING = 1 ,
HOLD = 2 ,
ACTIVE = 3 ,
STOPPED = 4 ,
SUSPENDED = 5 ,
DONE = 6 ,
//FAILED = 7,
POWEROFF = 8 ,
UNDEPLOYED = 9 ,
CLONING = 10 ,
CLONING_FAILURE = 11
2008-06-17 20:27:32 +04:00
} ;
2013-05-18 03:04:40 +04:00
static int vm_state_from_str ( string & st , VmState & state )
{
one_util : : toupper ( st ) ;
if ( st = = " INIT " ) { state = INIT ; }
else if ( st = = " PENDING " ) { state = PENDING ; }
else if ( st = = " HOLD " ) { state = HOLD ; }
else if ( st = = " ACTIVE " ) { state = ACTIVE ; }
else if ( st = = " STOPPED " ) { state = STOPPED ; }
else if ( st = = " SUSPENDED " ) { state = SUSPENDED ; }
else if ( st = = " DONE " ) { state = DONE ; }
else if ( st = = " POWEROFF " ) { state = POWEROFF ; }
else if ( st = = " UNDEPLOYED " ) { state = UNDEPLOYED ; }
2016-04-18 18:44:47 +03:00
else if ( st = = " CLONING " ) { state = CLONING ; }
2016-04-22 17:06:43 +03:00
else if ( st = = " CLONING_FAILURE " ) { state = CLONING_FAILURE ; }
2013-05-18 03:04:40 +04:00
else { return - 1 ; }
return 0 ;
}
static string & vm_state_to_str ( string & st , VmState state )
{
switch ( state )
{
2016-04-22 17:06:43 +03:00
case INIT : st = " INIT " ; break ;
case PENDING : st = " PENDING " ; break ;
case HOLD : st = " HOLD " ; break ;
case ACTIVE : st = " ACTIVE " ; break ;
case STOPPED : st = " STOPPED " ; break ;
case SUSPENDED : st = " SUSPENDED " ; break ;
case DONE : st = " DONE " ; break ;
case POWEROFF : st = " POWEROFF " ; break ;
case UNDEPLOYED : st = " UNDEPLOYED " ; break ;
case CLONING : st = " CLONING " ; break ;
case CLONING_FAILURE : st = " CLONING_FAILURE " ; break ;
2013-05-18 03:04:40 +04:00
}
return st ;
}
2008-06-17 20:27:32 +04:00
/**
2009-03-06 15:10:15 +03:00
* Virtual Machine state associated to the Life - cycle Manager
2008-06-17 20:27:32 +04:00
*/
enum LcmState
{
2012-10-16 16:59:16 +04:00
LCM_INIT = 0 ,
PROLOG = 1 ,
BOOT = 2 ,
RUNNING = 3 ,
MIGRATE = 4 ,
SAVE_STOP = 5 ,
SAVE_SUSPEND = 6 ,
SAVE_MIGRATE = 7 ,
PROLOG_MIGRATE = 8 ,
PROLOG_RESUME = 9 ,
EPILOG_STOP = 10 ,
EPILOG = 11 ,
SHUTDOWN = 12 ,
2015-04-26 17:47:00 +03:00
//CANCEL = 13,
2015-04-21 15:00:52 +03:00
//FAILURE = 14,
2013-01-21 15:27:18 +04:00
CLEANUP_RESUBMIT = 15 ,
2012-10-16 16:59:16 +04:00
UNKNOWN = 16 ,
HOTPLUG = 17 ,
SHUTDOWN_POWEROFF = 18 ,
2012-10-16 17:32:06 +04:00
BOOT_UNKNOWN = 19 ,
2012-10-17 14:34:32 +04:00
BOOT_POWEROFF = 20 ,
2012-10-17 17:40:02 +04:00
BOOT_SUSPENDED = 21 ,
2013-01-21 15:27:18 +04:00
BOOT_STOPPED = 22 ,
2013-02-28 05:49:56 +04:00
CLEANUP_DELETE = 23 ,
2013-03-06 21:33:18 +04:00
HOTPLUG_SNAPSHOT = 24 ,
2013-03-08 02:40:01 +04:00
HOTPLUG_NIC = 25 ,
HOTPLUG_SAVEAS = 26 ,
HOTPLUG_SAVEAS_POWEROFF = 27 ,
2013-03-27 21:15:53 +04:00
HOTPLUG_SAVEAS_SUSPENDED = 28 ,
2013-04-03 02:28:06 +04:00
SHUTDOWN_UNDEPLOY = 29 ,
2013-04-02 19:01:22 +04:00
EPILOG_UNDEPLOY = 30 ,
2013-04-04 19:29:16 +04:00
PROLOG_UNDEPLOY = 31 ,
2015-03-20 19:53:55 +03:00
BOOT_UNDEPLOY = 32 ,
2015-03-18 14:51:01 +03:00
HOTPLUG_PROLOG_POWEROFF = 33 ,
2015-03-23 14:08:36 +03:00
HOTPLUG_EPILOG_POWEROFF = 34 ,
2015-03-24 15:35:21 +03:00
BOOT_MIGRATE = 35 ,
BOOT_FAILURE = 36 ,
BOOT_MIGRATE_FAILURE = 37 ,
2015-03-24 17:36:30 +03:00
PROLOG_MIGRATE_FAILURE = 38 ,
2015-03-25 16:35:15 +03:00
PROLOG_FAILURE = 39 ,
EPILOG_FAILURE = 40 ,
EPILOG_STOP_FAILURE = 41 ,
2015-03-26 18:58:51 +03:00
EPILOG_UNDEPLOY_FAILURE = 42 ,
PROLOG_MIGRATE_POWEROFF = 43 ,
2015-03-26 20:51:13 +03:00
PROLOG_MIGRATE_POWEROFF_FAILURE = 44 ,
PROLOG_MIGRATE_SUSPEND = 45 ,
2015-04-28 12:44:56 +03:00
PROLOG_MIGRATE_SUSPEND_FAILURE = 46 ,
BOOT_UNDEPLOY_FAILURE = 47 ,
2015-05-08 14:47:48 +03:00
BOOT_STOPPED_FAILURE = 48 ,
PROLOG_RESUME_FAILURE = 49 ,
2015-05-20 01:21:26 +03:00
PROLOG_UNDEPLOY_FAILURE = 50 ,
2015-06-30 12:26:05 +03:00
DISK_SNAPSHOT_POWEROFF = 51 ,
DISK_SNAPSHOT_REVERT_POWEROFF = 52 ,
DISK_SNAPSHOT_DELETE_POWEROFF = 53 ,
DISK_SNAPSHOT_SUSPENDED = 54 ,
2015-06-25 16:35:48 +03:00
DISK_SNAPSHOT_REVERT_SUSPENDED = 55 ,
2015-06-30 12:26:05 +03:00
DISK_SNAPSHOT_DELETE_SUSPENDED = 56 ,
DISK_SNAPSHOT = 57 ,
2016-03-23 01:07:35 +03:00
//DISK_SNAPSHOT_REVERT = 58,
2015-08-31 15:10:53 +03:00
DISK_SNAPSHOT_DELETE = 59 ,
PROLOG_MIGRATE_UNKNOWN = 60 ,
PROLOG_MIGRATE_UNKNOWN_FAILURE = 61
2008-06-17 20:27:32 +04:00
} ;
2013-05-18 03:04:40 +04:00
static int lcm_state_from_str ( string & st , LcmState & state )
{
one_util : : toupper ( st ) ;
if ( st = = " LCM_INIT " ) { state = LCM_INIT ; }
else if ( st = = " PROLOG " ) { state = PROLOG ; }
else if ( st = = " BOOT " ) { state = BOOT ; }
else if ( st = = " RUNNING " ) { state = RUNNING ; }
else if ( st = = " MIGRATE " ) { state = MIGRATE ; }
else if ( st = = " SAVE_STOP " ) { state = SAVE_STOP ; }
else if ( st = = " SAVE_SUSPEND " ) { state = SAVE_SUSPEND ; }
else if ( st = = " SAVE_MIGRATE " ) { state = SAVE_MIGRATE ; }
else if ( st = = " PROLOG_MIGRATE " ) { state = PROLOG_MIGRATE ; }
else if ( st = = " PROLOG_RESUME " ) { state = PROLOG_RESUME ; }
else if ( st = = " EPILOG_STOP " ) { state = EPILOG_STOP ; }
else if ( st = = " EPILOG " ) { state = EPILOG ; }
else if ( st = = " SHUTDOWN " ) { state = SHUTDOWN ; }
else if ( st = = " CLEANUP_RESUBMIT " ) { state = CLEANUP_RESUBMIT ; }
else if ( st = = " UNKNOWN " ) { state = UNKNOWN ; }
else if ( st = = " HOTPLUG " ) { state = HOTPLUG ; }
else if ( st = = " SHUTDOWN_POWEROFF " ) { state = SHUTDOWN_POWEROFF ; }
else if ( st = = " BOOT_UNKNOWN " ) { state = BOOT_UNKNOWN ; }
else if ( st = = " BOOT_POWEROFF " ) { state = BOOT_POWEROFF ; }
else if ( st = = " BOOT_SUSPENDED " ) { state = BOOT_SUSPENDED ; }
else if ( st = = " BOOT_STOPPED " ) { state = BOOT_STOPPED ; }
else if ( st = = " CLEANUP_DELETE " ) { state = CLEANUP_DELETE ; }
else if ( st = = " HOTPLUG_SNAPSHOT " ) { state = HOTPLUG_SNAPSHOT ; }
else if ( st = = " HOTPLUG_NIC " ) { state = HOTPLUG_NIC ; }
else if ( st = = " HOTPLUG_SAVEAS " ) { state = HOTPLUG_SAVEAS ; }
else if ( st = = " HOTPLUG_SAVEAS_POWEROFF " ) { state = HOTPLUG_SAVEAS_POWEROFF ; }
else if ( st = = " HOTPLUG_SAVEAS_SUSPENDED " ) { state = HOTPLUG_SAVEAS_SUSPENDED ; }
else if ( st = = " SHUTDOWN_UNDEPLOY " ) { state = SHUTDOWN_UNDEPLOY ; }
else if ( st = = " EPILOG_UNDEPLOY " ) { state = EPILOG_UNDEPLOY ; }
else if ( st = = " PROLOG_UNDEPLOY " ) { state = PROLOG_UNDEPLOY ; }
else if ( st = = " BOOT_UNDEPLOY " ) { state = BOOT_UNDEPLOY ; }
2015-03-18 14:51:01 +03:00
else if ( st = = " HOTPLUG_PROLOG_POWEROFF " ) { state = HOTPLUG_PROLOG_POWEROFF ; }
else if ( st = = " HOTPLUG_EPILOG_POWEROFF " ) { state = HOTPLUG_EPILOG_POWEROFF ; }
2015-03-20 19:53:55 +03:00
else if ( st = = " BOOT_MIGRATE " ) { state = BOOT_MIGRATE ; }
else if ( st = = " BOOT_FAILURE " ) { state = BOOT_FAILURE ; }
else if ( st = = " BOOT_MIGRATE_FAILURE " ) { state = BOOT_MIGRATE_FAILURE ; }
2015-03-24 15:35:21 +03:00
else if ( st = = " PROLOG_MIGRATE_FAILURE " ) { state = PROLOG_MIGRATE_FAILURE ; }
2015-03-24 17:36:30 +03:00
else if ( st = = " PROLOG_FAILURE " ) { state = PROLOG_FAILURE ; }
2015-03-25 16:35:15 +03:00
else if ( st = = " EPILOG_FAILURE " ) { state = EPILOG_FAILURE ; }
else if ( st = = " EPILOG_STOP_FAILURE " ) { state = EPILOG_STOP_FAILURE ; }
else if ( st = = " EPILOG_UNDEPLOY_FAILURE " ) { state = EPILOG_UNDEPLOY_FAILURE ; }
2015-03-26 18:58:51 +03:00
else if ( st = = " PROLOG_MIGRATE_POWEROFF " ) { state = PROLOG_MIGRATE_POWEROFF ; }
else if ( st = = " PROLOG_MIGRATE_POWEROFF_FAILURE " ) { state = PROLOG_MIGRATE_POWEROFF_FAILURE ; }
2015-03-26 20:51:13 +03:00
else if ( st = = " PROLOG_MIGRATE_SUSPEND " ) { state = PROLOG_MIGRATE_SUSPEND ; }
else if ( st = = " PROLOG_MIGRATE_SUSPEND_FAILURE " ) { state = PROLOG_MIGRATE_SUSPEND_FAILURE ; }
2015-04-28 12:44:56 +03:00
else if ( st = = " BOOT_STOPPED_FAILURE " ) { state = BOOT_STOPPED_FAILURE ; }
else if ( st = = " BOOT_UNDEPLOY_FAILURE " ) { state = BOOT_UNDEPLOY_FAILURE ; }
2015-05-08 14:47:48 +03:00
else if ( st = = " PROLOG_RESUME_FAILURE " ) { state = PROLOG_RESUME_FAILURE ; }
else if ( st = = " PROLOG_UNDEPLOY_FAILURE " ) { state = PROLOG_UNDEPLOY_FAILURE ; }
2015-05-20 01:21:26 +03:00
else if ( st = = " DISK_SNAPSHOT_POWEROFF " ) { state = DISK_SNAPSHOT_POWEROFF ; }
2015-05-26 12:24:34 +03:00
else if ( st = = " DISK_SNAPSHOT_REVERT_POWEROFF " ) { state = DISK_SNAPSHOT_REVERT_POWEROFF ; }
2015-05-27 17:29:41 +03:00
else if ( st = = " DISK_SNAPSHOT_DELETE_POWEROFF " ) { state = DISK_SNAPSHOT_DELETE_POWEROFF ; }
2015-06-25 16:35:48 +03:00
else if ( st = = " DISK_SNAPSHOT_SUSPENDED " ) { state = DISK_SNAPSHOT_SUSPENDED ; }
else if ( st = = " DISK_SNAPSHOT_REVERT_SUSPENDED " ) { state = DISK_SNAPSHOT_REVERT_SUSPENDED ; }
else if ( st = = " DISK_SNAPSHOT_DELETE_SUSPENDED " ) { state = DISK_SNAPSHOT_DELETE_SUSPENDED ; }
2015-06-30 12:26:05 +03:00
else if ( st = = " DISK_SNAPSHOT " ) { state = DISK_SNAPSHOT ; }
else if ( st = = " DISK_SNAPSHOT_DELETE " ) { state = DISK_SNAPSHOT_DELETE ; }
2015-08-31 15:10:53 +03:00
else if ( st = = " PROLOG_MIGRATE_UNKNOWN " ) { state = PROLOG_MIGRATE_UNKNOWN ; }
else if ( st = = " PROLOG_MIGRATE_UNKNOWN_FAILURE " ) { state = PROLOG_MIGRATE_UNKNOWN_FAILURE ; }
2013-05-18 03:04:40 +04:00
else { return - 1 ; }
return 0 ;
}
2015-04-22 18:32:55 +03:00
static string & lcm_state_to_str ( string & st , LcmState state )
2013-05-18 03:04:40 +04:00
{
switch ( state )
{
case LCM_INIT : st = " LCM_INIT " ; break ;
case PROLOG : st = " PROLOG " ; break ;
case BOOT : st = " BOOT " ; break ;
case RUNNING : st = " RUNNING " ; break ;
case MIGRATE : st = " MIGRATE " ; break ;
case SAVE_STOP : st = " SAVE_STOP " ; break ;
case SAVE_SUSPEND : st = " SAVE_SUSPEND " ; break ;
case SAVE_MIGRATE : st = " SAVE_MIGRATE " ; break ;
case PROLOG_MIGRATE : st = " PROLOG_MIGRATE " ; break ;
case PROLOG_RESUME : st = " PROLOG_RESUME " ; break ;
case EPILOG_STOP : st = " EPILOG_STOP " ; break ;
case EPILOG : st = " EPILOG " ; break ;
case SHUTDOWN : st = " SHUTDOWN " ; break ;
case CLEANUP_RESUBMIT : st = " CLEANUP_RESUBMIT " ; break ;
case UNKNOWN : st = " UNKNOWN " ; break ;
case HOTPLUG : st = " HOTPLUG " ; break ;
case SHUTDOWN_POWEROFF : st = " SHUTDOWN_POWEROFF " ; break ;
case BOOT_UNKNOWN : st = " BOOT_UNKNOWN " ; break ;
case BOOT_POWEROFF : st = " BOOT_POWEROFF " ; break ;
case BOOT_SUSPENDED : st = " BOOT_SUSPENDED " ; break ;
case BOOT_STOPPED : st = " BOOT_STOPPED " ; break ;
case CLEANUP_DELETE : st = " CLEANUP_DELETE " ; break ;
case HOTPLUG_SNAPSHOT : st = " HOTPLUG_SNAPSHOT " ; break ;
case HOTPLUG_NIC : st = " HOTPLUG_NIC " ; break ;
case HOTPLUG_SAVEAS : st = " HOTPLUG_SAVEAS " ; break ;
case HOTPLUG_SAVEAS_POWEROFF : st = " HOTPLUG_SAVEAS_POWEROFF " ; break ;
case HOTPLUG_SAVEAS_SUSPENDED : st = " HOTPLUG_SAVEAS_SUSPENDED " ; break ;
case SHUTDOWN_UNDEPLOY : st = " SHUTDOWN_UNDEPLOY " ; break ;
case EPILOG_UNDEPLOY : st = " EPILOG_UNDEPLOY " ; break ;
case PROLOG_UNDEPLOY : st = " PROLOG_UNDEPLOY " ; break ;
case BOOT_UNDEPLOY : st = " BOOT_UNDEPLOY " ; break ;
2015-03-18 14:51:01 +03:00
case HOTPLUG_PROLOG_POWEROFF : st = " HOTPLUG_PROLOG_POWEROFF " ; break ;
case HOTPLUG_EPILOG_POWEROFF : st = " HOTPLUG_EPILOG_POWEROFF " ; break ;
2015-03-20 19:53:55 +03:00
case BOOT_MIGRATE : st = " BOOT_MIGRATE " ; break ;
case BOOT_FAILURE : st = " BOOT_FAILURE " ; break ;
case BOOT_MIGRATE_FAILURE : st = " BOOT_MIGRATE_FAILURE " ; break ;
2015-03-24 15:35:21 +03:00
case PROLOG_MIGRATE_FAILURE : st = " PROLOG_MIGRATE_FAILURE " ; break ;
2015-03-24 17:36:30 +03:00
case PROLOG_FAILURE : st = " PROLOG_FAILURE " ; break ;
2015-03-25 16:35:15 +03:00
case EPILOG_FAILURE : st = " EPILOG_FAILURE " ; break ;
case EPILOG_STOP_FAILURE : st = " EPILOG_STOP_FAILURE " ; break ;
case EPILOG_UNDEPLOY_FAILURE : st = " EPILOG_UNDEPLOY_FAILURE " ; break ;
2015-03-26 18:58:51 +03:00
case PROLOG_MIGRATE_POWEROFF : st = " PROLOG_MIGRATE_POWEROFF " ; break ;
case PROLOG_MIGRATE_POWEROFF_FAILURE : st = " PROLOG_MIGRATE_POWEROFF_FAILURE " ; break ;
2015-03-26 20:51:13 +03:00
case PROLOG_MIGRATE_SUSPEND : st = " PROLOG_MIGRATE_SUSPEND " ; break ;
case PROLOG_MIGRATE_SUSPEND_FAILURE : st = " PROLOG_MIGRATE_SUSPEND_FAILURE " ; break ;
2015-04-28 12:44:56 +03:00
case BOOT_STOPPED_FAILURE : st = " BOOT_STOPPED_FAILURE " ; break ;
case BOOT_UNDEPLOY_FAILURE : st = " BOOT_UNDEPLOY_FAILURE " ; break ;
2015-05-08 14:47:48 +03:00
case PROLOG_RESUME_FAILURE : st = " PROLOG_RESUME_FAILURE " ; break ;
case PROLOG_UNDEPLOY_FAILURE : st = " PROLOG_UNDEPLOY_FAILURE " ; break ;
2015-05-20 01:21:26 +03:00
case DISK_SNAPSHOT_POWEROFF : st = " DISK_SNAPSHOT_POWEROFF " ; break ;
2015-05-26 12:24:34 +03:00
case DISK_SNAPSHOT_REVERT_POWEROFF : st = " DISK_SNAPSHOT_REVERT_POWEROFF " ; break ;
2015-05-27 17:29:41 +03:00
case DISK_SNAPSHOT_DELETE_POWEROFF : st = " DISK_SNAPSHOT_DELETE_POWEROFF " ; break ;
2015-06-25 16:35:48 +03:00
case DISK_SNAPSHOT_SUSPENDED : st = " DISK_SNAPSHOT_SUSPENDED " ; break ;
case DISK_SNAPSHOT_REVERT_SUSPENDED : st = " DISK_SNAPSHOT_REVERT_SUSPENDED " ; break ;
case DISK_SNAPSHOT_DELETE_SUSPENDED : st = " DISK_SNAPSHOT_DELETE_SUSPENDED " ; break ;
2015-06-30 12:26:05 +03:00
case DISK_SNAPSHOT : st = " DISK_SNAPSHOT " ; break ;
case DISK_SNAPSHOT_DELETE : st = " DISK_SNAPSHOT_DELETE " ; break ;
2015-08-31 15:10:53 +03:00
case PROLOG_MIGRATE_UNKNOWN : st = " PROLOG_MIGRATE_UNKNOWN " ; break ;
case PROLOG_MIGRATE_UNKNOWN_FAILURE : st = " PROLOG_MIGRATE_UNKNOWN_FAILURE " ; break ;
2013-05-18 03:04:40 +04:00
}
return st ;
}
2015-03-30 18:41:22 +03:00
/**
* Returns the VM state to string , using the lcm state if the current state
* is ACTIVE .
* @ return the state sting
*/
string state_str ( )
{
2015-07-01 22:15:40 +03:00
string st ;
2015-03-30 18:41:22 +03:00
if ( state = = ACTIVE )
{
return lcm_state_to_str ( st , lcm_state ) ;
}
return vm_state_to_str ( st , state ) ;
}
2008-06-22 05:51:49 +04:00
// -------------------------------------------------------------------------
2008-06-17 20:27:32 +04:00
// Log & Print
2009-03-06 15:10:15 +03:00
// -------------------------------------------------------------------------
2008-06-17 20:27:32 +04:00
/**
* writes a log message in vm . log . The class lock should be locked and
2009-03-06 15:10:15 +03:00
* the VM MUST BE obtained through the VirtualMachinePool get ( ) method .
2008-06-17 20:27:32 +04:00
*/
void log (
const char * module ,
const Log : : MessageType type ,
const ostringstream & message ) const
{
if ( _log ! = 0 )
{
2010-04-21 02:40:16 +04:00
_log - > log ( module , type , message . str ( ) . c_str ( ) ) ;
2008-06-17 20:27:32 +04:00
}
} ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
* writes a log message in vm . log . The class lock should be locked and
2009-03-06 15:10:15 +03:00
* the VM MUST BE obtained through the VirtualMachinePool get ( ) method .
2008-06-17 20:27:32 +04:00
*/
void log (
const char * module ,
const Log : : MessageType type ,
2009-03-06 15:10:15 +03:00
const char * message ) const
2008-06-17 20:27:32 +04:00
{
if ( _log ! = 0 )
{
_log - > log ( module , type , message ) ;
}
} ;
2009-03-06 15:10:15 +03:00
2015-03-30 12:17:36 +03:00
/**
* writes a log message in vm . log . The class lock should be locked and
* the VM MUST BE obtained through the VirtualMachinePool get ( ) method .
*/
void log (
const char * module ,
const Log : : MessageType type ,
const string & message ) const
{
log ( module , type , message . c_str ( ) ) ;
} ;
2010-04-21 02:40:16 +04:00
/**
* Function to print the VirtualMachine object into a string in
* XML format
* @ param xml the resulting XML string
* @ return a reference to the generated string
*/
2012-05-11 21:15:25 +04:00
string & to_xml ( string & xml ) const
{
return to_xml_extended ( xml , 1 ) ;
}
2010-04-11 00:16:47 +04:00
2011-06-25 03:29:44 +04:00
/**
* Function to print the VirtualMachine object into a string in
* XML format , with extended information ( full history records )
* @ param xml the resulting XML string
* @ return a reference to the generated string
*/
2012-05-11 21:15:25 +04:00
string & to_xml_extended ( string & xml ) const
{
return to_xml_extended ( xml , 2 ) ;
}
2011-06-25 03:29:44 +04:00
2011-03-01 19:47:20 +03:00
/**
* Rebuilds the object from an xml formatted string
* @ param xml_str The xml - formatted string
*
* @ return 0 on success , - 1 otherwise
*/
int from_xml ( const string & xml_str ) ;
2008-06-17 20:27:32 +04:00
// ------------------------------------------------------------------------
// Dynamic Info
2009-03-06 15:10:15 +03:00
// ------------------------------------------------------------------------
2008-06-17 20:27:32 +04:00
/**
* Updates VM dynamic information ( id ) .
* @ param _deploy_id the VMM driver specific id
*/
2015-06-23 22:52:10 +03:00
void set_deploy_id ( const string & _deploy_id )
2008-06-17 20:27:32 +04:00
{
deploy_id = _deploy_id ;
} ;
/**
2015-04-28 12:44:56 +03:00
* Updates VM dynamic information ( usage counters ) , and updates last_poll ,
* and copies it to history record for acct .
2008-06-17 20:27:32 +04:00
*/
2015-06-23 22:52:10 +03:00
int update_info ( const string & monitor_data ) ;
2008-06-17 20:27:32 +04:00
2015-04-28 12:44:56 +03:00
/**
2015-07-13 19:24:58 +03:00
* Clears the VM monitor information usage counters ( MEMORY , CPU ) ,
* last_poll , custom attributes , and copies it to the history record
* for acct .
2015-04-28 12:44:56 +03:00
*/
void reset_info ( )
{
2015-06-23 22:52:10 +03:00
last_poll = time ( 0 ) ;
2015-04-28 12:44:56 +03:00
2015-07-13 19:24:58 +03:00
monitoring . replace ( " CPU " , " 0.0 " ) ;
monitoring . replace ( " MEMORY " , " 0 " ) ;
2015-06-23 22:52:10 +03:00
set_vm_info ( ) ;
clear_template_monitor_error ( ) ;
}
2015-07-09 15:02:28 +03:00
VirtualMachineMonitorInfo & get_info ( )
2015-06-23 22:52:10 +03:00
{
return monitoring ;
2015-04-28 12:44:56 +03:00
}
2008-06-17 20:27:32 +04:00
/**
* Returns the deployment ID
* @ return the VMM driver specific ID
*/
const string & get_deploy_id ( ) const
{
return deploy_id ;
} ;
/**
* Sets the VM exit time
2012-05-04 19:29:36 +04:00
* @ param _et VM exit time ( when it arrived DONE / FAILED states )
2008-06-17 20:27:32 +04:00
*/
void set_exit_time ( time_t et )
{
etime = et ;
} ;
2012-11-19 03:47:02 +04:00
/**
* Sets the KERNEL OS attribute ( path to the kernel file ) . Used when
* the template is using a FILE Datastore for it
* @ param path to the kernel ( in the remote host )
*/
void set_kernel ( const string & kernel )
{
2016-02-04 15:10:42 +03:00
VectorAttribute * os = obj_template - > get ( " OS " ) ;
2012-11-19 03:47:02 +04:00
2016-02-04 15:10:42 +03:00
if ( os = = 0 )
2012-11-19 03:47:02 +04:00
{
return ;
}
os - > replace ( " KERNEL " , kernel ) ;
} ;
/**
* Sets the INITRD OS attribute ( path to the initrd file ) . Used when
* the template is using a FILE Datastore for it
* @ param path to the initrd ( in the remote host )
*/
void set_initrd ( const string & initrd )
{
2016-02-04 15:10:42 +03:00
VectorAttribute * os = obj_template - > get ( " OS " ) ;
2012-11-19 03:47:02 +04:00
2016-02-04 15:10:42 +03:00
if ( os = = 0 )
2012-11-19 03:47:02 +04:00
{
return ;
}
os - > replace ( " INITRD " , initrd ) ;
} ;
2012-02-26 02:31:44 +04:00
// ------------------------------------------------------------------------
// Access to VM locations
// ------------------------------------------------------------------------
/**
* Returns the remote VM directory . The VM remote dir is in the form :
2016-04-10 23:39:21 +03:00
* $ DATASTORE_LOCATION / $ SYSTEM_DS_ID / $ VM_ID . The system_dir stores
2012-02-26 02:31:44 +04:00
* disks for a running VM in the target host .
* @ return the remote system directory for the VM
*/
2016-04-10 23:39:21 +03:00
const string & get_system_dir ( ) const
2012-10-05 15:23:44 +04:00
{
2016-04-10 23:39:21 +03:00
return history - > system_dir ;
2012-10-05 15:23:44 +04:00
}
2012-02-26 02:31:44 +04:00
2015-04-29 18:01:06 +03:00
/**
2016-04-10 23:39:21 +03:00
* Returns the remote VM directory for the previous host . It maybe different
* if a system ds migration
2015-04-29 18:01:06 +03:00
* The hasPreviousHistory ( ) function MUST be called before this one .
* @ return the remote system directory for the VM
*/
2016-04-10 23:39:21 +03:00
const string & get_previous_system_dir ( ) const
2015-04-29 18:01:06 +03:00
{
2016-04-10 23:39:21 +03:00
return previous_history - > system_dir ;
2015-04-29 18:01:06 +03:00
} ;
2008-06-17 20:27:32 +04:00
// ------------------------------------------------------------------------
// History
2009-03-06 15:10:15 +03:00
// ------------------------------------------------------------------------
2008-06-17 20:27:32 +04:00
/**
2008-06-23 02:38:55 +04:00
* Adds a new history record an writes it in the database .
2008-06-17 20:27:32 +04:00
*/
void add_history (
2011-03-08 19:55:14 +03:00
int hid ,
2013-10-25 19:09:00 +04:00
int cid ,
2011-03-08 19:55:14 +03:00
const string & hostname ,
const string & vmm_mad ,
2012-06-29 18:48:43 +04:00
const string & tm_mad ,
int ds_id ) ;
2008-06-22 05:51:49 +04:00
/**
* Duplicates the last history record . Only the host related fields are
2008-06-23 02:38:55 +04:00
* affected ( i . e . no counter is copied nor initialized ) .
2008-06-22 05:51:49 +04:00
* @ param reason explaining the new addition .
*/
2008-06-23 02:38:55 +04:00
void cp_history ( ) ;
2008-06-22 05:51:49 +04:00
/**
* Duplicates the previous history record . Only the host related fields are
2008-06-23 02:38:55 +04:00
* affected ( i . e . no counter is copied nor initialized ) .
2008-06-22 05:51:49 +04:00
* @ param reason explaining the new addition .
*/
2008-06-23 02:38:55 +04:00
void cp_previous_history ( ) ;
2008-06-17 20:27:32 +04:00
/**
2008-06-22 05:51:49 +04:00
* Checks if the VM has a valid history record . This function
2008-06-17 20:27:32 +04:00
* MUST be called before using any history related function .
* @ return true if the VM has a record
2009-03-06 15:10:15 +03:00
*/
2008-06-17 20:27:32 +04:00
bool hasHistory ( ) const
{
return ( history ! = 0 ) ;
} ;
2008-06-22 05:51:49 +04:00
/**
* Checks if the VM has a valid previous history record . This function
* MUST be called before using any previous_history related function .
* @ return true if the VM has a previous record
2009-03-06 15:10:15 +03:00
*/
2008-06-22 05:51:49 +04:00
bool hasPreviousHistory ( ) const
{
return ( previous_history ! = 0 ) ;
} ;
2009-07-09 18:34:34 +04:00
2008-06-17 20:27:32 +04:00
/**
* Returns the VMM driver name for the current host . The hasHistory ( )
* function MUST be called before this one .
* @ return the VMM mad name
2009-03-06 15:10:15 +03:00
*/
2008-06-17 20:27:32 +04:00
const string & get_vmm_mad ( ) const
{
return history - > vmm_mad_name ;
} ;
2009-07-09 18:34:34 +04:00
/**
* Returns the VMM driver name for the previous host . The hasPreviousHistory ( )
* function MUST be called before this one .
* @ return the VMM mad name
*/
const string & get_previous_vmm_mad ( ) const
{
return previous_history - > vmm_mad_name ;
} ;
2013-11-21 21:28:49 +04:00
/**
* Returns the datastore ID of the system DS for the host . The hasHistory ( )
* function MUST be called before this one .
* @ return the ds id
*/
int get_ds_id ( ) const
{
return history - > ds_id ;
} ;
2012-07-02 20:06:07 +04:00
/**
2012-10-05 15:23:44 +04:00
* Returns the datastore ID of the system DS for the previous host .
2012-07-02 20:06:07 +04:00
* The hasPreviousHistory ( ) function MUST be called before this one .
* @ return the TM mad name
*/
2013-11-22 13:15:57 +04:00
int get_previous_ds_id ( ) const
2012-07-02 20:06:07 +04:00
{
2013-11-22 13:15:57 +04:00
return previous_history - > ds_id ;
2012-07-02 20:06:07 +04:00
} ;
2012-06-28 17:32:52 +04:00
/**
* Returns the TM driver name for the current host . The hasHistory ( )
* function MUST be called before this one .
* @ return the TM mad name
*/
const string & get_tm_mad ( ) const
{
return history - > tm_mad_name ;
} ;
/**
* Returns the TM driver name for the previous host . The
* hasPreviousHistory ( ) function MUST be called before this one .
* @ return the TM mad name
*/
const string & get_previous_tm_mad ( ) const
{
return previous_history - > tm_mad_name ;
} ;
2008-06-17 20:27:32 +04:00
/**
2009-03-06 15:10:15 +03:00
* Returns the transfer filename . The transfer file is in the form :
2012-10-28 22:19:57 +04:00
* $ ONE_LOCATION / var / vms / $ VM_ID / transfer . $ SEQ
2009-01-02 17:58:51 +03:00
* or , in case that OpenNebula is installed in root
2012-10-28 22:19:57 +04:00
* / var / lib / one / vms / $ VM_ID / transfer . $ SEQ
2008-11-13 19:21:17 +03:00
* The hasHistory ( ) function MUST be called before this one .
* @ return the transfer filename
2009-03-06 15:10:15 +03:00
*/
2008-11-13 19:21:17 +03:00
const string & get_transfer_file ( ) const
2008-06-17 20:27:32 +04:00
{
2008-11-13 19:21:17 +03:00
return history - > transfer_file ;
2008-06-17 20:27:32 +04:00
} ;
/**
2008-11-13 19:21:17 +03:00
* Returns the deployment filename . The deployment file is in the form :
2012-10-28 22:19:57 +04:00
* $ ONE_LOCATION / var / vms / $ VM_ID / deployment . $ SEQ
2009-01-02 17:58:51 +03:00
* or , in case that OpenNebula is installed in root
2012-10-28 22:19:57 +04:00
* / var / lib / one / vms / $ VM_ID / deployment . $ SEQ
2008-11-13 19:21:17 +03:00
* The hasHistory ( ) function MUST be called before this one .
2013-07-05 03:31:30 +04:00
* @ return the deployment file path
2009-03-06 15:10:15 +03:00
*/
2008-11-13 19:21:17 +03:00
const string & get_deployment_file ( ) const
2008-06-17 20:27:32 +04:00
{
2008-11-13 19:21:17 +03:00
return history - > deployment_file ;
2008-06-17 20:27:32 +04:00
} ;
2009-03-06 15:10:15 +03:00
/**
* Returns the context filename . The context file is in the form :
2012-10-28 22:19:57 +04:00
* $ ONE_LOCATION / var / vms / $ VM_ID / context . sh
2009-03-06 15:10:15 +03:00
* or , in case that OpenNebula is installed in root
2012-10-28 22:19:57 +04:00
* / var / lib / one / vms / $ VM_ID / context . sh
2009-03-06 15:10:15 +03:00
* The hasHistory ( ) function MUST be called before this one .
2013-07-05 03:31:30 +04:00
* @ return the context file path
2009-03-06 15:10:15 +03:00
*/
const string & get_context_file ( ) const
{
return history - > context_file ;
}
2013-07-05 03:31:30 +04:00
/**
* Returns the token filename . The token file is in the form :
* $ ONE_LOCATION / var / vms / $ VM_ID / token . txt
* or , in case that OpenNebula is installed in root
* / var / lib / one / vms / $ VM_ID / token . txt
* The hasHistory ( ) function MUST be called before this one .
* @ return the token file path
*/
const string & get_token_file ( ) const
{
return history - > token_file ;
}
2008-11-13 19:21:17 +03:00
/**
* Returns the remote deployment filename . The file is in the form :
2012-10-28 22:19:57 +04:00
* $ DS_LOCATION / $ SYSTEM_DS / $ VM_ID / deployment . $ SEQ
2008-11-13 19:21:17 +03:00
* The hasHistory ( ) function MUST be called before this one .
* @ return the deployment filename
2009-03-06 15:10:15 +03:00
*/
2008-11-13 19:21:17 +03:00
const string & get_remote_deployment_file ( ) const
{
return history - > rdeployment_file ;
2009-03-06 15:10:15 +03:00
} ;
2008-06-17 20:27:32 +04:00
/**
2009-03-06 15:10:15 +03:00
* Returns the checkpoint filename for the current host . The checkpoint file
* is in the form :
2012-10-28 22:19:57 +04:00
* $ DS_LOCATION / $ SYSTEM_DS / $ VM_ID / checkpoint
2008-11-13 19:21:17 +03:00
* The hasHistory ( ) function MUST be called before this one .
2008-06-17 20:27:32 +04:00
* @ return the checkpoint filename
2009-03-06 15:10:15 +03:00
*/
2008-06-17 20:27:32 +04:00
const string & get_checkpoint_file ( ) const
{
return history - > checkpoint_file ;
} ;
2009-03-06 15:10:15 +03:00
2015-04-29 18:01:06 +03:00
/**
* Returns the checkpoint filename for the previous host .
* The hasPreviousHistory ( ) function MUST be called before this one .
* @ return the checkpoint filename
*/
const string & get_previous_checkpoint_file ( ) const
{
return previous_history - > checkpoint_file ;
} ;
2008-06-17 20:27:32 +04:00
/**
* Returns the hostname for the current host . The hasHistory ( )
* function MUST be called before this one .
* @ return the hostname
2009-03-06 15:10:15 +03:00
*/
2008-06-17 20:27:32 +04:00
const string & get_hostname ( ) const
{
return history - > hostname ;
} ;
2009-03-06 15:10:15 +03:00
2014-07-23 14:14:36 +04:00
/**
* Returns if the host is a public cloud based on the system ds and tm_mad .
* The hasHistory ( ) function MUST be called before this one .
* @ return the hostname
*/
bool get_host_is_cloud ( ) const
{
return ( ( history - > ds_id = = - 1 ) & & history - > tm_mad_name . empty ( ) ) ;
} ;
2013-09-02 14:53:54 +04:00
/**
* Updates the current hostname . The hasHistory ( )
* function MUST be called before this one .
* @ param hostname New hostname
*/
void set_hostname ( const string & hostname )
{
history - > hostname = hostname ;
} ;
2008-06-22 05:51:49 +04:00
/**
* Returns the hostname for the previous host . The hasPreviousHistory ( )
* function MUST be called before this one .
* @ return the hostname
2009-03-06 15:10:15 +03:00
*/
2008-06-22 05:51:49 +04:00
const string & get_previous_hostname ( ) const
{
return previous_history - > hostname ;
} ;
2009-03-06 15:10:15 +03:00
2008-11-13 19:21:17 +03:00
/**
2013-04-03 18:18:50 +04:00
* Returns the reason that closed the history record in the previous host
* @ return the reason to close the history record in the previous host
2008-11-13 19:21:17 +03:00
*/
2013-04-03 19:38:06 +04:00
const History : : EndReason get_previous_reason ( ) const
2008-11-13 19:21:17 +03:00
{
return previous_history - > reason ;
2009-03-06 15:10:15 +03:00
} ;
2013-11-21 21:28:49 +04:00
/**
* Returns the action that closed the current history record . The hasHistory ( )
* function MUST be called before this one .
* @ return the action that closed the current history record
*/
const History : : VMAction get_action ( ) const
{
return history - > action ;
} ;
2013-04-03 18:18:50 +04:00
/**
* Returns the action that closed the history record in the previous host
* @ return the action that closed the history record in the previous host
*/
2013-04-05 01:17:55 +04:00
const History : : VMAction get_previous_action ( ) const
2013-04-03 18:18:50 +04:00
{
return previous_history - > action ;
} ;
2008-06-17 20:27:32 +04:00
/**
* Get host id where the VM is or is going to execute . The hasHistory ( )
* function MUST be called before this one .
*/
int get_hid ( )
{
return history - > hid ;
}
2008-06-22 05:51:49 +04:00
/**
* Get host id where the VM was executing . The hasPreviousHistory ( )
* function MUST be called before this one .
*/
int get_previous_hid ( )
{
return previous_history - > hid ;
}
2009-03-06 15:10:15 +03:00
2015-07-22 20:14:07 +03:00
/**
* Get cluster id where the VM is or is going to execute . The hasHistory ( )
* function MUST be called before this one .
*/
int get_cid ( )
{
return history - > cid ;
}
/**
* Get cluster id where the VM was executing . The hasPreviousHistory ( )
* function MUST be called before this one .
*/
int get_previous_cid ( )
{
return previous_history - > cid ;
}
2008-06-17 20:27:32 +04:00
/**
* Sets start time of a VM .
* @ param _stime time when the VM started
*/
void set_stime ( time_t _stime )
{
history - > stime = _stime ;
} ;
2012-05-05 22:57:17 +04:00
/**
2012-10-05 15:23:44 +04:00
* Sets VM info ( with monitoring info ) in the history record
2012-05-05 22:57:17 +04:00
*/
2012-05-08 17:42:24 +04:00
void set_vm_info ( )
{
to_xml_extended ( history - > vm_info , 0 ) ;
} ;
2012-05-05 22:57:17 +04:00
/**
2012-10-05 15:23:44 +04:00
* Sets VM info ( with monitoring info ) in the previous history record
2012-05-05 22:57:17 +04:00
*/
2012-05-08 17:42:24 +04:00
void set_previous_vm_info ( )
{
to_xml_extended ( previous_history - > vm_info , 0 ) ;
} ;
2012-05-05 22:57:17 +04:00
2008-06-17 20:27:32 +04:00
/**
* Sets end time of a VM .
* @ param _etime time when the VM finished
*/
void set_etime ( time_t _etime )
{
history - > etime = _etime ;
} ;
2008-06-22 05:51:49 +04:00
/**
* Sets end time of a VM in the previous Host .
* @ param _etime time when the VM finished
*/
void set_previous_etime ( time_t _etime )
{
previous_history - > etime = _etime ;
} ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
* Sets start time of VM prolog .
* @ param _stime time when the prolog started
*/
void set_prolog_stime ( time_t _stime )
{
history - > prolog_stime = _stime ;
} ;
/**
* Sets end time of VM prolog .
* @ param _etime time when the prolog finished
*/
void set_prolog_etime ( time_t _etime )
{
history - > prolog_etime = _etime ;
} ;
/**
* Sets start time of VM running state .
* @ param _stime time when the running state started
*/
void set_running_stime ( time_t _stime )
{
history - > running_stime = _stime ;
} ;
2013-11-02 21:25:10 +04:00
/**
* Gets the running start time for the VM
*/
time_t get_running_stime ( )
{
return history - > running_stime ;
}
2008-06-17 20:27:32 +04:00
/**
* Sets end time of VM running state .
* @ param _etime time when the running state finished
*/
void set_running_etime ( time_t _etime )
{
history - > running_etime = _etime ;
} ;
2008-06-22 05:51:49 +04:00
/**
* Sets end time of VM running state in the previous host .
* @ param _etime time when the running state finished
*/
void set_previous_running_etime ( time_t _etime )
{
previous_history - > running_etime = _etime ;
} ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
* Sets start time of VM epilog .
* @ param _stime time when the epilog started
*/
void set_epilog_stime ( time_t _stime )
{
2008-06-22 05:51:49 +04:00
history - > epilog_stime = _stime ;
2008-06-17 20:27:32 +04:00
} ;
/**
* Sets end time of VM epilog .
* @ param _etime time when the epilog finished
*/
void set_epilog_etime ( time_t _etime )
{
2008-06-22 05:51:49 +04:00
history - > epilog_etime = _etime ;
2008-06-17 20:27:32 +04:00
} ;
/**
2013-04-03 18:18:50 +04:00
* Sets the reason that closed the history record
* @ param _reason reason to close the history record
2008-06-17 20:27:32 +04:00
*/
2013-04-03 19:38:06 +04:00
void set_reason ( History : : EndReason _reason )
2008-06-17 20:27:32 +04:00
{
history - > reason = _reason ;
} ;
2009-03-06 15:10:15 +03:00
2008-06-23 02:38:55 +04:00
/**
2013-04-03 18:18:50 +04:00
* Sets the reason that closed the history record in the previous host
* @ param _reason reason to close the history record in the previous host
2008-06-23 02:38:55 +04:00
*/
2013-04-03 19:38:06 +04:00
void set_previous_reason ( History : : EndReason _reason )
2008-06-23 02:38:55 +04:00
{
previous_history - > reason = _reason ;
2009-03-06 15:10:15 +03:00
} ;
2008-06-17 20:27:32 +04:00
2013-04-03 18:18:50 +04:00
/**
* Sets the action that closed the history record
* @ param action that closed the history record
*/
2013-04-05 01:17:55 +04:00
void set_action ( History : : VMAction action )
2013-04-03 18:18:50 +04:00
{
history - > action = action ;
} ;
/**
* Sets the action that closed the history record in the previous host
* @ param action that closed the history record in the previous host
*/
2013-04-05 01:17:55 +04:00
void set_previous_action ( History : : VMAction action )
2013-04-03 18:18:50 +04:00
{
previous_history - > action = action ;
} ;
2013-04-04 13:34:20 +04:00
2008-06-17 20:27:32 +04:00
// ------------------------------------------------------------------------
// Template
2009-03-06 15:10:15 +03:00
// ------------------------------------------------------------------------
2009-04-02 14:14:54 +04:00
/**
2010-04-11 00:16:47 +04:00
* Parse a string and substitute variables ( e . g . $ NAME ) using the VM
2009-04-02 14:14:54 +04:00
* template values :
* @ param attribute , the string to be parsed
* @ param parsed , the resulting parsed string
2012-11-23 04:40:05 +04:00
* @ param error description in case of failure
2009-04-02 14:14:54 +04:00
* @ return 0 on success .
2010-04-11 00:16:47 +04:00
*/
2012-11-23 04:40:05 +04:00
int parse_template_attribute ( const string & attribute ,
string & parsed ,
string & error ) ;
2012-11-17 05:46:03 +04:00
/**
* Parse a file string variable ( i . e . $ FILE ) using the FILE_DS datastores .
* It should be used for OS / DS_KERNEL , OS / DS_INITRD , CONTEXT / DS_FILES .
2012-11-18 03:01:43 +04:00
* @ param attribute the string to be parsed
* @ param img_ids ids of the FILE images in the attribute
* @ param error description in case of failure
2012-11-17 05:46:03 +04:00
* @ return 0 on success .
*/
2012-11-23 22:51:45 +04:00
int parse_file_attribute ( string attribute ,
vector < int > & img_ids ,
string & error ) ;
2016-04-19 17:22:37 +03:00
/**
2016-04-20 17:57:05 +03:00
* Updates the configuration attributes based on a template , the state of
* the virtual machine is checked to assure operation consistency
2016-04-22 12:30:21 +03:00
* @ param tmpl with the new attributes include : OS , RAW , FEAUTRES ,
* CONTEXT and GRAPHICS .
2016-04-20 17:57:05 +03:00
* @ param err description if any
2016-04-19 17:22:37 +03:00
*
2016-04-20 17:57:05 +03:00
* @ return 0 on success
2016-04-19 17:22:37 +03:00
*/
2016-04-20 17:57:05 +03:00
int updateconf ( VirtualMachineTemplate & tmpl , string & err ) ;
2016-04-19 17:22:37 +03:00
2011-06-02 01:53:09 +04:00
/**
* Factory method for virtual machine templates
*/
2012-03-14 18:48:06 +04:00
Template * get_new_template ( ) const
2011-06-02 01:53:09 +04:00
{
return new VirtualMachineTemplate ;
}
2011-04-08 03:02:55 +04:00
2012-06-06 19:05:11 +04:00
/**
* Returns a copy of the VirtualMachineTemplate
* @ return A copy of the VirtualMachineTemplate
*/
VirtualMachineTemplate * clone_template ( ) const
{
return new VirtualMachineTemplate (
* ( static_cast < VirtualMachineTemplate * > ( obj_template ) ) ) ;
} ;
2013-01-04 03:04:01 +04:00
/**
* This function replaces the * user template * .
* @ param tmpl_str new contents
2013-03-12 18:19:00 +04:00
* @ param keep_restricted If true , the restricted attributes of the
* current template will override the new template
2013-01-04 03:04:01 +04:00
* @ param error string describing the error if any
* @ return 0 on success
*/
2013-03-12 18:19:00 +04:00
int replace_template ( const string & tmpl_str , bool keep_restricted , string & error ) ;
2012-06-06 19:05:11 +04:00
2013-06-28 20:00:26 +04:00
/**
* Append new attributes to the * user template * .
* @ param tmpl_str new contents
* @ param keep_restricted If true , the restricted attributes of the
* current template will override the new template
* @ param error string describing the error if any
* @ return 0 on success
*/
int append_template ( const string & tmpl_str , bool keep_restricted , string & error ) ;
2013-03-15 20:37:47 +04:00
/**
* This function gets an attribute from the user template
* @ param name of the attribute
* @ param value of the attribute
*/
void get_user_template_attribute ( const char * name , string & value ) const
2013-02-26 17:32:31 +04:00
{
user_obj_template - > get ( name , value ) ;
}
2013-04-26 19:26:09 +04:00
/**
* Sets an error message with timestamp in the template
* @ param message Message string
*/
void set_template_error_message ( const string & message ) ;
/**
* Sets an error message with timestamp in the template
* @ param name of the error attribute
* @ param message Message string
*/
void set_template_error_message ( const string & name , const string & message ) ;
/**
* Deletes the error message from the template
*/
void clear_template_error_message ( ) ;
2013-03-15 20:37:47 +04:00
/**
* Sets an error message with timestamp in the template ( ERROR_MONITOR )
* @ param message Message string
*/
void set_template_monitor_error ( const string & message ) ;
/**
* Deletes the error message from the template ( ERROR_MONITOR )
* @ param message Message string
*/
void clear_template_monitor_error ( ) ;
2008-06-17 20:27:32 +04:00
// ------------------------------------------------------------------------
// States
2009-03-06 15:10:15 +03:00
// ------------------------------------------------------------------------
2008-06-17 20:27:32 +04:00
/**
* Returns the VM state ( Dispatch Manager )
* @ return the VM state
*/
VmState get_state ( ) const
{
return state ;
} ;
2015-02-19 18:12:09 +03:00
VmState get_prev_state ( ) const
{
return prev_state ;
} ;
2008-06-17 20:27:32 +04:00
/**
* Returns the VM state ( life - cycle Manager )
* @ return the VM state
*/
LcmState get_lcm_state ( ) const
{
return lcm_state ;
} ;
2015-02-19 18:12:09 +03:00
LcmState get_prev_lcm_state ( ) const
{
return prev_lcm_state ;
} ;
2008-06-17 20:27:32 +04:00
/**
* Sets VM state
* @ param s state
*/
void set_state ( VmState s )
{
2015-03-30 12:17:36 +03:00
string st ;
2008-06-17 20:27:32 +04:00
state = s ;
2015-03-30 12:17:36 +03:00
log ( " VM " , Log : : INFO , " New state is " + vm_state_to_str ( st , s ) ) ;
2008-06-17 20:27:32 +04:00
} ;
/**
* Sets VM LCM state
* @ param s state
*/
void set_state ( LcmState s )
{
2015-03-30 12:17:36 +03:00
string st ;
2008-06-17 20:27:32 +04:00
lcm_state = s ;
2015-03-30 12:17:36 +03:00
log ( " VM " , Log : : INFO , " New LCM state is " + lcm_state_to_str ( st , s ) ) ;
2008-06-17 20:27:32 +04:00
} ;
2009-03-06 15:10:15 +03:00
2015-02-19 18:12:09 +03:00
/**
* Sets the previous state to the current one
*/
void set_prev_state ( )
{
prev_state = state ;
prev_lcm_state = lcm_state ;
} ;
/**
* Test if the VM has changed state since last time prev state was set
* @ return true if VM changed state
*/
bool has_changed_state ( )
{
return ( prev_lcm_state ! = lcm_state | | prev_state ! = state ) ;
}
2012-04-26 21:06:49 +04:00
/**
* Sets the re - scheduling flag
* @ param set or unset the re - schedule flag
*/
void set_resched ( bool do_sched )
{
if ( do_sched = = true )
{
resched = 1 ;
}
else
{
resched = 0 ;
}
} ;
2008-06-17 20:27:32 +04:00
// ------------------------------------------------------------------------
2013-03-15 20:37:47 +04:00
// Timers & Requirements
2009-03-06 15:10:15 +03:00
// ------------------------------------------------------------------------
2008-06-17 20:27:32 +04:00
/**
* Gets time from last information polling .
* @ return time of last poll ( epoch ) or 0 if never polled
*/
time_t get_last_poll ( ) const
{
return last_poll ;
} ;
2009-03-06 15:10:15 +03:00
2013-03-15 20:37:47 +04:00
/**
* Sets time of last information polling .
* @ param poll time in epoch , normally time ( 0 )
*/
void set_last_poll ( time_t poll )
{
last_poll = poll ;
} ;
2008-06-17 20:27:32 +04:00
/**
* Get the VM physical requirements for the host .
* @ param cpu
* @ param memory
2009-03-06 15:10:15 +03:00
* @ param disk
2015-08-21 02:08:28 +03:00
* @ param pci_dev
2008-06-17 20:27:32 +04:00
*/
2015-08-21 02:08:28 +03:00
void get_requirements ( int & cpu , int & memory , int & disk ,
2016-02-04 15:10:42 +03:00
vector < VectorAttribute * > & pci_dev ) ;
2009-03-06 15:10:15 +03:00
2016-08-30 19:32:29 +03:00
/**
* Adds automatic placement requirements : Datastore and Cluster
2016-09-01 16:46:01 +03:00
* @ param cluster_ids set of viable clusters for this VM
2016-08-30 19:32:29 +03:00
* @ param error_str Returns the error reason , if any
* @ return 0 on success
*/
2016-09-01 16:46:01 +03:00
int automatic_requirements ( set < int > & cluster_ids , string & error_str ) ;
2016-08-18 17:18:59 +03:00
2013-02-25 20:01:55 +04:00
/**
* Checks if the resize parameters are valid
* @ param cpu New CPU . 0 means unchanged .
* @ param memory New MEMORY . 0 means unchanged .
* @ param vcpu New VCPU . 0 means unchanged .
* @ param error_str Error reason , if any
*
* @ return 0 on success
*/
int check_resize ( float cpu , int memory , int vcpu , string & error_str ) ;
2013-02-23 22:49:06 +04:00
/**
* Resize the VM capacity
* @ param cpu
* @ param memory
* @ param vcpu
2013-02-25 20:01:55 +04:00
* @ param error_str Error reason , if any
*
* @ return 0 on success
2013-02-23 22:49:06 +04:00
*/
2013-02-25 20:01:55 +04:00
int resize ( float cpu , int memory , int vcpu , string & error_str ) ;
2013-02-23 22:49:06 +04:00
2008-11-13 19:21:17 +03:00
// ------------------------------------------------------------------------
2010-06-25 15:24:54 +04:00
// Network Leases & Disk Images
2008-11-13 19:21:17 +03:00
// ------------------------------------------------------------------------
/**
* Releases all network leases taken by this Virtual Machine
*/
2009-03-06 18:54:57 +03:00
void release_network_leases ( ) ;
2009-03-06 15:10:15 +03:00
2012-12-12 21:31:27 +04:00
/**
* Releases the network lease taken by this NIC
*
* @ param nic NIC to be released
* @ param vmid Virtual Machine oid
*
* @ return 0 on success , - 1 otherwise
*/
2016-03-02 01:31:31 +03:00
static int release_network_leases ( const VectorAttribute * nic , int vmid ) ;
/**
2016-07-14 12:06:59 +03:00
* Returns a set of the security group IDs in use in this VM . VirtualMachine
* and static version .
2016-03-02 01:31:31 +03:00
* @ param sgs a set of security group IDs
*/
2016-07-14 12:06:59 +03:00
void get_security_groups ( set < int > & sgs ) const
{
get_security_groups ( static_cast < VirtualMachineTemplate * > ( obj_template ) , sgs ) ;
}
static void get_security_groups ( VirtualMachineTemplate * tmpl , set < int > & sgs ) ;
2016-03-02 01:31:31 +03:00
/**
* Remove the rules associated to the given security group rules
* @ param sgid the security group ID
*/
void remove_security_group ( int sgid ) ;
2012-12-12 21:31:27 +04:00
2010-06-25 15:24:54 +04:00
/**
* Releases all disk images taken by this Virtual Machine
*/
void release_disk_images ( ) ;
2013-10-04 22:24:31 +04:00
/**
* Check if the given disk is volatile
*/
2015-06-17 00:40:09 +03:00
static bool is_volatile ( const VectorAttribute * disk ) ;
2013-10-04 22:24:31 +04:00
2015-06-17 00:40:09 +03:00
/**
* Check if the disk is persistent
*/
static bool is_persistent ( const VectorAttribute * disk ) ;
2013-10-15 15:45:16 +04:00
2015-03-09 20:14:57 +03:00
/**
2015-11-18 15:10:55 +03:00
* Check if the VM is imported
2015-03-09 20:14:57 +03:00
*/
2015-06-17 00:40:09 +03:00
bool is_imported ( ) const ;
2015-03-09 20:14:57 +03:00
2016-02-09 14:56:01 +03:00
/**
* Return state of the VM right before import
*/
string get_import_state ( ) ;
2015-11-18 15:10:55 +03:00
/**
* Checks if the current VM MAD supports the given action for imported VMs
* @ param action VM action to check
* @ return true if the current VM MAD supports the given action for imported VMs
*/
bool is_imported_action_supported ( History : : VMAction action ) const ;
2013-10-04 22:24:31 +04:00
/**
2015-07-20 16:46:57 +03:00
* Return the total disk SIZE that the VM instance needs in the system DS
2013-10-04 22:24:31 +04:00
*/
2015-07-20 16:46:57 +03:00
static long long get_system_disk_size ( Template * tmpl ) ;
2013-10-04 22:24:31 +04:00
2015-07-23 13:30:39 +03:00
/**
* Returns the disk CLONE_TARGET or LN_TARGET
* @ param disk
* @ return NONE , SYSTEM , SELF . Empty string if it could not be determined
*/
2015-07-29 13:40:21 +03:00
static string disk_tm_target ( const VectorAttribute * disk ) ;
2015-07-23 13:30:39 +03:00
2014-11-11 20:52:06 +03:00
/**
2016-03-02 01:31:31 +03:00
* Returns the DISK attribute for a disk
* @ param disk_id of the DISK
* @ return pointer to the attribute ir null if not found
2015-07-01 22:15:40 +03:00
*/
2015-06-17 11:10:28 +03:00
const VectorAttribute * get_disk ( int disk_id ) const ;
2016-01-15 18:42:51 +03:00
const VectorAttribute * get_nic ( int nic_id ) const ;
2015-12-01 17:35:33 +03:00
// ------------------------------------------------------------------------
// Virtual Router related functions
// ------------------------------------------------------------------------
/**
* Returns the Virtual Router ID if this VM is a VR , or - 1
* @ return VR ID or - 1
*/
int get_vrouter_id ( ) ;
2015-12-16 14:32:19 +03:00
/**
* Returns true if this VM is a Virtual Router
* @ return true if this VM is a Virtual Router
*/
bool is_vrouter ( ) ;
2016-01-18 18:47:14 +03:00
2009-03-06 18:54:57 +03:00
// ------------------------------------------------------------------------
// Context related functions
// ------------------------------------------------------------------------
2009-03-06 15:10:15 +03:00
/**
2009-03-07 03:56:26 +03:00
* Writes the context file for this VM , and gets the paths to be included
* in the context block device ( CBD )
* @ param files space separated list of paths to be included in the CBD
2012-10-16 20:27:16 +04:00
* @ param disk_id CONTEXT / DISK_ID attribute value
2016-03-16 16:53:05 +03:00
* @ param password Password to encrypt the token , if it is set
2012-10-16 20:27:16 +04:00
* @ return - 1 in case of error , 0 if the VM has no context , 1 on success
2009-03-06 15:10:15 +03:00
*/
2016-03-16 16:53:05 +03:00
int generate_context ( string & files , int & disk_id , const string & password ) ;
2009-03-06 15:10:15 +03:00
2016-01-25 19:38:46 +03:00
/**
* Returns the CREATED_BY template attribute , or the uid if it does not exist
* @ return uid
*/
int get_created_by_uid ( ) const ;
2013-03-08 01:44:18 +04:00
// -------------------------------------------------------------------------
2015-06-10 20:56:35 +03:00
// "Save as" Disk related functions (save_as hot)
2013-03-08 01:44:18 +04:00
// -------------------------------------------------------------------------
/**
2015-06-10 20:56:35 +03:00
* Mark the disk that is going to be " save as "
2013-03-08 01:44:18 +04:00
* @ param disk_id of the VM
2015-06-10 20:56:35 +03:00
* @ param snap_id of the disk to save , - 1 to select the active snapshot
2015-10-16 18:56:29 +03:00
* @ param img_id The image id used by the disk
* @ param size The disk size . This may be different to the original
* image size
* @ param err_str describing the error if any
* @ return - 1 if the image cannot saveas , 0 on success
2013-03-08 01:44:18 +04:00
*/
2015-10-16 18:56:29 +03:00
int set_saveas_disk ( int disk_id , int snap_id , int & img_id , long long & size , string & err_str ) ;
2013-03-08 01:44:18 +04:00
2015-06-10 13:53:55 +03:00
/**
2015-06-10 20:56:35 +03:00
* Set save attributes for the disk
* @ param disk_id Index of the disk to save
2015-06-10 13:53:55 +03:00
* @ param source to save the disk
* @ param img_id ID of the image this disk will be saved to
*/
int set_saveas_disk ( int disk_id , const string & source , int img_id ) ;
2013-03-08 01:44:18 +04:00
/**
2015-06-10 20:56:35 +03:00
* Sets the corresponding state to save the disk .
* @ return 0 if the VM can be saved
2013-03-08 01:44:18 +04:00
*/
2015-06-10 00:25:10 +03:00
int set_saveas_state ( ) ;
2013-03-08 01:44:18 +04:00
/**
2015-06-10 20:56:35 +03:00
* Clears the save state , moving the VM to the original state .
* @ return 0 if the VM was in an saveas state
2013-03-08 01:44:18 +04:00
*/
2015-06-10 00:25:10 +03:00
int clear_saveas_state ( ) ;
2013-03-08 01:44:18 +04:00
2010-07-21 20:06:40 +04:00
/**
2015-06-10 20:56:35 +03:00
* Clears the SAVE_AS_ * attributes of the disk being saved as
2015-06-10 00:25:10 +03:00
* @ return the ID of the image this disk will be saved to or - 1 if it
* is not found .
2010-07-21 20:06:40 +04:00
*/
2015-06-10 00:25:10 +03:00
int clear_saveas_disk ( ) ;
2015-04-20 14:03:16 +03:00
2012-03-06 02:49:18 +04:00
/**
* Get the original image id of the disk . It also checks that the disk can
* be saved_as .
* @ param disk_id Index of the disk to save
2015-06-10 13:53:55 +03:00
* @ param source of the image to save the disk to
* @ param image_id of the image to save the disk to
* @ param tm_mad in use by the disk
* @ param ds_id of the datastore in use by the disk
2012-03-06 02:49:18 +04:00
* @ return - 1 if failure
*/
2015-06-10 13:53:55 +03:00
int get_saveas_disk ( int & disk_id , string & source , int & image_id ,
2015-06-10 20:56:35 +03:00
string & snap_id , string & tm_mad , string & ds_id ) ;
2013-03-08 01:44:18 +04:00
2011-06-01 14:41:46 +04:00
// ------------------------------------------------------------------------
// Authorization related functions
// ------------------------------------------------------------------------
/**
* Sets an authorization request for a VirtualMachine template based on
* the images and networks used
* @ param uid for template owner
* @ param ar the AuthRequest object
* @ param tmpl the virtual machine template
*/
2012-10-05 15:23:44 +04:00
static void set_auth_request ( int uid ,
AuthRequest & ar ,
2011-06-01 14:41:46 +04:00
VirtualMachineTemplate * tmpl ) ;
2012-06-13 20:42:42 +04:00
2015-07-22 18:20:37 +03:00
/**
* Adds extra info to the given template :
* DISK / IMAGE_ID and SIZE
* @ param uid for template owner
* @ param tmpl the virtual machine template
*/
static void disk_extended_info ( int uid ,
VirtualMachineTemplate * tmpl ) ;
2013-03-08 01:44:18 +04:00
// -------------------------------------------------------------------------
2012-06-13 20:42:42 +04:00
// Hotplug related functions
2013-03-08 01:44:18 +04:00
// -------------------------------------------------------------------------
2012-06-13 20:42:42 +04:00
2012-06-15 14:28:20 +04:00
/**
2016-04-18 17:46:02 +03:00
* Generate and attach a new DISK attribute to the VM . This method check
* that the DISK is compatible with the VM cluster allocation and disk target
* usage .
2012-06-15 14:28:20 +04:00
* @ param tmpl Template containing a single DISK vector attribute .
* @ param error_str describes the error
*
2016-04-18 17:46:02 +03:00
* @ return 0 if success
*/
int set_up_attach_disk ( VirtualMachineTemplate * tmpl , string & error_str ) ;
2012-06-13 20:42:42 +04:00
/**
* Returns the disk that is waiting for an attachment action
*
* @ return the disk waiting for an attachment action , or 0
*/
VectorAttribute * get_attach_disk ( ) ;
/**
2012-06-13 21:15:33 +04:00
* Cleans the ATTACH = YES attribute from the disks
2012-06-14 15:02:18 +04:00
*/
2012-06-15 14:28:20 +04:00
void clear_attach_disk ( ) ;
2012-06-14 15:02:18 +04:00
/**
2012-06-15 14:28:20 +04:00
* Deletes the DISK that was in the process of being attached
2012-06-14 15:02:18 +04:00
*
2012-06-15 14:28:20 +04:00
* @ return the DISK or 0 if no disk was deleted
2012-06-13 20:42:42 +04:00
*/
2015-06-02 02:50:28 +03:00
VectorAttribute * delete_attach_disk ( Snapshots * * snap ) ;
2012-06-15 14:28:20 +04:00
2012-06-15 18:28:30 +04:00
/**
* Sets the attach attribute to the given disk
* @ param disk_id of the DISK
* @ return 0 if the disk_id was found - 1 otherwise
*/
int set_attach_disk ( int disk_id ) ;
2012-12-12 21:31:27 +04:00
// ------------------------------------------------------------------------
// NIC Hotplug related functions
// ------------------------------------------------------------------------
2012-06-14 19:45:41 +04:00
/**
2016-04-18 17:46:02 +03:00
* Generate and attach a new NIC attribute to the VM . This method check
* that the NIC is compatible with the VM cluster allocation and fills SG
* information .
* @ param tmpl Template containing a single NIC vector attribute .
* @ param error_str error reason , if any
2014-07-10 18:24:25 +04:00
*
2016-04-18 17:46:02 +03:00
* @ return 0 on success , - 1 otherwise
2016-01-27 13:27:26 +03:00
*/
2016-04-18 17:46:02 +03:00
int set_up_attach_nic ( VirtualMachineTemplate * tmpl , string & error_str ) ;
2016-01-27 13:27:26 +03:00
2012-06-14 19:45:41 +04:00
/**
2012-12-12 21:31:27 +04:00
* Cleans the ATTACH = YES attribute from the NICs
*/
2016-01-27 13:27:26 +03:00
void attach_nic_success ( ) ;
2012-12-12 21:31:27 +04:00
/**
* Deletes the NIC that was in the process of being attached
2012-06-14 19:45:41 +04:00
*
2012-12-12 21:31:27 +04:00
* @ return the deleted NIC or 0 if none was deleted
*/
2016-01-27 13:27:26 +03:00
VectorAttribute * attach_nic_failure ( ) ;
2012-12-12 21:31:27 +04:00
/**
* Sets the attach attribute to the given NIC
* @ param nic_id of the NIC
* @ return 0 if the nic_id was found , - 1 otherwise
2012-06-14 19:45:41 +04:00
*/
2016-01-27 13:27:26 +03:00
int set_detach_nic ( int nic_id ) ;
2012-06-14 19:45:41 +04:00
2016-01-25 18:20:12 +03:00
/**
2016-01-27 13:27:26 +03:00
* Deletes the NIC that was in the process of being detached
*
* @ return the deleted NIC or 0 if none was deleted
2016-01-25 18:20:12 +03:00
*/
2016-01-27 13:27:26 +03:00
VectorAttribute * detach_nic_success ( ) ;
/**
* Cleans the ATTACH = YES attribute from the NIC , restores the NIC context
* variables
*/
void detach_nic_failure ( ) ;
2016-01-25 18:20:12 +03:00
2015-05-19 19:41:23 +03:00
// ------------------------------------------------------------------------
// Snapshot related functions
// ------------------------------------------------------------------------
2015-06-04 20:46:46 +03:00
/**
* Return the snapshot list for the disk
* @ param disk_id of the disk
* @ param error if any
* @ return pointer to Snapshots or 0 if not found
*/
const Snapshots * get_disk_snapshots ( int did , string & err ) const ;
2015-05-19 19:41:23 +03:00
/**
* Creates a new snapshot of the given disk
* @ param disk_id of the disk
2015-07-09 14:13:07 +03:00
* @ param name a description for this snapshot
2015-05-19 19:41:23 +03:00
* @ param error if any
* @ return the id of the new snapshot or - 1 if error
*/
2015-07-09 14:13:07 +03:00
int new_disk_snapshot ( int disk_id , const string & name , string & error ) ;
2015-05-19 19:41:23 +03:00
/**
* Sets the snap_id as active , the VM will boot from it next time
* @ param disk_id of the disk
2015-06-04 20:46:46 +03:00
* @ param snap_id of the snapshot
2015-05-19 19:41:23 +03:00
* @ param error if any
* @ return - 1 if error
*/
2015-06-04 20:46:46 +03:00
int revert_disk_snapshot ( int disk_id , int snap_id ) ;
2013-02-19 18:21:33 +04:00
2015-05-26 12:24:34 +03:00
/**
2015-07-23 13:30:39 +03:00
* Deletes the snap_id from the list
2015-05-26 12:24:34 +03:00
* @ param disk_id of the disk
2015-06-04 20:46:46 +03:00
* @ param snap_id of the snapshot
2015-07-23 13:30:39 +03:00
* @ param ds_quotas template with snapshot usage for the DS quotas
* @ param vm_quotas template with snapshot usage for the VM quotas
2015-05-26 12:24:34 +03:00
*/
2015-07-23 13:30:39 +03:00
void delete_disk_snapshot ( int disk_id , int snap_id , Template * * ds_quotas ,
Template * * vm_quotas ) ;
2015-05-26 12:24:34 +03:00
2015-11-12 15:23:58 +03:00
/**
* Deletes all the disk snapshots for non - persistent disks and for persistent
* disks in no shared system ds .
* @ param vm_quotas The SYSTEM_DISK_SIZE freed by the deleted snapshots
* @ param ds_quotas The DS SIZE freed from image datastores .
*/
void delete_non_persistent_disk_snapshots ( Template * * vm_quotas ,
map < int , Template * > & ds_quotas ) ;
2015-05-20 18:48:27 +03:00
/**
* Get information about the disk to take the snapshot from
* @ param ds_id id of the datastore
* @ param tm_mad used by the datastore
2015-05-21 15:12:35 +03:00
* @ param disk_id of the disk
2015-05-20 18:48:27 +03:00
* @ param snap_id of the snapshot
*/
2015-07-01 16:43:22 +03:00
int get_snapshot_disk ( int & ds_id , string & tm_mad , int & disk_id ,
int & snap_id ) ;
2015-05-26 12:24:34 +03:00
/**
* Unset the current disk being snapshotted ( reverted . . . )
*/
void clear_snapshot_disk ( ) ;
2015-05-20 18:48:27 +03:00
2015-05-21 15:12:35 +03:00
/**
2015-05-26 12:24:34 +03:00
* Set the disk as being snapshotted ( reverted . . . )
* @ param disk_id of the disk
* @ param snap_id of the target snap_id
2015-05-21 15:12:35 +03:00
*/
2015-05-26 12:24:34 +03:00
int set_snapshot_disk ( int disk_id , int snap_id ) ;
2013-02-19 18:21:33 +04:00
// ------------------------------------------------------------------------
// Snapshot related functions
// ------------------------------------------------------------------------
2013-02-20 19:04:09 +04:00
/**
* Creates a new Snapshot attribute , and sets it to ACTIVE = YES
*
2013-02-20 21:11:58 +04:00
* @ param name for the new Snapshot . If it is empty , the generated name
* will be placed in this param
* @ param snap_id Id of the new snapshot
2013-02-20 19:04:09 +04:00
*
* @ return 0 on success
*/
2013-02-20 21:11:58 +04:00
int new_snapshot ( string & name , int & snap_id ) ;
2013-02-19 18:21:33 +04:00
2013-02-20 19:04:09 +04:00
/**
* Sets the given Snapshot as ACTIVE = YES
*
* @ param snap_id the snapshow ID
*
* @ return 0 on success
*/
int set_active_snapshot ( int snap_id ) ;
2013-02-19 18:21:33 +04:00
/**
* Replaces HYPERVISOR_ID for the active SNAPSHOT
*
* @ param hypervisor_id Id returned by the hypervisor for the newly
* created snapshot
*/
void update_snapshot_id ( string & hypervisor_id ) ;
/**
* Cleans the ACTIVE = YES attribute from the snapshots
*/
void clear_active_snapshot ( ) ;
/**
* Deletes the SNAPSHOT that was in the process of being created
*/
void delete_active_snapshot ( ) ;
2013-02-20 21:51:06 +04:00
/**
* Deletes all SNAPSHOT attributes
2012-06-14 19:45:41 +04:00
*/
2013-02-20 21:51:06 +04:00
void delete_snapshots ( ) ;
2012-06-14 19:45:41 +04:00
2016-04-18 18:44:47 +03:00
// ------------------------------------------------------------------------
// Cloning state related functions
// ------------------------------------------------------------------------
/**
* Returns true if any of the disks is waiting for an image in LOCKED state
* @ return true if cloning
*/
bool has_cloning_disks ( ) ;
/**
* Returns the image IDs for the disks waiting for the LOCKED state to finish
2016-04-22 14:12:51 +03:00
* @ param ids image ID set
2016-04-18 18:44:47 +03:00
*/
2016-04-22 14:12:51 +03:00
void get_cloning_image_ids ( set < int > & ids ) ;
2016-04-18 18:44:47 +03:00
/**
* Clears the flag for the disks waiting for the given image
*/
2016-04-22 14:12:51 +03:00
void clear_cloning_image_id ( int image_id , const string & source ) ;
2016-04-18 18:44:47 +03:00
2008-06-17 20:27:32 +04:00
private :
// -------------------------------------------------------------------------
// Friends
// -------------------------------------------------------------------------
friend class VirtualMachinePool ;
// *************************************************************************
// Virtual Machine Attributes
// *************************************************************************
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
// -------------------------------------------------------------------------
// VM Scheduling & Managing Information
2009-03-06 15:10:15 +03:00
// -------------------------------------------------------------------------
2008-06-17 20:27:32 +04:00
/**
* Last time ( in epoch ) that the VM was polled to get its status
*/
time_t last_poll ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
// -------------------------------------------------------------------------
// Virtual Machine Description
// -------------------------------------------------------------------------
/**
* The state of the virtual machine .
*/
VmState state ;
2015-02-19 18:12:09 +03:00
/**
* Previous state og the virtual machine , to trigger state hooks
*/
VmState prev_state ;
2008-06-17 20:27:32 +04:00
/**
* The state of the virtual machine ( in the Life - cycle Manager ) .
*/
LcmState lcm_state ;
2015-02-19 18:12:09 +03:00
/**
* Previous state og the virtual machine , to trigger state hooks
*/
LcmState prev_lcm_state ;
2012-04-26 21:06:49 +04:00
/**
* Marks the VM as to be re - scheduled
*/
int resched ;
2008-06-17 20:27:32 +04:00
/**
* Start time , the VM enter the nebula system ( in epoch )
*/
time_t stime ;
/**
* Exit time , the VM leave the nebula system ( in epoch )
*/
time_t etime ;
/**
* Deployment specific identification string , as returned by the VM driver
*/
string deploy_id ;
/**
2012-05-08 18:18:24 +04:00
* Memory in Kilobytes used by the VM
2008-06-17 20:27:32 +04:00
*/
int memory ;
/**
* CPU usage ( percent )
*/
int cpu ;
/**
2012-05-08 18:18:24 +04:00
* Network usage , transmitted bytes
2008-06-17 20:27:32 +04:00
*/
2012-12-04 16:35:45 +04:00
long long net_tx ;
2008-06-17 20:27:32 +04:00
/**
2012-05-08 18:18:24 +04:00
* Network usage , received bytes
2008-06-17 20:27:32 +04:00
*/
2012-12-04 16:35:45 +04:00
long long net_rx ;
2008-06-17 20:27:32 +04:00
2015-06-20 01:42:20 +03:00
/**
* Network usage , received bytes
*/
long long disk_actual ;
/**
* Network usage , received bytes
*/
long long disk_virtual ;
2008-06-17 20:27:32 +04:00
/**
2008-06-22 05:51:49 +04:00
* History record , for the current host
2008-06-17 20:27:32 +04:00
*/
History * history ;
2008-06-22 05:51:49 +04:00
/**
* History record , for the previous host
*/
History * previous_history ;
2009-03-06 15:10:15 +03:00
2011-06-25 03:29:44 +04:00
/**
* Complete set of history records for the VM
*/
vector < History * > history_records ;
2015-05-19 19:41:23 +03:00
/**
* Snapshots for each disk
*/
map < int , Snapshots * > snapshots ;
2015-06-23 22:52:10 +03:00
/**
* User template to store custom metadata . This template can be updated
*/
VirtualMachineTemplate * user_obj_template ;
/**
* Monitoring information for the VM
*/
VirtualMachineMonitorInfo monitoring ;
2008-06-17 20:27:32 +04:00
/**
* Log class for the virtual machine , it writes log messages in
2010-04-11 00:16:47 +04:00
* $ ONE_LOCATION / var / $ VID / vm . log
2009-01-02 17:58:51 +03:00
* or , in case that OpenNebula is installed in root
2010-04-11 00:16:47 +04:00
* / var / log / one / $ VM_ID . log
2015-06-23 22:52:10 +03:00
* For the syslog it will use the predefined / var / log / locations
2008-06-17 20:27:32 +04:00
*/
2013-01-25 20:32:12 +04:00
Log * _log ;
2012-02-25 02:13:22 +04:00
2013-01-04 03:04:01 +04:00
2008-06-17 20:27:32 +04:00
// *************************************************************************
// DataBase implementation (Private)
// *************************************************************************
/**
* Bootstraps the database table ( s ) associated to the VirtualMachine
2011-10-10 17:14:46 +04:00
* @ return 0 on success
2008-06-17 20:27:32 +04:00
*/
2011-10-10 17:14:46 +04:00
static int bootstrap ( SqlDB * db )
2008-06-17 20:27:32 +04:00
{
2011-10-10 17:14:46 +04:00
int rc ;
2010-04-11 00:16:47 +04:00
ostringstream oss_vm ( VirtualMachine : : db_bootstrap ) ;
2012-05-16 18:09:27 +04:00
ostringstream oss_monit ( VirtualMachine : : monit_db_bootstrap ) ;
2010-04-11 00:16:47 +04:00
ostringstream oss_hist ( History : : db_bootstrap ) ;
2014-10-30 19:21:27 +03:00
ostringstream oss_showback ( VirtualMachine : : showback_db_bootstrap ) ;
2008-06-17 20:27:32 +04:00
2011-10-10 17:14:46 +04:00
rc = db - > exec ( oss_vm ) ;
2012-05-16 18:09:27 +04:00
rc + = db - > exec ( oss_monit ) ;
2011-10-10 17:14:46 +04:00
rc + = db - > exec ( oss_hist ) ;
2014-10-30 19:21:27 +03:00
rc + = db - > exec ( oss_showback ) ;
2011-10-10 17:14:46 +04:00
return rc ;
2008-06-17 20:27:32 +04:00
} ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
/**
2010-04-11 00:16:47 +04:00
* Callback function to unmarshall a VirtualMachine object
* ( VirtualMachine : : select )
2008-06-17 20:27:32 +04:00
* @ param num the number of columns read from the DB
2009-05-22 04:46:52 +04:00
* @ param names the column names
* @ param vaues the column values
2008-06-17 20:27:32 +04:00
* @ return 0 on success
*/
2010-04-11 00:16:47 +04:00
int select_cb ( void * nil , int num , char * * names , char * * values ) ;
2010-06-25 15:24:54 +04:00
2010-04-29 20:11:04 +04:00
/**
2010-06-25 15:24:54 +04:00
* Execute an INSERT or REPLACE Sql query .
2010-04-29 20:11:04 +04:00
* @ param db The SQL DB
2010-06-25 15:24:54 +04:00
* @ param replace Execute an INSERT or a REPLACE
2011-12-19 20:07:32 +04:00
* @ param error_str Returns the error reason , if any
2010-04-29 20:11:04 +04:00
* @ return 0 one success
2011-12-19 20:07:32 +04:00
*/
int insert_replace ( SqlDB * db , bool replace , string & error_str ) ;
2009-07-09 18:34:34 +04:00
2008-06-17 20:27:32 +04:00
/**
* Updates the VM history record
* @ param db pointer to the db
2009-03-06 15:10:15 +03:00
* @ return 0 on success
2008-06-17 20:27:32 +04:00
*/
2010-04-11 00:16:47 +04:00
int update_history ( SqlDB * db )
2008-06-17 20:27:32 +04:00
{
if ( history ! = 0 )
{
2010-05-03 21:29:08 +04:00
return history - > update ( db ) ;
2008-06-17 20:27:32 +04:00
}
else
return - 1 ;
} ;
/**
2008-06-22 05:51:49 +04:00
* Updates the previous history record
2008-06-17 20:27:32 +04:00
* @ param db pointer to the db
2009-03-06 15:10:15 +03:00
* @ return 0 on success
2008-06-17 20:27:32 +04:00
*/
2010-04-11 00:16:47 +04:00
int update_previous_history ( SqlDB * db )
2008-06-22 05:51:49 +04:00
{
if ( previous_history ! = 0 )
{
2010-05-03 21:29:08 +04:00
return previous_history - > update ( db ) ;
2008-06-22 05:51:49 +04:00
}
else
return - 1 ;
} ;
2009-03-06 15:10:15 +03:00
2012-05-16 18:09:27 +04:00
/**
* Inserts the last monitoring , and deletes old monitoring entries .
*
* @ param db pointer to the db
* @ return 0 on success
*/
int update_monitoring ( SqlDB * db ) ;
2009-04-02 14:14:54 +04:00
// -------------------------------------------------------------------------
// Attribute Parser
// -------------------------------------------------------------------------
2009-03-06 15:10:15 +03:00
2009-04-02 14:14:54 +04:00
/**
* Mutex to perform just one attribute parse at a time
*/
static pthread_mutex_t lex_mutex ;
2012-11-18 03:01:43 +04:00
/**
* Generates image attributes ( DS_ID , TM_MAD , SOURCE . . . ) for KERNEL and
* INITRD files .
* @ param os attribute of the VM template
* @ param base_name of the attribute " KERNEL " , or " INITRD "
2012-12-05 02:19:08 +04:00
* @ param base_type of the image attribute KERNEL , RAMDISK
2012-11-18 03:01:43 +04:00
* @ param error_str Returns the error reason , if any
* @ return 0 on success
*/
int set_os_file ( VectorAttribute * os ,
const string & base_name ,
2012-12-05 02:19:08 +04:00
Image : : ImageType base_type ,
2012-11-18 03:01:43 +04:00
string & error_str ) ;
2012-11-17 05:46:03 +04:00
/**
* Parse the " OS " attribute of the template by substituting
* $ FILE variables
* @ param error_str Returns the error reason , if any
* @ return 0 on success
*/
int parse_os ( string & error_str ) ;
2014-07-11 01:32:06 +04:00
/**
* Attributes not allowed in NIC_DEFAULT to avoid authorization bypass and
* inconsistencies for NIC_DEFAULTS
*/
static const char * NO_NIC_DEFAULTS [ ] ;
static const int NUM_NO_NIC_DEFAULTS ;
2016-03-16 16:53:05 +03:00
/**
* Parse and generate the ETH_ network attributed of a NIC
* @ param context attribute
* @ param nic attribute
*
* @ return 0 on success
*/
2016-05-06 13:17:31 +03:00
void parse_nic_context ( VectorAttribute * context , VectorAttribute * nic ) ;
2016-03-16 16:53:05 +03:00
/**
* Generate the NETWORK related CONTEXT setions , i . e . ETH_ * . This function
* is invoked when ever the context is prepared for the VM to capture
* netowrking updates .
* @ param context attribute of the VM
2016-09-13 14:10:33 +03:00
* @ param error string if any
* @ return 0 on success
2016-03-16 16:53:05 +03:00
*/
2016-09-13 14:10:33 +03:00
int generate_network_context ( VectorAttribute * context , string & error ) ;
2016-04-26 13:39:29 +03:00
2016-07-18 18:04:41 +03:00
/**
* Generate the PCI related CONTEXT setions , i . e . PCI_ * . This function
* is also adds basic network attributes for pass - through NICs
* @ param context attribute of the VM
* @ return true if the net context was generated .
*/
bool generate_pci_context ( VectorAttribute * context ) ;
2016-04-26 13:39:29 +03:00
/**
* Generate the ONE_GATE token & url
* @ param context attribute of the VM
* @ param error_str describing the error
* @ return 0 if success
*/
int generate_token_context ( VectorAttribute * context , string & error_str ) ;
2014-07-10 18:24:25 +04:00
/**
* Parse the " NIC_DEFAULT " attribute
* @ param error_str Returns the error reason , if any
* @ return 0 on success
*/
int parse_defaults ( string & error_str ) ;
2015-12-01 18:36:50 +03:00
/**
* Parse virtual router related attributes
* @ param error_str Returns the error reason , if any
* @ return 0 on success
*/
int parse_vrouter ( string & error_str ) ;
2016-01-19 20:13:31 +03:00
/**
* Known Virtual Router attributes , to be moved from the user template
* to the template
*/
static const char * VROUTER_ATTRIBUTES [ ] ;
static const int NUM_VROUTER_ATTRIBUTES ;
2015-05-19 19:41:23 +03:00
/**
2015-04-28 17:24:40 +03:00
* Known attributes for network contextualization rendered as :
* ETH_ < nicid > _ < context [ 0 ] > = $ NETWORK [ context [ 1 ] , vnet_name ]
*
2015-05-19 19:41:23 +03:00
* The context [ 1 ] values in the map are searched in the NIC and
* if not found in the AR and VNET . They can be also set in the
2015-04-28 17:24:40 +03:00
* CONTEXT section it self using full name ( ETH_ ) .
*
* IPv4 context variables :
* { " IP " , " IP " } ,
* { " MAC " , " MAC " } ,
2015-04-29 18:58:26 +03:00
* { " MASK " , " NETWORK_MASK " } ,
2015-04-28 17:24:40 +03:00
* { " NETWORK " , " NETWORK_ADDRESS " } ,
* { " GATEWAY " , " GATEWAY " } ,
* { " DNS " , " DNS " } ,
* { " SEARCH_DOMAIN " , " SEARCH_DOMAIN " }
*
* IPv6 context :
* { " IP6 " , " IP6_GLOBAL " } ,
* { " GATEWAY6 " , " GATEWAY6 " } ,
* { " CONTEXT_FORCE_IPV4 " , " CONTEXT_FORCE_IPV4 " }
*/
static const char * NETWORK_CONTEXT [ ] [ 2 ] ;
static const int NUM_NETWORK_CONTEXT ;
static const char * NETWORK6_CONTEXT [ ] [ 2 ] ;
static const int NUM_NETWORK6_CONTEXT ;
2015-09-02 18:30:51 +03:00
/**
* Parse the " PCI " attribute of the template and checks mandatory attributes
* @ param error_str Returns the error reason , if any
* @ return 0 on success
*/
int parse_pci ( string & error_str ) ;
2009-04-02 14:14:54 +04:00
/**
2010-03-05 21:17:52 +03:00
* Parse the " CONTEXT " attribute of the template by substituting
* $ VARIABLE , $ VARIABLE [ ATTR ] and $ VARIABLE [ ATTR , ATTR = VALUE ]
2011-03-22 20:40:03 +03:00
* @ param error_str Returns the error reason , if any
2010-03-05 21:17:52 +03:00
* @ return 0 on success
*/
2011-03-22 20:40:03 +03:00
int parse_context ( string & error_str ) ;
2010-03-05 21:17:52 +03:00
2016-01-27 13:27:26 +03:00
/**
2016-02-07 20:01:42 +03:00
* Parses the current contents of the context vector attribute , without
* adding any attributes . Substitutes $ VARIABLE , $ VARIABLE [ ATTR ] and
* $ VARIABLE [ ATTR , ATTR = VALUE ]
* @ param pointer to the context attribute . It will be updated to point
* to the new parsed CONTEXT
* @ param error_str description in case of error
* @ return 0 on success
*/
int parse_context_variables ( VectorAttribute * * context , string & error_str ) ;
2016-01-27 13:27:26 +03:00
2010-03-05 21:17:52 +03:00
/**
2013-02-06 19:34:46 +04:00
* Parse the " SCHED_REQUIREMENTS " attribute of the template by substituting
2010-03-05 21:17:52 +03:00
* $ VARIABLE , $ VARIABLE [ ATTR ] and $ VARIABLE [ ATTR , ATTR = VALUE ]
2011-03-22 20:40:03 +03:00
* @ param error_str Returns the error reason , if any
2010-03-05 21:17:52 +03:00
* @ return 0 on success
*/
2011-03-22 20:40:03 +03:00
int parse_requirements ( string & error_str ) ;
2010-06-25 16:34:44 +04:00
2010-03-05 21:17:52 +03:00
/**
* Parse the " GRAPHICS " attribute and generates a default PORT if not
* defined
2010-04-11 00:16:47 +04:00
*/
2013-11-21 15:07:06 +04:00
int parse_graphics ( string & error_str ) ;
2010-04-11 00:16:47 +04:00
2013-02-26 16:03:40 +04:00
/**
* Searches the meaningful attributes and moves them from the user template
* to the internal template
*/
void parse_well_known_attributes ( ) ;
2011-06-25 03:29:44 +04:00
/**
* Function that renders the VM in XML format optinally including
* extended information ( all history records )
* @ param xml the resulting XML string
2012-05-08 17:42:24 +04:00
* @ param n_history Number of history records to include :
* 0 : none
* 1 : the last one
* 2 : all
2011-06-25 03:29:44 +04:00
* @ return a reference to the generated string
*/
2012-05-08 17:42:24 +04:00
string & to_xml_extended ( string & xml , int n_history ) const ;
2011-06-25 03:29:44 +04:00
2014-07-11 01:32:06 +04:00
/**
* Merges NIC_DEFAULT with the given NIC
* @ param nic NIC to process
*/
void merge_nic_defaults ( VectorAttribute * nic ) ;
2014-11-11 18:42:49 +03:00
// -------------------------------------------------------------------------
// NIC & DISK Management Helpers
// -------------------------------------------------------------------------
/**
* Get all network leases for this Virtual Machine
* @ return 0 if success
*/
int get_network_leases ( string & error_str ) ;
/**
* Returns a set of the security group IDs of this NIC
* @ param nic NIC to get the security groups from
2014-11-11 20:52:06 +03:00
* @ param sgs a set of security group IDs
2014-11-11 18:42:49 +03:00
*/
2015-06-24 21:02:37 +03:00
static void get_security_groups ( const VectorAttribute * nic , set < int > & sgs )
2014-11-11 20:52:06 +03:00
{
one_util : : split_unique ( nic - > vector_value ( " SECURITY_GROUPS " ) , ' , ' , sgs ) ;
}
2014-11-11 18:42:49 +03:00
/**
* Get all disk images for this Virtual Machine
* @ param error_str Returns the error reason , if any
* @ return 0 if success
*/
int get_disk_images ( string & error_str ) ;
2015-05-19 19:41:23 +03:00
/**
* Return the VectorAttribute representation of a disk
* @ param disk_id of the disk
* @ return pointer to the VectorAttribute
*/
2015-06-04 20:46:46 +03:00
VectorAttribute * get_disk ( int disk_id )
{
return const_cast < VectorAttribute * > (
static_cast < const VirtualMachine & > ( * this ) . get_disk ( disk_id ) ) ;
} ;
2016-01-27 13:27:26 +03:00
/**
* Returns the NIC that is waiting for an attachment action
*
* @ return the NIC waiting for an attachment action , or 0
*/
VectorAttribute * get_attach_nic ( ) ;
2015-10-23 21:23:59 +03:00
// ------------------------------------------------------------------------
// Public cloud templates related functions
// ------------------------------------------------------------------------
/**
* Gets the list of public clouds defined in this VM .
* @ param clouds list to store the cloud hypervisors in the template
* @ return the number of public cloud hypervisors
*/
int get_public_clouds ( set < string > & clouds ) const
{
2015-10-30 17:41:09 +03:00
get_public_clouds ( " PUBLIC_CLOUD " , clouds ) ;
2015-10-23 21:23:59 +03:00
2015-10-30 17:41:09 +03:00
return clouds . size ( ) ;
2015-10-23 21:23:59 +03:00
} ;
/**
* Same as above but specifies the attribute name to handle old versions
2015-10-30 17:41:09 +03:00
* @ param name Attribute name
* @ param clouds list to store the cloud hypervisors in the template
2015-10-23 21:23:59 +03:00
*/
2015-10-30 17:41:09 +03:00
void get_public_clouds ( const string & name , set < string > & clouds ) const ;
2015-10-23 21:23:59 +03:00
/**
* Parse the public cloud attributes and subsititue variable definition
* for the values in the template , i . e . :
* INSTANCE_TYPE = " m1-small "
*
* PUBLIC_CLOUD = [ TYPE = " ec2 " , INSTANCE = " $INSTANCE_TYPE " . . .
*
* @ param error description if any
* @ return - 1 in case of error
*/
int parse_public_clouds ( string & error )
{
int rc = parse_public_clouds ( " PUBLIC_CLOUD " , error ) ;
if ( rc = = 0 )
{
rc = parse_public_clouds ( " EC2 " , error ) ;
}
return rc ;
} ;
/**
* Same as above but specifies the attribute name to handle old versions
*/
int parse_public_clouds ( const char * name , string & error ) ;
2015-05-19 19:41:23 +03:00
2008-06-17 20:27:32 +04:00
protected :
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
//**************************************************************************
// Constructor
//**************************************************************************
2009-03-06 15:10:15 +03:00
2012-10-05 15:23:44 +04:00
VirtualMachine ( int id ,
2011-06-30 13:31:00 +04:00
int uid ,
2012-10-05 15:23:44 +04:00
int gid ,
2011-06-30 13:31:00 +04:00
const string & uname ,
const string & gname ,
2013-01-18 21:34:51 +04:00
int umask ,
2011-06-30 13:31:00 +04:00
VirtualMachineTemplate * _vm_template ) ;
2008-06-17 20:27:32 +04:00
virtual ~ VirtualMachine ( ) ;
2009-03-06 15:10:15 +03:00
2008-06-17 20:27:32 +04:00
// *************************************************************************
// DataBase implementation
// *************************************************************************
2012-10-05 15:23:44 +04:00
2012-05-05 05:18:25 +04:00
static const char * table ;
2008-06-17 20:27:32 +04:00
static const char * db_names ;
static const char * db_bootstrap ;
2009-03-06 15:10:15 +03:00
2012-05-16 18:09:27 +04:00
static const char * monit_table ;
static const char * monit_db_names ;
static const char * monit_db_bootstrap ;
2014-10-30 19:21:27 +03:00
static const char * showback_table ;
static const char * showback_db_names ;
static const char * showback_db_bootstrap ;
2008-06-17 20:27:32 +04:00
/**
* Reads the Virtual Machine ( identified with its OID ) from the database .
* @ param db pointer to the db
* @ return 0 on success
*/
2010-04-11 00:16:47 +04:00
int select ( SqlDB * db ) ;
2008-06-17 20:27:32 +04:00
/**
* Writes the Virtual Machine and its associated template in the database .
* @ param db pointer to the db
* @ return 0 on success
*/
2011-03-08 19:55:14 +03:00
int insert ( SqlDB * db , string & error_str ) ;
2008-06-17 20:27:32 +04:00
/**
* Writes / updates the Virtual Machine data fields in the database .
* @ param db pointer to the db
* @ return 0 on success
*/
2011-03-08 19:55:14 +03:00
int update ( SqlDB * db )
{
2011-12-19 20:07:32 +04:00
string error_str ;
return insert_replace ( db , true , error_str ) ;
2011-03-08 19:55:14 +03:00
}
2010-04-11 00:16:47 +04:00
2008-06-17 20:27:32 +04:00
/**
2010-05-25 20:19:22 +04:00
* Deletes a VM from the database and all its associated information
2008-06-17 20:27:32 +04:00
* @ param db pointer to the db
2010-05-25 20:19:22 +04:00
* @ return - 1
2008-06-17 20:27:32 +04:00
*/
2011-03-08 19:55:14 +03:00
int drop ( SqlDB * db )
2009-03-06 15:10:15 +03:00
{
2010-05-25 20:19:22 +04:00
NebulaLog : : log ( " ONE " , Log : : ERROR , " VM Drop not implemented! " ) ;
return - 1 ;
2008-06-17 20:27:32 +04:00
}
2013-03-13 20:43:42 +04:00
2008-06-17 20:27:32 +04:00
} ;
# endif /*VIRTUAL_MACHINE_H_*/