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

+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