From e0a6ca1c21f355d4362e3ad5f35fdfe943baf393 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn?= Date: Thu, 9 Jun 2011 18:03:22 +0200 Subject: [PATCH] Feature #662, #607: Add host update method to ruby and Java OCA --- .../src/org/opennebula/client/host/Host.java | 26 ++++++++++++++++++- src/oca/java/test/HostTest.java | 26 ++++++++++++++++++- src/oca/ruby/OpenNebula/Host.rb | 10 ++++++- 3 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/oca/java/src/org/opennebula/client/host/Host.java b/src/oca/java/src/org/opennebula/client/host/Host.java index 2b5cf12cec..20a82df64b 100644 --- a/src/oca/java/src/org/opennebula/client/host/Host.java +++ b/src/oca/java/src/org/opennebula/client/host/Host.java @@ -32,6 +32,7 @@ public class Host extends PoolElement{ private static final String INFO = METHOD_PREFIX + "info"; private static final String DELETE = METHOD_PREFIX + "delete"; private static final String ENABLE = METHOD_PREFIX + "enable"; + private static final String UPDATE = METHOD_PREFIX + "update"; private static final String[] HOST_STATES = {"INIT", "MONITORING", "MONITORED", "ERROR", "DISABLED"}; @@ -122,7 +123,19 @@ public class Host extends PoolElement{ { return client.call(ENABLE, id, enable); } - + + /** + * Replaces the template contents. + * + * @param client XML-RPC Client. + * @param id The image id of the target host we want to modify. + * @param new_template New template contents + * @return If successful the message contains the host id. + */ + public static OneResponse update(Client client, int id, String new_template) + { + return client.call(UPDATE, id, new_template); + } // ================================= // Instanced object XML-RPC methods @@ -181,6 +194,17 @@ public class Host extends PoolElement{ return enable(false); } + /** + * Replaces the template contents. + * + * @param new_template New template contents + * @return If successful the message contains the host id. + */ + public OneResponse update(String new_template) + { + return update(client, id, new_template); + } + // ================================= // Helpers // ================================= diff --git a/src/oca/java/test/HostTest.java b/src/oca/java/test/HostTest.java index 9a8435fe41..81f1878b6a 100644 --- a/src/oca/java/test/HostTest.java +++ b/src/oca/java/test/HostTest.java @@ -99,7 +99,7 @@ public class HostTest } @Test - public void update() + public void info() { res = host.info(); assertTrue( !res.isError() ); @@ -152,6 +152,30 @@ public class HostTest assertTrue( !found ); } + + @Test + public void update() + { + res = host.info(); + assertTrue( !res.isError() ); + + assertTrue( host.xpath("TEMPLATE/ATT1").equals( "" ) ); + assertTrue( host.xpath("TEMPLATE/ATT2").equals( "" ) ); + + String new_template = "ATT2 = NEW_VAL\n" + + "ATT3 = VAL3"; + + res = host.update(new_template); + assertTrue( !res.isError() ); + + + res = host.info(); + assertTrue( !res.isError() ); + assertTrue( host.xpath("TEMPLATE/ATT1").equals( "" ) ); + assertTrue( host.xpath("TEMPLATE/ATT2").equals( "NEW_VAL" ) ); + assertTrue( host.xpath("TEMPLATE/ATT3").equals( "VAL3" ) ); + } + /* @Test public void attributes() diff --git a/src/oca/ruby/OpenNebula/Host.rb b/src/oca/ruby/OpenNebula/Host.rb index 173d772111..1d6a0b9e30 100644 --- a/src/oca/ruby/OpenNebula/Host.rb +++ b/src/oca/ruby/OpenNebula/Host.rb @@ -25,7 +25,8 @@ module OpenNebula :info => "host.info", :allocate => "host.allocate", :delete => "host.delete", - :enable => "host.enable" + :enable => "host.enable", + :update => "host.update" } HOST_STATES=%w{INIT MONITORING MONITORED ERROR DISABLED} @@ -102,6 +103,13 @@ module OpenNebula set_enabled(false) end + # Replaces the template contents + # + # +new_template+ New template contents + def update(new_template) + super(HOST_METHODS[:update], new_template) + end + ####################################################################### # Helpers to get Host information #######################################################################