diff --git a/include/Image.h b/include/Image.h index a59b6c9fac..eb360f109c 100644 --- a/include/Image.h +++ b/include/Image.h @@ -186,25 +186,25 @@ public: * @param pub true to publish the image * @return 0 on success */ - bool publish(bool pub) + int publish(bool pub) { - bool success = false; + int rc = -1; if (pub == true) { if (!isPersistent()) { - public_obj = 1; - success = true; + public_obj = 1; + rc = 0; } } else { - public_obj = 0; - success = true; + public_obj = 0; + rc = 0; } - return success; + return rc; } /** diff --git a/include/Request.h b/include/Request.h index c5fb3ac7ba..8b194c11d5 100644 --- a/include/Request.h +++ b/include/Request.h @@ -59,17 +59,17 @@ protected: /* ------------------- Attributes of the Request ---------------------- */ - int uid; /** id of the user performing the request */ + int uid; /**< id of the user performing the request */ - int gid; /** id of the user performing the request */ + int gid; /**< id of the user's group */ - PoolSQL * pool; /** id of the user performing the request */ + PoolSQL * pool; /**< Pool of objects */ - string method_name; /** The name of the XML-RPC method */ + string method_name; /**< The name of the XML-RPC method */ - AuthRequest::Object auth_object; /** Auth object for the request */ + AuthRequest::Object auth_object; /**< Auth object for the request */ - AuthRequest::Operation auth_op; /** Auth operation for the request */ + AuthRequest::Operation auth_op; /**< Auth operation for the request */ /* -------------------- Constructors ---------------------------------- */ @@ -93,14 +93,14 @@ protected: * the public attribute and its owner. The authorization is based on * object and type of operation for the request. * @param oid of the object. + * + * @return true if the user is authorized. */ bool basic_authorization(int oid); /** * Actual Execution method for the request. Must be implemented by the * XML-RPC requests - * @param uid of the user making the request - * @param gid of the user making the request * @param _paramlist of the XML-RPC call (complete list) */ virtual void request_execute(xmlrpc_c::paramList const& _paramList) = 0; @@ -131,7 +131,7 @@ protected: * Gets a string representation for the Auth object in the * request. * @param ob object for the auth operation - * @returns string equivalent of the object + * @return string equivalent of the object */ static string object_name(AuthRequest::Object ob); @@ -141,7 +141,7 @@ protected: * @param object object that needs to be authorized * @param uid user that is authorized * @param id id of the object, -1 for Pool - * @returns string for logging + * @return string for logging */ string authorization_error (const string &action, const string &object, @@ -149,7 +149,7 @@ protected: int id); /** * Logs authenticate errors - * @returns string for logging + * @return string for logging */ string authenticate_error (); @@ -157,7 +157,7 @@ protected: * Logs get object errors * @param object over which the get failed * @param id of the object over which the get failed - * @returns string for logging + * @return string for logging */ string get_error (const string &object, int id); @@ -169,7 +169,7 @@ protected: * @param id id of the object, -1 for Pool, -2 for no-id objects * (allocate error, parse error) * @param rc returned error code (NULL to ignore) - * @returns string for logging + * @return string for logging */ string action_error (const string &action, const string &object, diff --git a/include/Template.h b/include/Template.h index 3d74d6f3e7..ffca1d9612 100644 --- a/include/Template.h +++ b/include/Template.h @@ -128,7 +128,7 @@ public: * attributes MUST be freed by the calling funtion * @param name of the attribute * @param values a vector containing a pointer to the attributes - * @returns the number of attributes removed + * @return the number of attributes removed */ virtual int remove( const string& name, @@ -137,14 +137,14 @@ public: /** * Removes an attribute from the template, and frees the attributes. * @param name of the attribute - * @returns the number of attributes removed + * @return the number of attributes removed */ virtual int erase(const string& name); /** * Gets all the attributes with the given name. * @param name the attribute name. - * @returns the number of elements in the vector + * @return the number of elements in the vector */ virtual int get( const string& name, @@ -153,7 +153,7 @@ public: /** * Gets all the attributes with the given name, non-const version * @param name the attribute name. - * @returns the number of elements in the vector + * @return the number of elements in the vector */ virtual int get( const string& name, @@ -175,7 +175,7 @@ public: * @param value the attribute value, an int, 0 if the attribute is not * defined or not Single * - * @returns True if the Single attribute was found + * @return True if the Single attribute was found */ virtual bool get( string& name, diff --git a/include/VMTemplate.h b/include/VMTemplate.h index 948d9fb5fc..7b28fb10a7 100644 --- a/include/VMTemplate.h +++ b/include/VMTemplate.h @@ -47,7 +47,7 @@ public: * @param pub true to publish the object * @return 0 on success */ - bool publish(bool pub) + int publish(bool pub) { if (pub == true) { @@ -58,7 +58,7 @@ public: public_obj = 0; } - return true; + return 0; }; // ------------------------------------------------------------------------ diff --git a/src/cli/oneimage b/src/cli/oneimage index b3a9a2ec0f..ce0f0c5ace 100755 --- a/src/cli/oneimage +++ b/src/cli/oneimage @@ -231,11 +231,8 @@ Commands: * addattr (Add a new image attribute) oneimage addattr -* update (Modifies an image attribute) - oneimage update - -* rmattr (Deletes an Image attribute) - oneimage rmattr +* update (Lets the user edit and replace the image template) + oneimage update * enable (Enabled an Image) oneimage enable @@ -358,29 +355,28 @@ when "register", "create", "add" puts "ID: " + image.id.to_s if ops[:verbose] end - -when "update", "addattr" - check_parameters("update", 3) +when "update" + check_parameters("update", 1) image_id=get_image_id(ARGV[0]) image=OpenNebula::Image.new_with_id(image_id, get_one_client) - - result=image.update(ARGV[1],ARGV[2]) + rc = image.info if is_successful?(result) - puts "Modified image" if ops[:verbose] + file = File.open('/tmp/template', "w") + file << image.template_str + file.close + + system "vim /tmp/template" + str = File.read('/tmp/test') + + result = image.update( str ) + + if is_successful?(result) + puts "Modified image" if ops[:verbose] + end + end -when "rmattr" - check_parameters("rmattr", 2) - image_id=get_image_id(ARGV[0]) - - image=OpenNebula::Image.new_with_id(image_id, get_one_client) - - result=image.remove_attr(ARGV[1]) - if is_successful?(result) - puts "Removed image atrribute" if ops[:verbose] - end - when "enable" check_parameters("enable", 1) image_id=get_image_id(ARGV[0]) diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 29a346dbd3..c9e5121607 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -180,14 +180,11 @@ Commands: file is a file name where the Template description is located -* addattr (Add a new Template attribute) - onetemplate addattr +* instantiate (Creates a VM instance from a Template) + onetemplate instantiate -* update (Modifies a Template attribute) - onetemplate update - -* rmattr (Deletes a Template attribute) - onetemplate rmattr +* update (Lets the user edit and replace the Template contents) + onetemplate update * publish (Publish a Template) onetemplate publish @@ -299,27 +296,19 @@ when "create", "register", "add" exit 0 end -when "update", "addattr" - check_parameters("update", 3) +when "instantiate" + check_parameters("instantiate", 1) template_id = get_template_id(ARGV[0]) template = OpenNebula::Template.new_with_id(template_id, get_one_client) - result = template.update(ARGV[1],ARGV[2]) + result = template.instantiate if is_successful?(result) - puts "Modified template" if ops[:verbose] + puts "Template instantiated." if ops[:verbose] end -when "rmattr" - check_parameters("rmattr", 2) - template_id = get_template_id(ARGV[0]) - - template = OpenNebula::Template.new_with_id(template_id, get_one_client) - - result = template.remove_attr(ARGV[1]) - if is_successful?(result) - puts "Removed template attribute" if ops[:verbose] - end +when "update" + puts "TODO" when "publish" check_parameters("publish", 1) diff --git a/src/cli/onevm b/src/cli/onevm index 72a9676f37..1628b9bf20 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -334,15 +334,9 @@ machine with the functionality present in onevm. Commands: * create (Submits a new virtual machine, adding it to the ONE VM pool) - onevm create [OPTION] {, , } + onevm create [OPTION] is a file name where the VM description is located. - is the numeric ID of a registered template (using onetemplate) - is the name of a registered template (using onetemplate) - - OPTION: -n STRING, --name=STRING - Replaces the NAME attribute if the VM is being created from a registered - Template * deploy (Starts an existing VM in an specific host) onevm deploy @@ -539,32 +533,12 @@ when "submit", "create" check_parameters("create", 1) vm=OpenNebula::VirtualMachine.new( OpenNebula::VirtualMachine.build_xml, get_one_client) - - template = "" - success = false - - if( File.file?(ARGV[0]) ) - # argument is a file path - begin - template = File.read(ARGV[0]) - success = true - rescue - result = OpenNebula::Error.new("Can not read template: #{ARGV[0]}") - end - else - # argument could be a template ID or a template name - template_id = get_template_id(ARGV[0]) - - template = "TEMPLATE_ID = #{template_id}" - template << "\nNAME = #{ops[:vm_name]}" if ops[:vm_name] - - success = true + begin + template=File.read(ARGV[0]) + result=vm.allocate(template) + rescue + result=OpenNebula::Error.new("Can not read template: #{ARGV[0]}") end - - if( success ) - result = vm.allocate(template) - end - if is_successful?(result) puts "ID: " + vm.id.to_s if ops[:verbose] exit 0 diff --git a/src/oca/ruby/OpenNebula/Image.rb b/src/oca/ruby/OpenNebula/Image.rb index 62a80e6e77..e8387131f0 100644 --- a/src/oca/ruby/OpenNebula/Image.rb +++ b/src/oca/ruby/OpenNebula/Image.rb @@ -26,7 +26,6 @@ module OpenNebula :info => "image.info", :allocate => "image.allocate", :update => "image.update", - :rmattr => "image.rmattr", :enable => "image.enable", :publish => "image.publish", :persistent => "image.persistent", @@ -93,13 +92,11 @@ module OpenNebula super(IMAGE_METHODS[:allocate],description) end - # Modifies an image attribute + # Replaces the template contents # - # +name+ Name of the attribute to be changed - # - # +value+ New value for the attribute - def update(name, value) - super(IMAGE_METHODS[:update], name, value) + # +new_template+ New template contents + def update(new_template) + super(IMAGE_METHODS[:update], new_template) end # Deletes an Image attribute diff --git a/src/oca/ruby/OpenNebula/Pool.rb b/src/oca/ruby/OpenNebula/Pool.rb index 99af00f5fd..30fa180c51 100644 --- a/src/oca/ruby/OpenNebula/Pool.rb +++ b/src/oca/ruby/OpenNebula/Pool.rb @@ -148,13 +148,12 @@ module OpenNebula # Calls to the corresponding update method to modify # the object's template # xml_method:: _String_ the name of the XML-RPC method - # name:: _String_ the name of the property to be modified - # value:: _String_ the new value of the property to be modified + # new_template:: _String_ the new template contents # [return] nil in case of success or an Error object - def update(xml_method, name, value) + def update(xml_method, new_template) return Error.new('ID not defined') if !@pe_id - rc = @client.call(xml_method,@pe_id, name, value) + rc = @client.call(xml_method,@pe_id, new_template) rc = nil if !OpenNebula.is_error?(rc) return rc diff --git a/src/oca/ruby/OpenNebula/Template.rb b/src/oca/ruby/OpenNebula/Template.rb index 89e5285c08..49012c1ae4 100644 --- a/src/oca/ruby/OpenNebula/Template.rb +++ b/src/oca/ruby/OpenNebula/Template.rb @@ -23,9 +23,9 @@ module OpenNebula # --------------------------------------------------------------------- TEMPLATE_METHODS = { :allocate => "template.allocate", + :instantiate => "template.instantiate", :info => "template.info", :update => "template.update", - :rmattr => "template.rmattr", :publish => "template.publish", :delete => "template.delete", :chown => "template.chown" @@ -78,20 +78,21 @@ module OpenNebula super(TEMPLATE_METHODS[:delete]) end - # Modifies a template attribute - # - # +name+ Name of the attribute to be changed - # - # +value+ New value for the attribute - def update(name, value) - super(TEMPLATE_METHODS[:update], name, value) + # Creates a VM instance from a Template + def instantiate(name="") + return Error.new('ID not defined') if !@pe_id + + rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id, name) + rc = nil if !OpenNebula.is_error?(rc) + + return rc end - # Deletes a template attribute + # Replaces the template contents # - # +name+ Name of the attribute to be deleted - def remove_attr(name) - do_rm_attr(name) + # +new_template+ New template contents + def update(new_template) + super(TEMPLATE_METHODS[:update], new_template) end # Publishes the Template, to be used by other users @@ -132,14 +133,5 @@ module OpenNebula return rc end - - def do_rm_attr(name) - return Error.new('ID not defined') if !@pe_id - - rc = @client.call(TEMPLATE_METHODS[:rmattr], @pe_id, name) - rc = nil if !OpenNebula.is_error?(rc) - - return rc - end end end diff --git a/src/rm/RequestManagerInfo.cc b/src/rm/RequestManagerInfo.cc index 576189d5a8..671c7fe87a 100644 --- a/src/rm/RequestManagerInfo.cc +++ b/src/rm/RequestManagerInfo.cc @@ -23,10 +23,9 @@ using namespace std; void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList) { - ostringstream oss; - int oid = xmlrpc_c::value_int(paramList.getInt(1)); PoolObjectSQL * object; + string str; if ( basic_authorization(oid) == false ) { @@ -41,11 +40,12 @@ void RequestManagerInfo::request_execute(xmlrpc_c::paramList const& paramList) return; } - oss << *object; + + object->to_xml(str); object->unlock(); - success_response(oss.str()); + success_response(str); return; } diff --git a/src/vm_template/test/VMTemplatePoolTest.cc b/src/vm_template/test/VMTemplatePoolTest.cc index 0130e416c3..a394548a72 100644 --- a/src/vm_template/test/VMTemplatePoolTest.cc +++ b/src/vm_template/test/VMTemplatePoolTest.cc @@ -453,18 +453,18 @@ public: i++; } - bool success; + int success; // temp 0 is not public. temp = tpool->get( 0, false ); CPPUNIT_ASSERT( temp != 0 ); success = temp->publish(false); - CPPUNIT_ASSERT( success == true ); + CPPUNIT_ASSERT( success == 0 ); CPPUNIT_ASSERT( temp->isPublic() == false ); success = temp->publish(true); - CPPUNIT_ASSERT( success == true ); + CPPUNIT_ASSERT( success == 0 ); CPPUNIT_ASSERT( temp->isPublic() == true ); }