1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-01-08 21:17:43 +03:00

feature #1393: DATASTORE_LOCATION can be set in the cluster template

This commit is contained in:
Ruben S. Montero 2012-10-05 13:23:44 +02:00
parent ffc8d58844
commit ee40a04c83
9 changed files with 133 additions and 89 deletions

View File

@ -48,6 +48,15 @@ public:
return ds_id;
}
/**
* Returns the DATASTORE_LOCATION for the hosts of the cluster. If not
* defined that in oned.conf is returned.
*
* @param ds_location string to copy the DATASTORE_LOCATION to
* @return DATASTORE_LOCATION
*/
string& get_ds_location(string &ds_location);
// *************************************************************************
// Object Collections (Public)
// *************************************************************************

View File

@ -47,6 +47,7 @@ public:
const string& vmm,
const string& vnm,
const string& tmm,
const string& ds_location,
int ds_id,
const string& vm_info);
@ -73,7 +74,7 @@ private:
// DataBase implementation variables
// ----------------------------------------
static const char * table;
static const char * db_names;
static const char * db_bootstrap;
@ -93,6 +94,7 @@ private:
string vnm_mad_name;
string tm_mad_name;
string ds_location;
int ds_id;
time_t stime;
@ -122,6 +124,7 @@ private:
// Remote paths
string checkpoint_file;
string rdeployment_file;
string rsystem_dir;
/**
* Writes the history record in the DB

View File

@ -48,17 +48,23 @@ protected:
virtual void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att) = 0;
bool vm_authorization(int id,
bool vm_authorization(int id,
ImageTemplate * tmpl,
VirtualMachineTemplate* vtmpl,
RequestAttributes& att,
PoolObjectAuth * host_perms,
RequestAttributes& att,
PoolObjectAuth * host_perms,
PoolObjectAuth * ds_perm,
AuthRequest::Operation op);
int get_host_information(int hid, string& name, string& vmm, string& vnm,
string& tm, int& ds_id, RequestAttributes& att,
PoolObjectAuth& host_perms);
int get_host_information(int hid,
string& name,
string& vmm,
string& vnm,
string& tm,
string& ds_location,
int& ds_id,
RequestAttributes& att,
PoolObjectAuth& host_perms);
int add_history(VirtualMachine * vm,
int hid,
@ -66,6 +72,7 @@ protected:
const string& vmm_mad,
const string& vnm_mad,
const string& tm_mad,
const string& ds_location,
int ds_id,
RequestAttributes& att);

View File

@ -225,7 +225,10 @@ public:
* disks for a running VM in the target host.
* @return the remote system directory for the VM
*/
string get_remote_system_dir() const;
const string& get_remote_system_dir() const
{
return history->rsystem_dir;
}
/**
* Returns the local VM directory. The VM local dir is in the form:
@ -246,6 +249,7 @@ public:
const string& vmm_mad,
const string& vnm_mad,
const string& tm_mad,
const string& ds_location,
int ds_id);
/**
@ -338,7 +342,7 @@ public:
};
/**
* Returns the datastore ID of the system DS for the previous host.
* Returns the datastore ID of the system DS for the previous host.
* The hasPreviousHistory() function MUST be called before this one.
* @return the TM mad name
*/
@ -347,7 +351,7 @@ public:
ostringstream oss;
oss << previous_history->ds_id;
return oss.str();
};
@ -490,7 +494,7 @@ public:
};
/**
* Sets VM info (with monitoring info) in the history record
* Sets VM info (with monitoring info) in the history record
*/
void set_vm_info()
{
@ -498,7 +502,7 @@ public:
};
/**
* Sets VM info (with monitoring info) in the previous history record
* Sets VM info (with monitoring info) in the previous history record
*/
void set_previous_vm_info()
{
@ -615,7 +619,7 @@ public:
* @return 0 on success.
*/
int parse_template_attribute(const string& attribute, string& parsed);
/**
* Factory method for virtual machine templates
*/
@ -766,7 +770,7 @@ public:
* @param img_id ID of the image this disk will be saved to (SAVE_AS).
* @return 0 if success
*/
int save_disk(const string& disk_id,
int save_disk(const string& disk_id,
const string& source,
int img_id);
@ -789,8 +793,8 @@ public:
* @param ar the AuthRequest object
* @param tmpl the virtual machine template
*/
static void set_auth_request(int uid,
AuthRequest& ar,
static void set_auth_request(int uid,
AuthRequest& ar,
VirtualMachineTemplate *tmpl);
// ------------------------------------------------------------------------
@ -805,7 +809,7 @@ public:
void get_disk_info(int& num_disks, set<string>& used_targets);
/**
* Generate a DISK attributed to be attached to the VM.
* Generate a DISK attributed to be attached to the VM.
* @param tmpl Template containing a single DISK vector attribute.
* @param used_targets targets in use by current DISKS
* @param num_disks of the VM
@ -843,7 +847,7 @@ public:
VectorAttribute * delete_attach_disk();
/**
* Adds a new disk to the virtual machine template. The disk should be
* Adds a new disk to the virtual machine template. The disk should be
* generated by the build_attach_disk
* @param new_disk must be allocated in the heap
*/
@ -1111,9 +1115,9 @@ protected:
// Constructor
//**************************************************************************
VirtualMachine(int id,
VirtualMachine(int id,
int uid,
int gid,
int gid,
const string& uname,
const string& gname,
VirtualMachineTemplate * _vm_template);
@ -1123,7 +1127,7 @@ protected:
// *************************************************************************
// DataBase implementation
// *************************************************************************
static const char * table;
static const char * db_names;

View File

@ -85,11 +85,14 @@ MAC_PREFIX = "02:00"
#*******************************************************************************
# DataStore Configuration
#*******************************************************************************
# DATASTORE_LOCATION: Path for Datastores in the hosts. It IS the same for all
# the hosts in the cluster. DATASTORE_LOCATION IS ONLY FOR THE HOSTS AND *NOT*
# THE FRONT-END. It defaults to /var/lib/one/datastores (or
# DATASTORE_LOCATION: *Default* Path for Datastores in the hosts. It IS the
# same for all the hosts in the cluster. DATASTORE_LOCATION IS ONLY FOR THE
# HOSTS AND *NOT* THE FRONT-END. It defaults to /var/lib/one/datastores (or
# $ONE_LOCATION/var/datastores in self-contained mode)
#
# You can define a different DATASTORE_LOCATION in each cluster by updating
# its properties with onecluster update.
#
# DEFAULT_IMAGE_TYPE: This can take values
# OS Image file holding an operating system
# CDROM Image file holding a CDROM

View File

@ -22,6 +22,7 @@
#include "Cluster.h"
#include "GroupPool.h"
#include "Nebula.h"
const char * Cluster::table = "cluster_pool";
@ -95,6 +96,23 @@ error_common:
return -1;
}
/* ------------------------------------------------------------------------ */
/* ------------------------------------------------------------------------ */
string& Cluster::get_ds_location(string &ds_location)
{
obj_template->get("DATASTORE_LOCATION", ds_location);
if ( ds_location.empty() == true )
{
Nebula& nd = Nebula::instance();
nd.get_configuration_attribute("DATASTORE_LOCATION", ds_location);
}
return ds_location;
}
/* ************************************************************************ */
/* Cluster :: Database Access Functions */
/* ************************************************************************ */

View File

@ -77,7 +77,7 @@ bool RequestManagerVirtualMachine::vm_authorization(
if ( ds_perm != 0 )
{
ar.add_auth(AuthRequest::USE, *ds_perm);
ar.add_auth(AuthRequest::USE, *ds_perm);
}
if (UserPool::authorize(ar) == -1)
@ -95,11 +95,12 @@ bool RequestManagerVirtualMachine::vm_authorization(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int RequestManagerVirtualMachine::get_host_information(int hid,
string& name,
int RequestManagerVirtualMachine::get_host_information(int hid,
string& name,
string& vmm,
string& vnm,
string& tm,
string& ds_location,
int& ds_id,
RequestAttributes& att,
PoolObjectAuth& host_perms)
@ -149,6 +150,8 @@ int RequestManagerVirtualMachine::get_host_information(int hid,
ds_id = cluster->get_ds_id();
cluster->get_ds_location(ds_location);
cluster->unlock();
}
else
@ -220,6 +223,7 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm,
const string& vmm_mad,
const string& vnm_mad,
const string& tm_mad,
const string& ds_location,
int ds_id,
RequestAttributes& att)
{
@ -228,7 +232,7 @@ int RequestManagerVirtualMachine::add_history(VirtualMachine * vm,
VirtualMachinePool * vmpool = static_cast<VirtualMachinePool *>(pool);
vm->add_history(hid,hostname,vmm_mad,vnm_mad,tm_mad,ds_id);
vm->add_history(hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id);
rc = vmpool->update_history(vm);
@ -378,6 +382,7 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
string vmm_mad;
string vnm_mad;
string tm_mad;
string ds_location;
int ds_id;
int id = xmlrpc_c::value_int(paramList.getInt(1));
@ -386,7 +391,8 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
bool auth = false;
if (get_host_information(
hid,hostname,vmm_mad,vnm_mad,tm_mad, ds_id, att, host_perms) != 0)
hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, att,
host_perms) != 0)
{
return;
}
@ -413,7 +419,8 @@ void VirtualMachineDeploy::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
if ( add_history(vm,hid,hostname,vmm_mad,vnm_mad,tm_mad,ds_id,att) != 0)
if ( add_history(
vm,hid,hostname,vmm_mad,vnm_mad,tm_mad,ds_location,ds_id,att) != 0)
{
vm->unlock();
return;
@ -442,6 +449,7 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
string vmm_mad;
string vnm_mad;
string tm_mad;
string ds_location;
int ds_id;
PoolObjectAuth aux_perms;
@ -456,7 +464,8 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
bool auth = false;
if (get_host_information(
hid,hostname,vmm_mad,vnm_mad,tm_mad,ds_id, att, host_perms) != 0)
hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location, ds_id, att,
host_perms) != 0)
{
return;
}
@ -490,8 +499,8 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
vm->unlock();
if (get_host_information(
current_hid,aux_st,aux_st,aux_st,
aux_st,current_ds_id, att, aux_perms) != 0)
current_hid, aux_st, aux_st, aux_st, aux_st, aux_st, current_ds_id,
att, aux_perms) != 0)
{
return;
}
@ -518,7 +527,8 @@ void VirtualMachineMigrate::request_execute(xmlrpc_c::paramList const& paramList
return;
}
if ( add_history(vm,hid,hostname,vmm_mad,vnm_mad,tm_mad,ds_id,att) != 0)
if ( add_history(vm, hid, hostname, vmm_mad, vnm_mad, tm_mad, ds_location,
ds_id, att) != 0)
{
vm->unlock();
return;
@ -572,11 +582,11 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
// -------------------------------------------------------------------------
// Prepare and check the VM/DISK to be saved_as
// -------------------------------------------------------------------------
if ( (vm = get_vm(id, att)) == 0 )
{
{
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::VM), id),
get_error(object_name(PoolObjectSQL::VM), id),
att);
return;
}
@ -589,7 +599,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
if ( iid_orig == -1 )
{
failure_response(INTERNAL,
failure_response(INTERNAL,
request_error("Cannot use selected DISK", error_str),
att);
return;
@ -604,7 +614,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
if ( img == 0 )
{
failure_response(NO_EXISTS,
get_error(object_name(PoolObjectSQL::IMAGE), iid_orig),
get_error(object_name(PoolObjectSQL::IMAGE), iid_orig),
att);
return;
}
@ -637,7 +647,7 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
ds->get_permissions(ds_perms);
ds->to_xml(ds_data);
ds_disk_type = ds->get_disk_type();
ds->unlock();
@ -697,17 +707,17 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
if ( quota_authorization(&img_usage, Quotas::DATASTORE, att) == false )
{
delete itemplate;
return;
return;
}
// -------------------------------------------------------------------------
// Create the image
// -------------------------------------------------------------------------
rc = ipool->allocate(att.uid,
att.gid,
att.uname,
att.gname,
rc = ipool->allocate(att.uid,
att.gid,
att.uname,
att.gname,
itemplate,
ds_id,
ds_name,
@ -807,7 +817,7 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
// -------------------------------------------------------------------------
// Authorize the operation & check quotas
// -------------------------------------------------------------------------
if ( vm_authorization(id, 0, tmpl, att, 0, 0, auth_op) == false )
{
delete tmpl;
@ -817,7 +827,7 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
if ( quota_authorization(tmpl, Quotas::IMAGE, att) == false )
{
delete tmpl;
return;
return;
}
rc = dm->attach(id, tmpl, error_str);
@ -832,7 +842,7 @@ void VirtualMachineAttach::request_execute(xmlrpc_c::paramList const& paramList,
}
else
{
success_response(id, att);
success_response(id, att);
}
delete tmpl;
@ -857,7 +867,7 @@ void VirtualMachineDetach::request_execute(xmlrpc_c::paramList const& paramList,
// -------------------------------------------------------------------------
// Authorize the operation
// -------------------------------------------------------------------------
if ( vm_authorization(id, 0, 0, att, 0, 0, auth_op) == false )
{
return;
@ -873,10 +883,10 @@ void VirtualMachineDetach::request_execute(xmlrpc_c::paramList const& paramList,
}
else
{
success_response(id, att);
success_response(id, att);
}
return;
return;
}
/* -------------------------------------------------------------------------- */

View File

@ -45,6 +45,7 @@ History::History(
vmm_mad_name(""),
vnm_mad_name(""),
tm_mad_name(""),
ds_location(""),
ds_id(0),
stime(0),
etime(0),
@ -67,6 +68,7 @@ History::History(
const string& _vmm,
const string& _vnm,
const string& _tmm,
const string& _ds_location,
int _ds_id,
const string& _vm_info):
oid(_oid),
@ -76,6 +78,7 @@ History::History(
vmm_mad_name(_vmm),
vnm_mad_name(_vnm),
tm_mad_name(_tmm),
ds_location(_ds_location),
ds_id(_ds_id),
stime(0),
etime(0),
@ -99,9 +102,7 @@ void History::non_persistent_data()
ostringstream os;
string vm_lhome;
string vm_rhome;
string ds_location;
Nebula& nd = Nebula::instance();
// ----------- Local Locations ------------
@ -128,16 +129,15 @@ void History::non_persistent_data()
os.str("");
nd.get_configuration_attribute("DATASTORE_LOCATION", ds_location);
os << ds_location << "/" << ds_id << "/" << oid;
vm_rhome = os.str();
rsystem_dir = os.str();
os << "/checkpoint";
checkpoint_file = os.str();
os.str("");
os << vm_rhome << "/deployment." << seq;
os << rsystem_dir << "/deployment." << seq;
rdeployment_file = os.str();
}
@ -299,6 +299,7 @@ string& History::to_xml(string& xml, bool database) const
"<VMMMAD>" << vmm_mad_name << "</VMMMAD>"<<
"<VNMMAD>" << vnm_mad_name << "</VNMMAD>"<<
"<TMMAD>" << tm_mad_name << "</TMMAD>" <<
"<DS_LOCATION>" << ds_location << "</DS_LOCATION>" <<
"<DS_ID>" << ds_id << "</DS_ID>" <<
"<PSTIME>" << prolog_stime << "</PSTIME>"<<
"<PETIME>" << prolog_etime << "</PETIME>"<<
@ -329,22 +330,23 @@ int History::rebuild_attributes()
int int_reason;
int rc = 0;
rc += xpath(seq , "/HISTORY/SEQ", -1);
rc += xpath(hostname , "/HISTORY/HOSTNAME", "not_found");
rc += xpath(hid , "/HISTORY/HID", -1);
rc += xpath(stime , "/HISTORY/STIME", 0);
rc += xpath(etime , "/HISTORY/ETIME", 0);
rc += xpath(vmm_mad_name , "/HISTORY/VMMMAD", "not_found");
xpath(vnm_mad_name , "/HISTORY/VNMMAD", "dummy");
rc += xpath(tm_mad_name , "/HISTORY/TMMAD", "not_found");
rc += xpath(ds_id , "/HISTORY/DS_ID", 0);
rc += xpath(prolog_stime , "/HISTORY/PSTIME", 0);
rc += xpath(prolog_etime , "/HISTORY/PETIME", 0);
rc += xpath(running_stime , "/HISTORY/RSTIME", 0);
rc += xpath(running_etime , "/HISTORY/RETIME", 0);
rc += xpath(epilog_stime , "/HISTORY/ESTIME", 0);
rc += xpath(epilog_etime , "/HISTORY/EETIME", 0);
rc += xpath(int_reason , "/HISTORY/REASON", 0);
rc += xpath(seq , "/HISTORY/SEQ", -1);
rc += xpath(hostname , "/HISTORY/HOSTNAME", "not_found");
rc += xpath(hid , "/HISTORY/HID", -1);
rc += xpath(stime , "/HISTORY/STIME", 0);
rc += xpath(etime , "/HISTORY/ETIME", 0);
rc += xpath(vmm_mad_name , "/HISTORY/VMMMAD", "not_found");
xpath(vnm_mad_name , "/HISTORY/VNMMAD", "dummy");
rc += xpath(tm_mad_name , "/HISTORY/TMMAD", "not_found");
rc += xpath(ds_location , "/HISTORY/DS_LOCATION", "not_found");
rc += xpath(ds_id , "/HISTORY/DS_ID", 0);
rc += xpath(prolog_stime , "/HISTORY/PSTIME", 0);
rc += xpath(prolog_etime , "/HISTORY/PETIME", 0);
rc += xpath(running_stime , "/HISTORY/RSTIME", 0);
rc += xpath(running_etime , "/HISTORY/RETIME", 0);
rc += xpath(epilog_stime , "/HISTORY/ESTIME", 0);
rc += xpath(epilog_etime , "/HISTORY/EETIME", 0);
rc += xpath(int_reason , "/HISTORY/REASON", 0);
reason = static_cast<MigrationReason>(int_reason);

View File

@ -842,6 +842,7 @@ void VirtualMachine::add_history(
const string& vmm_mad,
const string& vnm_mad,
const string& tm_mad,
const string& ds_location,
int ds_id)
{
ostringstream os;
@ -868,6 +869,7 @@ void VirtualMachine::add_history(
vmm_mad,
vnm_mad,
tm_mad,
ds_location,
ds_id,
vm_xml);
@ -896,6 +898,7 @@ void VirtualMachine::cp_history()
history->vmm_mad_name,
history->vnm_mad_name,
history->tm_mad_name,
history->ds_location,
history->ds_id,
vm_xml);
@ -927,6 +930,7 @@ void VirtualMachine::cp_previous_history()
previous_history->vmm_mad_name,
previous_history->vnm_mad_name,
previous_history->tm_mad_name,
previous_history->ds_location,
previous_history->ds_id,
vm_xml);
@ -1994,22 +1998,6 @@ int VirtualMachine::from_xml(const string &xml_str)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string VirtualMachine::get_remote_system_dir() const
{
ostringstream oss;
string ds_location;
Nebula& nd = Nebula::instance();
nd.get_configuration_attribute("DATASTORE_LOCATION", ds_location);
oss << ds_location << "/" << history->ds_id << "/" << oid;
return oss.str();
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string VirtualMachine::get_system_dir() const
{
ostringstream oss;