1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-03-21 14:50:08 +03:00

feature #1327: Extend arguments only support long options. Add examples to create methods using

options. Restructure checks for options and template files
This commit is contained in:
Ruben S. Montero 2012-09-21 23:30:40 +02:00
parent d105000dda
commit 674d689016
4 changed files with 117 additions and 68 deletions

View File

@ -20,8 +20,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
TEMPLATE_OPTIONS=[
{
:name => "name",
:short => "-n name",
:large => "--name type",
:large => "--name name",
:format => String,
:description => "Name of the new image"
},
@ -33,10 +32,9 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
},
{
:name => "type",
:short => "-t type",
:large => "--type type",
:format => String,
:description => "Type of the new Image",
:description => "Type of the new Image: OS, CDROM or DATABLOCK",
:proc => lambda do |o, options|
type=o.strip.upcase
@ -49,14 +47,13 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
},
{
:name => "persistent",
:short => "-p",
:large => "--persistent",
:description => "Tells if the image will be persistent"
},
{
:name => "prefix",
:large => "--prefix prefix",
:description => "Device prefix for the disk (hd, sd, xvd or vd)",
:description => "Device prefix for the disk (eg. hd, sd, xvd or vd)",
:format => String,
:proc => lambda do |o, options|
prefix=o.strip.downcase
@ -182,7 +179,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
type_str = Image::IMAGE_TYPES[id]
return Image::SHORT_IMAGE_TYPES[type_str]
end
def format_pool(options)
config_file = self.class.table_conf
@ -217,7 +214,7 @@ class OneImageHelper < OpenNebulaHelper::OneHelper
:size=>15 do |d|
OpenNebulaHelper.time_to_str(d["REGTIME"])
end
column :PERSISTENT, "Whether the Image is persistent or not",
:size=>3 do |d|
OpenNebulaHelper.boolean_to_str(d["PERSISTENT"])

View File

@ -77,11 +77,32 @@ cmd=CommandParser::CmdParser.new(ARGV) do
########################################################################
create_desc = <<-EOT.unindent
Creates a new Image from the given template file
Creates a new Image
Examples:
- using a template description file:
oneimage create -d default centOS.tmpl
- new image "arch" using a path of type centOS:
oneimage create -d default --name arch --path /tmp/arch.img
- new persistent image, OS type and qcow2 format:
oneimage create -d 1 --name ubuntu --path /tmp/ubuntu.qcow2 \\
--prefix sd --type OS --driver qcow2 \\
--description "A OS plain installation"
- a datablock image of 400MB:
oneimage create -d 1 --name data --type DATABLOCK --size 400 \\
--fstype ext2
EOT
command :create, create_desc, [:file, nil], :options=>CREATE_OPTIONS+
command :create, create_desc, [:file, nil], :options=>CREATE_OPTIONS +
OneImageHelper::TEMPLATE_OPTIONS do
if options[:datastore].nil?
STDERR.puts "Datastore to save the image is mandatory: "
STDERR.puts "\t -d datastore_id"
@ -94,22 +115,21 @@ cmd=CommandParser::CmdParser.new(ARGV) do
next -1
end
res=OneImageHelper.create_image_template(options)
if res.first!=0
STDERR.puts res.last
next -1
end
helper.create_resource(options) do |image|
begin
if args[0]
template=File.read(args[0])
else
template=''
res = OneImageHelper.create_image_template(options)
if res.first != 0
STDERR.puts res.last
next -1
end
template = res.last
end
template<<res.last
image.allocate(template, options[:datastore])
rescue => e
STDERR.puts e.messsage
@ -156,7 +176,7 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
unpublish_desc = <<-EOT.unindent
DEPRECATED, use chmod instead. Unpublishes the given Image. A private
DEPRECATED, use chmod instead. Unpublishes the given Image. A private
Image can't be used by any other user.
EOT

View File

@ -79,12 +79,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do
########################################################################
create_desc = <<-EOT.unindent
Creates a new Template from the given template file
Creates a new VM Template from the given description
Examples:
- using a VM Template description file:
onetemplate create vm_description.tmpl
- new VM Template named "arch vm" with a disk and a nic:
onetemplate create --name "arch vm" --memory 128 --cpu 1 --disk arch \\
--network private_lan
- using two disks:
onevm create --name "test vm" --memory 128 --cpu 1 --disk arch,data
EOT
command :create, create_desc, [:file, nil],
:options=>OpenNebulaHelper::TEMPLATE_OPTIONS do
res=OpenNebulaHelper.create_template(options)
command :create, create_desc, [:file, nil], :options =>
OpenNebulaHelper::TEMPLATE_OPTIONS do
if args[0] && OpenNebulaHelper.create_template_options_used?(options)
STDERR.puts "You can not use both template file and template"<<
@ -92,20 +106,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do
next -1
end
if res.first!=0
STDERR.puts res.last
next -1
end
helper.create_resource(options) do |tmpl|
begin
if args[0]
template = File.read(args[0])
else
res = OpenNebulaHelper.create_template(options)
helper.create_resource(options) do |t|
if args[0]
template=File.read(args[0])
else
template=''
if res.first != 0
STDERR.puts res.last
next -1
end
template = res.last
end
tmpl.allocate(template)
rescue => e
STDERR.puts e.messsage
exit -1
end
template<<res.last
t.allocate(template)
end
end
@ -165,8 +185,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do
end
publish_desc = <<-EOT.unindent
DEPRECATED, use chmod instead. Publishes the given Template. A public
Template can be seen and instantiated by other users in the Template's
DEPRECATED, use chmod instead. Publishes the given Template. A public
Template can be seen and instantiated by other users in the Template's
group.
EOT

View File

@ -94,50 +94,62 @@ cmd=CommandParser::CmdParser.new(ARGV) do
########################################################################
create_desc = <<-EOT.unindent
Creates a new VM from the given template file. This command bypasses
the Template pool, which is the preferred way to instantiate new VMs.
See 'onetemplate create' and 'onetemplate instantiate'
Creates a new VM from the given description instead of using a previously
defined template (see 'onetemplate create' and 'onetemplate instantiate').
Examples:
- using a template description file:
onevm create vm_description.tmpl
- new VM named "arch vm" with a disk and a nic
onevm create --name "arch vm" --memory 128 --cpu 1 --disk arch \\
--network private_lan
- a vm with two disks
onevm create --name "test vm" --memory 128 --cpu 1 --disk arch,data
EOT
command :create, create_desc, [:file, nil],
:options=>[OneVMHelper::MULTIPLE]+
OpenNebulaHelper::TEMPLATE_OPTIONS do
number = options[:multiple] || 1
command :create, create_desc, [:file, nil], :options =>
[OneVMHelper::MULTIPLE] + OpenNebulaHelper::TEMPLATE_OPTIONS do
exit_code=nil
number = options[:multiple] || 1
exit_code = nil
res=OpenNebulaHelper.create_template(options)
if res.first!=0
STDERR.puts res.last
if args[0] && OpenNebulaHelper.create_template_options_used?(options)
STDERR.puts "You can not use both template file and template"<<
" creation options."
next -1
end
if args[0]
if OpenNebulaHelper.create_template_options_used?(options)
STDERR.puts "You can not use both template file and template"<<
" creation options."
next -1
end
begin
begin
if args[0]
template=File.read(args[0])
rescue
STDERR.puts "Error reading template."
next -1
else
res = OpenNebulaHelper.create_template(options)
if res.first != 0
STDERR.puts res.last
next -1
end
template = res.last
end
else
template=''
rescue Exception => e
STDERR.puts "Error reading template."
next -1
end
template<<res.last
number.times do
exit_code=helper.create_resource(options) do |vm|
error=vm.allocate(template)
exit_code = helper.create_resource(options) do |vm|
error = vm.allocate(template)
end
break if exit_code==-1
break if exit_code == -1
end
exit_code