From 7d016df19b5a9fd91c42e4d18cb6f8632568e726 Mon Sep 17 00:00:00 2001 From: Daniel Molina Date: Wed, 3 Aug 2011 14:30:43 +0200 Subject: [PATCH] Bug #733: New options for onetemplate instantiate; name of the new VM and instance multiple VMs --- src/cli/one_helper/onetemplate_helper.rb | 16 +++++++++++++ src/cli/onetemplate | 29 ++++++++++++++++++------ src/oca/ruby/OpenNebula/Template.rb | 3 ++- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/cli/one_helper/onetemplate_helper.rb b/src/cli/one_helper/onetemplate_helper.rb index ea24bca273..83e50b572e 100644 --- a/src/cli/one_helper/onetemplate_helper.rb +++ b/src/cli/one_helper/onetemplate_helper.rb @@ -17,6 +17,22 @@ require 'one_helper' class OneTemplateHelper < OpenNebulaHelper::OneHelper + VM_NAME={ + :name => "vm_name", + :short => "-n vm_name", + :large => "--name vm_name", + :format => String, + :description => "Name of the new Virtual Machine" + } + + MULTIPLE={ + :name => "multiple", + :short => "-m x", + :large => "--multiple x", + :format => Integer, + :description => "Instance multiple VMs" + } + def self.rname "VMTEMPLATE" end diff --git a/src/cli/onetemplate b/src/cli/onetemplate index 1e412a15d0..7b652fa65a 100755 --- a/src/cli/onetemplate +++ b/src/cli/onetemplate @@ -40,11 +40,16 @@ cmd=CommandParser::CmdParser.new(ARGV) do # Global Options ######################################################################## set :option, CommandParser::OPTIONS - + list_options = CLIHelper::OPTIONS list_options << OpenNebulaHelper::XML list_options << OpenNebulaHelper::NUMERIC + instantiate_options = [ + OneTemplateHelper::VM_NAME, + OneTemplateHelper::MULTIPLE + ] + ######################################################################## # Formatters for arguments ######################################################################## @@ -98,16 +103,26 @@ cmd=CommandParser::CmdParser.new(ARGV) do managed with the 'onevm' command EOT - command :instantiate, instantiate_desc, [:range,:templateid_list] do - helper.perform_actions(args[0],options,"instantiated") do |t| - res = t.instantiate + command :instantiate, instantiate_desc, :templateid, + :options=>instantiate_options do + exit_code=0 - if !OpenNebula.is_error?(res) - puts "VM ID: #{res}" + number = options[:multiple] || 1 + number.times do + exit_code=helper.perform_action(args[0],options,"instantiated") do |t| + res = t.instantiate(options[:vm_name]) + + if !OpenNebula.is_error?(res) + puts "VM ID: #{res}" + end + + res end - res + break if exit_code==-1 end + + exit_code end publish_desc = <<-EOT.unindent diff --git a/src/oca/ruby/OpenNebula/Template.rb b/src/oca/ruby/OpenNebula/Template.rb index ffb099edd4..fa12eea96e 100644 --- a/src/oca/ruby/OpenNebula/Template.rb +++ b/src/oca/ruby/OpenNebula/Template.rb @@ -60,7 +60,7 @@ module OpenNebula # --------------------------------------------------------------------- # XML-RPC Methods for the Template Object # --------------------------------------------------------------------- - + # Retrieves the information of the given Template. def info() super(TEMPLATE_METHODS[:info], 'VMTEMPLATE') @@ -85,6 +85,7 @@ module OpenNebula def instantiate(name="") return Error.new('ID not defined') if !@pe_id + name ||= "" rc = @client.call(TEMPLATE_METHODS[:instantiate], @pe_id, name) return rc