1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-02-01 05:47:01 +03:00

Moved default conf file managemnt to VirtualMachineManagerDriver class so it

can be used by all the drivers
Added vector attribute support for defaults
Moved xen paths to driver rc file


git-svn-id: http://svn.opennebula.org/trunk@37 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Rubén S. Montero 2008-07-05 15:46:29 +00:00
parent 8abe0a4ded
commit 45663d6c33
5 changed files with 119 additions and 93 deletions

View File

@ -42,14 +42,9 @@ public:
int userid,
const map<string,string>& attrs,
bool sudo,
VirtualMachinePool * pool):
Mad(userid,attrs,sudo),vmpool(pool)
{}
;
VirtualMachinePool * pool);
virtual ~VirtualMachineManagerDriver()
{}
;
virtual ~VirtualMachineManagerDriver(){};
/**
* Implements the VM Manager driver protocol.
@ -73,8 +68,41 @@ public:
virtual int deployment_description(
const VirtualMachine * vm,
const string& file_name) const = 0;
protected:
/**
* Gets a configuration attr from driver configuration file (single
* version)
* @param name of config attribute
* @param value of the attribute
*/
void get_default(
const char * name,
string& value) const
{
string sn = name;
driver_conf.get(sn,value);
}
private:
/**
* Gets a configuration attr from driver configuration file (vector
* version)
* @param name of config vector attribute for the domain
* @param vname of the attribute
* @param value of the attribute
*/
void get_default(
const char * name,
const char * vname,
string& value) const;
private:
/**
* Configuration file for the driver
*/
Template driver_conf;
/**
* Pointer to the Virtual Machine Pool, to access VMs
*/
@ -187,28 +215,5 @@ private:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
class KvmDriver : public VirtualMachineManagerDriver
{
public:
KvmDriver(
int userid,
const map<string,string> &attrs,
bool sudo,
VirtualMachinePool * pool):
VirtualMachineManagerDriver(userid, attrs,sudo,pool)
{};
~KvmDriver(){};
private:
int deployment_description(
const VirtualMachine * vm,
const string& file_name) const
{
return 0;
};
};
#endif /*VIRTUAL_MACHINE_MANAGER_DRIVER_H_*/

View File

@ -21,7 +21,6 @@
#include <map>
#include <string>
#include <sstream>
#include "Nebula.h"
#include "VirtualMachineManagerDriver.h"
using namespace std;
@ -40,66 +39,11 @@ public:
bool sudo,
VirtualMachinePool * pool):
VirtualMachineManagerDriver(userid, attrs,sudo,pool)
{
map<string,string>::const_iterator it;
char * error_msg = 0;
const char * cfile;
string file;
int rc;
ostringstream oss;
it = attrs.find("DEFAULT");
if ( it != attrs.end() )
{
if (it->second[0] != '/') //Look in ONE_LOCATION
{
Nebula& nd = Nebula::instance();
file = nd.get_nebula_location() + "/" + it->second;
cfile = file.c_str();
}
else //Absolute Path
{
cfile = it->second.c_str();
}
rc = xen_conf.parse(cfile, &error_msg);
if (( rc != 0 ) && ( error_msg != 0))
{
oss << "Error loading xen driver configuration file: "
<< error_msg;
Nebula::log("VMM", Log::ERROR, oss);
free(error_msg);
}
}
};
{};
~XenDriver(){};
private:
/**
* Configuration file for the driver
*/
Template xen_conf;
/**
* Generates a configuration attr from driver configuration file
* @param name of config attribute for the domain
* @param value of the attribute
*/
void get_default(
const char * name,
string& value) const
{
string sn = name;
xen_conf.get(sn,value);
}
private:
/**
* Generates a xen-specific deployment file seexmdomain.cfg(5):
* @param vm pointer to a virtual machine

View File

@ -13,4 +13,12 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
#--------------------------------------------------------------------------- #
#--------------------------------------------------------------------------- #
#---------------------------------------------------------------------------
# Path to Xen utilities
#---------------------------------------------------------------------------
XENTOP_PATH="/usr/sbin/xentop"
XM_PATH="/usr/sbin/xm"

View File

@ -20,6 +20,75 @@
#include "LifeCycleManager.h"
#include <sstream>
VirtualMachineManagerDriver::VirtualMachineManagerDriver(
int userid,
const map<string,string>& attrs,
bool sudo,
VirtualMachinePool * pool):
Mad(userid,attrs,sudo),driver_conf(true),vmpool(pool)
{
map<string,string>::const_iterator it;
char * error_msg = 0;
const char * cfile;
string file;
int rc;
it = attrs.find("DEFAULT");
if ( it != attrs.end() )
{
if (it->second[0] != '/') //Look in ONE_LOCATION
{
Nebula& nd = Nebula::instance();
file = nd.get_nebula_location() + "/" + it->second;
cfile = file.c_str();
}
else //Absolute Path
{
cfile = it->second.c_str();
}
rc = driver_conf.parse(cfile, &error_msg);
if (( rc != 0 ) && ( error_msg != 0))
{
ostringstream oss;
oss << "Error loading driver configuration file " << cfile <<
" : " << error_msg;
Nebula::log("VMM", Log::ERROR, oss);
free(error_msg);
}
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::get_default(
const char * name,
const char * vname,
string& value) const
{
vector<const Attribute *> attrs;
string sn = name;
if ( driver_conf.get(sn,attrs) == 1 )
{
const VectorAttribute * vattr;
vattr = static_cast<const VectorAttribute *>(attrs[0]);
value = vattr->vector_value(vname);
}
else
{
value = "";
}
}
/* ************************************************************************** */
/* Driver ASCII Protocol Implementation */

View File

@ -1,7 +1,7 @@
#!/usr/bin/env ruby
XENTOP_PATH="/usr/sbin/xentop"
XM_PATH="/usr/sbin/xm"
XENTOP_PATH=ENV["XENTOP_PATH"]
XM_PATH=ENV["XM_PATH"]
ONE_LOCATION=ENV["ONE_LOCATION"]
@ -24,7 +24,7 @@ class DM < ONEMad
def initialize
super(5, 4)
# Set log file
#Set log file
#log_file=File.open("dm.log", "w")
#set_logger(log_file)