diff --git a/include/ImagePool.h b/include/ImagePool.h index 29273b9d50..37873768e5 100644 --- a/include/ImagePool.h +++ b/include/ImagePool.h @@ -124,6 +124,12 @@ public: { Image::bootstrap(_db); }; + + /** + * Get the template table name + * @return string with the name of the template table + */ + string get_template_table_name(); /** * Dumps the Image pool in XML format. A filter can be also added to the diff --git a/include/ImageTemplate.h b/include/ImageTemplate.h index d1fd8847fd..8a999aa9f4 100644 --- a/include/ImageTemplate.h +++ b/include/ImageTemplate.h @@ -35,6 +35,7 @@ public: private: friend class Image; + friend class ImagePool; static const char * table; diff --git a/include/RequestManager.h b/include/RequestManager.h index 101b9247e2..549b1cf6c2 100644 --- a/include/RequestManager.h +++ b/include/RequestManager.h @@ -646,7 +646,7 @@ private: UserPoolInfo(UserPool * _upool):upool(_upool) { _signature="A:s"; - _help="Creates a new user"; + _help="Returns content of the user pool"; }; ~UserPoolInfo(){}; @@ -667,10 +667,13 @@ private: class ImageAllocate: public xmlrpc_c::method { public: - ImageAllocate(UserPool * _upool):upool(_upool) + ImageAllocate(ImagePool * _ipool, + UserPool * _upool): + ipool(_ipool), + upool(_upool) { - _signature="A:sss"; - _help="Creates a new user"; + _signature="A:ss"; + _help="Creates a new image"; }; ~ImageAllocate(){}; @@ -680,7 +683,8 @@ private: xmlrpc_c::value * const retvalP); private: - UserPool * upool; + ImagePool * ipool; + UserPool * upool; }; /* ---------------------------------------------------------------------- */ @@ -718,8 +722,8 @@ private: ipool(_ipool), upool(_upool) { - _signature="A:ss"; - _help="Allocates an image in the pool"; + _signature="A:si"; + _help="Returns content of image pool attending to the filter flag"; }; ~ImagePoolInfo(){}; diff --git a/src/image/ImagePool.cc b/src/image/ImagePool.cc index ddaf5c50f6..ff9c4433b9 100644 --- a/src/image/ImagePool.cc +++ b/src/image/ImagePool.cc @@ -288,3 +288,13 @@ string ImagePool::sha1_digest(const string& pass) return oss.str(); } + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +string ImagePool::get_template_table_name() +{ + string table(ImageTemplate::table); + + return table; +} diff --git a/src/rm/RequestManager.cc b/src/rm/RequestManager.cc index db61e32989..fc294acbeb 100644 --- a/src/rm/RequestManager.cc +++ b/src/rm/RequestManager.cc @@ -270,8 +270,14 @@ void RequestManager::register_xml_methods() xmlrpc_c::methodPtr userpool_info(new RequestManager::UserPoolInfo(upool)); + xmlrpc_c::methodPtr image_allocate(new + RequestManager::ImageAllocate(ipool, upool)); + xmlrpc_c::methodPtr image_info(new RequestManager::ImageInfo(ipool, upool)); + + xmlrpc_c::methodPtr imagepool_info(new + RequestManager::ImagePoolInfo(ipool, upool)); /* VM related methods */ @@ -310,8 +316,11 @@ void RequestManager::register_xml_methods() RequestManagerRegistry.addMethod("one.userpool.info", userpool_info); /* Image related methods*/ + + RequestManagerRegistry.addMethod("one.image.allocate", image_allocate); + RequestManagerRegistry.addMethod("one.image.info", image_info); - RequestManagerRegistry.addMethod("one.image.info", image_info); + RequestManagerRegistry.addMethod("one.imagepool.info", imagepool_info); }; diff --git a/src/rm/RequestManagerImageAllocate.cc b/src/rm/RequestManagerImageAllocate.cc new file mode 100644 index 0000000000..ce266d3a6d --- /dev/null +++ b/src/rm/RequestManagerImageAllocate.cc @@ -0,0 +1,107 @@ +/* -------------------------------------------------------------------------- */ +/* Copyright 2002-2010, OpenNebula Project Leads (OpenNebula.org) */ +/* */ +/* 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. */ +/* -------------------------------------------------------------------------- */ + +#include "RequestManager.h" +#include "NebulaLog.h" + +#include "Nebula.h" + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ + +void RequestManager::ImageAllocate::execute( + xmlrpc_c::paramList const& paramList, + xmlrpc_c::value * const retval) +{ + string session; + string image_template; + + int iid; + int uid; + int rc; + + ostringstream oss; + + vector arrayData; + xmlrpc_c::value_array * arrayresult; + + + NebulaLog::log("ReM",Log::DEBUG,"ImageAllocate invoked"); + + session = xmlrpc_c::value_string(paramList.getString(0)); + image_template = xmlrpc_c::value_string(paramList.getString(1)); + image_template += "\n"; + + + // First, we need to authenticate the user + rc = ImageAllocate::upool->authenticate(session); + + if ( rc == -1 ) + { + goto error_authenticate; + } + + uid = rc; + + rc = ImageAllocate::ipool->allocate(uid,image_template,&iid); + + if ( rc < 0 ) + { + goto error_allocate; + + } + + arrayData.push_back(xmlrpc_c::value_boolean(true)); + arrayData.push_back(xmlrpc_c::value_int(iid)); + + // Copy arrayresult into retval mem space + arrayresult = new xmlrpc_c::value_array(arrayData); + *retval = *arrayresult; + + delete arrayresult; // and get rid of the original + + return; + +error_authenticate: + oss << "User not authenticated, aborting ImageAllocate call."; + goto error_common; + +error_allocate: + if (rc == -1) + { + oss << "Error allocating image, check oned.log"; + } + else + { + oss << "Error parsing image template"; + } + goto error_common; + +error_common: + arrayData.push_back(xmlrpc_c::value_boolean(false)); // FAILURE + arrayData.push_back(xmlrpc_c::value_string(oss.str())); + + NebulaLog::log("ReM",Log::ERROR,oss); + + xmlrpc_c::value_array arrayresult_error(arrayData); + + *retval = arrayresult_error; + + return; +} + +/* -------------------------------------------------------------------------- */ +/* -------------------------------------------------------------------------- */ diff --git a/src/rm/SConstruct b/src/rm/SConstruct index 94102c992a..0af5d52e08 100644 --- a/src/rm/SConstruct +++ b/src/rm/SConstruct @@ -34,7 +34,9 @@ source_files=[ 'RequestManagerHostInfo.cc', 'RequestManagerHostPoolInfo.cc', 'RequestManagerHostEnable.cc', + 'RequestManagerImageAllocate.cc', 'RequestManagerImageInfo.cc', + 'RequestManagerImagePoolInfo.cc', 'RequestManagerVirtualNetworkAllocate.cc', 'RequestManagerVirtualNetworkInfo.cc', 'RequestManagerVirtualNetworkPoolInfo.cc',