mirror of
https://github.com/OpenNebula/one.git
synced 2024-12-22 13:33:52 +03:00
Added CPU credit scheduling
git-svn-id: http://svn.opennebula.org/trunk@20 3034c82b-c49b-4eb3-8279-a7acafdc01c0
This commit is contained in:
parent
4eef1f1d4b
commit
4f484c20cf
@ -8,3 +8,5 @@ MEMORY = 128
|
||||
KERNEL = /vmlinuz
|
||||
|
||||
RAMDISK = /initrd.img
|
||||
|
||||
CREDIT = 256
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "Nebula.h"
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <math.h>
|
||||
|
||||
int XenDriver::deployment_description(
|
||||
const VirtualMachine * vm,
|
||||
@ -27,13 +28,17 @@ int XenDriver::deployment_description(
|
||||
ofstream file;
|
||||
|
||||
int num;
|
||||
vector<const Attribute *> attrs;
|
||||
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 mode;
|
||||
@ -45,6 +50,23 @@ 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
|
||||
file << "name = 'one-" << vm->get_oid() << "'" << endl;
|
||||
|
@ -36,7 +36,43 @@ class DM < ONEMad
|
||||
end
|
||||
|
||||
def action_deploy(args)
|
||||
std_action("DEPLOY", "create #{args[3]}", args)
|
||||
#std_action("DEPLOY", "create #{args[3]}", args)
|
||||
|
||||
# TODO: check for error
|
||||
file=open(args[3])
|
||||
f=file.read
|
||||
file.close
|
||||
|
||||
# Get values passed in the deployment file, the form is:
|
||||
# [["CPU_CREDITS", "3"], ["OTHER_VARIABLE", "value"]]
|
||||
values=f.scan(/^#O (.*?) = (.*)$/)
|
||||
|
||||
# Gets the first pair with the name provided or nil if not found
|
||||
credits=values.assoc("CPU_CREDITS")
|
||||
credits=credits[1] if credits
|
||||
|
||||
# Get the name of the VM (used to set credit scheduling)
|
||||
vm_name=f.match(/^name = '(.*?)'$/)[1]
|
||||
|
||||
action_number=args[1]
|
||||
action_host=args[2]
|
||||
|
||||
cmd_str="sudo #{XM_PATH} create #{args[3]}"
|
||||
|
||||
# Add sched-cred command if credits are defined
|
||||
if(credits)
|
||||
cmd_str+=" \\&\\& sudo #{XM_PATH} sched-cred -d #{vm_name} -w #{credits}"
|
||||
STDERR.puts "Setting credits for the VM"
|
||||
STDERR.puts "Command: #{cmd_str}"
|
||||
end
|
||||
|
||||
cmd=SSHCommand.new(cmd_str)
|
||||
cmd.callback=lambda do |a, num|
|
||||
write_response("DEPLOY", a.stdout, a.stderr, args)
|
||||
end
|
||||
|
||||
action=SSHAction.new(action_number, action_host, cmd)
|
||||
send_ssh_action(action_number, action_host, action)
|
||||
end
|
||||
|
||||
def action_shutdown(args)
|
||||
|
Loading…
Reference in New Issue
Block a user