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

Ticket #3: Extended template attributes. Xen driver rewritten to use new format. Also Attributes can now have blanks (but not ','). A file with all the attributes has been included.

git-svn-id: http://svn.opennebula.org/trunk@38 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
Rubén S. Montero 2008-07-06 17:15:16 +00:00
parent 45663d6c33
commit d08bc4d673
5 changed files with 419 additions and 167 deletions

View File

@ -1,12 +1,11 @@
#
# Default configuration attributes for the Xen driver
# (all domains will use these values as defaults)
#
# Valid atributes:
# - credit
# - os [memory,initr,boot]
# - memory
MEMORY = 128
KERNEL = /vmlinuz
RAMDISK = /initrd.img
CREDIT = 256
MEMORY = 128
OS = [ kernel="/vmlinuz", initrd="/initrd.img"]
CREDIT = 256

87
share/examples/vm.schema Normal file
View File

@ -0,0 +1,87 @@
# ----------------------------------------------------------------------
# VM ATTRIBUTES
# Each attribute is labeled as Optional or Mandatory, also if it
# can be defined in the driver conf file is tagged with default. Finally
# the hypervisors that support the attribute are listed.
# ----------------------------------------------------------------------
#---------------------------------------
# Name of the VM
#---------------------------------------
NAME = vm-example # Optional, Default: one-$VMID, XEN, KVM
#---------------------------------------
# Capacity
#---------------------------------------
CPU = "amount_of_requested_CPU" # Mandatory, XEN, KVM
MEMORY = "amount_of_requested_MEM" # Mandatory, XEN, KVM
#---------------------------------------
# OS and boot options
#---------------------------------------
OS = [
kernel = "path_to_os_kernel", # Mandatory, default, XEN, KVM
initrd = "path_to_initrd_image", # Optional, default, XEN, KVM
kernel_cmd = "kernel_command_line", # Optional, default, KVM
boot = "device to boot from" ] # Mandatory, default, XEN, KVM
#---------------------------------------
# Features of the hypervisor
#---------------------------------------
FEATURES = [
pae = "yes|no", # Optional, KVM
acpi = "yes|no" ] # Optional, KVM
#---------------------------------------
# VM Disks
#---------------------------------------
DISK = [
type = "floppy|disk|cdrom", #Optional, KVM
source = "path_to_disk_image_file|physical_dev", #Mandatory, XEN, KVM
target = "device_to_map_disk", #Mandatory, XEN, KVM
bus = "ide|scsi|virtio|xen", #Optional, KVM
readonly = "yes|no" ] #Optional, XEN, KVM
#---------------------------------------
# Network Interfaces
#---------------------------------------
NIC = [
bridge = "name_of_bridge_to_bind_if", #Optional, XEN, KVM
target = "device_name_to_map_if", #Optional, KVM
mac = "HW_address", #Optional, XEN, KVM
script = "path_to_script_to_bring_up_if"] #Optional, KVM
#---------------------------------------
# I/O Interfaces
#---------------------------------------
INPUT = [ #Optional, KVM
type = "mouse|tablet",
bus = "usb|ps2|xen" ]
GRAPHICS = [ #Optional, XEN, KVM
type = "vnc|sdl",
listen = "IP-to-listen-on",
port = "port_for_VNC_server",
passwd = "passwor_for_VNC_server" ]
#---------------------------------------
# Raw Hypervisor attributes
#---------------------------------------
RAW = [ # Optional, KVM, XEN
type = "xen|kvm",
data = "raw_domain_configutarion"]
#---------------------------------------
# Scheduler
#---------------------------------------
REQUIREMENTS = "Bool_expression_for_reqs" #Optional
RANK = "Arith_expression_to_rank_hosts" #Optional

View File

@ -1,6 +1,38 @@
DISK=[image="/local/xen/domains/xen-etch/disk.img",dev="sda1",mode=w]
DISK=[image="/local/xen/domains/xen-etch/swap.img",dev="sda2",mode=w]
KERNEL=/boot/vmlinuz-2.6.18-4-xen-amd64
RAMDISK=/boot/initrd.img-2.6.18-4-xen-amd64
MEMORY=64
CPU=1
#---------------------------------------
# VM definition example
#---------------------------------------
NAME = vm-example
CPU = 0.5
MEMORY = 128
# --- kernel & boot device ---
OS = [
kernel = "/vmlinuz",
initrd = "/initrd.img",
boot = "sda1" ]
# --- 2 disks ---
DISK = [
source = "/local/xen/domains/etch/disk.img",
target = "sda1",
readonly = "no" ]
DISK = [
source = "/local/xen/domains/etch/swap.img",
target = "sda2",
readonly = "no" ]
# --- 1 NIC ---
NIC = [ mac="00:ff:72:17:20:27"]
# --- VNC server ---
GRAPHICS = [
type = "vnc",
listen = "127.0.0.1",
port = "5"]

View File

@ -52,22 +52,34 @@ string * VectorAttribute::marshall()
void VectorAttribute::unmarshall(string& sattr)
{
size_t pos;
string tmp;
while ( (pos = sattr.find(',')) != string::npos )
size_t bpos=0,epos,mpos;
string tmp;
bool cont = true;
while(cont)
{
sattr.replace(pos,1," ");
}
istringstream is(sattr);
while ( is >> tmp )
{
pos = tmp.find("=");
attribute_value.insert(make_pair(tmp.substr(0,pos),
tmp.substr(pos+1)));
epos=sattr.find(',',bpos);
if (epos == string::npos)
{
tmp = sattr.substr(bpos);
cont = false;
}
else
{
tmp = sattr.substr(bpos,epos-bpos);
bpos = epos + 1;
}
mpos = tmp.find('=');
if (mpos == string::npos)
{
continue;
}
attribute_value.insert(make_pair(tmp.substr(0,mpos),
tmp.substr(mpos+1)));
}
}

View File

@ -29,20 +29,41 @@ int XenDriver::deployment_description(
int num;
vector<const Attribute *> attrs;
const VectorAttribute * disk;
const VectorAttribute * nic;
string boot_device = "";
string str_value;
// Base Scheduler Credit
float base_credit = 1.0;
float cpu_units = 1.0;
string dev;
string image;
string credits;
string cpu;
string memory;
float base_credit = 1.0;
float cpu_units = 1.0;
string kernel = "";
string initrd = "";
string boot = "";
const VectorAttribute * disk;
string source = "";
string target = "";
string ro = "";
string mode;
string boot;
const VectorAttribute * nic;
string mac = "";
string bridge = "";
const VectorAttribute * graphics;
string type = "";
string listen = "";
string port = "";
string passwd = "";
const VectorAttribute * raw;
string data;
// ------------------------------------------------------------------------
file.open(file_name.c_str(), ios::out);
@ -50,178 +71,279 @@ int XenDriver::deployment_description(
{
goto error_file;
}
// ------------------------------------------------------------------------
// CPU Credits
// ------------------------------------------------------------------------
get_default("CREDIT", str_value);
if(str_value!="")
base_credit = atof(str_value.c_str());
vm->get_template_attribute("CPU", str_value);
if(str_value!="")
cpu_units = atof(str_value.c_str());
file << "#O CPU_CREDITS = " << ceil(cpu_units*base_credit) << endl;
// VM name
// ------------------------------------------------------------------------
// Domain name
// ------------------------------------------------------------------------
file << "name = 'one-" << vm->get_oid() << "'" << endl;
// ------------------------------------------------------------------------
// Disks and Boot Device
// Capacity CPU, Mem & Credits
// ------------------------------------------------------------------------
get_default("CREDIT", credits);
if(!credits.empty())
{
base_credit = atof(credits.c_str());
}
vm->get_template_attribute("CPU", cpu);
if(!cpu.empty())
{
cpu_units = atof(cpu.c_str());
}
file << "#O CPU_CREDITS = " << ceil(cpu_units*base_credit) << endl;
// ------------------------------------------------------------------------
vm->get_template_attribute("MEMORY",memory);
if (memory.empty())
{
get_default("MEMORY",memory);
}
if (!memory.empty())
{
file << "memory = '" << memory << "'" << endl;
}
else
{
goto error_memory;
}
// ------------------------------------------------------------------------
// OS and boot options
// ------------------------------------------------------------------------
num = vm->get_template_attribute("OS",attrs);
if ( num >= 0 )
{
const VectorAttribute * os;
os = static_cast<const VectorAttribute *>(attrs[0]);
kernel = os->vector_value("KERNEL");
initrd = os->vector_value("INITRD");
boot = os->vector_value("BOOT");
}
if ( kernel.empty() )
{
get_default("OS","KERNEL",kernel);
}
if ( initrd.empty() )
{
get_default("OS","INITRD",initrd);
}
if ( boot.empty() )
{
get_default("OS","BOOT",boot);
}
if ( kernel.empty() )
{
goto error_kernel;
}
else
{
file << "kernel = '" << kernel << "'" << endl;
}
if ( boot.empty() )
{
goto error_boot;
}
else
{
file << "root = '/dev/" << boot << " ro'" << endl;
}
if ( !initrd.empty() )
{
file << "ramdisk = '" << initrd << "'" << endl;
}
attrs.clear();
// ------------------------------------------------------------------------
// Disks
// ------------------------------------------------------------------------
num = vm->get_template_attribute("DISK",attrs);
file << "disk = [" << endl;
for (int i=0; i < num ;i++)
for (int i=0; i < num ;i++,source="",target="",ro="")
{
disk = static_cast<const VectorAttribute *>(attrs[i]);
image = disk->vector_value("IMAGE");
dev = disk->vector_value("DEV");
mode = disk->vector_value("MODE");
if ( image == "" | dev == "")
source = disk->vector_value("SOURCE");
target = disk->vector_value("TARGET");
ro = disk->vector_value("READONLY");
if ( source.empty() | target.empty())
{
goto error_disk;
}
if (mode == "")
{
mode = "rw";
}
mode = "w";
if ( !ro.empty() )
{
transform(ro.begin(),ro.end(),ro.begin(),(int(*)(int))toupper);
if ( ro == "YES" )
{
mode = "r";
}
}
file << " "
<< "'file:" << image << ","
<< dev << ","
<< "'file:" << source << ","
<< target << ","
<< mode
<< "'," << endl;
}
file << "]" << endl;
// --- Boot device ---
vm->get_template_attribute("BOOT",boot);
if (boot != "")
{
boot_device = boot;
}
else
{
// Boot device default value
boot_device =
static_cast<const VectorAttribute *>(attrs[0])->vector_value("DEV");
}
file << "root = '/dev/" << boot_device << " ro'" << endl;
attrs.clear();
// ------------------------------------------------------------------------
// Kernel & Ramdisk
// ------------------------------------------------------------------------
vm->get_template_attribute("KERNEL",str_value);
if ( str_value == "" )
{
get_default("KERNEL",str_value);
}
if ( str_value != "" )
{
file << "kernel = '" << str_value << "'" << endl;
}
vm->get_template_attribute("RAMDISK",str_value);
if( str_value == "" )
{
get_default("RAMDISK",str_value);
}
if ( str_value != "" )
{
file << "ramdisk = '" << str_value << "'" << endl;
}
// ------------------------------------------------------------------------
// Memory
// ------------------------------------------------------------------------
vm->get_template_attribute("MEMORY",str_value);
if( str_value == "" )
{
get_default("MEMORY",str_value);
}
if ( str_value != "" )
{
file << "memory = '" << str_value << "'" << endl;
}
// ------------------------------------------------------------------------
// Network
// ------------------------------------------------------------------------
num = vm->get_template_attribute("NIC",attrs);
if ( num != 0 )
{
file << "vif = [" << endl;
file << "vif = [" << endl;
for(int i=0; i<num;i++)
{
char pre_char = ' ';
for(int i=0; i<num;i++,mac="",bridge="")
{
char pre_char = ' ';
nic = static_cast<const VectorAttribute *>(attrs[i]);
nic = static_cast<const VectorAttribute *>(attrs[i]);
file << " '";
file << " '";
str_value = nic->vector_value("MAC");
if( str_value != "" )
{
file << "mac=" << str_value;
pre_char = ',';
}
str_value = nic->vector_value("BRIDGE");
if( str_value != "" )
{
file << pre_char << "bridge=" << str_value;
pre_char = ',';
}
file << "',";
file << endl;
}
mac = nic->vector_value("MAC");
file << "]" << endl;
if( !mac.empty() )
{
file << "mac=" << mac;
pre_char = ',';
}
bridge = nic->vector_value("BRIDGE");
if( !bridge.empty() )
{
file << pre_char << "bridge=" << bridge;
}
file << "',";
file << endl;
}
file << "]" << endl;
attrs.clear();
// ------------------------------------------------------------------------
// Graphics
// ------------------------------------------------------------------------
if ( vm->get_template_attribute("GRAPHICS",attrs) > 0 )
{
graphics = static_cast<const VectorAttribute *>(attrs[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 ( !listen.empty() )
{
file << ",vnclisten=" << listen;
}
if ( !port.empty() )
{
file << ",vncdisplay=" << port;
}
if ( !passwd.empty() )
{
file << ",vncpasswd=" << passwd;
}
file <<"']" << endl;
}
else
{
vm->log("VMM", Log::WARNING, "Not supported graphics type, ignored.");
}
}
attrs.clear();
// ------------------------------------------------------------------------
// Raw XEN attributes
// ------------------------------------------------------------------------
num = vm->get_template_attribute("RAW",attrs);
for(int i=0; i<num;i++)
{
raw = static_cast<const VectorAttribute *>(attrs[i]);
type = raw->vector_value("TYPE");
transform(type.begin(),type.end(),type.begin(),(int(*)(int))toupper);
if ( type == "XEN" )
{
data = raw->vector_value("DATA");
file << data << endl;
}
}
file.close();
return 0;
error_file:
vm->log("VMM", Log::ERROR, "Could not open Xen deployment file\n.");
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;
error_kernel:
vm->log("VMM", Log::ERROR, "No kernel 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;
error_disk:
vm->log("VMM", Log::ERROR, "Wrong dev or image value in DISK attribute\n.");
vm->log("VMM", Log::ERROR, "Wrong source or target value in DISK.");
file.close();
return -1;
}