From 8d8da16758ff1c05abdc31044ebc8775bc362525 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 20 Dec 2012 16:25:42 +0100 Subject: [PATCH] Feature #1103: Add hold param to ruby & java oca, and cli. onetemplate instantiate needs to be done also --- src/cli/one_helper/onevm_helper.rb | 6 ++++++ src/cli/onevm | 7 +++++-- .../opennebula/client/vm/VirtualMachine.java | 17 ++++++++++++++++- src/oca/ruby/OpenNebula/VirtualMachine.rb | 9 ++++++--- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/src/cli/one_helper/onevm_helper.rb b/src/cli/one_helper/onevm_helper.rb index e6bafadab4..e540239f9f 100644 --- a/src/cli/one_helper/onevm_helper.rb +++ b/src/cli/one_helper/onevm_helper.rb @@ -51,6 +51,12 @@ class OneVMHelper < OpenNebulaHelper::OneHelper } } + HOLD = { + :name => "hold", + :large => "--hold", + :description => "Creates the new VM on hold state instead of pending" + } + def self.rname "VM" end diff --git a/src/cli/onevm b/src/cli/onevm index 466b989238..04fd4a414f 100755 --- a/src/cli/onevm +++ b/src/cli/onevm @@ -125,7 +125,8 @@ cmd=CommandParser::CmdParser.new(ARGV) do EOT command :create, create_desc, [:file, nil], :options => - [OneVMHelper::MULTIPLE]+OpenNebulaHelper::TEMPLATE_OPTIONS_VM do + [OneVMHelper::MULTIPLE, OneVMHelper::HOLD]+ + OpenNebulaHelper::TEMPLATE_OPTIONS_VM do number = options[:multiple] || 1 exit_code = nil @@ -160,9 +161,11 @@ cmd=CommandParser::CmdParser.new(ARGV) do exit 0 end + on_hold = options[:hold] != nil + number.times do exit_code = helper.create_resource(options) do |vm| - error = vm.allocate(template) + error = vm.allocate(template, on_hold) end break if exit_code == -1 diff --git a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java index 93ddc1c123..51f3779513 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -150,7 +150,22 @@ public class VirtualMachine extends PoolElement{ */ public static OneResponse allocate(Client client, String description) { - return client.call(ALLOCATE, description); + return allocate(client, description, false); + } + + /** + * Allocates a new VM in OpenNebula. + * + * @param client XML-RPC Client. + * @param description A string containing the template of the vm. + * @param onHold False to create this VM in pending state, true on hold + * @return If successful the message contains the associated + * id generated for this VM. + */ + public static OneResponse allocate(Client client, String description, + boolean onHold) + { + return client.call(ALLOCATE, description, onHold); } /** diff --git a/src/oca/ruby/OpenNebula/VirtualMachine.rb b/src/oca/ruby/OpenNebula/VirtualMachine.rb index 31cd2952e8..f38819597f 100644 --- a/src/oca/ruby/OpenNebula/VirtualMachine.rb +++ b/src/oca/ruby/OpenNebula/VirtualMachine.rb @@ -134,9 +134,12 @@ module OpenNebula # Allocates a new VirtualMachine in OpenNebula # - # +description+ A string containing the template of the VirtualMachine. - def allocate(description) - super(VM_METHODS[:allocate],description) + # @param description [String] A string containing the template of + # the VirtualMachine. + # @param hold [true,false] false to create the VM in pending state, + # true to create it on hold + def allocate(description, hold=false) + super(VM_METHODS[:allocate], description, hold) end # Initiates the instance of the VM on the target host.