diff --git a/include/TemplateSQL.h b/include/TemplateSQL.h index b643ff9207..99cc37cc96 100644 --- a/include/TemplateSQL.h +++ b/include/TemplateSQL.h @@ -118,11 +118,6 @@ protected: */ int remove_attribute(SqlDB * db, const string& name); - /** - * Callback to set the template id (TemplateSQL::insert) - */ - int insert_cb(void *nil, int num, char **values, char **names); - /** * Callback to recover template attributes (TemplateSQL::select) */ diff --git a/include/VirtualMachine.h b/include/VirtualMachine.h index 933e49c6d3..b56f4bb8ef 100644 --- a/include/VirtualMachine.h +++ b/include/VirtualMachine.h @@ -1001,18 +1001,17 @@ protected: UID = 1, NAME = 2, LAST_POLL = 3, - TEMPLATE_ID = 4, - STATE = 5, - LCM_STATE = 6, - STIME = 7, - ETIME = 8, - DEPLOY_ID = 9, - MEMORY = 10, - CPU = 11, - NET_TX = 12, - NET_RX = 13, - LAST_SEQ = 14, - LIMIT = 15 + STATE = 4, + LCM_STATE = 5, + STIME = 6, + ETIME = 7, + DEPLOY_ID = 8, + MEMORY = 9, + CPU = 10, + NET_TX = 11, + NET_RX = 12, + LAST_SEQ = 13, + LIMIT = 14 }; static const char * table; diff --git a/share/etc/oned.conf b/share/etc/oned.conf index 2b31197cb1..ef9998103e 100644 --- a/share/etc/oned.conf +++ b/share/etc/oned.conf @@ -257,6 +257,28 @@ TM_MAD = [ HM_MAD = [ executable = "one_hm" ] + + +#-------------------------------- Image Hook ----------------------------------- +# This hook is used to handle image saving and overwriting when virtual machines +# reach the DONE state after being shutdown. +# +# Uncomment one of the following: +# +# Self-contained (substitute [ONE_LOCATION] with its proper path) +# VM_HOOK = [ +# name = "image", +# on = "SHUTDOWN", +# command = "[ONE_LOCATION]/share/hooks/image.rb", +# arguments = "$VMID" ] +# +# System-wide +# VM_HOOK = [ +# name = "image", +# on = "SHUTDOWN", +# command = "/usr/share/doc/opennebula/hooks/image.rb", +# arguments = "$VMID" ] +#------------------------------------------------------------------------------- #-------------------------------- Hook Examples -------------------------------- #VM_HOOK = [ diff --git a/src/template/TemplateSQL.cc b/src/template/TemplateSQL.cc index 05f26caa82..d296f4d5a0 100644 --- a/src/template/TemplateSQL.cc +++ b/src/template/TemplateSQL.cc @@ -27,36 +27,10 @@ const char * TemplateSQL::db_names = "(id,name,type,value)"; /* ------------------------------------------------------------------------ */ /* ------------------------------------------------------------------------ */ -int TemplateSQL::insert_cb(void *nil, int num, char **values, char **names) -{ - if ( num<=0 ) - { - return -1; - } - - if ( values[0] == 0 ) - { - id = 0; - } - else - { - id = atoi(values[0]) + 1; - } - - return 0; -} - -/* ------------------------------------------------------------------------ */ - int TemplateSQL::insert(SqlDB * db) { int rc; - if ( rc != 0 ) - { - return -1; - } - rc = insert_replace(db, false); return rc; diff --git a/src/vm/VirtualMachine.cc b/src/vm/VirtualMachine.cc index 61238a222b..d3a5c80acf 100644 --- a/src/vm/VirtualMachine.cc +++ b/src/vm/VirtualMachine.cc @@ -83,13 +83,13 @@ VirtualMachine::~VirtualMachine() const char * VirtualMachine::table = "vm_pool"; const char * VirtualMachine::db_names = - "(oid,uid,name,last_poll,template_id,state,lcm_state,stime,etime,deploy_id" - ",memory,cpu,net_tx,net_rx,last_seq)"; + "(oid,uid,name,last_poll, state,lcm_state,stime,etime,deploy_id" + ",memory,cpu,net_tx,net_rx,last_seq)"; const char * VirtualMachine::db_bootstrap = "CREATE TABLE IF NOT EXISTS " "vm_pool (" "oid INTEGER PRIMARY KEY,uid INTEGER,name TEXT," - "last_poll INTEGER, template_id INTEGER,state INTEGER,lcm_state INTEGER," + "last_poll INTEGER, state INTEGER,lcm_state INTEGER," "stime INTEGER,etime INTEGER,deploy_id TEXT,memory INTEGER,cpu INTEGER," "net_tx INTEGER,net_rx INTEGER, last_seq INTEGER)"; @@ -102,7 +102,6 @@ int VirtualMachine::select_cb(void *nil, int num, char **values, char **names) (values[UID] == 0) || (values[NAME] == 0) || (values[LAST_POLL] == 0) || - (values[TEMPLATE_ID] == 0) || (values[STATE] == 0) || (values[LCM_STATE] == 0) || (values[STIME] == 0) || @@ -140,7 +139,8 @@ int VirtualMachine::select_cb(void *nil, int num, char **values, char **names) net_rx = atoi(values[NET_RX]); last_seq = atoi(values[LAST_SEQ]); - vm_template.id = atoi(values[TEMPLATE_ID]); + // Virtual Machine template ID is the VM ID + vm_template.id = oid; return 0; } @@ -266,6 +266,14 @@ int VirtualMachine::insert(SqlDB * db) SingleAttribute * attr; string value; ostringstream oss; + + // ----------------------------------------------------------------------- + // Set a template ID if it wasn't already assigned + // ------------------------------------------------------------------------ + if ( vm_template.id == -1 ) + { + vm_template.id = oid; + } // ----------------------------------------------------------------------- // Set a name if the VM has not got one and VM_ID @@ -593,7 +601,6 @@ int VirtualMachine::insert_replace(SqlDB *db, bool replace) << uid << "," << "'" << sql_name << "'," << last_poll << "," - << vm_template.id << "," << state << "," << lcm_state << "," << stime << ","