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

Reindentation and cosmetic changes

git-svn-id: http://svn.opennebula.org/one/trunk@443 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Javier Fontán Muiños 2009-04-01 16:34:45 +00:00
parent ebbd5244c2
commit 1e63cb63c1
6 changed files with 522 additions and 517 deletions

View File

@ -27,294 +27,295 @@ int LibVirtDriver::deployment_description(
const string& file_name) const
{
ofstream file;
ofstream file;
int num;
vector<const Attribute *> attrs;
int num;
vector<const Attribute *> attrs;
string vcpu;
string memory;
string vcpu;
string memory;
int memory_in_kb = 0;
int memory_in_kb = 0;
string kernel = "";
string initrd = "";
string boot = "";
string root = "";
string kernel_cmd = "";
string bootloader = "";
string kernel = "";
string initrd = "";
string boot = "";
string root = "";
string kernel_cmd = "";
string bootloader = "";
const VectorAttribute * disk;
const VectorAttribute * context;
const VectorAttribute * disk;
const VectorAttribute * context;
string type = "";
string target = "";
string bus = "";
string ro = "";
bool readonly;
string type = "";
string target = "";
string bus = "";
string ro = "";
bool readonly;
const VectorAttribute * nic;
const VectorAttribute * nic;
string mac = "";
string bridge = "";
string script = "";
string mac = "";
string bridge = "";
string script = "";
const VectorAttribute * graphics;
const VectorAttribute * graphics;
string listen = "";
string port = "";
string passwd = "";
string listen = "";
string port = "";
string passwd = "";
const VectorAttribute * input;
const VectorAttribute * input;
const VectorAttribute * features;
const VectorAttribute * features;
string pae = "";
string acpi = "";
string pae = "";
string acpi = "";
const VectorAttribute * raw;
string data;
const VectorAttribute * raw;
string data;
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
file.open(file_name.c_str(), ios::out);
file.open(file_name.c_str(), ios::out);
if (file.fail() == true)
{
goto error_file;
}
if (file.fail() == true)
{
goto error_file;
}
// ------------------------------------------------------------------------
// Starting XML document
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Starting XML document
// ------------------------------------------------------------------------
file << "<domain type='" << emulator << "'>" << endl;
file << "<domain type='" << emulator << "'>" << endl;
// ------------------------------------------------------------------------
// Domain name
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Domain name
// ------------------------------------------------------------------------
file << "\t<name>one-" << vm->get_oid() << "</name>" << endl;
file << "\t<name>one-" << vm->get_oid() << "</name>" << endl;
// ------------------------------------------------------------------------
// CPU
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// CPU
// ------------------------------------------------------------------------
vm->get_template_attribute("VCPU", vcpu);
vm->get_template_attribute("VCPU", vcpu);
if(vcpu.empty())
{
get_default("VCPU", vcpu);
}
if(vcpu.empty())
{
get_default("VCPU", vcpu);
}
if (!vcpu.empty())
{
file << "\t<vcpu>" << vcpu << "</vcpu>" << endl;
}
if (!vcpu.empty())
{
file << "\t<vcpu>" << vcpu << "</vcpu>" << endl;
}
// ------------------------------------------------------------------------
// Memory
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Memory
// ------------------------------------------------------------------------
vm->get_template_attribute("MEMORY",memory);
vm->get_template_attribute("MEMORY",memory);
if (memory.empty())
{
get_default("MEMORY",memory);
}
if (memory.empty())
{
get_default("MEMORY",memory);
}
if (!memory.empty())
{
if (!memory.empty())
{
memory_in_kb = atoi(memory.c_str()) * 1024;
file << "\t<memory>" << memory_in_kb << "</memory>" << endl;
}
else
{
goto error_memory;
}
file << "\t<memory>" << memory_in_kb << "</memory>" << endl;
}
else
{
goto error_memory;
}
// ------------------------------------------------------------------------
// OS and boot options
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// OS and boot options
// ------------------------------------------------------------------------
file << "\t<os>" << endl;
file << "\t<os>" << endl;
if (emulator == "kvm")
{
file << "\t\t<type>hvm</type>" << endl;
}
if (emulator == "kvm")
{
file << "\t\t<type>hvm</type>" << endl;
}
num = vm->get_template_attribute("OS",attrs);
num = vm->get_template_attribute("OS",attrs);
// Get values & defaults
// Get values & defaults
if ( num > 0 )
{
const VectorAttribute * os;
if ( num > 0 )
{
const VectorAttribute * os;
os = dynamic_cast<const VectorAttribute *>(attrs[0]);
os = dynamic_cast<const VectorAttribute *>(attrs[0]);
if( os != 0 )
{
kernel = os->vector_value("KERNEL");
initrd = os->vector_value("INITRD");
boot = os->vector_value("BOOT");
root = os->vector_value("ROOT");
kernel_cmd = os->vector_value("KERNEL_CMD");
bootloader = os->vector_value("BOOTLOADER");
}
}
if ( kernel.empty() )
{
get_default("OS","KERNEL",kernel);
}
if ( initrd.empty() )
{
get_default("OS","INITRD",initrd);
}
if ( bootloader.empty() )
{
get_default("OS","BOOTLOADER",bootloader);
}
if ( boot.empty() )
{
get_default("OS","BOOT",boot);
if ( boot.empty() )
if( os != 0 )
{
goto error_boot;
kernel = os->vector_value("KERNEL");
initrd = os->vector_value("INITRD");
boot = os->vector_value("BOOT");
root = os->vector_value("ROOT");
kernel_cmd = os->vector_value("KERNEL_CMD");
bootloader = os->vector_value("BOOTLOADER");
}
}
}
if ( root.empty() )
{
get_default("OS","ROOT",root);
}
if ( kernel.empty() )
{
get_default("OS","KERNEL",kernel);
}
if ( kernel_cmd.empty() )
{
get_default("OS","KERNEL_CMD",kernel_cmd);
}
if ( initrd.empty() )
{
get_default("OS","INITRD",initrd);
}
// Start writing to the file with the info we got
if ( bootloader.empty() )
{
get_default("OS","BOOTLOADER",bootloader);
}
if ( !kernel.empty() )
{
file << "\t\t<kernel>" << kernel << "</kernel>" << endl;
if ( boot.empty() )
{
get_default("OS","BOOT",boot);
if ( boot.empty() )
{
goto error_boot;
}
}
if ( root.empty() )
{
get_default("OS","ROOT",root);
}
if ( kernel_cmd.empty() )
{
get_default("OS","KERNEL_CMD",kernel_cmd);
}
// Start writing to the file with the info we got
if ( !kernel.empty() )
{
file << "\t\t<kernel>" << kernel << "</kernel>" << endl;
if ( !initrd.empty() )
{
file << "\t\t<initrd>" << initrd << "</initrd>" << endl;
file << "\t\t<initrd>" << initrd << "</initrd>" << endl;
}
if ( !root.empty() )
{
kernel_cmd = "root=/dev/" + root + " " + kernel_cmd;
kernel_cmd = "root=/dev/" + root + " " + kernel_cmd;
}
if (!kernel_cmd.empty())
{
file << "\t\t<cmdline>" << kernel_cmd << "</cmdline>" << endl;
file << "\t\t<cmdline>" << kernel_cmd << "</cmdline>" << endl;
}
}
else if ( !bootloader.empty() )
{
file << "\t\t<bootloader>" << bootloader << "</bootloader>" << endl;
}
}
else if ( !bootloader.empty() )
{
file << "\t\t<bootloader>" << bootloader << "</bootloader>" << endl;
}
file << "\t\t<boot dev='" << boot << "'/>" << endl;
file << "\t\t<boot dev='" << boot << "'/>" << endl;
file << "\t</os>" << endl;
file << "\t</os>" << endl;
attrs.clear();
attrs.clear();
// ------------------------------------------------------------------------
// Disks
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Disks
// ------------------------------------------------------------------------
file << "\t<devices>" << endl;
file << "\t<devices>" << endl;
if (emulator == "kvm")
{
file << "\t\t<emulator>/usr/bin/kvm</emulator>" << endl;
}
if (emulator == "kvm")
{
file << "\t\t<emulator>/usr/bin/kvm</emulator>" << endl;
}
num = vm->get_template_attribute("DISK",attrs);
num = vm->get_template_attribute("DISK",attrs);
for (int i=0; i < num ;i++,target="",ro="")
{
disk = dynamic_cast<const VectorAttribute *>(attrs[i]);
for (int i=0; i < num ;i++,target="",ro="")
{
disk = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( disk == 0 )
{
continue;
}
if ( disk == 0 )
{
continue;
}
type = disk->vector_value("TYPE");
target = disk->vector_value("TARGET");
ro = disk->vector_value("READONLY");
bus = disk->vector_value("BUS");
type = disk->vector_value("TYPE");
target = disk->vector_value("TARGET");
ro = disk->vector_value("READONLY");
bus = disk->vector_value("BUS");
if (target.empty())
{
goto error_disk;
}
if (target.empty())
{
goto error_disk;
}
readonly = false;
readonly = false;
if ( !ro.empty() )
{
transform(ro.begin(),ro.end(),ro.begin(),(int(*)(int))toupper);
if ( !ro.empty() )
{
transform(ro.begin(),ro.end(),ro.begin(),(int(*)(int))toupper);
if ( ro == "YES" )
{
if ( ro == "YES" )
{
readonly = true;
}
}
}
}
if ( type.empty() )
{
type = "disk";
}
else
{
if ( type.empty() )
{
type = "disk";
}
else
{
string type_=type;
transform(type_.begin(),type_.end(),type_.begin(),(int(*)(int))toupper);
transform(type_.begin(),type_.end(),
type_.begin(),(int(*)(int))toupper);
if ( type_ == "SWAP" )
{
type="disk";
}
}
}
file << "\t\t<disk type='file' device='" << type << "'>" << endl;
file << "\t\t\t<source file='" << vm->get_remote_dir() << "/disk." << i
<< "'/>" << endl;
file << "\t\t\t<target dev='" << target << "'";
file << "\t\t<disk type='file' device='" << type << "'>" << endl;
file << "\t\t\t<source file='" << vm->get_remote_dir() << "/disk." << i
<< "'/>" << endl;
file << "\t\t\t<target dev='" << target << "'";
if (!bus.empty())
{
file << " bus='" << bus << "'/>" << endl;
}
else
{
file << "/>" << endl;
}
if (!bus.empty())
{
file << " bus='" << bus << "'/>" << endl;
}
else
{
file << "/>" << endl;
}
if (readonly)
{
file << "\t\t\t<readonly/>" << endl;
}
if (readonly)
{
file << "\t\t\t<readonly/>" << endl;
}
file << "\t\t</disk>" << endl;
}
file << "\t\t</disk>" << endl;
}
attrs.clear();
attrs.clear();
// ------------------------------------------------------------------------
// Context Device
@ -347,213 +348,214 @@ int LibVirtDriver::deployment_description(
// Network interfaces
// ------------------------------------------------------------------------
num = vm->get_template_attribute("NIC",attrs);
num = vm->get_template_attribute("NIC",attrs);
for(int i=0; i<num;i++,mac="",bridge="",target="",script="")
{
nic = dynamic_cast<const VectorAttribute *>(attrs[i]);
for(int i=0; i<num;i++,mac="",bridge="",target="",script="")
{
nic = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( nic == 0 )
{
continue;
}
if ( nic == 0 )
{
continue;
}
bridge = nic->vector_value("BRIDGE");
bridge = nic->vector_value("BRIDGE");
if ( bridge.empty() )
{
file << "\t\t<interface type='ethernet'>" << endl;
}
else
{
file << "\t\t<interface type='bridge'>" << endl;
file << "\t\t\t<source bridge='" << bridge << "'/>" << endl;
}
if ( bridge.empty() )
{
file << "\t\t<interface type='ethernet'>" << endl;
}
else
{
file << "\t\t<interface type='bridge'>" << endl;
file << "\t\t\t<source bridge='" << bridge << "'/>" << endl;
}
mac = nic->vector_value("MAC");
mac = nic->vector_value("MAC");
if( !mac.empty() )
{
file << "\t\t\t<mac address='" << mac << "'/>" << endl;
}
if( !mac.empty() )
{
file << "\t\t\t<mac address='" << mac << "'/>" << endl;
}
target = nic->vector_value("TARGET");
target = nic->vector_value("TARGET");
if( !target.empty() )
{
file << "\t\t\t<target dev='" << target << "'/>" << endl;
}
if( !target.empty() )
{
file << "\t\t\t<target dev='" << target << "'/>" << endl;
}
script = nic->vector_value("SCRIPT");
script = nic->vector_value("SCRIPT");
if( !script.empty() )
{
file << "\t\t\t<script path='" << script << "'/>" << endl;
}
if( !script.empty() )
{
file << "\t\t\t<script path='" << script << "'/>" << endl;
}
file << "\t\t</interface>" << endl;
file << "\t\t</interface>" << endl;
}
}
attrs.clear();
attrs.clear();
// ------------------------------------------------------------------------
// Graphics
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Graphics
// ------------------------------------------------------------------------
if ( vm->get_template_attribute("GRAPHICS",attrs) > 0 )
{
graphics = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( vm->get_template_attribute("GRAPHICS",attrs) > 0 )
{
graphics = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( graphics != 0 )
{
type = graphics->vector_value("TYPE");
listen = graphics->vector_value("LISTEN");
port = graphics->vector_value("PORT");
passwd = graphics->vector_value("PASSWD");
if ( graphics != 0 )
{
type = graphics->vector_value("TYPE");
listen = graphics->vector_value("LISTEN");
port = graphics->vector_value("PORT");
passwd = graphics->vector_value("PASSWD");
if ( type == "vnc" || type == "VNC" )
{
if ( type == "vnc" || type == "VNC" )
{
file << "\t\t<graphics type='vnc'";
if ( !listen.empty() )
{
if ( !listen.empty() )
{
file << " listen='" << listen << "'";
}
}
if ( !port.empty() )
{
if ( !port.empty() )
{
file << " port='" << port << "'";
}
}
if ( !passwd.empty() )
{
file << " password='" << passwd << "'";
}
if ( !passwd.empty() )
{
file << " password='" << passwd << "'";
}
file << "/>" << endl;
}
else
{
vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored.");
}
}
}
file << "/>" << endl;
}
else
{
vm->log("VMM", Log::WARNING,
"Not supported graphics type, ignored.");
}
}
}
attrs.clear();
attrs.clear();
// ------------------------------------------------------------------------
// Input
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Input
// ------------------------------------------------------------------------
if ( vm->get_template_attribute("INPUT",attrs) > 0 )
{
input = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( vm->get_template_attribute("INPUT",attrs) > 0 )
{
input = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( input != 0 )
{
type = input->vector_value("TYPE");
bus = input->vector_value("BUS");
if ( input != 0 )
{
type = input->vector_value("TYPE");
bus = input->vector_value("BUS");
if ( !type.empty() )
{
if ( !type.empty() )
{
file << "\t\t<input type='" << type << "'";
if ( !bus.empty() )
{
{
file << " bus='" << bus << "'";
}
}
file << "/>" << endl;
}
}
}
}
}
}
attrs.clear();
attrs.clear();
file << "\t</devices>" << endl;
file << "\t</devices>" << endl;
// ------------------------------------------------------------------------
// Features
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Features
// ------------------------------------------------------------------------
num = vm->get_template_attribute("FEATURES",attrs);
num = vm->get_template_attribute("FEATURES",attrs);
if ( num > 0 )
{
features = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( num > 0 )
{
features = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( features != 0 )
{
pae = features->vector_value("PAE");
acpi = features->vector_value("ACPI");
if ( features != 0 )
{
pae = features->vector_value("PAE");
acpi = features->vector_value("ACPI");
file << "\t<features>" << endl;
if ( pae == "yes" )
{
file << "\t\t<pae/>" << endl;
}
if ( pae == "yes" )
{
file << "\t\t<pae/>" << endl;
}
if ( acpi == "no" )
{
file << "\t\t<acpi/>" << endl;
}
if ( acpi == "no" )
{
file << "\t\t<acpi/>" << endl;
}
file << "\t</features>" << endl;
}
}
}
}
attrs.clear();
attrs.clear();
// ------------------------------------------------------------------------
// Raw KVM attributes
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
// Raw KVM attributes
// ------------------------------------------------------------------------
num = vm->get_template_attribute("RAW",attrs);
num = vm->get_template_attribute("RAW",attrs);
for(int i=0; i<num;i++)
{
raw = dynamic_cast<const VectorAttribute *>(attrs[i]);
for(int i=0; i<num;i++)
{
raw = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( raw == 0 )
{
continue;
}
if ( raw == 0 )
{
continue;
}
type = raw->vector_value("TYPE");
type = raw->vector_value("TYPE");
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
if ( type == "KVM" )
{
data = raw->vector_value("DATA");
file << "\t" << data << endl;
}
}
if ( type == "KVM" )
{
data = raw->vector_value("DATA");
file << "\t" << data << endl;
}
}
file << "</domain>" << endl;
file << "</domain>" << endl;
file.close();
file.close();
return 0;
return 0;
error_file:
vm->log("VMM", Log::ERROR, "Could not open KVM deployment file.");
return -1;
vm->log("VMM", Log::ERROR, "Could not open KVM deployment file.");
return -1;
error_memory:
vm->log("VMM", Log::ERROR, "No MEMORY defined and no default provided.");
file.close();
return -1;
vm->log("VMM", Log::ERROR, "No MEMORY defined and no default provided.");
file.close();
return -1;
error_boot:
vm->log("VMM", Log::ERROR, "No BOOT device defined and no default provided.");
file.close();
return -1;
vm->log("VMM", Log::ERROR, "No BOOT device defined and no default provided.");
file.close();
return -1;
error_disk:
vm->log("VMM", Log::ERROR, "Wrong target value in DISK.");
file.close();
return -1;
vm->log("VMM", Log::ERROR, "Wrong target value in DISK.");
file.close();
return -1;
}

View File

@ -23,11 +23,11 @@ lib_name='nebula_vmm'
# Sources to generate the library
source_files=[
'VirtualMachineManager.cc',
'VirtualMachineManagerDriver.cc',
'XenDriver.cc',
'LibVirtDriver.cc',
'XMLDriver.cc'
'VirtualMachineManager.cc',
'VirtualMachineManagerDriver.cc',
'XenDriver.cc',
'LibVirtDriver.cc',
'XMLDriver.cc'
]
# Build library

View File

@ -325,7 +325,7 @@ void VirtualMachineManager::save_action(
{
if (!vm->hasPreviousHistory())
{
goto error_previous_history;
goto error_previous_history;
}
hostname = vm->get_previous_hostname();
@ -495,8 +495,8 @@ error_common:
void VirtualMachineManager::migrate_action(
int vid)
{
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
VirtualMachine * vm;
const VirtualMachineManagerDriver * vmd;
ostringstream os;
// Get the VM from the pool
@ -527,9 +527,9 @@ void VirtualMachineManager::migrate_action(
// Invoke driver method
vmd->migrate(vid,
vm->get_previous_hostname(),
vm->get_deploy_id(),
vm->get_hostname());
vm->get_previous_hostname(),
vm->get_deploy_id(),
vm->get_hostname());
vm->unlock();
@ -546,9 +546,9 @@ error_driver:
goto error_common;
error_previous_history:
os.str("");
os << "migrate_action, error VM has no previous history";
goto error_common;
os.str("");
os << "migrate_action, error VM has no previous history";
goto error_common;
error_common:
Nebula &ne = Nebula::instance();
@ -758,13 +758,13 @@ void VirtualMachineManager::timer_action()
void VirtualMachineManager::load_mads(int uid)
{
unsigned int i;
ostringstream oss;
const VectorAttribute * vattr;
int rc;
string name;
string type;
VirtualMachineManagerDriver * vmm_driver = 0;
unsigned int i;
ostringstream oss;
const VectorAttribute * vattr;
int rc;
string name;
string type;
VirtualMachineManagerDriver * vmm_driver = 0;
oss << "Loading Virtual Machine Manager drivers.";
@ -785,24 +785,25 @@ void VirtualMachineManager::load_mads(int uid)
if ( type == "XEN" )
{
vmm_driver = new XenDriver(uid, vattr->value(),(uid != 0),vmpool);
vmm_driver = new XenDriver(uid, vattr->value(),(uid != 0),vmpool);
}
else if ( type == "KVM" )
{
vmm_driver = new LibVirtDriver(uid, vattr->value(),(uid != 0),vmpool,"kvm");
vmm_driver = new LibVirtDriver(uid, vattr->value(),
(uid != 0),vmpool,"kvm");
}
else if ( type == "XML" )
{
vmm_driver = new XMLDriver(uid, vattr->value(),(uid != 0),vmpool);
vmm_driver = new XMLDriver(uid, vattr->value(),(uid != 0),vmpool);
}
else
{
oss.str("");
oss << "\tUnknown driver type: " << type;
oss.str("");
oss << "\tUnknown driver type: " << type;
Nebula::log("VMM",Log::ERROR,oss);
Nebula::log("VMM",Log::ERROR,oss);
continue;
continue;
}
rc = add(vmm_driver);

View File

@ -21,53 +21,53 @@
#include <sstream>
VirtualMachineManagerDriver::VirtualMachineManagerDriver(
int userid,
int userid,
const map<string,string>& attrs,
bool sudo,
VirtualMachinePool * pool):
Mad(userid,attrs,sudo),driver_conf(true),vmpool(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;
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/etc or in "/etc/one"
if (it->second[0] != '/') //Look in ONE_LOCATION/etc or in "/etc/one"
{
Nebula& nd = Nebula::instance();
Nebula& nd = Nebula::instance();
file = nd.get_defaults_location() + it->second;
cfile = file.c_str();
}
else //Absolute Path
{
cfile = it->second.c_str();
cfile = it->second.c_str();
}
rc = driver_conf.parse(cfile, &error_msg);
if ( rc != 0 )
{
ostringstream oss;
ostringstream oss;
if ( error_msg != 0 )
{
oss << "Error loading driver configuration file " << cfile <<
" : " << error_msg;
if ( error_msg != 0 )
{
oss << "Error loading driver configuration file " << cfile <<
" : " << error_msg;
free(error_msg);
}
else
{
oss << "Error loading driver configuration file " << cfile;
}
free(error_msg);
}
else
{
oss << "Error loading driver configuration file " << cfile;
}
Nebula::log("VMM", Log::ERROR, oss);
Nebula::log("VMM", Log::ERROR, oss);
}
}
}
@ -76,24 +76,24 @@ VirtualMachineManagerDriver::VirtualMachineManagerDriver(
/* -------------------------------------------------------------------------- */
void VirtualMachineManagerDriver::get_default(
const char * name,
const char * name,
const char * vname,
string& value) const
{
vector<const Attribute *> attrs;
string sn = name;
vector<const Attribute *> attrs;
string sn = name;
if ( driver_conf.get(sn,attrs) == 1 )
{
const VectorAttribute * vattr;
const VectorAttribute * vattr;
vattr = static_cast<const VectorAttribute *>(attrs[0]);
vattr = static_cast<const VectorAttribute *>(attrs[0]);
value = vattr->vector_value(vname);
value = vattr->vector_value(vname);
}
else
{
value = "";
value = "";
}
}
@ -442,7 +442,7 @@ void VirtualMachineManagerDriver::protocol(
int memory = -1;
int net_tx = -1;
int net_rx = -1;
char state = '-';
char state = '-';
while(is.good())
{
@ -486,11 +486,11 @@ void VirtualMachineManagerDriver::protocol(
}
else if (var == "STATE")
{
tiss >> state;
tiss >> state;
}
else
{
string val;
string val;
os.str("");
os << "Unknown monitoring attribute (adding/updating"
@ -510,48 +510,48 @@ void VirtualMachineManagerDriver::protocol(
if (state != '-' && vm->get_lcm_state() == VirtualMachine::RUNNING)
{
Nebula &ne = Nebula::instance();
LifeCycleManager * lcm = ne.get_lcm();
Nebula &ne = Nebula::instance();
LifeCycleManager * lcm = ne.get_lcm();
switch (state)
{
case 'a': // Still active, good!
switch (state)
{
case 'a': // Still active, good!
os.str("");
os << "Monitor Information:\n"
<< "\tCPU : "<< cpu << "\n"
<< "\tMemory: "<< memory << "\n"
<< "\tNet_TX: "<< net_tx << "\n"
<< "\tNet_RX: "<< net_rx << "\n";
<< "\tCPU : "<< cpu << "\n"
<< "\tMemory: "<< memory << "\n"
<< "\tNet_TX: "<< net_tx << "\n"
<< "\tNet_RX: "<< net_rx << "\n";
vm->log("VMM",Log::INFO,os);
break;
break;
case 'p': // It's paused
case 'p': // It's paused
os.str("");
os << "VM running but new state from monitor is PAUSED.\n";
vm->log("VMM",Log::INFO,os);
lcm->trigger(LifeCycleManager::MONITOR_SUSPEND, id);
break;
break;
case 'e': //Failed
os.str("");
case 'e': //Failed
os.str("");
os << "VM running but new state from monitor is ERROR.\n";
vm->log("VMM",Log::INFO,os);
lcm->trigger(LifeCycleManager::MONITOR_FAILURE, id);
break;
break;
case 'd': //Failed
os.str("");
case 'd': //Failed
os.str("");
os << "VM running but it was not found. Assuming it is done.\n";
vm->log("VMM",Log::INFO,os);
lcm->trigger(LifeCycleManager::MONITOR_DONE, id);
break;
}
break;
}
}
}
else

View File

@ -26,14 +26,14 @@ int XMLDriver::deployment_description(
const string& file_name) const
{
ofstream file;
string xml;
string xml;
file.open(file_name.c_str(), ios::out);
if (file.fail() == true)
{
vm->log("VMM", Log::ERROR, "Could not open XML deployment file.");
return -1;
vm->log("VMM", Log::ERROR, "Could not open XML deployment file.");
return -1;
}
vm->template_to_xml(xml);

View File

@ -30,7 +30,7 @@ int XenDriver::deployment_description(
int num;
vector<const Attribute *> attrs;
string credits;
string credits;
string cpu;
string memory;
string vcpu;
@ -58,21 +58,21 @@ int XenDriver::deployment_description(
const VectorAttribute * graphics;
string type = "";
string listen = "";
string port = "";
string passwd = "";
string type = "";
string listen = "";
string port = "";
string passwd = "";
const VectorAttribute * raw;
string data;
const VectorAttribute * raw;
string data;
// ------------------------------------------------------------------------
// ------------------------------------------------------------------------
file.open(file_name.c_str(), ios::out);
if (file.fail() == true)
{
goto error_file;
goto error_file;
}
// ------------------------------------------------------------------------
@ -107,16 +107,16 @@ int XenDriver::deployment_description(
if (memory.empty())
{
get_default("MEMORY",memory);
get_default("MEMORY",memory);
}
if (!memory.empty())
{
file << "memory = '" << memory << "'" << endl;
file << "memory = '" << memory << "'" << endl;
}
else
{
goto error_memory;
goto error_memory;
}
// -------------------------------------------------------------------------
@ -125,12 +125,12 @@ int XenDriver::deployment_description(
if (vcpu.empty())
{
get_default("VCPU",vcpu);
get_default("VCPU",vcpu);
}
if (!vcpu.empty())
{
file << "vcpu = '" << vcpu << "'" << endl;
file << "vcpu = '" << vcpu << "'" << endl;
}
// ------------------------------------------------------------------------
@ -141,48 +141,48 @@ int XenDriver::deployment_description(
if ( num > 0 )
{
const VectorAttribute * os;
const VectorAttribute * os;
os = dynamic_cast<const VectorAttribute *>(attrs[0]);
os = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( os != 0 )
{
if ( os != 0 )
{
kernel = os->vector_value("KERNEL");
initrd = os->vector_value("INITRD");
root = os->vector_value("ROOT");
kernel_cmd = os->vector_value("KERNEL_CMD");
bootloader = os->vector_value("BOOTLOADER");
}
}
}
if ( kernel.empty() )
{
get_default("OS","KERNEL",kernel);
get_default("OS","KERNEL",kernel);
}
if ( initrd.empty() )
{
get_default("OS","INITRD",initrd);
get_default("OS","INITRD",initrd);
}
if ( bootloader.empty() )
{
get_default("OS","BOOTLOADER",bootloader);
get_default("OS","BOOTLOADER",bootloader);
}
if ( root.empty() )
{
get_default("OS","ROOT",root);
get_default("OS","ROOT",root);
}
if ( kernel_cmd.empty() )
{
get_default("OS","KERNEL_CMD",kernel_cmd);
get_default("OS","KERNEL_CMD",kernel_cmd);
}
if ( !kernel.empty() ) //Direct Kernel boot method
{
file << "kernel = '" << kernel << "'" << endl;
file << "kernel = '" << kernel << "'" << endl;
if ( !initrd.empty() )
{
@ -191,7 +191,7 @@ int XenDriver::deployment_description(
if ( !root.empty() )
{
file << "root = '/dev/" << root << "'" << endl;
file << "root = '/dev/" << root << "'" << endl;
}
if ( !kernel_cmd.empty() )
@ -201,11 +201,11 @@ int XenDriver::deployment_description(
}
else if ( !bootloader.empty() ) //Host loader boot method
{
file << "bootloader = \"" << bootloader << "\"" << endl;
file << "bootloader = \"" << bootloader << "\"" << endl;
}
else
{
goto error_boot;
goto error_boot;
}
attrs.clear();
@ -232,19 +232,19 @@ int XenDriver::deployment_description(
if ( target.empty() )
{
goto error_disk;
goto error_disk;
}
mode = "w";
if ( !ro.empty() )
{
transform(ro.begin(),ro.end(),ro.begin(),(int(*)(int))toupper);
transform(ro.begin(),ro.end(),ro.begin(),(int(*)(int))toupper);
if ( ro == "YES" )
{
mode = "r";
}
if ( ro == "YES" )
{
mode = "r";
}
}
// TODO: "file" method to specify disk images in xen is deprecated.
@ -295,7 +295,7 @@ int XenDriver::deployment_description(
for(int i=0; i<num;i++,mac="",bridge="")
{
char pre_char = ' ';
char pre_char = ' ';
nic = dynamic_cast<const VectorAttribute *>(attrs[i]);
@ -310,7 +310,7 @@ int XenDriver::deployment_description(
if( !mac.empty() )
{
file << "mac=" << mac;
file << "mac=" << mac;
pre_char = ',';
}
@ -318,7 +318,7 @@ int XenDriver::deployment_description(
if( !bridge.empty() )
{
file << pre_char << "bridge=" << bridge;
file << pre_char << "bridge=" << bridge;
}
file << "',";
@ -335,41 +335,42 @@ int XenDriver::deployment_description(
if ( vm->get_template_attribute("GRAPHICS",attrs) > 0 )
{
graphics = dynamic_cast<const VectorAttribute *>(attrs[0]);
graphics = dynamic_cast<const VectorAttribute *>(attrs[0]);
if ( graphics != 0 )
{
type = graphics->vector_value("TYPE");
listen = graphics->vector_value("LISTEN");
port = graphics->vector_value("PORT");
passwd = graphics->vector_value("PASSWD");
if ( graphics != 0 )
{
type = graphics->vector_value("TYPE");
listen = graphics->vector_value("LISTEN");
port = graphics->vector_value("PORT");
passwd = graphics->vector_value("PASSWD");
if ( type == "vnc" || type == "VNC" )
{
file << "vfb = ['type=vnc";
if ( type == "vnc" || type == "VNC" )
{
file << "vfb = ['type=vnc";
if ( !listen.empty() )
{
file << ",vnclisten=" << listen;
}
if ( !listen.empty() )
{
file << ",vnclisten=" << listen;
}
if ( !port.empty() )
{
file << ",vncdisplay=" << port;
}
if ( !port.empty() )
{
file << ",vncdisplay=" << port;
}
if ( !passwd.empty() )
{
file << ",vncpasswd=" << passwd;
}
if ( !passwd.empty() )
{
file << ",vncpasswd=" << passwd;
}
file <<"']" << endl;
}
else
{
vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored.");
}
}
file <<"']" << endl;
}
else
{
vm->log("VMM", Log::WARNING,
"Not supported graphics type, ignored.");
}
}
}
attrs.clear();
@ -382,22 +383,22 @@ int XenDriver::deployment_description(
for(int i=0; i<num;i++)
{
raw = dynamic_cast<const VectorAttribute *>(attrs[i]);
raw = dynamic_cast<const VectorAttribute *>(attrs[i]);
if ( raw == 0 )
{
if ( raw == 0 )
{
continue;
}
}
type = raw->vector_value("TYPE");
type = raw->vector_value("TYPE");
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
if ( type == "XEN" )
{
data = raw->vector_value("DATA");
file << data << endl;
}
if ( type == "XEN" )
{
data = raw->vector_value("DATA");
file << data << endl;
}
}
file.close();
@ -405,21 +406,22 @@ int XenDriver::deployment_description(
return 0;
error_file:
vm->log("VMM", Log::ERROR, "Could not open Xen deployment file.");
return -1;
vm->log("VMM", Log::ERROR, "Could not open Xen deployment file.");
return -1;
error_memory:
vm->log("VMM", Log::ERROR, "No memory defined and no default provided.");
file.close();
return -1;
vm->log("VMM", Log::ERROR, "No memory defined and no default provided.");
file.close();
return -1;
error_boot:
vm->log("VMM", Log::ERROR, "No kernel or bootloader defined and no default provided.");
file.close();
return -1;
vm->log("VMM", Log::ERROR,
"No kernel or bootloader defined and no default provided.");
file.close();
return -1;
error_disk:
vm->log("VMM", Log::ERROR, "Wrong target value in DISK.");
file.close();
return -1;
vm->log("VMM", Log::ERROR, "Wrong target value in DISK.");
file.close();
return -1;
}