From 57f19a5c6859d5247402ef64952fe68b19f0b07f Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 20 Dec 2011 23:21:28 -0800 Subject: [PATCH] cleanup of terremark wrt credentials --- .../TerremarkVCloudComputeService.java | 7 +---- .../ImageForVCloudExpressVAppTemplate.java | 2 +- .../compute/functions/VAppToNodeMetadata.java | 26 +++++++------------ .../compute/strategy/CleanupOrphanKeys.java | 5 +--- ...scriptionToGetDefaultLoginCredentials.java | 2 +- .../StartVAppWithGroupEncodedIntoName.java | 11 ++------ .../suppliers/VAppTemplatesInOrgs.java | 20 +------------- .../ecloud/TerremarkECloudClientLiveTest.java | 5 ++-- 8 files changed, 18 insertions(+), 60 deletions(-) diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/TerremarkVCloudComputeService.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/TerremarkVCloudComputeService.java index ae99bcdc02..590c02a995 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/TerremarkVCloudComputeService.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/TerremarkVCloudComputeService.java @@ -20,7 +20,6 @@ package org.jclouds.trmk.vcloud_0_8.compute; import java.util.Map; import java.util.Set; -import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ExecutorService; import javax.inject.Inject; @@ -51,9 +50,6 @@ import org.jclouds.compute.strategy.SuspendNodeStrategy; import org.jclouds.domain.Credentials; import org.jclouds.domain.Location; import org.jclouds.scriptbuilder.functions.InitAdminAccess; -import org.jclouds.trmk.vcloud_0_8.compute.domain.KeyPairCredentials; -import org.jclouds.trmk.vcloud_0_8.compute.domain.OrgAndName; -import org.jclouds.trmk.vcloud_0_8.compute.functions.NodeMetadataToOrgAndName; import org.jclouds.trmk.vcloud_0_8.compute.options.TerremarkVCloudTemplateOptions; import org.jclouds.trmk.vcloud_0_8.compute.strategy.CleanupOrphanKeys; @@ -81,8 +77,7 @@ public class TerremarkVCloudComputeService extends BaseComputeService { InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess, PersistNodeCredentials persistNodeCredentials, Timeouts timeouts, - @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, CleanupOrphanKeys cleanupOrphanKeys, - ConcurrentMap credentialsMap, NodeMetadataToOrgAndName nodeToOrgAndName) { + @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, CleanupOrphanKeys cleanupOrphanKeys) { super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/functions/ImageForVCloudExpressVAppTemplate.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/functions/ImageForVCloudExpressVAppTemplate.java index cc92b241da..219a49f874 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/functions/ImageForVCloudExpressVAppTemplate.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/functions/ImageForVCloudExpressVAppTemplate.java @@ -64,7 +64,7 @@ public class ImageForVCloudExpressVAppTemplate implements Function { builder.privateAddresses(computeClient.getPrivateAddresses(from.getHref())); String group = parseGroupFromName(from.getName()); builder.group(group); + // node-specific credentials override those from cache based on group if (group != null && !credentialStore.containsKey("node#" + from.getHref().toASCIIString())) { - installCredentialsFromCache(from.getHref(), URI.create(vdcLocation.getParent().getId()), group, builder); + OrgAndName orgAndName = new OrgAndName(URI.create(vdcLocation.getParent().getId()), group); + if (credentialsMap.containsKey(orgAndName)) { + builder.credentials(LoginCredentials.builder(credentialsMap.get(orgAndName)).build()); + } } else { - builder.credentials(credentialStore.get("node#" + from.getHref().toASCIIString())); + builder.credentials(LoginCredentials.builder(credentialStore.get("node#" + from.getHref().toASCIIString())) + .build()); } + return builder.build(); } - - protected void installCredentialsFromCache(URI nodeId, URI orgId, String group, NodeMetadataBuilder builder) { - OrgAndName orgAndName = new OrgAndName(orgId, group); - if (credentialsMap.containsKey(orgAndName)) { - Credentials creds = credentialsMap.get(orgAndName); - builder.credentials(creds); - credentialStore.put("node#" + nodeId, creds); - } - // this is going to need refactoring.. we really need a credential list in - // the store per node. - String adminPasswordKey = "node#" + nodeId + "#adminPassword"; - if (credentialStore.containsKey(adminPasswordKey)) { - builder.adminPassword(credentialStore.get(adminPasswordKey).credential); - } - } } \ No newline at end of file diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/CleanupOrphanKeys.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/CleanupOrphanKeys.java index 5867d17125..b3797f9bdd 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/CleanupOrphanKeys.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/CleanupOrphanKeys.java @@ -24,8 +24,8 @@ import static com.google.common.collect.Iterables.filter; import static com.google.common.collect.Iterables.size; import static com.google.common.collect.Iterables.transform; import static org.jclouds.compute.predicates.NodePredicates.TERMINATED; -import static org.jclouds.compute.predicates.NodePredicates.parentLocationId; import static org.jclouds.compute.predicates.NodePredicates.inGroup; +import static org.jclouds.compute.predicates.NodePredicates.parentLocationId; import java.util.Map; @@ -61,11 +61,8 @@ public class CleanupOrphanKeys { } public void execute(Iterable deadOnes) { - // TODO refactor so that admin passwords are cached properly, probably as a list value in the - // credentialStore for (NodeMetadata node : deadOnes){ credentialStore.remove("node#" + node.getId()); - credentialStore.remove("node#" + node.getId() + "#adminPassword"); } Iterable orgGroups = filter(transform(deadOnes, nodeToOrgAndName), notNull()); for (OrgAndName orgGroup : orgGroups) { diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.java index 51bb55b8cc..2dda033169 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/ParseVAppTemplateDescriptionToGetDefaultLoginCredentials.java @@ -66,7 +66,7 @@ public class ParseVAppTemplateDescriptionToGetDefaultLoginCredentials extends Re } else { Matcher matcher = USER_PASSWORD_PATTERN.matcher(search); if (matcher.find()) { - return LoginCredentials.builder().user(matcher.group(1)).password(matcher.group(2)).build(); + return LoginCredentials.builder().user(matcher.group(1)).password(matcher.group(2)).authenticateSudo(true).build(); } else { logger.warn("could not parse username/password for image: " + template.getHref() + "\n" + search); return null; diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/StartVAppWithGroupEncodedIntoName.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/StartVAppWithGroupEncodedIntoName.java index bde6e381b2..cae27a6664 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/StartVAppWithGroupEncodedIntoName.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/strategy/StartVAppWithGroupEncodedIntoName.java @@ -65,15 +65,8 @@ public class StartVAppWithGroupEncodedIntoName implements CreateNodeWithGroupEnc .getImage().getId()), name, options, template.getOptions().getInboundPorts()); NodeMetadata node = vAppToNodeMetadata.apply(vApp); NodeMetadataBuilder builder = NodeMetadataBuilder.fromNodeMetadata(node); - // TODO refactor this so that it is automatic in any provider - if (template.getImage().getAdminPassword() != null) { - builder.adminPassword(template.getImage().getAdminPassword()); - // this is going to need refactoring.. we really need a credential list in the store per - // node. we need to store the credential here explicitly, as there's no connection from a node - // in vcloud to the image it was created with. - credentialStore.put("node#" + node.getId() + "#adminPassword", new Credentials("root", template.getImage() - .getAdminPassword())); - } + if (template.getImage().getDefaultCredentials() != null) + credentialStore.put("node#" + node.getId(), template.getImage().getDefaultCredentials()); return builder.build(); } diff --git a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/VAppTemplatesInOrgs.java b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/VAppTemplatesInOrgs.java index 0d92f1ed34..abab3a76ab 100644 --- a/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/VAppTemplatesInOrgs.java +++ b/common/trmk/src/main/java/org/jclouds/trmk/vcloud_0_8/compute/suppliers/VAppTemplatesInOrgs.java @@ -31,7 +31,6 @@ import javax.inject.Singleton; import org.jclouds.collect.Memoized; import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.ImageBuilder; import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.domain.Location; import org.jclouds.logging.Logger; @@ -71,23 +70,6 @@ public class VAppTemplatesInOrgs implements Supplier> { @Override public Set get() { logger.debug(">> providing vAppTemplates"); - return newLinkedHashSet(transform( - concat(transform(organizatonsForLocations.apply(locations.get()), imagesInOrg)), - new Function() { - - @Override - public Image apply(Image from) { - ImageBuilder builder = ImageBuilder.fromImage(from); - // the password in the image is the sudo password - // TODO refactor authenticate image logic so that it can populate the - // adminPassword - // value - // independently - if (from.getDefaultCredentials() != null) - builder.adminPassword(from.getDefaultCredentials().credential); - return builder.build(); - } - - })); + return newLinkedHashSet(concat(transform(organizatonsForLocations.apply(locations.get()), imagesInOrg))); } } \ No newline at end of file diff --git a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java index c1c81736dc..de207758ae 100644 --- a/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java +++ b/providers/trmk-ecloud/src/test/java/org/jclouds/trmk/ecloud/TerremarkECloudClientLiveTest.java @@ -20,8 +20,8 @@ package org.jclouds.trmk.ecloud; import static org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.Builder.processorCount; -import java.util.Map.Entry; import java.util.Properties; +import java.util.Map.Entry; import org.jclouds.domain.Credentials; import org.jclouds.net.IPSocket; @@ -34,7 +34,6 @@ import org.jclouds.trmk.vcloud_0_8.domain.PublicIpAddress; import org.jclouds.trmk.vcloud_0_8.domain.VApp; import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions; import org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; /** @@ -66,7 +65,7 @@ public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest { @Override protected SshClient getConnectionFor(IPSocket socket) { - return sshFactory.create(socket, new Credentials("ecloud", "TmrkCl0ud1s#1!")); + return sshFactory.create(socket, new Credentials("ecloud", "$Ep455l0ud!2")); } @Override