Return-Path: X-Original-To: apmail-brooklyn-dev-archive@minotaur.apache.org Delivered-To: apmail-brooklyn-dev-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id ECA8F19EE1 for ; Tue, 29 Mar 2016 10:59:48 +0000 (UTC) Received: (qmail 83361 invoked by uid 500); 29 Mar 2016 10:59:48 -0000 Delivered-To: apmail-brooklyn-dev-archive@brooklyn.apache.org Received: (qmail 83331 invoked by uid 500); 29 Mar 2016 10:59:48 -0000 Mailing-List: contact dev-help@brooklyn.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@brooklyn.apache.org Delivered-To: mailing list dev@brooklyn.apache.org Received: (qmail 83320 invoked by uid 99); 29 Mar 2016 10:59:48 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 29 Mar 2016 10:59:48 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 6823EDFF10; Tue, 29 Mar 2016 10:59:48 +0000 (UTC) From: aledsage To: dev@brooklyn.apache.org Reply-To: dev@brooklyn.apache.org References: In-Reply-To: Subject: [GitHub] brooklyn-server pull request: Windows @ GCE: exec startup script t... Content-Type: text/plain Message-Id: <20160329105948.6823EDFF10@git1-us-west.apache.org> Date: Tue, 29 Mar 2016 10:59:48 +0000 (UTC) Github user aledsage commented on a diff in the pull request: https://github.com/apache/brooklyn-server/pull/89#discussion_r57705093 --- Diff: locations/jclouds/src/main/java/org/apache/brooklyn/location/jclouds/JcloudsLocation.java --- @@ -1536,10 +1536,45 @@ public Template buildTemplate(ComputeService computeService, ConfigBag config) { } 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 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 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)) { --- End diff -- Yes, it would have been (I left the names as-is). Feel free to rename that in a new PR. --- If your project is set up for it, you can reply to this email and have your reply appear on GitHub as well. If your project does not have this feature enabled and wishes so, or if the feature is enabled but not working, please contact infrastructure at infrastructure@apache.org or file a JIRA ticket with INFRA. ---