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

Feature #1112: WIP, Use XML data in image manager driver messages

This commit is contained in:
Carlos Martín 2012-02-17 17:28:31 +01:00
parent 2b50e27a66
commit b0063c0f80
5 changed files with 90 additions and 15 deletions

View File

@ -220,6 +220,17 @@ private:
* @param source path of the disk file
*/
void move_image(Image *img, const string& source);
/**
* Formats an XML message for the MAD
*
* @param img_data Image XML representation
* @param ds_data Datastore XML representation
* @return the XML message
*/
string * format_message(
const string& img_data,
const string& ds_data);
};
#endif /*IMAGE_MANAGER_H*/

View File

@ -70,7 +70,12 @@ private:
*/
//Template driver_conf;
void cp(int oid, const string& source) const;
/**
* Sends a copy request to the MAD
* @param oid the image id.
* @param drv_msg xml data for the mad operation.
*/
void cp(int oid, const string& drv_msg) const;
/**
* Sends a move request to the MAD: "MV IMAGE_ID SRC_PATH DST_PATH"
@ -93,9 +98,9 @@ private:
/**
* Sends a delete request to the MAD: "DELETE IMAGE_ID PATH"
* @param oid the image id.
* @param destination is the path to the image to be removed
* @param drv_msg xml data for the mad operation.
*/
void rm(int oid, const string& destination) const;
void rm(int oid, const string& drv_msg) const;
};
/* -------------------------------------------------------------------------- */

View File

@ -17,6 +17,7 @@
#include "ImageManager.h"
#include "NebulaLog.h"
#include "ImagePool.h"
#include "SSLTools.h"
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
@ -311,8 +312,10 @@ int ImageManager::enable_image(int iid, bool to_enable)
int ImageManager::delete_image(int iid, const string& ds_data)
{
Image * img;
string source;
Image * img;
string source;
string img_tmpl;
string * drv_msg;
img = ipool->get(iid,true);
@ -350,6 +353,8 @@ int ImageManager::delete_image(int iid, const string& ds_data)
return -1;
}
drv_msg = format_message(img->to_xml(img_tmpl), ds_data);
source = img->get_source();
if (source.empty())
@ -367,11 +372,13 @@ int ImageManager::delete_image(int iid, const string& ds_data)
}
else
{
imd->rm(img->get_oid(),img->get_source());
imd->rm(img->get_oid(), *drv_msg);
}
img->unlock();
delete drv_msg;
return 0;
}
@ -384,8 +391,11 @@ int ImageManager::register_image(int iid, const string& ds_data)
ostringstream oss;
Image * img;
string path;
string path;
string img_tmpl;
string * drv_msg;
if ( imd == 0 )
{
@ -400,6 +410,8 @@ int ImageManager::register_image(int iid, const string& ds_data)
return -1;
}
drv_msg = format_message(img->to_xml(img_tmpl), ds_data);
path = img->get_path();
if ( path.empty() == true ) //NO PATH -> USE SOURCE OR MKFS FOR DATABLOCK
@ -430,7 +442,7 @@ int ImageManager::register_image(int iid, const string& ds_data)
}
else //PATH -> COPY TO REPOSITORY AS SOURCE
{
imd->cp(img->get_oid(), path);
imd->cp(img->get_oid(), *drv_msg);
oss << "Copying " << path <<" to repository for image "<<img->get_oid();
}
@ -438,9 +450,28 @@ int ImageManager::register_image(int iid, const string& ds_data)
img->unlock();
delete drv_msg;
return 0;
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */
string * ImageManager::format_message(
const string& img_data,
const string& ds_data)
{
ostringstream oss;
oss << "<DS_DRIVER_ACTION_DATA>"
<< img_data
<< ds_data
<< "</DS_DRIVER_ACTION_DATA>";
return SSLTools::base64_encode(oss.str());
}
/* -------------------------------------------------------------------------- */
/* -------------------------------------------------------------------------- */

View File

@ -27,11 +27,11 @@
/* ************************************************************************** */
void ImageManagerDriver::cp(int oid,
const string& source) const
const string& drv_msg) const
{
ostringstream os;
os << "CP " << oid << " " << source << endl;
os << "CP " << oid << " " << drv_msg << endl;
write(os);
}
@ -63,11 +63,11 @@ void ImageManagerDriver::mkfs(int oid,
/* -------------------------------------------------------------------------- */
void ImageManagerDriver::rm(int oid, const string& destination) const
void ImageManagerDriver::rm(int oid, const string& drv_msg) const
{
ostringstream os;
os << "RM " << oid << " " << destination << endl;
os << "RM " << oid << " " << drv_msg << endl;
write(os);
}

View File

@ -33,6 +33,8 @@ $: << RUBY_LIB_LOCATION
require "OpenNebulaDriver"
require 'getoptlong'
require 'base64'
require 'rexml/document'
# This class provides basic messaging and logging functionality
# to implement Image Repository Drivers. A image repository driver
@ -86,11 +88,23 @@ class ImageDriver < OpenNebulaDriver
do_image_action(id, ds, :mv, "'#{src}' '#{dst}' '#{id}'")
end
def cp(id, ds, src)
def cp(id, drv_message)
data = decode(drv_message)
# TODO
# ds = data.elements['DATASTORE/DRIVER'].text
ds = "fs"
src = data.elements['IMAGE/PATH'].text
do_image_action(id, ds, :cp, "'#{src}' '#{id}'")
end
def rm(id, ds, dst)
def rm(id, drv_message)
data = decode(drv_message)
# TODO
# ds = data.elements['DATASTORE/DRIVER'].text
ds = "fs"
dst = data.elements['IMAGE/SOURCE'].text
do_image_action(id, ds, :rm, "'#{dst}' '#{id}'")
end
@ -124,6 +138,20 @@ class ImageDriver < OpenNebulaDriver
send_message(ACTION[action], result, id, info)
end
# TODO: Move decode to OpenNebulaDriver ?
# Decodes the encoded XML driver message received from the core
#
# @param [String] drv_message the driver message
# @return [REXML::Element] the root element of the decoded XML message
def decode(drv_message)
message = Base64.decode64(drv_message)
xml_doc = REXML::Document.new(message)
xml_doc.root
end
end