You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@brooklyn.apache.org by sv...@apache.org on 2016/03/29 10:38:49 UTC

[1/2] brooklyn-server git commit: Windows @ GCE: exec startup script to enable WinRM

Repository: brooklyn-server
Updated Branches:
  refs/heads/master 85770a0d6 -> e171d1b41


Windows @ GCE: exec startup script to enable WinRM

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

Branch: refs/heads/master
Commit: c56f713a3566b7e5f64f0e0ee9c0d1b612d46774
Parents: 660ebbb
Author: Aled Sage <al...@gmail.com>
Authored: Mon Mar 28 23:37:01 2016 +0100
Committer: Aled Sage <al...@gmail.com>
Committed: Mon Mar 28 23:37:01 2016 +0100

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       | 39 +++++++++++++++++++-
 1 file changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/c56f713a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
----------------------------------------------------------------------
diff --git a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
index aebd778..83addb3 100644
--- a/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
+++ b/locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java
@@ -1536,10 +1536,45 @@ public class JcloudsLocation extends AbstractCloudMachineProvisioningLocation im
         }
         TemplateOptions options = template.getOptions();
 
+        // For windows, we need a startup-script to be executed that will enable winrm access.
+        // If there is already conflicting userMetadata, then don't replace it (and just warn).
+        // TODO this injection is hacky and (currently) cloud specific.
         boolean windows = isWindows(template, config);
         if (windows) {
-            if (!(config.containsKey(JcloudsLocationConfig.USER_METADATA_STRING) || config.containsKey(JcloudsLocationConfig.USER_METADATA_MAP))) {
-                config.put(JcloudsLocationConfig.USER_METADATA_STRING, WinRmMachineLocation.getDefaultUserMetadataString(config()));
+            String initScript = WinRmMachineLocation.getDefaultUserMetadataString(config());
+            String provider = getProvider();
+            if ("google-compute-engine".equals(provider)) {
+                // see https://cloud.google.com/compute/docs/startupscript:
+                // Set "sysprep-specialize-script-cmd" in metadata.
+                String startupScriptKey = "sysprep-specialize-script-cmd";
+                Object metadataMapRaw = config.get(USER_METADATA_MAP);
+                if (metadataMapRaw instanceof Map) {
+                    Map<?,?> metadataMap = (Map<?, ?>) metadataMapRaw;
+                    if (metadataMap.containsKey(startupScriptKey)) {
+                        LOG.warn("Not adding startup-script for Windows VM on "+provider+", because already has key "+startupScriptKey+" in config "+USER_METADATA_MAP.getName());
+                    } else {
+                        Map<Object, Object> metadataMapReplacement = MutableMap.copyOf(metadataMap);
+                        metadataMapReplacement.put(startupScriptKey, initScript);
+                        config.put(USER_METADATA_MAP, metadataMapReplacement);
+                        LOG.debug("Adding startup-script to enable WinRM for Windows VM on "+provider);
+                    }
+                } else if (metadataMapRaw == null) {
+                    Map<String, String> metadataMapReplacement = MutableMap.of(startupScriptKey, initScript);
+                    config.put(USER_METADATA_MAP, metadataMapReplacement);
+                    LOG.debug("Adding startup-script to enable WinRM for Windows VM on "+provider);
+                }
+            } else {
+                // For AWS and vCloudDirector, we just set user_metadata_string.
+                // For Azure-classic, there is no capability to execute a startup script.
+                boolean userMetadataString = config.containsKey(JcloudsLocationConfig.USER_METADATA_STRING);
+                boolean userMetadataMap = config.containsKey(JcloudsLocationConfig.USER_METADATA_MAP);
+                if (!(userMetadataString || userMetadataMap)) {
+                    config.put(JcloudsLocationConfig.USER_METADATA_STRING, WinRmMachineLocation.getDefaultUserMetadataString(config()));
+                    LOG.debug("Adding startup-script to enable WinRM for Windows VM on "+provider);
+                } else {
+                    LOG.warn("Not adding startup-script for Windows VM on "+provider+", because already has config "
+                            +(userMetadataString ? USER_METADATA_STRING.getName() : USER_METADATA_MAP.getName()));
+                }
             }
         }
                


[2/2] brooklyn-server git commit: Closes #89

Posted by sv...@apache.org.
Closes #89

Windows @ GCE: exec startup script to enable WinRM

Longer term, we should look at how better to configure a startup script. Different clouds within jclouds seem to use userMetadata in different ways, making our code fiddly.

Note this change isn't enough to get Windows@GCE working. We also need to write some code for generating + retrieving a Windows password. See https://cloud.google.com/compute/docs/instances/automate-pw-generation

If testing, the following location config is also important for users, to avoid jclouds waiting for port 22 to be reachable (and thus failing): `templateOptions: { autoCreateKeyPair: false }`


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

Branch: refs/heads/master
Commit: e171d1b416ba235351d8354ecfa154c1db60be37
Parents: 85770a0 c56f713
Author: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Authored: Tue Mar 29 11:38:24 2016 +0300
Committer: Svetoslav Neykov <sv...@cloudsoftcorp.com>
Committed: Tue Mar 29 11:38:24 2016 +0300

----------------------------------------------------------------------
 .../location/jclouds/JcloudsLocation.java       | 39 +++++++++++++++++++-
 1 file changed, 37 insertions(+), 2 deletions(-)
----------------------------------------------------------------------