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

Merge branch 'master' into feature-1664

This commit is contained in:
Ruben S. Montero 2013-03-13 23:14:33 +01:00
commit 6b5e43c2cd
24 changed files with 608 additions and 303 deletions

View File

@ -393,7 +393,7 @@ public:
/**
* Clones the current attribute
*/
Attribute* clone() const
VectorAttribute* clone() const
{
return new VectorAttribute(*this);
};

View File

@ -113,10 +113,12 @@ public:
/**
* Enables the image
* @param iid Image id
* @param to_enable true will enable the image.
* @param error_str Error reason, if any
* @return 0 on success
*/
int enable_image(int iid, bool to_enable);
int enable_image(int iid, bool to_enable, string& error_str);
/**
* Adds a new image to the repository copying or creating it as needed
@ -155,9 +157,10 @@ public:
/**
* Deletes an image from the repository and the DB
* @param iid id of image
* @param error_str Error reason, if any
* @return 0 on success
*/
int delete_image(int iid, const string& ds_data);
int delete_image(int iid, const string& ds_data, string& error_str);
/**
* Gets the size of an image by calling the STAT action of the associated

View File

@ -42,6 +42,9 @@ protected:
void request_execute(xmlrpc_c::paramList const& _paramList,
RequestAttributes& att);
virtual int replace_template(PoolObjectSQL * object, const string & tmpl,
const RequestAttributes &att, string &error_str);
};
/* ------------------------------------------------------------------------- */
@ -78,6 +81,11 @@ public:
};
~VirtualMachineUpdateTemplate(){};
/* -------------------------------------------------------------------- */
int replace_template(PoolObjectSQL * object, const string & tmpl,
const RequestAttributes &att, string &error_str);
};
/* ------------------------------------------------------------------------- */

View File

@ -691,10 +691,12 @@ public:
/**
* This function replaces the *user template*.
* @param tmpl_str new contents
* @param keep_restricted If true, the restricted attributes of the
* current template will override the new template
* @param error string describing the error if any
* @return 0 on success
*/
int replace_template(const string& tmpl_str, string& error);
int replace_template(const string& tmpl_str, bool keep_restricted, string& error);
void get_user_template_attribute(
const char * name,
@ -862,15 +864,19 @@ public:
/**
* Sets the corresponding SAVE_AS state.
* @param disk_id Index of the disk to save
* @param hot is this a save_as hot operation
* @return 0 if the VM can be saved as
*/
int set_saveas_state();
int set_saveas_state(int disk_id, bool hot);
/**
* Clears the SAVE_AS state, moving the VM to the original state.
* @param disk_id Index of the disk to save
* @param hot is this a save_as hot operation
* @return 0 if the VM was in a SAVE_AS state
*/
int clear_saveas_state();
int clear_saveas_state(int disk_id, bool hot);
/**
* Set the SAVE_AS attribute for the "disk_id"th disk.
@ -878,7 +884,7 @@ public:
* @param source to save the disk (SAVE_AS_SOURCE)
* @param img_id ID of the image this disk will be saved to (SAVE_AS).
*/
int save_disk(const string& disk_id,
int save_disk(int disk_id,
const string& source,
int img_id);
@ -888,7 +894,7 @@ public:
* @param source to save the disk (SAVE_AS_SOURCE)
* @param img_id ID of the image this disk will be saved to (SAVE_AS).
*/
int save_disk_hot(const string& disk_id,
int save_disk_hot(int disk_id,
const string& source,
int img_id);
/**
@ -900,11 +906,6 @@ public:
*/
int get_saveas_disk_hot(int& disk_id, string& source, int& image_id);
/**
* Cleans the HOTPLUG_SAVEAS = YES attribute from the disks
*/
void clear_saveas_disk_hot();
// ------------------------------------------------------------------------
// Authorization related functions
// ------------------------------------------------------------------------
@ -1207,7 +1208,7 @@ private:
* User template to store custom metadata. This template can be updated
*
*/
Template * user_obj_template;
VirtualMachineTemplate * user_obj_template;
// *************************************************************************
// DataBase implementation (Private)
@ -1434,6 +1435,12 @@ protected:
NebulaLog::log("ONE",Log::ERROR, "VM Drop not implemented!");
return -1;
}
// *************************************************************************
// Helpers
// *************************************************************************
VectorAttribute* get_disk(int disk_id);
};
#endif /*VIRTUAL_MACHINE_H_*/

View File

@ -32,6 +32,12 @@ public:
VirtualMachineTemplate():
Template(false,'=',"TEMPLATE"){};
VirtualMachineTemplate(
bool _replace_mode,
const char _separator,
const char * _xml_root):
Template(_replace_mode, _separator, _xml_root){};
~VirtualMachineTemplate(){};
VirtualMachineTemplate(VirtualMachineTemplate& vmt):Template(vmt){};
@ -51,6 +57,16 @@ public:
Template::set_xml_root(_xml_root);
};
/**
* Deletes all restricted attributes
*/
void remove_restricted();
/**
* Deletes all the attributes, excepts the restricted ones
*/
void remove_all_except_restricted();
private:
friend class VirtualMachinePool;

View File

@ -1104,7 +1104,9 @@ ONEDB_MIGRATOR_FILES="src/onedb/2.0_to_2.9.80.rb \
src/onedb/3.6.0_to_3.7.80.rb \
src/onedb/3.7.80_to_3.8.0.rb \
src/onedb/3.8.0_to_3.8.1.rb \
src/onedb/3.8.1_to_3.9.80.rb \
src/onedb/3.8.1_to_3.8.2.rb \
src/onedb/3.8.2_to_3.8.3.rb \
src/onedb/3.8.3_to_3.9.80.rb \
src/onedb/fsck.rb \
src/onedb/onedb.rb \
src/onedb/onedb_backend.rb"

View File

@ -273,9 +273,9 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
puts str % [e, mask]
}
puts
if vm.has_elements?("/VM/TEMPLATE/DISK")
puts
CLIHelper.print_header(str_h1 % "VM DISKS",false)
CLIHelper::ShowTable.new(nil, self) do
column :ID, "", :size=>3 do |d|
@ -286,7 +286,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
d["DATASTORE"]
end
column :TARGET, "", :size=>6 do |d|
column :TARGET, "", :left, :size=>6 do |d|
d["TARGET"]
end
@ -335,12 +335,11 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
while vm.has_elements?("/VM/TEMPLATE/DISK")
vm.delete_element("/VM/TEMPLATE/DISK")
end if !options[:all]
puts
end
if vm.has_elements?("/VM/TEMPLATE/NIC")
CLIHelper.print_header(str_h1 % "VM NICS",false)
puts
CLIHelper.print_header(str_h1 % "VM NICS",false)
vm_nics = [vm.to_hash['VM']['TEMPLATE']['NIC']].flatten
@ -388,7 +387,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
}
CLIHelper::ShowTable.new(nil, self) do
column :ID, "", :size=>2 do |d|
column :ID, "", :size=>3 do |d|
if d["DOUBLE_ENTRY"]
""
else
@ -396,7 +395,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
end
end
column :NETWORK, "", :left, :size=>12 do |d|
column :NETWORK, "", :left, :size=>20 do |d|
if d["DOUBLE_ENTRY"]
""
else
@ -412,7 +411,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
end
end
column :BRIDGE, "", :left, :size=>8 do |d|
column :BRIDGE, "", :left, :size=>12 do |d|
if d["DOUBLE_ENTRY"]
""
else
@ -437,11 +436,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
while vm.has_elements?("/VM/TEMPLATE/NIC")
vm.delete_element("/VM/TEMPLATE/NIC")
end if !options[:all]
puts
end
if vm.has_elements?("/VM/TEMPLATE/SNAPSHOT")
puts
CLIHelper.print_header(str_h1 % "SNAPSHOTS",false)
CLIHelper::ShowTable.new(nil, self) do
@ -465,8 +463,6 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
end.show([vm.to_hash['VM']['TEMPLATE']['SNAPSHOT']].flatten, {})
vm.delete_element("/VM/TEMPLATE/SNAPSHOT")
puts
end
if vm.has_elements?("/VM/HISTORY_RECORDS")
@ -477,6 +473,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
end
if vm.has_elements?("/VM/USER_TEMPLATE/SCHED_ACTION")
puts
CLIHelper.print_header(str_h1 % "SCHEDULED ACTIONS",false)
CLIHelper::ShowTable.new(nil, self) do
@ -485,7 +482,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
d["ID"] if !d.nil?
end
column :"ACTION", "", :left, :size=>10 do |d|
column :"ACTION", "", :left, :size=>15 do |d|
d["ACTION"] if !d.nil?
end
@ -497,12 +494,10 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
OpenNebulaHelper.time_to_str(d["DONE"], false) if !d.nil?
end
column :"MESSAGE", "", :left, :donottruncate, :size=>40 do |d|
column :"MESSAGE", "", :left, :donottruncate, :size=>35 do |d|
d["MESSAGE"] if !d.nil?
end
end.show([vm.to_hash['VM']['USER_TEMPLATE']['SCHED_ACTION']].flatten, {})
puts
end
if vm.has_elements?("/VM/USER_TEMPLATE")
@ -516,6 +511,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
puts vm.template_like_str('USER_TEMPLATE')
end
puts
CLIHelper.print_header(str_h1 % "VIRTUAL MACHINE TEMPLATE",false)
puts vm.template_str
end
@ -526,7 +522,7 @@ class OneVMHelper < OpenNebulaHelper::OneHelper
d["SEQ"]
end
column :HOST, "Host name of the VM container", :left, :size=>15 do |d|
column :HOST, "Host name of the VM container", :left, :size=>20 do |d|
d["HOSTNAME"]
end

View File

@ -282,7 +282,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
"the image #{image_name}"
helper.perform_action(args[0],options,verbose) do |vm|
res = vm.save_as(disk_id, image_name, image_type, options[:hot])
res = vm.save_as(disk_id, image_name, image_type,
options[:hot]==true)
if !OpenNebula.is_error?(res)
puts "Image ID: #{res}"

View File

@ -87,6 +87,8 @@ int ImageManager::acquire_image(int vm_id, Image *img, string& error)
{
int rc = 0;
ostringstream oss;
switch(img->get_type())
{
case Image::OS:
@ -97,8 +99,6 @@ int ImageManager::acquire_image(int vm_id, Image *img, string& error)
case Image::KERNEL:
case Image::RAMDISK:
case Image::CONTEXT:
ostringstream oss;
oss << "Image " << img->get_oid() << " (" << img->get_name() << ") "
<< "of type " << Image::type_to_str(img->get_type())
<< " cannot be used as DISK.";
@ -125,7 +125,10 @@ int ImageManager::acquire_image(int vm_id, Image *img, string& error)
break;
case Image::USED_PERS:
error = "Cannot acquire persistent image, it is already in use";
oss << "Cannot acquire image " << img->get_oid()
<< ", it is persistent and already in use";
error = oss.str();
rc = -1;
break;
@ -140,9 +143,8 @@ int ImageManager::acquire_image(int vm_id, Image *img, string& error)
case Image::ERROR:
case Image::DELETE:
case Image::CLONE:
ostringstream oss;
oss << "Cannot acquire image in state: "
<< Image::state_to_str(img->get_state());
oss << "Cannot acquire image " << img->get_oid()
<<", it is in state: " << Image::state_to_str(img->get_state());
error = oss.str();
rc = -1;
@ -326,11 +328,13 @@ void ImageManager::release_cloning_image(int iid, int clone_img_id)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ImageManager::enable_image(int iid, bool to_enable)
int ImageManager::enable_image(int iid, bool to_enable, string& error_str)
{
int rc = 0;
Image * img;
ostringstream oss;
img = ipool->get(iid,true);
if ( img == 0 )
@ -349,6 +353,10 @@ int ImageManager::enable_image(int iid, bool to_enable)
case Image::READY:
break;
default:
oss << "Image cannot be in state "
<< Image::state_to_str(img->get_state()) << ".";
error_str = oss.str();
rc = -1;
break;
}
@ -364,6 +372,10 @@ int ImageManager::enable_image(int iid, bool to_enable)
case Image::DISABLED:
break;
default:
oss << "Image cannot be in state "
<< Image::state_to_str(img->get_state()) << ".";
error_str = oss.str();
rc = -1;
break;
}
@ -377,7 +389,7 @@ int ImageManager::enable_image(int iid, bool to_enable)
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int ImageManager::delete_image(int iid, const string& ds_data)
int ImageManager::delete_image(int iid, const string& ds_data, string& error_str)
{
Image * img;
@ -392,6 +404,8 @@ int ImageManager::delete_image(int iid, const string& ds_data)
int gid;
int cloning_id = -1;
ostringstream oss;
img = ipool->get(iid,true);
if ( img == 0 )
@ -404,14 +418,27 @@ int ImageManager::delete_image(int iid, const string& ds_data)
case Image::READY:
if ( img->get_running() != 0 )
{
oss << "There are " << img->get_running() << " VMs using it.";
error_str = oss.str();
img->unlock();
return -1; //Cannot remove images in use
}
break;
case Image::CLONE:
oss << "There are " << img->get_cloning() << " active clone operations.";
error_str = oss.str();
img->unlock();
return -1; //Cannot remove images in use
break;
case Image::USED:
case Image::USED_PERS:
case Image::CLONE:
oss << "There are " << img->get_running() << " VMs using it.";
error_str = oss.str();
img->unlock();
return -1; //Cannot remove images in use
break;
@ -434,6 +461,8 @@ int ImageManager::delete_image(int iid, const string& ds_data)
if ( imd == 0 )
{
error_str = "Error getting ImageManagerDriver";
img->unlock();
return -1;
}

View File

@ -324,8 +324,8 @@ static void mkfs_action(istringstream& is,
string info;
int rc;
int vm_id = -1;
string disk_id;
int vm_id = -1;
int disk_id;
VirtualMachine * vm;
ostringstream oss;
@ -427,7 +427,7 @@ static void mkfs_action(istringstream& is,
goto error_save_state;
}
vm->clear_saveas_state();
vm->clear_saveas_state(disk_id, is_hot);
}
vmpool->update(vm);
@ -478,7 +478,7 @@ error:
{
if ((vm = vmpool->get(vm_id, true)) != 0)
{
vm->clear_saveas_state();
vm->clear_saveas_state(disk_id, is_hot);
vmpool->update(vm);
vm->unlock();

View File

@ -981,7 +981,6 @@ void LifeCycleManager::monitor_suspend_action(int vid)
{
VirtualMachine * vm;
int cpu,mem,disk;
time_t the_time = time(0);
Nebula& nd = Nebula::instance();
@ -1019,10 +1018,6 @@ void LifeCycleManager::monitor_suspend_action(int vid)
vmpool->update_history(vm);
vm->get_requirements(cpu,mem,disk);
hpool->del_capacity(vm->get_hid(), vm->get_oid(), cpu, mem, disk);
vm->log("LCM", Log::INFO, "VM is suspended.");
//----------------------------------------------------
@ -1498,7 +1493,9 @@ void LifeCycleManager::saveas_hot_success_action(int vid)
return;
}
if (vm->clear_saveas_state() == -1)
int rc = vm->get_saveas_disk_hot(disk_id, source, image_id);
if (vm->clear_saveas_state(disk_id, true) == -1)
{
vm->log("LCM", Log::ERROR, "saveas_hot_success_action, VM in a wrong state");
vm->unlock();
@ -1506,10 +1503,6 @@ void LifeCycleManager::saveas_hot_success_action(int vid)
return;
}
int rc = vm->get_saveas_disk_hot(disk_id, source, image_id);
vm->clear_saveas_disk_hot();
vmpool->update(vm);
vm->unlock();
@ -1555,7 +1548,9 @@ void LifeCycleManager::saveas_hot_failure_action(int vid)
return;
}
if (vm->clear_saveas_state() == -1)
int rc = vm->get_saveas_disk_hot(disk_id, source, image_id);
if (vm->clear_saveas_state(disk_id, true) == -1)
{
vm->log("LCM", Log::ERROR, "saveas_hot_success_action, VM in a wrong state");
vm->unlock();
@ -1563,10 +1558,6 @@ void LifeCycleManager::saveas_hot_failure_action(int vid)
return;
}
int rc = vm->get_saveas_disk_hot(disk_id, source, image_id);
vm->clear_saveas_disk_hot();
vmpool->update(vm);
vm->unlock();

View File

@ -0,0 +1,29 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# 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. #
#--------------------------------------------------------------------------- #
module Migrator
def db_version
"3.8.2"
end
def one_version
"OpenNebula 3.8.2"
end
def up
return true
end
end

View File

@ -0,0 +1,29 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2013, OpenNebula Project (OpenNebula.org), C12G Labs #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); you may #
# not use this file except in compliance with the License. You may obtain #
# a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# 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. #
#--------------------------------------------------------------------------- #
module Migrator
def db_version
"3.8.3"
end
def one_version
"OpenNebula 3.8.3"
end
def up
return true
end
end

View File

@ -174,7 +174,7 @@ int ImageDelete::drop(int oid, PoolObjectSQL * object, string& error_msg)
ds->unlock();
rc = imagem->delete_image(oid, ds_data);
rc = imagem->delete_image(oid, ds_data, error_msg);
if ( rc == 0 )
{

View File

@ -38,17 +38,17 @@ void ImageEnable::request_execute(xmlrpc_c::paramList const& paramList,
return;
}
rc = imagem->enable_image(id,enable_flag);
rc = imagem->enable_image(id,enable_flag, err_msg);
if( rc < 0 )
{
if (enable_flag == true)
{
err_msg = "Could not enable image.";
err_msg = "Could not enable image: " + err_msg;
}
else
{
err_msg = "Could not disable image.";
err_msg = "Could not disable image: " + err_msg;
}
failure_response(INTERNAL, request_error(err_msg,""), att);

View File

@ -21,6 +21,40 @@ using namespace std;
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
int RequestManagerUpdateTemplate::replace_template(
PoolObjectSQL * object,
const string & tmpl,
const RequestAttributes &att,
string &error_str)
{
return object->replace_template(tmpl, error_str);
}
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
int VirtualMachineUpdateTemplate::replace_template(
PoolObjectSQL * object,
const string & tmpl,
const RequestAttributes & att,
string & error_str)
{
VirtualMachine* vm = static_cast<VirtualMachine*>(object);
if (att.uid!=UserPool::ONEADMIN_ID && att.gid!=GroupPool::ONEADMIN_ID)
{
return vm->replace_template(tmpl, true, error_str);
}
else
{
return vm->replace_template(tmpl, false, error_str);
}
}
/* ------------------------------------------------------------------------- */
/* ------------------------------------------------------------------------- */
void RequestManagerUpdateTemplate::request_execute(
xmlrpc_c::paramList const& paramList,
RequestAttributes& att)
@ -49,7 +83,9 @@ void RequestManagerUpdateTemplate::request_execute(
return;
}
rc = object->replace_template(tmpl, error_str);
rc = replace_template(object, tmpl, att, error_str);
// rc = object->replace_template(tmpl, error_str);
if ( rc != 0 )
{

View File

@ -734,28 +734,33 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
return;
}
int rc = vm->set_saveas_state();
if ( vm->set_saveas_state(disk_id, is_hot) != 0 )
{
vm->unlock();
failure_response(INTERNAL,
request_error("VM has to be RUNNING, POWEROFF or"
" SUSPENDED to saveas disks.",""), att);
return;
}
int iid_orig = vm->get_image_from_disk(disk_id, is_hot, error_str);
vmpool->update(vm);
vm->unlock();
if ( iid_orig == -1 )
{
vm->clear_saveas_state(disk_id, is_hot);
vm->unlock();
failure_response(INTERNAL,
request_error("Cannot use selected DISK", error_str),
att);
return;
}
if ( rc != 0 )
{
failure_response(INTERNAL,
request_error("VM has to be RUNNING, POWEROFF or"
" SUSPENDED to saveas disks.",""), att);
return;
}
vmpool->update(vm);
vm->unlock();
// -------------------------------------------------------------------------
// Get the data of the Image to be saved
@ -770,7 +775,8 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
if ((vm = vmpool->get(id, true)) != 0)
{
vm->clear_saveas_state();
vm->clear_saveas_state(disk_id, is_hot);
vmpool->update(vm);
vm->unlock();
}
@ -801,7 +807,8 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
if ((vm = vmpool->get(id, true)) != 0)
{
vm->clear_saveas_state();
vm->clear_saveas_state(disk_id, is_hot);
vmpool->update(vm);
vm->unlock();
}
@ -898,7 +905,8 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
if ((vm = vmpool->get(id, true)) != 0)
{
vm->clear_saveas_state();
vm->clear_saveas_state(disk_id, is_hot);
vmpool->update(vm);
vm->unlock();
}
@ -909,27 +917,28 @@ void VirtualMachineSaveDisk::request_execute(xmlrpc_c::paramList const& paramLis
// -------------------------------------------------------------------------
// Create the image
// -------------------------------------------------------------------------
rc = ipool->allocate(att.uid,
att.gid,
att.uname,
att.gname,
umask,
itemplate,
ds_id,
ds_name,
ds_disk_type,
ds_data,
Datastore::IMAGE_DS,
-1,
&iid,
error_str);
int rc = ipool->allocate(att.uid,
att.gid,
att.uname,
att.gname,
umask,
itemplate,
ds_id,
ds_name,
ds_disk_type,
ds_data,
Datastore::IMAGE_DS,
-1,
&iid,
error_str);
if (rc < 0)
{
quota_rollback(&img_usage, Quotas::DATASTORE, att);
if ((vm = vmpool->get(id, true)) != 0)
{
vm->clear_saveas_state();
vm->clear_saveas_state(disk_id, is_hot);
vmpool->update(vm);
vm->unlock();
}

View File

@ -18,6 +18,7 @@
# This class provides support for launching and stopping a websockify proxy
#
require 'rubygems'
require 'json'
require 'opennebula'
@ -81,13 +82,15 @@ class OpenNebulaVNC
begin
@logger.info { "Starting VNC proxy: #{cmd}" }
pid=start_daemon(cmd, 'VNC_LOG')
pid=start_daemon(cmd, VNC_LOG)
rescue Exception => e
@logger.error e.message
return false
end
File.write(@lock_file, pid)
File.open(@lock_file, "w") do |f|
f.write(pid.to_s)
end
sleep 1
@ -242,12 +245,33 @@ class OpenNebulaVNC
end
alias_method :get_pid, :is_running?
if RUBY_VERSION<'1.9'
def spawn(*args)
fork {
command=args[0..-2]
# Close stdin and point out and err to log file
$stdin.close
$stdout.reopen(VNC_LOG, "a")
$stderr.reopen(VNC_LOG, "a")
# Detach process from the parent
Process.setsid
exec(*command)
}
end
end
def start_daemon(cmd, log)
pid=spawn(*cmd.split(" "),
options={
:pgroup => true,
:in => :close,
[:out, :err] => [log, "a"],
:close_others => true )
:close_others => true }
params=cmd.split(" ")+[options]
pid=spawn( *params )
Process.detach(pid)

View File

@ -509,29 +509,48 @@ void TransferManager::prolog_action(int vid)
if ( num > 0 )
{
string kernel;
string initrd;
bool update = false;
const VectorAttribute * os_attr;
os_attr = dynamic_cast<const VectorAttribute *>(attrs[0]);
string kernel = prolog_os_transfer_commands(vm,
os_attr,
"KERNEL",
opennebula_hostname,
xfr);
if (os_attr != 0 )
{
kernel = prolog_os_transfer_commands(
vm,
os_attr,
"KERNEL",
opennebula_hostname,
xfr);
initrd = prolog_os_transfer_commands(
vm,
os_attr,
"initrd",
opennebula_hostname,
xfr);
}
if ( !kernel.empty() )
{
vm->set_kernel(kernel);
vmpool->update(vm);
update = true;
}
string initrd = prolog_os_transfer_commands(vm,
os_attr,
"initrd",
opennebula_hostname,
xfr);
if ( !initrd.empty() )
{
vm->set_initrd(initrd);
update = true;
}
if ( update )
{
vmpool->update(vm);
}
}

View File

@ -70,7 +70,7 @@ VirtualMachine::VirtualMachine(int id,
}
else
{
user_obj_template = new Template(false,'=',"USER_TEMPLATE");
user_obj_template = new VirtualMachineTemplate(false,'=',"USER_TEMPLATE");
}
obj_template = new VirtualMachineTemplate;
@ -1686,7 +1686,15 @@ VectorAttribute * VirtualMachine::set_up_attach_disk(
return 0;
}
new_disk = new VectorAttribute(*(dynamic_cast<VectorAttribute * >(disks[0])));
new_disk = dynamic_cast<VectorAttribute * >(disks[0]);
if ( new_disk == 0 )
{
error_str = "Internal error parsing DISK attribute";
return 0;
}
new_disk = new_disk->clone();
// -------------------------------------------------------------------------
// Acquire the new disk image
@ -1740,30 +1748,14 @@ VectorAttribute * VirtualMachine::set_up_attach_disk(
int VirtualMachine::set_attach_disk(int disk_id)
{
int num_disks;
int d_id;
VectorAttribute * disk;
vector<Attribute *> disks;
VectorAttribute * disk;
disk = get_disk(disk_id);
num_disks = obj_template->get("DISK", disks);
for(int i=0; i<num_disks; i++)
if ( disk != 0 )
{
disk = dynamic_cast<VectorAttribute * >(disks[i]);
if ( disk == 0 )
{
continue;
}
disk->vector_value("DISK_ID", d_id);
if ( d_id == disk_id )
{
disk->replace("ATTACH", "YES");
return 0;
}
disk->replace("ATTACH", "YES");
return 0;
}
return -1;
@ -1916,7 +1908,15 @@ VectorAttribute * VirtualMachine::set_up_attach_nic(
return 0;
}
new_nic = new VectorAttribute(*(dynamic_cast<VectorAttribute * >(nics[0])));
new_nic = dynamic_cast<VectorAttribute * >(nics[0]);
if ( new_nic == 0 )
{
error_str = "Internal error parsing NIC attribute";
return 0;
}
new_nic = new_nic->clone();
// -------------------------------------------------------------------------
// Acquire the new network lease
@ -2433,67 +2433,38 @@ int VirtualMachine::generate_context(string &files, int &disk_id)
int VirtualMachine::get_image_from_disk(int disk_id, bool hot, string& err_str)
{
int num_disks;
int tid;
int iid = -1;
int rc;
vector<Attribute * > disks;
VectorAttribute * disk;
ostringstream oss;
num_disks = obj_template->get("DISK",disks);
disk = get_disk(disk_id);
if ( state == DONE || state == FAILED )
if ( disk == 0 )
{
goto error_state;
goto error_not_found;
}
for(int i=0; i<num_disks; i++)
if(!((disk->vector_value("SAVE_AS")).empty()))
{
disk = dynamic_cast<VectorAttribute * >(disks[i]);
if ( disk == 0 )
{
continue;
}
rc = disk->vector_value("DISK_ID", tid);
if ( rc != 0 )
{
continue;
}
if ( disk_id == tid )
{
if(!((disk->vector_value("SAVE_AS")).empty()))
{
goto error_saved;
}
if(!(disk->vector_value("PERSISTENT").empty()) && !hot)
{
goto error_persistent;
}
rc = disk->vector_value("IMAGE_ID", iid);
if ( rc != 0 )
{
goto error_image_id;
}
return iid;
}
goto error_saved;
}
goto error_not_found;
if(!(disk->vector_value("PERSISTENT").empty()) && !hot)
{
goto error_persistent;
}
error_state:
oss << "VM cannot be in DONE or FAILED state.";
goto error_common;
rc = disk->vector_value("IMAGE_ID", iid);
if ( rc != 0 )
{
goto error_image_id;
}
return iid;
error_persistent:
oss << "Source image for DISK " << disk_id << " is persistent.";
@ -2519,8 +2490,10 @@ error_common:
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachine::set_saveas_state()
int VirtualMachine::set_saveas_state(int disk_id, bool hot)
{
VectorAttribute* disk;
switch (state)
{
case ACTIVE:
@ -2528,7 +2501,8 @@ int VirtualMachine::set_saveas_state()
{
case RUNNING:
lcm_state = HOTPLUG_SAVEAS;
return 0;
break;
default:
return -1;
}
@ -2537,84 +2511,28 @@ int VirtualMachine::set_saveas_state()
case POWEROFF:
state = ACTIVE;
lcm_state = HOTPLUG_SAVEAS_POWEROFF;
return 0;
break;
case SUSPENDED:
state = ACTIVE;
lcm_state = HOTPLUG_SAVEAS_SUSPENDED;
return 0;
break;
default:
return -1;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
disk = get_disk(disk_id);
int VirtualMachine::clear_saveas_state()
{
switch (lcm_state)
if ( disk != 0 )
{
case HOTPLUG_SAVEAS:
lcm_state = RUNNING;
return 0;
case HOTPLUG_SAVEAS_POWEROFF:
state = POWEROFF;
lcm_state = LCM_INIT;
return 0;
case HOTPLUG_SAVEAS_SUSPENDED:
state = SUSPENDED;
lcm_state = LCM_INIT;
return 0;
default:
return -1;
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachine::save_disk(const string& disk_id,
const string& source,
int img_id)
{
vector<Attribute * > disks;
VectorAttribute * disk;
string tdisk_id;
int num_disks = obj_template->get("DISK",disks);
if (lcm_state != HOTPLUG_SAVEAS && lcm_state != HOTPLUG_SAVEAS_SUSPENDED
&& lcm_state != HOTPLUG_SAVEAS_POWEROFF )
{
return -1;
}
for(int i=0; i<num_disks; i++)
{
disk = dynamic_cast<VectorAttribute * >(disks[i]);
if ( disk == 0 )
if (hot)
{
continue;
disk->replace("HOTPLUG_SAVE_AS_ACTIVE", "YES");
}
tdisk_id = disk->vector_value("DISK_ID");
if ( tdisk_id == disk_id )
else
{
disk->replace("SAVE_AS_SOURCE", source);
disk->replace("SAVE_AS", img_id);
disk->replace("SAVE", "YES");
break;
disk->replace("SAVE_AS_ACTIVE", "YES");
}
}
@ -2624,24 +2542,62 @@ int VirtualMachine::save_disk(const string& disk_id,
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachine::save_disk_hot(const string& disk_id,
const string& source,
int img_id)
int VirtualMachine::clear_saveas_state(int disk_id, bool hot)
{
VectorAttribute * disk;
disk = get_disk(disk_id);
if (disk != 0)
{
if (hot)
{
disk->remove("HOTPLUG_SAVE_AS_ACTIVE");
disk->remove("HOTPLUG_SAVE_AS");
disk->remove("HOTPLUG_SAVE_AS_SOURCE");
}
else
{
disk->remove("SAVE_AS_ACTIVE");
}
}
switch (lcm_state)
{
case HOTPLUG_SAVEAS:
lcm_state = RUNNING;
break;
case HOTPLUG_SAVEAS_POWEROFF:
state = POWEROFF;
lcm_state = LCM_INIT;
break;
case HOTPLUG_SAVEAS_SUSPENDED:
state = SUSPENDED;
lcm_state = LCM_INIT;
break;
default:
return -1;
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
VectorAttribute* VirtualMachine::get_disk(int disk_id)
{
int num_disks;
string tdisk_id;
int tdisk_id;
vector<Attribute *> disks;
VectorAttribute * disk;
num_disks = obj_template->get("DISK", disks);
if (lcm_state != HOTPLUG_SAVEAS && lcm_state != HOTPLUG_SAVEAS_SUSPENDED
&& lcm_state != HOTPLUG_SAVEAS_POWEROFF )
{
return -1;
}
for(int i=0; i<num_disks; i++)
{
disk = dynamic_cast<VectorAttribute * >(disks[i]);
@ -2651,20 +2607,71 @@ int VirtualMachine::save_disk_hot(const string& disk_id,
continue;
}
tdisk_id = disk->vector_value("DISK_ID");
disk->vector_value("DISK_ID", tdisk_id);
if ( tdisk_id == disk_id )
{
disk->replace("HOTPLUG_SAVEAS", "YES");
disk->replace("HOTPLUG_SAVEAS_IMAGE_ID", img_id);
disk->replace("HOTPLUG_SAVEAS_SOURCE", source);
break;
return disk;
}
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachine::save_disk(int disk_id,
const string& source,
int img_id)
{
VectorAttribute * disk;
if (lcm_state != HOTPLUG_SAVEAS && lcm_state != HOTPLUG_SAVEAS_SUSPENDED
&& lcm_state != HOTPLUG_SAVEAS_POWEROFF )
{
return -1;
}
disk = get_disk(disk_id);
if ( disk != 0 )
{
disk->replace("SAVE_AS_SOURCE", source);
disk->replace("SAVE_AS", img_id);
disk->replace("SAVE", "YES");
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachine::save_disk_hot(int disk_id,
const string& source,
int img_id)
{
VectorAttribute * disk;
if (lcm_state != HOTPLUG_SAVEAS && lcm_state != HOTPLUG_SAVEAS_SUSPENDED
&& lcm_state != HOTPLUG_SAVEAS_POWEROFF )
{
return -1;
}
disk = get_disk(disk_id);
if ( disk != 0 )
{
disk->replace("HOTPLUG_SAVE_AS", img_id);
disk->replace("HOTPLUG_SAVE_AS_SOURCE", source);
}
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -2688,11 +2695,11 @@ int VirtualMachine::get_saveas_disk_hot(int& disk_id, string& source, int& image
continue;
}
if ( disk->vector_value("HOTPLUG_SAVEAS") == "YES" )
if ( disk->vector_value("HOTPLUG_SAVE_AS_ACTIVE") == "YES" )
{
source = disk->vector_value("HOTPLUG_SAVEAS_SOURCE");
source = disk->vector_value("HOTPLUG_SAVE_AS_SOURCE");
rc = disk->vector_value("HOTPLUG_SAVEAS_IMAGE_ID", image_id);
rc = disk->vector_value("HOTPLUG_SAVE_AS", image_id);
rc += disk->vector_value("DISK_ID", disk_id);
if ( rc != 0 || source.empty() )
@ -2707,37 +2714,6 @@ int VirtualMachine::get_saveas_disk_hot(int& disk_id, string& source, int& image
return -1;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachine::clear_saveas_disk_hot()
{
int num_disks;
vector<Attribute *> disks;
VectorAttribute * disk;
num_disks = obj_template->get("DISK", disks);
for(int i=0; i<num_disks; i++)
{
disk = dynamic_cast<VectorAttribute * >(disks[i]);
if ( disk == 0 )
{
continue;
}
if ( disk->vector_value("HOTPLUG_SAVEAS") == "YES" )
{
disk->remove("HOTPLUG_SAVEAS");
disk->remove("HOTPLUG_SAVEAS_IMAGE_ID");
disk->remove("HOTPLUG_SAVEAS_SOURCE");
return;
}
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -3143,9 +3119,13 @@ void VirtualMachine::update_info(
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
int VirtualMachine::replace_template(const string& tmpl_str, string& error)
int VirtualMachine::replace_template(
const string& tmpl_str,
bool keep_restricted,
string& error)
{
Template * new_tmpl = new Template(false,'=',"USER_TEMPLATE");
VirtualMachineTemplate * new_tmpl =
new VirtualMachineTemplate(false,'=',"USER_TEMPLATE");
if ( new_tmpl == 0 )
{
@ -3159,11 +3139,21 @@ int VirtualMachine::replace_template(const string& tmpl_str, string& error)
return -1;
}
if (user_obj_template != 0)
if (keep_restricted)
{
delete user_obj_template;
new_tmpl->remove_restricted();
if (user_obj_template != 0)
{
user_obj_template->remove_all_except_restricted();
string aux_error;
new_tmpl->merge(user_obj_template, aux_error);
}
}
delete user_obj_template;
user_obj_template = new_tmpl;
return 0;

View File

@ -23,3 +23,116 @@ vector<string> VirtualMachineTemplate::restricted_attributes;
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineTemplate::remove_restricted()
{
size_t pos;
string avector, vattr;
vector<Attribute *> values;
for (unsigned int i=0; i < restricted_attributes.size(); i++)
{
pos = restricted_attributes[i].find("/");
if (pos != string::npos) //Vector Attribute
{
int num;
avector = restricted_attributes[i].substr(0,pos);
vattr = restricted_attributes[i].substr(pos+1);
if ((num = get(avector,values)) > 0 ) //Template contains the attr
{
VectorAttribute * attr;
for (int j=0; j<num ; j++ )
{
attr = dynamic_cast<VectorAttribute *>(values[j]);
if (attr == 0)
{
continue;
}
attr->remove(vattr);
}
}
}
else //Single Attribute
{
erase(restricted_attributes[i]);
}
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
void VirtualMachineTemplate::remove_all_except_restricted()
{
size_t pos;
string avector, vattr;
vector<Attribute *> values;
vector<Attribute *> restricted;
for (unsigned int i=0; i < restricted_attributes.size(); i++)
{
pos = restricted_attributes[i].find("/");
if (pos != string::npos) //Vector Attribute
{
int num;
avector = restricted_attributes[i].substr(0,pos);
vattr = restricted_attributes[i].substr(pos+1);
if ((num = get(avector,values)) > 0 ) //Template contains the attr
{
VectorAttribute * attr;
for (int j=0; j<num ; j++ )
{
attr = dynamic_cast<VectorAttribute *>(values[j]);
if (attr == 0)
{
continue;
}
if ( !attr->vector_value(vattr.c_str()).empty() )
{
restricted.push_back(attr);
}
}
}
}
else //Single Attribute
{
this->get(restricted_attributes[i], restricted);
}
}
vector<Attribute *>::iterator res_it;
for (res_it = restricted.begin(); res_it != restricted.end(); res_it++)
{
remove(*res_it);
}
multimap<string,Attribute *>::iterator att_it;
for ( att_it = attributes.begin(); att_it != attributes.end(); att_it++)
{
delete att_it->second;
}
attributes.clear();
for (res_it = restricted.begin(); res_it != restricted.end(); res_it++)
{
set(*res_it);
}
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -403,7 +403,7 @@ void VirtualMachineManagerDriver::protocol(
if ( result == "SUCCESS" )
{
vm->log("VMM", Log::ERROR, "VM NIC Successfully attached.");
vm->log("VMM", Log::INFO, "VM NIC Successfully attached.");
lcm->trigger(LifeCycleManager::ATTACH_NIC_SUCCESS, id);
}
@ -422,7 +422,7 @@ void VirtualMachineManagerDriver::protocol(
if ( result == "SUCCESS" )
{
vm->log("VMM",Log::ERROR,"VM NIC Successfully detached.");
vm->log("VMM",Log::INFO, "VM NIC Successfully detached.");
lcm->trigger(LifeCycleManager::DETACH_NIC_SUCCESS, id);
}

View File

@ -273,7 +273,10 @@ int VirtualNetworkPool::nic_attribute(VectorAttribute * nic,
}
else
{
error = "Cannot get IP/MAC lease from virtual network.";
ostringstream oss;
oss << "Cannot get IP/MAC lease from virtual network " << vnet->get_oid() << ".";
error = oss.str();
}
vnet->unlock();