Feature #662: New update method for Images and Templates added to OCA and CLI (work in progress).

New template instantiate method in OCA and CLI.
Fix small bugs in RM.
This commit is contained in:
Carlos Martín committed 2011-06-02 19:17:22 +02:00
1 parent 9af500b4cd
commit fa46633339
12 files changed
+88 -141

No files matched your search

+7 -7
View File
@@ -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;
}
/**
+13 -13
View File
@@ -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,
+5 -5
View File
@@ -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,
+2 -2
View File
@@ -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;
};
// ------------------------------------------------------------------------
+18 -22
View File
@@ -231,11 +231,8 @@ Commands:
* addattr (Add a new image attribute)
oneimage addattr <image_id> <attribute_name> <attribute_value>
* update (Modifies an image attribute)
oneimage update <image_id> <attribute_name> <attribute_value>
* rmattr (Deletes an Image attribute)
oneimage rmattr <image_id> <attribute_name>
* update (Lets the user edit and replace the image template)
oneimage update <image_id>
* enable (Enabled an Image)
oneimage enable <image_id>
@@ -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])
+10 -21
View File
@@ -180,14 +180,11 @@ Commands:
file is a file name where the Template description is located
* addattr (Add a new Template attribute)
onetemplate addattr <template_id> <attribute_name> <attribute_value>
* instantiate (Creates a VM instance from a Template)
onetemplate instantiate <template_id>
* update (Modifies a Template attribute)
onetemplate update <template_id> <attribute_name> <attribute_value>
* rmattr (Deletes a Template attribute)
onetemplate rmattr <template_id> <attribute_name>
* update (Lets the user edit and replace the Template contents)
onetemplate update <template_id>
* publish (Publish a Template)
onetemplate publish <template_id>
@@ -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)
+6 -32
View File
@@ -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] {<template-file-path>, <template-id>, <template-name>}
onevm create [OPTION] <template-file-path>
<template-file-path> is a file name where the VM description is located.
<template-id> is the numeric ID of a registered template (using onetemplate)
<template-name> 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 <vm_id> <host_id>
@@ -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
+4 -7
View File
@@ -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
+3 -4
View File
@@ -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
+13 -21
View File
@@ -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
+4 -4
View File
@@ -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;
}
+3 -3
View File
@@ -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 );
}