add a custom template-options script in case sudoers or something else needs 
changing on first boot


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

Branch: refs/heads/master
Commit: aafddb59c576df3842ed70a15e759426cfe0ee4d
Parents: 5039559
Author: Alex Heneveld <[email protected]>
Authored: Thu Jan 22 21:18:17 2015 +0000
Committer: Alex Heneveld <[email protected]>
Committed: Thu Jan 22 21:18:17 2015 +0000

----------------------------------------------------------------------
 .../main/java/brooklyn/location/jclouds/JcloudsLocation.java | 8 ++++++++
 .../brooklyn/location/jclouds/JcloudsLocationConfig.java     | 5 +++++
 2 files changed, 13 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/aafddb59/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 0916b21..94dfd54 100644
--- 
a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
+++ 
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocation.java
@@ -73,6 +73,8 @@ import org.jclouds.ec2.compute.options.EC2TemplateOptions;
 import 
org.jclouds.googlecomputeengine.compute.options.GoogleComputeEngineTemplateOptions;
 import org.jclouds.openstack.nova.v2_0.compute.options.NovaTemplateOptions;
 import org.jclouds.rest.AuthorizationException;
+import org.jclouds.scriptbuilder.ScriptBuilder;
+import org.jclouds.scriptbuilder.domain.LiteralStatement;
 import org.jclouds.scriptbuilder.domain.Statement;
 import org.jclouds.scriptbuilder.domain.StatementList;
 import org.jclouds.scriptbuilder.domain.Statements;
@@ -1457,6 +1459,12 @@ public class JcloudsLocation extends 
AbstractCloudMachineProvisioningLocation im
             } else if (passwordToSet!=null) {
                 createdUserCreds = 
LoginCredentials.builder().user(user).password(passwordToSet).build();
             }
+
+        }
+        
+        String customTemplateOptionsScript = 
config.get(CUSTOM_TEMPLATE_OPTIONS_SCRIPT_CONTENTS);
+        if (Strings.isNonBlank(customTemplateOptionsScript)) {
+            statements.add(new LiteralStatement(customTemplateOptionsScript));
         }
         
         return new UserCreation(createdUserCreds, statements);

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/aafddb59/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
----------------------------------------------------------------------
diff --git 
a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
 
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
index 4e57fa2..cc70915 100644
--- 
a/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
+++ 
b/locations/jclouds/src/main/java/brooklyn/location/jclouds/JcloudsLocationConfig.java
@@ -85,6 +85,11 @@ public interface JcloudsLocationConfig extends 
CloudLocationConfig {
         "Whether to disable direct SSH access for root and disable 
password-based SSH, "
         + "if creating a user with a key-based login; "
         + "defaults to true (set false to leave root users alone)", true);
+    public static final ConfigKey<String> 
CUSTOM_TEMPLATE_OPTIONS_SCRIPT_CONTENTS = 
ConfigKeys.newStringConfigKey("customTemplateOptionsScriptContents",
+        "A custom script to pass to jclouds as part of template options, run 
after AdminAccess, "
+        + "for use primarily where a command which must run as root on first 
login before switching to the admin user, "
+        + "e.g. to customize sudoers; may start in an odd location (e.g. 
/tmp/bootstrap); "
+        + "NB: most commands should be run by entities, or if VM-specific but 
sudo is okay, then via setup.script, not via this");
     
     public static final ConfigKey<LoginCredentials> CUSTOM_CREDENTIALS = new 
BasicConfigKey<LoginCredentials>(LoginCredentials.class,
             "customCredentials", "Custom jclouds LoginCredentials object to be 
used to connect to the VM", null);

Reply via email to