You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by al...@apache.org on 2015/06/14 22:47:52 UTC

[02/10] incubator-brooklyn git commit: jclouds userData: support for vCloud Director

jclouds userData: support for vCloud Director

- Reflectively invoke userData(String) or guestCustomizationScript(String)
  so that works with other clouds, including vCloud Director.
- Don’t really want to add a direct dependency from Brooklyn to 
  vCD (https://github.com/cloudsoft/jclouds-vcloud-director/).
  That is an unofficial jclouds provider, rather than part of core
  jclouds or jclouds labs.

Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/51e7e0b1
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/51e7e0b1
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/51e7e0b1

Branch: refs/heads/master
Commit: 51e7e0b1a5424e6eb8dd92af1047b8a24a66d0b3
Parents: ae3790e
Author: Aled Sage <al...@gmail.com>
Authored: Thu Jun 11 14:49:47 2015 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Thu Jun 11 14:49:47 2015 +0100

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       | 28 +++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/51e7e0b1/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
index c665ba7..7d3d50e 100644
--- a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -1057,7 +1057,33 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
                         } else if (t instanceof SoftLayerTemplateOptions) {
                             ((SoftLayerTemplateOptions)t).userData(Strings.toString(v));
                         } else {
-                            LOG.info("ignoring userDataString({}) in VM creation because not supported for cloud/type ({})", v, t.getClass());
+                            // Try reflection: userData(String), or guestCustomizationScript(String);
+                            // the latter is used by vCloud Director.
+                            Class<? extends TemplateOptions> clazz = t.getClass();
+                            Method userDataMethod = null;
+                            try {
+                                userDataMethod = clazz.getMethod("userData", String.class);
+                            } catch (SecurityException e) {
+                                LOG.info("Problem reflectively inspecting methods of "+t.getClass()+" for setting userData", e);
+                            } catch (NoSuchMethodException e) {
+                                try {
+                                    // For vCloud Director
+                                    userDataMethod = clazz.getMethod("guestCustomizationScript", String.class);
+                                } catch (NoSuchMethodException e2) {
+                                    // expected on various other clouds
+                                }
+                            }
+                            if (userDataMethod != null) {
+                                try {
+                                    userDataMethod.invoke(Strings.toString(v));
+                                } catch (InvocationTargetException e) {
+                                    LOG.info("Problem invoking "+userDataMethod.getName()+" of "+t.getClass()+", for setting userData", e);
+                                } catch (IllegalAccessException e) {
+                                    LOG.info("Unable to reflectively invoke "+userDataMethod.getName()+" of "+t.getClass()+", for setting userData", e);
+                                }
+                            } else {
+                                LOG.info("ignoring userDataString({}) in VM creation because not supported for cloud/type ({})", v, t.getClass());
+                            }
                         }
                     }})
             .put(USER_DATA_UUENCODED, new CustomizeTemplateOptions() {