1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-25 02:50:08 +03:00

Cosmetic changes...

git-svn-id: http://svn.opennebula.org/one/trunk@389 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Rubén S. Montero 2009-03-06 15:54:57 +00:00
parent 2e4beab16e
commit 1d94e0ba52
7 changed files with 245 additions and 218 deletions

View File

@ -639,19 +639,22 @@ public:
void get_requirements (int& cpu, int& memory, int& disk);
// ------------------------------------------------------------------------
// Leases
// Network Leases
// ------------------------------------------------------------------------
/**
* Get all network leases for this Virtual Machine
* @return 0 if success
*/
int get_leases();
int get_network_leases();
/**
* Releases all network leases taken by this Virtual Machine
*/
void release_leases();
void release_network_leases();
// ------------------------------------------------------------------------
// Context related functions
// ------------------------------------------------------------------------
/**
* Writes the context file for this VM.
* @return 0 if success
@ -844,9 +847,11 @@ private:
rc = vm_template.replace_attribute(db,sattr);
if (rc != 0)
{
delete sattr;
}
return rc;
return rc;
}
/**

View File

@ -292,7 +292,9 @@ private:
rc = vn_template.replace_attribute(db,sattr);
if (rc != 0)
{
delete sattr;
}
return rc;
}

View File

@ -27,7 +27,7 @@ int DispatchManager::allocate (
int * oid)
{
Nebula::log("DiM",Log::DEBUG,"Allocating a new VM");
return vmpool->allocate(uid,stemplate,oid);
};
@ -39,45 +39,45 @@ int DispatchManager::deploy (
{
ostringstream oss;
int vid;
if ( vm == 0 )
{
return -1;
}
vid = vm->get_oid();
oss << "Deploying VM " << vid;
oss << "Deploying VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
if ( vm->get_state() == VirtualMachine::PENDING )
{
Nebula& nd = Nebula::instance();
LifeCycleManager * lcm = nd.get_lcm();
vm->set_state(VirtualMachine::ACTIVE);
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is ACTIVE.");
lcm->trigger(LifeCycleManager::DEPLOY,vid);
}
else
{
goto error;
goto error;
}
vm->unlock();
return 0;
error:
oss.str("");
oss << "Could not deploy VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -1;
}
@ -90,42 +90,42 @@ int DispatchManager::migrate(
{
ostringstream oss;
int vid;
if ( vm == 0 )
{
return -1;
}
vid = vm->get_oid();
oss << "Migrating VM " << vid;
oss << "Migrating VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
Nebula& nd = Nebula::instance();
LifeCycleManager * lcm = nd.get_lcm();
lcm->trigger(LifeCycleManager::MIGRATE,vid);
lcm->trigger(LifeCycleManager::MIGRATE,vid);
}
else
{
goto error;
goto error;
}
vm->unlock();
return 0;
error:
oss.str("");
oss << "Could not migrate VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -1;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -135,42 +135,42 @@ int DispatchManager::live_migrate(
{
ostringstream oss;
int vid;
if ( vm == 0 )
{
return -1;
}
vid = vm->get_oid();
oss << "Live-migrating VM " << vid;
oss << "Live-migrating VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
Nebula& nd = Nebula::instance();
LifeCycleManager * lcm = nd.get_lcm();
lcm->trigger(LifeCycleManager::LIVE_MIGRATE,vid);
lcm->trigger(LifeCycleManager::LIVE_MIGRATE,vid);
}
else
{
goto error;
goto error;
}
vm->unlock();
return 0;
error:
oss.str("");
oss << "Could not live-migrate VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -1;
}
}
/* ************************************************************************** */
/* ************************************************************************** */
@ -180,40 +180,40 @@ int DispatchManager::shutdown (
{
ostringstream oss;
VirtualMachine * vm;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return -1;
}
oss << "Shutting down VM " << vid;
oss << "Shutting down VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
Nebula& nd = Nebula::instance();
LifeCycleManager * lcm = nd.get_lcm();
lcm->trigger(LifeCycleManager::SHUTDOWN,vid);
lcm->trigger(LifeCycleManager::SHUTDOWN,vid);
}
else
{
goto error;
goto error;
}
vm->unlock();
return 0;
error:
oss.str("");
oss << "Could not shutdown VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -2;
}
@ -226,43 +226,43 @@ int DispatchManager::hold(
{
VirtualMachine * vm;
ostringstream oss;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return -1;
}
oss << "Holding VM " << vid;
oss << "Holding VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
if (vm->get_state() == VirtualMachine::PENDING)
{
vm->set_state(VirtualMachine::HOLD);
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is HOLD.");
}
else
{
goto error;
goto error;
}
vm->unlock();
return 0;
error:
oss.str("");
oss << "Could not hold VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -2;
}
return -2;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -272,42 +272,42 @@ int DispatchManager::release(
{
VirtualMachine * vm;
ostringstream oss;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return -1;
}
oss << "Releasing VM " << vid;
oss << "Releasing VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
if (vm->get_state() == VirtualMachine::HOLD)
{
vm->set_state(VirtualMachine::PENDING);
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is PENDING.");
}
else
{
goto error;
goto error;
}
vm->unlock();
return 0;
error:
oss.str("");
oss << "Could not release VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -2;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -317,42 +317,42 @@ int DispatchManager::stop(
{
VirtualMachine * vm;
ostringstream oss;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return -1;
}
oss << "Stopping VM " << vid;
oss << "Stopping VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
Nebula& nd = Nebula::instance();
LifeCycleManager * lcm = nd.get_lcm();
lcm->trigger(LifeCycleManager::STOP,vid);
lcm->trigger(LifeCycleManager::STOP,vid);
}
else
{
goto error;
goto error;
}
vm->unlock();
return 0;
error:
oss.str("");
oss << "Could not stop VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -2;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -362,17 +362,17 @@ int DispatchManager::cancel(
{
VirtualMachine * vm;
ostringstream oss;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return -1;
}
oss << "Cancelling VM " << vid;
oss << "Cancelling VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
@ -380,21 +380,21 @@ int DispatchManager::cancel(
LifeCycleManager * lcm = nd.get_lcm();
vm->unlock();
lcm->trigger(LifeCycleManager::CANCEL,vid);
lcm->trigger(LifeCycleManager::CANCEL,vid);
}
else
{
goto error;
goto error;
}
return 0;
error:
oss.str("");
oss << "Could not cancel VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -2;
}
@ -407,42 +407,42 @@ int DispatchManager::suspend(
{
VirtualMachine * vm;
ostringstream oss;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return -1;
}
oss << "Suspending VM " << vid;
oss << "Suspending VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
if (vm->get_state() == VirtualMachine::ACTIVE &&
vm->get_lcm_state() == VirtualMachine::RUNNING )
{
Nebula& nd = Nebula::instance();
LifeCycleManager * lcm = nd.get_lcm();
lcm->trigger(LifeCycleManager::SUSPEND,vid);
lcm->trigger(LifeCycleManager::SUSPEND,vid);
}
else
{
goto error;
goto error;
}
vm->unlock();
return 0;
error:
oss.str("");
oss << "Could not suspend VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -2;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -452,24 +452,24 @@ int DispatchManager::resume(
{
VirtualMachine * vm;
ostringstream oss;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return -1;
}
oss << "Resuming VM " << vid;
oss << "Resuming VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
if (vm->get_state() == VirtualMachine::STOPPED )
{
vm->set_state(VirtualMachine::PENDING);
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is PENDING.");
vm->log("DiM", Log::INFO, "New VM state is PENDING.");
}
else if (vm->get_state() == VirtualMachine::SUSPENDED)
{
@ -477,30 +477,30 @@ int DispatchManager::resume(
LifeCycleManager * lcm = nd.get_lcm();
vm->set_state(VirtualMachine::ACTIVE);
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is ACTIVE.");
lcm->trigger(LifeCycleManager::RESTORE,vid);
lcm->trigger(LifeCycleManager::RESTORE,vid);
}
else
{
goto error;
goto error;
}
vm->unlock();
return 0;
error:
oss.str("");
oss << "Could not resume VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -2;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -510,45 +510,45 @@ int DispatchManager::finalize(
{
VirtualMachine * vm;
ostringstream oss;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return -1;
}
if (vm->get_state() != VirtualMachine::ACTIVE &&
if (vm->get_state() != VirtualMachine::ACTIVE &&
vm->get_state() != VirtualMachine::DONE )
{
oss << "Finalizing VM " << vid;
oss << "Finalizing VM " << vid;
Nebula::log("DiM",Log::DEBUG,oss);
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_state(VirtualMachine::DONE);
vm->set_exit_time(time(0));
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is DONE.");
vm->release_leases();
vm->release_network_leases();
vmpool->remove(vm);
return 0;
}
oss.str("");
oss << "Could not finalize VM " << vid << ", wrong state.";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
return -2;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -21,40 +21,40 @@
void DispatchManager::suspend_success_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return;
}
if (vm->get_state() == VirtualMachine::ACTIVE )
{
{
vm->set_state(VirtualMachine::SUSPENDED);
vm->set_state(VirtualMachine::LCM_INIT);
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is SUSPENDED");
}
else
{
goto error;
goto error;
}
vm->unlock();
return;
error:
ostringstream oss;
oss << "suspend_success action received but VM " << vid
<< " not in ACTIVE state";
oss << "suspend_success action received but VM " << vid
<< " not in ACTIVE state";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
}
@ -64,40 +64,40 @@ error:
void DispatchManager::stop_success_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return;
}
if (vm->get_state() == VirtualMachine::ACTIVE )
{
{
vm->set_state(VirtualMachine::STOPPED);
vm->set_state(VirtualMachine::LCM_INIT);
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is STOPPED");
}
else
{
goto error;
goto error;
}
vm->unlock();
return;
error:
ostringstream oss;
oss << "stop_success action received but VM " << vid
<< " not in ACTIVE state";
oss << "stop_success action received but VM " << vid
<< " not in ACTIVE state";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
}
@ -107,43 +107,43 @@ error:
void DispatchManager::done_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return;
}
if ( vm->get_state() == VirtualMachine::ACTIVE )
{
vm->set_state(VirtualMachine::DONE);
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_exit_time(time(0));
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is DONE");
vm->release_leases();
vm->release_network_leases();
vmpool->remove(vm);
}
else
{
goto error;
goto error;
}
return;
error:
ostringstream oss;
oss << "done action received but VM " << vid << " not in ACTIVE state";
oss << "done action received but VM " << vid << " not in ACTIVE state";
Nebula::log("DiM",Log::ERROR,oss);
vm->unlock();
}
@ -153,26 +153,26 @@ error:
void DispatchManager::failed_action(int vid)
{
VirtualMachine * vm;
vm = vmpool->get(vid,true);
if ( vm == 0 )
{
return;
}
vm->set_state(VirtualMachine::LCM_INIT);
vm->set_state(VirtualMachine::FAILED);
vm->set_exit_time(time(0));
vmpool->update(vm);
vm->log("DiM", Log::INFO, "New VM state is FAILED");
vm->unlock();
return;
}

View File

@ -272,7 +272,9 @@ int TemplateSQL::replace_attribute(SqliteDB * db, Attribute * attribute)
delete astr;
if ((rc = db->exec(oss)) != 0 )
rc = db->exec(oss);
if (rc != 0 )
{
return rc;
}
@ -314,7 +316,9 @@ int TemplateSQL::insert_attribute(SqliteDB * db, Attribute * attribute)
delete astr;
if ((rc = db->exec(oss)) == 0)
rc = db->exec(oss);
if (rc == 0)
{
attributes.insert(make_pair(attribute->name(),attribute));
}

View File

@ -302,7 +302,7 @@ int VirtualMachine::insert(SqliteDB * db)
// Get network leases
// ------------------------------------------------------------------------
rc = get_leases();
rc = get_network_leases();
if ( rc != 0 )
{
@ -336,12 +336,12 @@ error_update:
error_template:
Nebula::log("ONE",Log::ERROR, "Can not insert template in the database");
release_leases();
release_network_leases();
return -1;
error_leases:
Nebula::log("ONE",Log::ERROR, "Could not get network lease for VM");
release_leases();
release_network_leases();
return -1;
}
@ -496,7 +496,7 @@ void VirtualMachine::get_requirements (int& cpu, int& memory, int& disk)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachine::get_leases()
int VirtualMachine::get_network_leases()
{
int num_nics, rc;
vector<Attribute * > nics;
@ -579,7 +579,7 @@ int VirtualMachine::get_leases()
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachine::release_leases()
void VirtualMachine::release_network_leases()
{
Nebula& nd = Nebula::instance();

View File

@ -37,8 +37,9 @@ int VirtualMachinePool::allocate (
vector<Attribute *> attrs;
// ------------------------------------------------------------------------
// Build a new Virtual Machine object
// ------------------------------------------------------------------------
vm = new VirtualMachine;
if (on_hold == true)
@ -52,6 +53,9 @@ int VirtualMachinePool::allocate (
vm->uid = uid;
// ------------------------------------------------------------------------
// Parse template and keep CONTEXT apart
// ------------------------------------------------------------------------
rc = vm->vm_template.parse(stemplate,&error_msg);
if ( rc != 0 )
@ -67,8 +71,9 @@ int VirtualMachinePool::allocate (
vm->vm_template.remove("CONTEXT",attrs);
// ------------------------------------------------------------------------
// Insert the Object in the pool
// ------------------------------------------------------------------------
*oid = PoolSQL::allocate(vm);
if ( *oid == -1 )
@ -76,12 +81,17 @@ int VirtualMachinePool::allocate (
return -1;
}
// ------------------------------------------------------------------------
// Insert parsed context in the VM template and clean-up
// ------------------------------------------------------------------------
generate_context(*oid,attrs);
for (int i = 0; i < attrs.size() ; i++)
{
if (attrs[i] != 0)
delete attrs[i];
{
delete attrs[i];
}
}
return 0;
@ -183,10 +193,14 @@ void VirtualMachinePool::generate_context(int vm_id, vector<Attribute *> attrs)
if ( vm == 0 )
{
delete context_parsed;
return;
}
vm->insert_template_attribute(db,context_parsed);
if ( vm->insert_template_attribute(db,context_parsed) != 0 )
{
delete context_parsed;
}
vm->unlock();
}
@ -210,6 +224,8 @@ extern "C"
void vm_var__delete_buffer(YY_BUFFER_STATE);
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachinePool::parse_attribute(int vm_id,
string &attribute,