From 5b2750d4831855e0bb80e093710ba470109fb853 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Mon, 25 Feb 2013 17:32:47 +0100 Subject: [PATCH] Feature #1772: Add vm resize method to Java OCA --- .../opennebula/client/vm/VirtualMachine.java | 36 +++++++++++++++++++ src/oca/java/test/VirtualMachineTest.java | 10 ++++++ src/oca/ruby/opennebula/virtual_machine.rb | 3 +- 3 files changed, 48 insertions(+), 1 deletion(-) 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 0cc1260ec2..fbd9f39ed1 100644 --- a/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java +++ b/src/oca/java/src/org/opennebula/client/vm/VirtualMachine.java @@ -41,6 +41,7 @@ public class VirtualMachine extends PoolElement{ private static final String DETACH = METHOD_PREFIX + "detach"; private static final String RENAME = METHOD_PREFIX + "rename"; private static final String UPDATE = METHOD_PREFIX + "update"; + private static final String RESIZE = METHOD_PREFIX + "resize"; private static final String[] VM_STATES = { @@ -184,6 +185,25 @@ public class VirtualMachine extends PoolElement{ return client.call(UPDATE, id, new_template); } + /** + * Resizes the VM capacity + * + * @param client XML-RPC Client. + * @param id The id of the target vm. + * @param cpu the new CPU value + * @param memory the new MEMORY value + * @param vcpu the new VCPU value + * @param enforce If it is set to true, the host capacity + * will be checked. This will only affect oneadmin requests, regular users + * resize requests will always be enforced + * @return If an error occurs the error message contains the reason. + */ + public static OneResponse resize(Client client, int id, + double cpu, int memory, int vcpu, boolean enforce) + { + return client.call(RESIZE, id, cpu, memory, vcpu, enforce); + } + /** * Retrieves the information of the given VM. * @@ -571,6 +591,22 @@ public class VirtualMachine extends PoolElement{ return client.call(UPDATE, id, new_template); } + /** + * Resizes this VM's capacity + * + * @param cpu the new CPU value + * @param memory the new MEMORY value + * @param vcpu the new VCPU value + * @param enforce If it is set to true, the host capacity + * will be checked. This will only affect oneadmin requests, regular users + * resize requests will always be enforced + * @return If an error occurs the error message contains the reason. + */ + public OneResponse resize(double cpu, int memory, int vcpu, boolean enforce) + { + return client.call(RESIZE, id, cpu, memory, vcpu, enforce); + } + // ================================= // Helpers // ================================= diff --git a/src/oca/java/test/VirtualMachineTest.java b/src/oca/java/test/VirtualMachineTest.java index 02b0632f2e..5abcf065b6 100644 --- a/src/oca/java/test/VirtualMachineTest.java +++ b/src/oca/java/test/VirtualMachineTest.java @@ -341,4 +341,14 @@ public class VirtualMachineTest res = vm.info(); assertTrue( res.getErrorMessage(), !res.isError() ); } + + @Test + public void resize() + { + res = vm.resize(2.5, 512, 0, true); + assertTrue( res.getErrorMessage(), !res.isError() ); + + res = vm.resize(1, 128, 2, false); + assertTrue( res.getErrorMessage(), !res.isError() ); + } } diff --git a/src/oca/ruby/opennebula/virtual_machine.rb b/src/oca/ruby/opennebula/virtual_machine.rb index 489ac9a560..54978beb0a 100644 --- a/src/oca/ruby/opennebula/virtual_machine.rb +++ b/src/oca/ruby/opennebula/virtual_machine.rb @@ -343,7 +343,8 @@ module OpenNebula # @param memory [Integer] the new MEMORY value # @param vcpu [Integer] the new VCPU value # @param enforce [true|false] If it is set to true, the host capacity - # will be checked + # will be checked. This will only affect oneadmin requests, regular users + # resize requests will always be enforced # # @return [nil, OpenNebula::Error] nil in case of success, Error # otherwise