Repository: jclouds-labs Updated Branches: refs/heads/fix/AzureTemplateBuilderLiveTest [created] 8b6750b49
Fix AzureTemplateBuilderLiveTest - remove default creds for all images Project: http://git-wip-us.apache.org/repos/asf/jclouds-labs/repo Commit: http://git-wip-us.apache.org/repos/asf/jclouds-labs/commit/52d66b00 Tree: http://git-wip-us.apache.org/repos/asf/jclouds-labs/tree/52d66b00 Diff: http://git-wip-us.apache.org/repos/asf/jclouds-labs/diff/52d66b00 Branch: refs/heads/fix/AzureTemplateBuilderLiveTest Commit: 52d66b0059003d215afdd4df0e7c383f1641a873 Parents: c458baf Author: Andrea Turli <[email protected]> Authored: Wed Sep 28 18:20:26 2016 +0200 Committer: Andrea Turli <[email protected]> Committed: Wed Sep 28 20:57:54 2016 +0200 ---------------------------------------------------------------------- azurecompute-arm/pom.xml | 7 +-- .../arm/AzureComputeProviderMetadata.java | 38 ++++++------- .../arm/compute/AzureComputeServiceAdapter.java | 36 ++++-------- .../AzureComputeServiceContextModule.java | 16 +----- .../functions/DeploymentToNodeMetadata.java | 35 +++--------- .../arm/compute/functions/VMImageToImage.java | 30 +++------- ...DefaultLoginCredentialsForImageStrategy.java | 43 -------------- .../arm/util/DeploymentTemplateBuilder.java | 60 +++++--------------- 8 files changed, 61 insertions(+), 204 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/52d66b00/azurecompute-arm/pom.xml ---------------------------------------------------------------------- diff --git a/azurecompute-arm/pom.xml b/azurecompute-arm/pom.xml index df5b835..824e552 100644 --- a/azurecompute-arm/pom.xml +++ b/azurecompute-arm/pom.xml @@ -46,7 +46,7 @@ <dependency> <groupId>org.apache.jclouds</groupId> <artifactId>jclouds-compute</artifactId> - <version>${project.parent.version}</version> + <version>${project.version}</version> </dependency> <dependency> <groupId>com.google.auto.service</groupId> @@ -80,11 +80,6 @@ <groupId>org.apache.jclouds</groupId> <artifactId>jclouds-compute</artifactId> <version>${project.version}</version> - </dependency> - <dependency> - <groupId>org.apache.jclouds</groupId> - <artifactId>jclouds-compute</artifactId> - <version>${project.version}</version> <type>test-jar</type> <scope>test</scope> </dependency> http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/52d66b00/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java index 460df67..98c212f 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/AzureComputeProviderMetadata.java @@ -17,34 +17,31 @@ package org.jclouds.azurecompute.arm; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.IMAGE_PUBLISHERS; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.RESOURCE_GROUP_NAME; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.OPERATION_TIMEOUT; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.OPERATION_POLL_INITIAL_PERIOD; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.OPERATION_POLL_MAX_PERIOD; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TCP_RULE_FORMAT; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TCP_RULE_REGEXP; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_VNET_ADDRESS_SPACE_PREFIX; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_SUBNET_ADDRESS_PREFIX; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_DATADISKSIZE; - -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_IMAGE_LOGIN; - -import static org.jclouds.oauth.v2.config.CredentialType.CLIENT_CREDENTIALS_SECRET; -import static org.jclouds.oauth.v2.config.OAuthProperties.RESOURCE; -import static org.jclouds.oauth.v2.config.OAuthProperties.CREDENTIAL_TYPE; - import java.net.URI; import java.util.Properties; + import org.jclouds.azurecompute.arm.domain.Region; +import org.jclouds.compute.config.ComputeServiceProperties; import org.jclouds.providers.ProviderMetadata; import org.jclouds.providers.internal.BaseProviderMetadata; -import org.jclouds.compute.config.ComputeServiceProperties; - -import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED; import com.google.auto.service.AutoService; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_DATADISKSIZE; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_SUBNET_ADDRESS_PREFIX; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_VNET_ADDRESS_SPACE_PREFIX; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.IMAGE_PUBLISHERS; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.OPERATION_POLL_INITIAL_PERIOD; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.OPERATION_POLL_MAX_PERIOD; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.OPERATION_TIMEOUT; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.RESOURCE_GROUP_NAME; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TCP_RULE_FORMAT; +import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.TCP_RULE_REGEXP; +import static org.jclouds.compute.config.ComputeServiceProperties.TIMEOUT_NODE_TERMINATED; +import static org.jclouds.oauth.v2.config.CredentialType.CLIENT_CREDENTIALS_SECRET; +import static org.jclouds.oauth.v2.config.OAuthProperties.CREDENTIAL_TYPE; +import static org.jclouds.oauth.v2.config.OAuthProperties.RESOURCE; + @AutoService(ProviderMetadata.class) public class AzureComputeProviderMetadata extends BaseProviderMetadata { @@ -77,7 +74,6 @@ public class AzureComputeProviderMetadata extends BaseProviderMetadata { properties.put(DEFAULT_SUBNET_ADDRESS_PREFIX, "10.0.0.0/24"); properties.put(DEFAULT_DATADISKSIZE, "100"); properties.put(IMAGE_PUBLISHERS, "Canonical,RedHat"); - properties.put(DEFAULT_IMAGE_LOGIN, "jclouds:Password1!"); properties.put(TIMEOUT_NODE_TERMINATED, 60 * 10 * 1000); return properties; } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/52d66b00/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java index 61807a9..11a9257 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/AzureComputeServiceAdapter.java @@ -16,11 +16,6 @@ */ package org.jclouds.azurecompute.arm.compute; -import static com.google.common.base.Preconditions.checkState; -import static java.lang.String.format; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.jclouds.util.Predicates2.retry; - import java.util.Collection; import java.util.List; import java.util.Set; @@ -57,7 +52,6 @@ import org.jclouds.azurecompute.arm.util.DeploymentTemplateBuilder; import org.jclouds.compute.ComputeServiceAdapter; import org.jclouds.compute.domain.Template; import org.jclouds.compute.reference.ComputeServiceConstants; -import org.jclouds.domain.LoginCredentials; import org.jclouds.location.Region; import org.jclouds.logging.Logger; @@ -73,6 +67,11 @@ import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import com.google.common.net.UrlEscapers; +import static com.google.common.base.Preconditions.checkState; +import static java.lang.String.format; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.jclouds.util.Predicates2.retry; + /** * Defines the connection between the {@link AzureComputeApi} implementation and the jclouds * {@link org.jclouds.compute.ComputeService}. @@ -80,12 +79,12 @@ import com.google.common.net.UrlEscapers; @Singleton public class AzureComputeServiceAdapter implements ComputeServiceAdapter<VMDeployment, VMHardware, VMImage, Location> { - private String azureGroup; - protected final CleanupResources cleanupResources; - @Resource @Named(ComputeServiceConstants.COMPUTE_LOGGER) private Logger logger = Logger.NULL; + + private String azureGroup; + private final CleanupResources cleanupResources; private final AzureComputeApi api; private final AzureComputeConstants azureComputeConstants; private final Supplier<Set<String>> regionIds; @@ -113,12 +112,7 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<VMDeplo final String group, final String name, final Template template) { DeploymentTemplateBuilder deploymentTemplateBuilder = api.deploymentTemplateFactory().create(group, name, template); - - final String loginUser = DeploymentTemplateBuilder.getLoginUserUsername(); - final String loginPassword = DeploymentTemplateBuilder.getLoginPassword(); - - DeploymentBody deploymentTemplateBody = deploymentTemplateBuilder.getDeploymentTemplate(); - + DeploymentBody deploymentTemplateBody = deploymentTemplateBuilder.getDeploymentTemplate(); DeploymentProperties properties = DeploymentProperties.create(deploymentTemplateBody); final String deploymentTemplate = UrlEscapers.urlFormParameterEscaper().escape(deploymentTemplateBuilder.getDeploymentTemplateJson(properties)); @@ -151,16 +145,8 @@ public class AzureComputeServiceAdapter implements ComputeServiceAdapter<VMDeplo throw new IllegalStateException(illegalStateExceptionMessage); } final VMDeployment deployment = deployments.iterator().next(); - NodeAndInitialCredentials<VMDeployment> credential; - if (template.getOptions().getPublicKey() != null){ - String privateKey = template.getOptions().getPrivateKey(); - credential = new NodeAndInitialCredentials<VMDeployment>(deployment, name, - LoginCredentials.builder().user(loginUser).privateKey(privateKey).authenticateSudo(true).build()); - } else { - credential = new NodeAndInitialCredentials<VMDeployment>(deployment, name, - LoginCredentials.builder().user(loginUser).password(loginPassword).authenticateSudo(true).build()); - } - return credential; + // Safe to pass null credentials here, as jclouds will default populate the node with the default credentials from the image, or the ones in the options, if provided. + return new NodeAndInitialCredentials<VMDeployment>(deployment, name, null); } @Override http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/52d66b00/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/config/AzureComputeServiceContextModule.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/config/AzureComputeServiceContextModule.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/config/AzureComputeServiceContextModule.java index 6033f42..8e0d118 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/config/AzureComputeServiceContextModule.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/config/AzureComputeServiceContextModule.java @@ -32,7 +32,6 @@ import org.jclouds.azurecompute.arm.compute.functions.LocationToLocation; import org.jclouds.azurecompute.arm.compute.functions.VMHardwareToHardware; import org.jclouds.azurecompute.arm.compute.functions.VMImageToImage; import org.jclouds.azurecompute.arm.compute.options.AzureTemplateOptions; -import org.jclouds.azurecompute.arm.compute.strategy.AzurePopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.azurecompute.arm.compute.strategy.CreateResourceGroupThenCreateNodes; import org.jclouds.azurecompute.arm.domain.Location; import org.jclouds.azurecompute.arm.domain.ResourceDefinition; @@ -47,12 +46,13 @@ import org.jclouds.compute.config.ComputeServiceAdapterContextModule; import org.jclouds.compute.domain.Hardware; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.extensions.ImageExtension; +import org.jclouds.compute.functions.NodeAndTemplateOptionsToStatement; +import org.jclouds.compute.functions.NodeAndTemplateOptionsToStatementWithoutPublicKey; import org.jclouds.compute.options.TemplateOptions; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants.PollPeriod; import org.jclouds.compute.reference.ComputeServiceConstants.Timeouts; import org.jclouds.compute.strategy.CreateNodesInGroupThenAddToSet; -import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; import org.jclouds.logging.Logger; import com.google.common.annotations.VisibleForTesting; @@ -64,7 +64,6 @@ import com.google.inject.TypeLiteral; import static com.google.common.base.Preconditions.checkNotNull; import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_DATADISKSIZE; -import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_IMAGE_LOGIN; import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_SUBNET_ADDRESS_PREFIX; import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.DEFAULT_VNET_ADDRESS_SPACE_PREFIX; import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.IMAGE_PUBLISHERS; @@ -105,8 +104,7 @@ public class AzureComputeServiceContextModule }); bind(TemplateOptions.class).to(AzureTemplateOptions.class); - bind(PopulateDefaultLoginCredentialsForImageStrategy.class).to(AzurePopulateDefaultLoginCredentialsForImageStrategy.class); - //bind(TemplateOptionsToStatement.class).to(TemplateOptionsToStatementWithoutPublicKey.class); + bind(NodeAndTemplateOptionsToStatement.class).to(NodeAndTemplateOptionsToStatementWithoutPublicKey.class); bind(CreateNodesInGroupThenAddToSet.class).to(CreateResourceGroupThenCreateNodes.class); bind(new TypeLiteral<ImageExtension>() { }).to(AzureComputeImageExtension.class); @@ -143,10 +141,6 @@ public class AzureComputeServiceContextModule @Inject private String azureImagePublishersProperty; - @Named(DEFAULT_IMAGE_LOGIN) - @Inject - private String azureDefaultImageLoginProperty; - @Named(DEFAULT_VNET_ADDRESS_SPACE_PREFIX) @Inject private String azureDefaultVnetAddressPrefixProperty; @@ -171,10 +165,6 @@ public class AzureComputeServiceContextModule return azureImagePublishersProperty; } - public String azureDefaultImageLogin() { - return azureDefaultImageLoginProperty; - } - public String azureDefaultVnetAddressPrefixProperty() { return azureDefaultVnetAddressPrefixProperty; } http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/52d66b00/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToNodeMetadata.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToNodeMetadata.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToNodeMetadata.java index 532e786..ba6ce6d 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToNodeMetadata.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/DeploymentToNodeMetadata.java @@ -22,7 +22,6 @@ import java.util.Set; import javax.inject.Inject; -import com.google.common.collect.Sets; import org.jclouds.azurecompute.arm.AzureComputeApi; import org.jclouds.azurecompute.arm.domain.ComputeNode; import org.jclouds.azurecompute.arm.domain.Deployment; @@ -35,25 +34,22 @@ import org.jclouds.azurecompute.arm.domain.VMHardware; import org.jclouds.azurecompute.arm.domain.VMImage; import org.jclouds.azurecompute.arm.domain.VMSize; import org.jclouds.azurecompute.arm.domain.VirtualMachineInstance; -import org.jclouds.azurecompute.arm.util.DeploymentTemplateBuilder; import org.jclouds.azurecompute.arm.util.GetEnumValue; +import org.jclouds.compute.domain.Hardware; +import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.NodeMetadata; import org.jclouds.compute.domain.NodeMetadataBuilder; import org.jclouds.compute.functions.GroupNamingConvention; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; +import org.jclouds.domain.LoginCredentials; + import com.google.common.base.Function; import com.google.common.collect.ImmutableMap; -import org.jclouds.domain.LoginCredentials; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.Hardware; +import com.google.common.collect.Sets; public class DeploymentToNodeMetadata implements Function<VMDeployment, NodeMetadata> { - public static final String JCLOUDS_DEFAULT_USERNAME = "root"; - public static final String AZURE_LOGIN_USERNAME = DeploymentTemplateBuilder.getLoginUserUsername(); - public static final String AZURE_LOGIN_PASSWORD = DeploymentTemplateBuilder.getLoginPassword(); - private static final Map<ComputeNode.Status, NodeMetadata.Status> INSTANCESTATUS_TO_NODESTATUS = ImmutableMap.<ComputeNode.Status, NodeMetadata.Status>builder(). put(ComputeNode.Status.GOOD, NodeMetadata.Status.RUNNING). @@ -84,15 +80,10 @@ public class DeploymentToNodeMetadata implements Function<VMDeployment, NodeMeta } private final AzureComputeApi api; - private final LocationToLocation locationToLocation; - private final GroupNamingConvention nodeNamingConvention; - private final VMImageToImage vmImageToImage; - private final VMHardwareToHardware vmHardwareToHardware; - private final Map<String, Credentials> credentialStore; @Inject @@ -146,20 +137,8 @@ public class DeploymentToNodeMetadata implements Function<VMDeployment, NodeMeta } Credentials credentials = credentialStore.get("node#" + from.deployment().name()); - if (credentials != null && credentials.identity.equals(JCLOUDS_DEFAULT_USERNAME)) { - credentials = new Credentials(AZURE_LOGIN_USERNAME, credentials.credential); - } - else if (credentials == null) { - String username = AZURE_LOGIN_USERNAME; - String password = AZURE_LOGIN_PASSWORD; - if (username == null) { - username = "jclouds"; - } - if (password == null) { - password = "Password1!"; - } - - credentials = new Credentials(username, password); + if (credentials != null) { + builder.credentials(LoginCredentials.fromCredentials(credentials)); } builder.credentials(LoginCredentials.fromCredentials(credentials)); http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/52d66b00/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VMImageToImage.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VMImageToImage.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VMImageToImage.java index f784842..b515959 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VMImageToImage.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/functions/VMImageToImage.java @@ -16,48 +16,35 @@ */ package org.jclouds.azurecompute.arm.compute.functions; -import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.azurecompute.arm.compute.functions.DeploymentToNodeMetadata.AZURE_LOGIN_PASSWORD; -import static org.jclouds.azurecompute.arm.compute.functions.DeploymentToNodeMetadata.AZURE_LOGIN_USERNAME; +import java.util.Set; -import com.google.common.base.Supplier; -import com.google.common.collect.FluentIterable; import org.jclouds.azurecompute.arm.domain.VMImage; import org.jclouds.collect.Memoized; import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.domain.OperatingSystem; import org.jclouds.compute.domain.OsFamily; +import org.jclouds.domain.Location; +import org.jclouds.location.predicates.LocationPredicates; import com.google.common.base.Function; +import com.google.common.base.Supplier; +import com.google.common.collect.FluentIterable; import com.google.inject.Inject; -import org.jclouds.domain.Credentials; -import org.jclouds.domain.Location; -import org.jclouds.domain.LoginCredentials; -import org.jclouds.location.predicates.LocationPredicates; -import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; public class VMImageToImage implements Function<VMImage, Image> { private static final String UNRECOGNIZED = "UNRECOGNIZED"; - private static final String UBUNTU = "Ubuntu"; - private static final String WINDOWS = "Windows"; - private static final String OPENLOGIC = "openLogic"; - private static final String CENTOS = "CentOS"; - private static final String COREOS = "CoreOS"; - private static final String OPENSUSE = "openSUSE"; - private static final String SUSE = "SUSE"; - private static final String SQL_SERVER = "SQL Server"; - private static final String ORACLE_lINUX = "Oracle Linux"; private final Supplier<Set<? extends org.jclouds.domain.Location>> locations; @@ -103,7 +90,6 @@ public class VMImageToImage implements Function<VMImage, Image> { @Override public Image apply(final VMImage image) { - Credentials credentials = new Credentials(AZURE_LOGIN_USERNAME, AZURE_LOGIN_PASSWORD); if (image.custom()) { final ImageBuilder builder = new ImageBuilder() @@ -115,8 +101,7 @@ public class VMImageToImage implements Function<VMImage, Image> { .status(Image.Status.AVAILABLE) .version(image.storage()) .providerId(image.vhd1()) - .id(encodeFieldsToUniqueIdCustom(image)) - .defaultCredentials(LoginCredentials.fromCredentials(credentials)); + .id(encodeFieldsToUniqueIdCustom(image)); final OperatingSystem.Builder osBuilder = osFamily().apply(image); Image retimage = builder.operatingSystem(osBuilder.build()).build(); @@ -130,7 +115,6 @@ public class VMImageToImage implements Function<VMImage, Image> { .status(Image.Status.AVAILABLE) .version(image.sku()) .id(encodeFieldsToUniqueId(image)) - .defaultCredentials(LoginCredentials.fromCredentials(credentials)) .providerId(image.publisher()) .location(image.globallyAvailable() ? null : FluentIterable.from(locations.get()) .firstMatch(LocationPredicates.idEquals(image.location())) http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/52d66b00/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/strategy/AzurePopulateDefaultLoginCredentialsForImageStrategy.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/strategy/AzurePopulateDefaultLoginCredentialsForImageStrategy.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/strategy/AzurePopulateDefaultLoginCredentialsForImageStrategy.java deleted file mode 100644 index 55d1a3c..0000000 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/compute/strategy/AzurePopulateDefaultLoginCredentialsForImageStrategy.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.azurecompute.arm.compute.strategy; - -import org.jclouds.compute.domain.internal.ImageImpl; -import org.jclouds.compute.strategy.PopulateDefaultLoginCredentialsForImageStrategy; -import org.jclouds.domain.Credentials; -import org.jclouds.domain.LoginCredentials; - -import static org.jclouds.azurecompute.arm.compute.functions.DeploymentToNodeMetadata.AZURE_LOGIN_PASSWORD; -import static org.jclouds.azurecompute.arm.compute.functions.DeploymentToNodeMetadata.AZURE_LOGIN_USERNAME; - -public class AzurePopulateDefaultLoginCredentialsForImageStrategy implements PopulateDefaultLoginCredentialsForImageStrategy { - @Override - public LoginCredentials apply(Object o) { - ImageImpl node = (ImageImpl)o; - String username = AZURE_LOGIN_USERNAME; - String password = AZURE_LOGIN_PASSWORD; - if (username == null) { - username = "jclouds"; - } - if (password == null) { - password = "Password1!"; - } - Credentials creds = new Credentials(username, password); - LoginCredentials credentials = LoginCredentials.fromCredentials(creds); - return credentials; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/52d66b00/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/DeploymentTemplateBuilder.java ---------------------------------------------------------------------- diff --git a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/DeploymentTemplateBuilder.java b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/DeploymentTemplateBuilder.java index e5b0a43..31fa6bc 100644 --- a/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/DeploymentTemplateBuilder.java +++ b/azurecompute-arm/src/main/java/org/jclouds/azurecompute/arm/util/DeploymentTemplateBuilder.java @@ -54,10 +54,12 @@ import org.jclouds.azurecompute.arm.domain.TemplateParameterType; import org.jclouds.azurecompute.arm.domain.VHD; import org.jclouds.azurecompute.arm.domain.VirtualMachineProperties; import org.jclouds.compute.domain.Template; +import org.jclouds.domain.LoginCredentials; import org.jclouds.json.Json; import org.jclouds.predicates.Validator; import org.jclouds.predicates.validators.DnsNameValidator; +import com.google.common.base.Function; import com.google.common.base.Joiner; import com.google.common.base.Preconditions; import com.google.common.base.Strings; @@ -65,7 +67,6 @@ import com.google.common.collect.Lists; import com.google.inject.Inject; import com.google.inject.assistedinject.Assisted; -import static com.google.common.io.BaseEncoding.base64; import static org.jclouds.azurecompute.arm.compute.extensions.AzureComputeImageExtension.CUSTOM_IMAGE_PREFIX; import static org.jclouds.azurecompute.arm.config.AzureComputeProperties.STORAGE_API_VERSION; @@ -75,28 +76,23 @@ public class DeploymentTemplateBuilder { } private final String name; - private final String azureGroup; - private final String group; private final Template template; private final Json json; + private final LoginCredentials loginCredentials; private AzureTemplateOptions options; private Iterable<String> tags; private Map<String, String> userMetaData; private List<ResourceDefinition> resources; private Map<String, String> variables; - private static String loginUser; - private static String loginPassword; private String location; private AzureComputeServiceContextModule.AzureComputeConstants azureComputeConstants; private static final String DEPLOYMENT_MODE = "Incremental"; @Inject - DeploymentTemplateBuilder(Json json, @Assisted("group") String group, @Assisted("name") String name, @Assisted Template template, - final AzureComputeServiceContextModule.AzureComputeConstants azureComputeConstants) { + DeploymentTemplateBuilder(Json json, @Assisted("group") String group, @Assisted("name") String name, @Assisted Template template, Function<Template, LoginCredentials> templateToLoginCredentials) { this.name = name; - this.group = group; this.template = template; this.options = template.getOptions().as(AzureTemplateOptions.class); this.tags = template.getOptions().getTags(); @@ -105,29 +101,7 @@ public class DeploymentTemplateBuilder { this.resources = new ArrayList<ResourceDefinition>(); this.location = template.getLocation().getId(); this.json = json; - - this.azureComputeConstants = azureComputeConstants; - this.azureGroup = this.azureComputeConstants.azureResourceGroup(); - - String[] defaultLogin = this.azureComputeConstants.azureDefaultImageLogin().split(":"); - String defaultUser = null; - String defaultPassword = null; - - if (defaultLogin.length == 2) { - defaultUser = defaultLogin[0].trim(); - defaultPassword = defaultLogin[1].trim(); - } - - loginUser = options.getLoginUser() == null ? defaultUser : options.getLoginUser(); - loginPassword = options.getLoginPassword() == null ? defaultPassword : options.getLoginPassword(); - } - - public static String getLoginUserUsername() { - return loginUser; - } - - public static String getLoginPassword() { - return loginPassword; + this.loginCredentials = templateToLoginCredentials.apply(template); } public Template getTemplate() { @@ -378,28 +352,24 @@ public class DeploymentTemplateBuilder { //Build OS Profile final String computerName = name + "pc"; - variables.put("loginUser", loginUser); + variables.put("loginUser", loginCredentials.getUser()); OSProfile.Builder profileBuilder = OSProfile.builder() - .adminUsername(loginUser) + .adminUsername(loginCredentials.getUser()) .computerName(computerName); - profileBuilder.adminPassword(loginPassword); - //boolean usePublicKey = options.getPublicKey() != null; + boolean usePublicKey = options.getPublicKey() != null; - if (keyVaultInUse()) { - OSProfile.LinuxConfiguration configuration = OSProfile.LinuxConfiguration.create("false", + if (usePublicKey) { + OSProfile.LinuxConfiguration configuration = OSProfile.LinuxConfiguration.create("true", OSProfile.LinuxConfiguration.SSH.create(Arrays.asList( OSProfile.LinuxConfiguration.SSH.SSHPublicKey.create( "[concat('/home/',variables('loginUser'),'/.ssh/authorized_keys')]", - "[parameters('publicKeyFromAzureKeyVault')]" - )) - )); + options.getPublicKey()) + )) + ); profileBuilder.linuxConfiguration(configuration); - } - - if (!Strings.isNullOrEmpty(options.getCustomData())){ - String encodedCustomData = base64().encode(options.getCustomData().getBytes()); - profileBuilder.customData(encodedCustomData); + } else if (loginCredentials.getOptionalPassword().isPresent()) { + profileBuilder.adminPassword(loginCredentials.getOptionalPassword().get()); } OSProfile osProfile = profileBuilder.build();
