mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-11 05:17:41 +03:00
feature #1112: Add system_dir for VMs
This commit is contained in:
parent
a40bb000fd
commit
80b49ff6b4
@ -72,6 +72,15 @@ public:
|
||||
return tm_mad;
|
||||
};
|
||||
|
||||
/**
|
||||
* Retrieves the base path
|
||||
* @return base path string
|
||||
*/
|
||||
const string& get_base_path() const
|
||||
{
|
||||
return base_path;
|
||||
};
|
||||
|
||||
/**
|
||||
* Modifies the given VM disk attribute adding the relevant datastore
|
||||
* attributes
|
||||
|
@ -199,9 +199,8 @@ public:
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the path where the OpenNebula DB and the VM local directories
|
||||
* are stored. When ONE_LOCATION is defined this path points to
|
||||
* $ONE_LOCATION/var, otherwise it is /var/lib/one.
|
||||
* Returns the default var location. When ONE_LOCATION is defined this path
|
||||
* points to $ONE_LOCATION/var, otherwise it is /var/lib/one.
|
||||
* @return the log location.
|
||||
*/
|
||||
const string& get_var_location()
|
||||
@ -209,6 +208,26 @@ public:
|
||||
return var_location;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the base for the system datastore (for tmp VM images). When
|
||||
* ONE_LOCATION is defined this path points to $ONE_LOCATION/var/system_ds,
|
||||
* otherwise it is /var/lib/one/system_ds.
|
||||
* @return the log location.
|
||||
*/
|
||||
string get_system_ds_path()
|
||||
{
|
||||
Datastore * ds;
|
||||
string system_ds_path;
|
||||
|
||||
ds = dspool->get(DatastorePool::SYSTEM_DS_ID, true);
|
||||
|
||||
system_ds_path = ds->get_base_path();
|
||||
|
||||
ds->unlock();
|
||||
|
||||
return system_ds_path;
|
||||
};
|
||||
|
||||
/**
|
||||
* Returns the path of the log file for a VM, depending where OpenNebula is
|
||||
* installed,
|
||||
|
@ -760,14 +760,13 @@ private:
|
||||
*/
|
||||
History * previous_history;
|
||||
|
||||
|
||||
/**
|
||||
* Complete set of history records for the VM
|
||||
*/
|
||||
vector<History *> history_records;
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Logging
|
||||
// Logging & Dirs
|
||||
// -------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
@ -776,7 +775,13 @@ private:
|
||||
* or, in case that OpenNebula is installed in root
|
||||
* /var/log/one/$VM_ID.log
|
||||
*/
|
||||
FileLog * _log;
|
||||
FileLog * _log;
|
||||
|
||||
/**
|
||||
* Directory for the VM in the System DS (system_ds_path/$VID). Defaults to
|
||||
* $ONE_LOCATION/var/system_ds/$VID or /var/log/one/system_ds/$VID
|
||||
*/
|
||||
string system_dir;
|
||||
|
||||
// *************************************************************************
|
||||
// DataBase implementation (Private)
|
||||
|
@ -56,7 +56,8 @@ VirtualMachine::VirtualMachine(int id,
|
||||
net_rx(0),
|
||||
history(0),
|
||||
previous_history(0),
|
||||
_log(0)
|
||||
_log(0),
|
||||
system_dir("")
|
||||
{
|
||||
if (_vm_template != 0)
|
||||
{
|
||||
@ -148,14 +149,28 @@ int VirtualMachine::select(SqlDB * db)
|
||||
}
|
||||
}
|
||||
|
||||
//Create support directory for this VM
|
||||
if ( state == DONE ) //Do not recreate dirs. They may be deleted
|
||||
{
|
||||
_log = 0;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//Create support directories for this VM
|
||||
//--------------------------------------------------------------------------
|
||||
oss.str("");
|
||||
oss << nd.get_var_location() << oid;
|
||||
|
||||
mkdir(oss.str().c_str(), 0777);
|
||||
chmod(oss.str().c_str(), 0777);
|
||||
mkdir(oss.str().c_str(), 0700);
|
||||
chmod(oss.str().c_str(), 0700);
|
||||
|
||||
mkdir(system_dir.c_str(), 0700);
|
||||
chmod(system_dir.c_str(), 0700);
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
//Create Log support for this VM
|
||||
//--------------------------------------------------------------------------
|
||||
try
|
||||
{
|
||||
_log = new FileLog(nd.get_vm_log_filename(oid),Log::DEBUG);
|
||||
@ -191,6 +206,7 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
|
||||
string value;
|
||||
ostringstream oss;
|
||||
|
||||
Nebula& nd = Nebula::instance();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Check template for restricted attributes
|
||||
@ -279,6 +295,15 @@ int VirtualMachine::insert(SqlDB * db, string& error_str)
|
||||
|
||||
parse_graphics();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Set the System DataStore Path for the VM
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
oss.str("");
|
||||
oss << nd.get_system_ds_path() << "/" << oid;
|
||||
|
||||
system_dir = oss.str();
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Insert the VM
|
||||
// ------------------------------------------------------------------------
|
||||
@ -1259,6 +1284,7 @@ string& VirtualMachine::to_xml_extended(string& xml, bool extended) const
|
||||
<< "<CPU>" << cpu << "</CPU>"
|
||||
<< "<NET_TX>" << net_tx << "</NET_TX>"
|
||||
<< "<NET_RX>" << net_rx << "</NET_RX>"
|
||||
<< "<SYSTEM_DIR>"<< system_dir<< "</SYSTEM_DIR>"
|
||||
<< obj_template->to_xml(template_xml);
|
||||
|
||||
if ( hasHistory() )
|
||||
@ -1328,6 +1354,8 @@ int VirtualMachine::from_xml(const string &xml_str)
|
||||
rc += xpath(net_tx, "/VM/NET_TX", 0);
|
||||
rc += xpath(net_rx, "/VM/NET_RX", 0);
|
||||
|
||||
rc += xpath(system_dir,"/VM/SYSTEM_DIR","not_found");
|
||||
|
||||
// Permissions
|
||||
rc += perms_from_xml();
|
||||
|
||||
|
@ -216,7 +216,7 @@ int VirtualMachinePool::allocate (
|
||||
{
|
||||
vm->state = VirtualMachine::PENDING;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Insert the Object in the pool
|
||||
// ------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user