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

Merge branch 'feature-863' of git.opennebula.org:one into feature-863

This commit is contained in:
Carlos Martín 2011-11-10 03:14:42 -08:00
commit 9b0f47068a
33 changed files with 334 additions and 123 deletions

View File

@ -259,9 +259,9 @@ public:
* Generates a XML string for the template of the Object
* @param xml the string to store the XML description.
*/
void template_to_xml(string &xml) const
string& template_to_xml(string &xml) const
{
obj_template->to_xml(xml);
return obj_template->to_xml(xml);
}
/**

View File

@ -273,6 +273,32 @@ public:
return previous_history->vmm_mad_name;
};
/**
* Returns the VNM driver name for the current host. The hasHistory()
* function MUST be called before this one.
* @return the VMM mad name
*/
// const string & get_vnm_mad() const
string get_vnm_mad() const
{
string tmp = "TODO";
return tmp;
//TODO return history->vnm_mad_name;
};
/**
* Returns the VNM driver name for the previous host. The hasPreviousHistory()
* function MUST be called before this one.
* @return the VMM mad name
*/
// const string & get_previous_vnm_mad() const
string get_previous_vnm_mad() const
{
string tmp = "TODO";
return tmp;
//return previous_history->vnm_mad_name;
};
/**
* Returns the TM driver name for the current host. The hasHistory()
* function MUST be called before this one.

View File

@ -175,6 +175,40 @@ private:
const string & action,
void * arg);
/**
* Function to format a VMM Driver message in the form:
* <VMM_DRIVER_ACTION_DATA>
* <HOST> hostname </HOST>
* <NET_DRV> net_drv </NET_DRV>
* <MIGR_HOST> m_hostname </MIGR_HOST>
* <MIGR_NET_DRV> m_net_drv </MIGR_NET_DRV>
* <DOMAIN> domain_id </DOMAIN>
* <DEPLOYMENT_FILE> dfile </DEPLOYMENT_FILE>
* <CHECKPOINT_FILE> cfile </CHECKPOINT_FILE>
* <VM_TEMPLATE>
* VM representation in XML
* </VM_TEMPLATE>
* </VMM_DRIVER_ACTION_DATA>
*
* @param hostname of the host to perform the action
* @param net_drv name of the vlan driver
* @param m_hostname name of the host to migrate the VM
* @param m_net_drv name of the vlan driver
* @param domain domain id as returned by the hypervisor
* @param dfile deployment file to boot the VM
* @param cfile checkpoint file to save the VM
* @param tmpl the VM information in XML
*/
string * format_message(
const string& hostname,
const string& net_drv,
const string& m_hostname,
const string& m_net_drv,
const string& domain,
const string& dfile,
const string& cfile,
const string& tmpl);
/**
* Function executed when a DEPLOY action is received. It deploys a VM on
* a Host.

View File

@ -110,108 +110,76 @@ private:
friend class VirtualMachineManager;
/**
* Sends a deploy request to the MAD: "DEPLOY ID HOST CONF -"
* Sends a deploy request to the MAD: "DEPLOY ID XML_DRV_MSG"
* @param oid the virtual machine id.
* @param host the hostname
* @param conf the filename of the deployment file
* @param drv_msg xml data for the mad operation
*/
void deploy (
const int oid,
const string& host,
const string& conf) const;
const string& drv_msg) const;
/**
* Sends a shutdown request to the MAD: "SHUTDOWN ID HOST NAME -"
* Sends a shutdown request to the MAD: "SHUTDOWN ID XML_DRV_MSG"
* @param oid the virtual machine id.
* @param host the hostname
* @param name of the Virtual Machine (deployment id), as returned by the
* driver
* @param drv_msg xml data for the mad operation
*/
void shutdown (
const int oid,
const string& host,
const string& name) const;
const string& drv_msg) const;
/**
* Sends a cancel request to the MAD: "CANCEL ID HOST NAME -"
* Sends a cancel request to the MAD: "CANCEL ID XML_DRV_MSG"
* @param oid the virtual machine id.
* @param host the hostname
* @param name of the Virtual Machine (deployment id), as returned by the
* driver
* @param drv_msg xml data for the mad operation
*/
void cancel (
const int oid,
const string& host,
const string& name) const;
const string& drv_msg) const;
/**
* Sends a checkpoint request to the MAD: "CHECKPOINT ID HOST NAME FILE"
* Sends a checkpoint request to the MAD: "CHECKPOINT ID XML_DRV_MSG"
* @param oid the virtual machine id.
* @param host the hostname
* @param name of the Virtual Machine (deployment id), as returned by the
* driver
* @param file the filename to generate the checkpoint file
* @param drv_msg xml data for the mad operation
*/
void checkpoint (
const int oid,
const string& host,
const string& name,
const string& file) const;
const string& drv_msg) const;
/**
* Sends a save request to the MAD: "SAVE ID HOST NAME FILE"
* Sends a save request to the MAD: "SAVE ID XML_DRV_MSG"
* @param oid the virtual machine id.
* @param host the hostname
* @param name of the Virtual Machine (deployment id), as returned by the
* driver
* @param file the filename to generate the checkpoint file
* @param drv_msg xml data for the mad operation
*/
void save (
const int oid,
const string& host,
const string& name,
const string& file) const;
const string& drv_msg) const;
/**
* Sends a save request to the MAD: "RESTORE ID HOST FILE -"
* Sends a save request to the MAD: "RESTORE ID XML_DRV_MSG"
* @param oid the virtual machine id.
* @param host the hostname
* @param name of the Virtual Machine (deployment id), as returned by the
* driver
* @param file the filename of the checkpoint file to restore the VM
* from
* @param drv_msg xml data for the mad operation
*/
void restore (
const int oid,
const string& host,
const string& name,
const string& file) const;
const string& drv_msg) const;
/**
* Sends a migrate request to the MAD: "MIGRATE ID HOST NAME DEST"
* Sends a migrate request to the MAD: "MIGRATE ID XML_DRV_MSG"
* @param oid the virtual machine id.
* @param shost the original host (source)
* @param name of the Virtual Machine (deployment id), as returned by the
* driver
* @param dhost the destination host
* @param drv_msg xml data for the mad operation
*/
void migrate (
const int oid,
const string& shost,
const string& name,
const string& dhost) const;
const string& drv_msg) const;
/**
* Sends a poll request to the MAD: "POLL ID HOST NAME -"
* Sends a poll request to the MAD: "POLL ID XML_DRV_MSG"
* @param oid the virtual machine id.
* @param host the hostname
* @param name of the Virtual Machine (deployment id), as returned by the
* driver
* @param drv_msg xml data for the mad operation
*/
void poll (
const int oid,
const string& host,
const string& name) const;
const string& drv_msg) const;
};
/* -------------------------------------------------------------------------- */

View File

@ -245,12 +245,77 @@ void VirtualMachineManager::do_action(const string &action, void * arg)
/* Manager Actions */
/* ************************************************************************** */
string * VirtualMachineManager::format_message(
const string& hostname,
const string& net_drv,
const string& m_hostname,
const string& m_net_drv,
const string& domain,
const string& dfile,
const string& cfile,
const string& tmpl)
{
ostringstream oss;
oss << "<VMM_DRIVER_ACTION_DATA>"
<< "<HOST>" << hostname << "</HOST>"
<< "<NET_DRV>" << net_drv << "</NET_DRV>";
if (!m_hostname.empty())
{
oss << "<MIGR_HOST>" << m_hostname << "</MIGR_HOST>"
<< "<MIGR_NET_DRV>"<< m_net_drv << "</MIGR_NET_DRV>";
}
else
{
oss << "</MIGR_HOST></MIGR_NET_DRV>";
}
if (!domain.empty())
{
oss << "<DOMAIN>" << domain << "</DOMAIN>";
}
else
{
oss << "</DOMAIN>";
}
if (!dfile.empty())
{
oss << "<DEPLOYMENT_FILE>" << dfile << "</DEPLOYMENT_FILE>";
}
else
{
oss << "</DEPLOYMENT_FILE>";
}
if (!cfile.empty())
{
oss << "<CHECKPOINT_FILE>" << cfile << "</CHECKPOINT_FILE>";
}
else
{
oss << "</CHECKPOINT_FILE>";
}
oss << "<VM_TEMPLATE>" << tmpl << "</VM_TEMPLATE>"
<< "</VMM_DRIVER_ACTION_DATA>";
return SSLTools::base64_encode(oss.str());
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManager::deploy_action(int vid)
{
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
int rc;
ostringstream os;
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
int rc;
ostringstream os;
string vm_tmpl;
string * drv_msg;
// Get the VM from the pool
vm = vmpool->get(vid,true);
@ -287,7 +352,19 @@ void VirtualMachineManager::deploy_action(int vid)
}
// Invoke driver method
vmd->deploy(vid,vm->get_hostname(),vm->get_remote_deployment_file());
drv_msg = format_message(
vm->get_hostname(),
vm->get_vnm_mad(),
"",
"",
"",
vm->get_remote_deployment_file(),
"",
vm->template_to_xml(vm_tmpl));
vmd->deploy(vid, *drv_msg);
delete drv_msg;
vm->unlock();
@ -326,8 +403,11 @@ void VirtualMachineManager::save_action(
{
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
string hostname;
ostringstream os;
string hostname, vnm_mad;
string vm_tmpl;
string * drv_msg;
ostringstream os;
// Get the VM from the pool
vm = vmpool->get(vid,true);
@ -359,20 +439,31 @@ void VirtualMachineManager::save_action(
}
hostname = vm->get_previous_hostname();
vnm_mad = vm->get_previous_vnm_mad();
}
else
{
hostname=vm->get_hostname();
hostname = vm->get_hostname();
vnm_mad = vm->get_vnm_mad();
}
// Invoke driver method
vmd->save(
vid,
drv_msg = format_message(
hostname,
vnm_mad,
"",
"",
vm->get_deploy_id(),
vm->get_checkpoint_file());
"",
vm->get_checkpoint_file(),
vm->to_xml(vm_tmpl));
vmd->save(vid, *drv_msg);
delete drv_msg;
vm->unlock();
return;
error_history:
@ -406,9 +497,12 @@ error_common:
void VirtualMachineManager::shutdown_action(
int vid)
{
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
ostringstream os;
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
string vm_tmpl;
string * drv_msg;
ostringstream os;
// Get the VM from the pool
vm = vmpool->get(vid,true);
@ -432,9 +526,22 @@ void VirtualMachineManager::shutdown_action(
}
// Invoke driver method
vmd->shutdown(vid,vm->get_hostname(),vm->get_deploy_id());
drv_msg = format_message(
vm->get_hostname(),
vm->get_vnm_mad(),
"",
"",
vm->get_deploy_id(),
"",
"",
vm->to_xml(vm_tmpl));
vmd->shutdown(vid, *drv_msg);
delete drv_msg;
vm->unlock();
return;
error_history:
@ -466,6 +573,9 @@ void VirtualMachineManager::cancel_action(
VirtualMachine * vm;
ostringstream os;
string vm_tmpl;
string * drv_msg;
const VirtualMachineManagerDriver * vmd;
// Get the VM from the pool
@ -490,9 +600,22 @@ void VirtualMachineManager::cancel_action(
}
// Invoke driver method
vmd->cancel(vid,vm->get_hostname(),vm->get_deploy_id());
drv_msg = format_message(
vm->get_hostname(),
vm->get_vnm_mad(),
"",
"",
vm->get_deploy_id(),
"",
"",
vm->to_xml(vm_tmpl));
vmd->cancel(vid, *drv_msg);
delete drv_msg;
vm->unlock();
return;
error_history:
@ -527,6 +650,9 @@ void VirtualMachineManager::cancel_previous_action(
VirtualMachine * vm;
ostringstream os;
string vm_tmpl;
string * drv_msg;
const VirtualMachineManagerDriver * vmd;
// Get the VM from the pool
@ -551,9 +677,22 @@ void VirtualMachineManager::cancel_previous_action(
}
// Invoke driver method
vmd->cancel(vid,vm->get_previous_hostname(),vm->get_deploy_id());
drv_msg = format_message(
vm->get_previous_hostname(),
vm->get_previous_vnm_mad(),
"",
"",
vm->get_deploy_id(),
"",
"",
vm->to_xml(vm_tmpl));
vmd->cancel(vid, *drv_msg);
delete drv_msg;
vm->unlock();
return;
error_history:
@ -579,7 +718,10 @@ void VirtualMachineManager::migrate_action(
{
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
ostringstream os;
ostringstream os;
string vm_tmpl;
string * drv_msg;
// Get the VM from the pool
vm = vmpool->get(vid,true);
@ -608,10 +750,19 @@ void VirtualMachineManager::migrate_action(
}
// Invoke driver method
vmd->migrate(vid,
vm->get_previous_hostname(),
vm->get_deploy_id(),
vm->get_hostname());
drv_msg = format_message(
vm->get_previous_hostname(),
vm->get_previous_vnm_mad(),
vm->get_hostname(),
vm->get_vnm_mad(),
vm->get_deploy_id(),
"",
"",
vm->to_xml(vm_tmpl));
vmd->migrate(vid, *drv_msg);
delete drv_msg;
vm->unlock();
@ -648,9 +799,13 @@ error_common:
void VirtualMachineManager::restore_action(
int vid)
{
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
ostringstream os;
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
ostringstream os;
string vm_tmpl;
string * drv_msg;
// Get the VM from the pool
vm = vmpool->get(vid,true);
@ -674,12 +829,22 @@ void VirtualMachineManager::restore_action(
}
// Invoke driver method
vmd->restore(vid,
vm->get_hostname(),
vm->get_deploy_id(),
vm->get_checkpoint_file());
drv_msg = format_message(
vm->get_hostname(),
vm->get_vnm_mad(),
"",
"",
vm->get_deploy_id(),
"",
vm->get_checkpoint_file(),
vm->to_xml(vm_tmpl));
vmd->restore(vid, *drv_msg);
delete drv_msg;
vm->unlock();
return;
error_history:
@ -708,9 +873,13 @@ error_common:
void VirtualMachineManager::poll_action(
int vid)
{
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
ostringstream os;
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
ostringstream os;
string vm_tmpl;
string * drv_msg;
// Get the VM from the pool
vm = vmpool->get(vid,true);
@ -734,9 +903,22 @@ void VirtualMachineManager::poll_action(
}
// Invoke driver method
vmd->poll(vid,vm->get_hostname(),vm->get_deploy_id());
drv_msg = format_message(
vm->get_hostname(),
vm->get_vnm_mad(),
"",
"",
vm->get_deploy_id(),
"",
"",
vm->to_xml(vm_tmpl));
vmd->poll(vid, *drv_msg);
delete drv_msg;
vm->unlock();
return;
error_history:
@ -824,6 +1006,9 @@ void VirtualMachineManager::timer_action()
const VirtualMachineManagerDriver * vmd;
string vm_tmpl;
string * drv_msg;
mark = mark + timer_period;
if ( mark >= 600 )
@ -874,7 +1059,19 @@ void VirtualMachineManager::timer_action()
continue;
}
vmd->poll(*it,vm->get_hostname(),vm->get_deploy_id());
drv_msg = format_message(
vm->get_hostname(),
vm->get_vnm_mad(),
"",
"",
vm->get_deploy_id(),
"",
"",
vm->to_xml(vm_tmpl));
vmd->poll(*it, *drv_msg);
delete drv_msg;
vmpool->update(vm);

View File

@ -104,12 +104,11 @@ void VirtualMachineManagerDriver::get_default(
void VirtualMachineManagerDriver::deploy (
const int oid,
const string& host,
const string& conf) const
const string& drv_msg) const
{
ostringstream os;
os << "DEPLOY " << oid << " " << host << " " << conf << " -" << endl;
os << "DEPLOY " << oid << " " << drv_msg << endl;
write(os);
};
@ -119,12 +118,11 @@ void VirtualMachineManagerDriver::deploy (
void VirtualMachineManagerDriver::shutdown (
const int oid,
const string& host,
const string& name) const
const string& drv_msg) const
{
ostringstream os;
os << "SHUTDOWN " << oid << " " << host << " " << name << " -" << endl;
os << "SHUTDOWN " << oid << " " << drv_msg << endl;
write(os);
};
@ -134,12 +132,11 @@ void VirtualMachineManagerDriver::shutdown (
void VirtualMachineManagerDriver::cancel (
const int oid,
const string& host,
const string& name) const
const string& drv_msg) const
{
ostringstream os;
os << "CANCEL " << oid << " " << host << " " << name << " -" << endl;
os << "CANCEL " << oid << " " << drv_msg << endl;
write(os);
};
@ -149,13 +146,11 @@ void VirtualMachineManagerDriver::cancel (
void VirtualMachineManagerDriver::checkpoint (
const int oid,
const string& host,
const string& name,
const string& file) const
const string& drv_msg) const
{
ostringstream os;
os<< "CHECKPOINT " << oid<< " "<< host<< " "<< name<< " "<< file<< endl;
os<< "CHECKPOINT " << oid << " " << drv_msg << endl;
write(os);
};
@ -165,13 +160,11 @@ void VirtualMachineManagerDriver::checkpoint (
void VirtualMachineManagerDriver::save (
const int oid,
const string& host,
const string& name,
const string& file) const
const string& drv_msg) const
{
ostringstream os;
os<< "SAVE " << oid << " " << host << " " << name << " "<< file << endl;
os<< "SAVE " << oid << " " << drv_msg << endl;
write(os);
};
@ -181,13 +174,11 @@ void VirtualMachineManagerDriver::save (
void VirtualMachineManagerDriver::restore (
const int oid,
const string& host,
const string& name,
const string& file) const
const string& drv_msg) const
{
ostringstream os;
os << "RESTORE " << oid << " " << host << " " << name << " " << file<< endl;
os << "RESTORE " << oid << " " << drv_msg << endl;
write(os);
};
@ -197,13 +188,11 @@ void VirtualMachineManagerDriver::restore (
void VirtualMachineManagerDriver::migrate (
const int oid,
const string& shost,
const string& name,
const string& dhost) const
const string& drv_msg) const
{
ostringstream os;
os<< "MIGRATE " << oid << " "<< shost<< " "<< name<< " "<< dhost<< endl;
os<< "MIGRATE " << oid << " " << drv_msg << endl;
write(os);
};
@ -213,12 +202,11 @@ void VirtualMachineManagerDriver::migrate (
void VirtualMachineManagerDriver::poll (
const int oid,
const string& host,
const string& name) const
const string& drv_msg) const
{
ostringstream os;
os << "POLL " << oid << " " << host << " " << name << " -" << endl;
os << "POLL " << oid << " " << drv_msg << endl;
write(os);
};

View File

@ -35,9 +35,7 @@ int XMLDriver::deployment_description(
return -1;
}
vm->template_to_xml(xml);
file << xml ;
file << vm->template_to_xml(xml);
file.close();