mirror of
https://github.com/OpenNebula/one.git
synced 2026-11-21 04:12:37 +09:00
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:
1 parent
9af500b4cd
commit
fa46633339
12 files changed
+88
-141
No files matched your search
+18
-22
@@ -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
@@ -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
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user