cleanup of terremark wrt credentials

This commit is contained in:
Adrian Cole 2011-12-20 23:21:28 -08:00
parent 4def02f00e
commit 57f19a5c68
8 changed files with 18 additions and 60 deletions

View File

@ -20,7 +20,6 @@ package org.jclouds.trmk.vcloud_0_8.compute;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import javax.inject.Inject; import javax.inject.Inject;
@ -51,9 +50,6 @@ import org.jclouds.compute.strategy.SuspendNodeStrategy;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.scriptbuilder.functions.InitAdminAccess; 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.options.TerremarkVCloudTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.compute.strategy.CleanupOrphanKeys; import org.jclouds.trmk.vcloud_0_8.compute.strategy.CleanupOrphanKeys;
@ -81,8 +77,7 @@ public class TerremarkVCloudComputeService extends BaseComputeService {
InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory, InitializeRunScriptOnNodeOrPlaceInBadMap.Factory initScriptRunnerFactory,
RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess, RunScriptOnNode.Factory runScriptOnNodeFactory, InitAdminAccess initAdminAccess,
PersistNodeCredentials persistNodeCredentials, Timeouts timeouts, PersistNodeCredentials persistNodeCredentials, Timeouts timeouts,
@Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, CleanupOrphanKeys cleanupOrphanKeys, @Named(Constants.PROPERTY_USER_THREADS) ExecutorService executor, CleanupOrphanKeys cleanupOrphanKeys) {
ConcurrentMap<OrgAndName, KeyPairCredentials> credentialsMap, NodeMetadataToOrgAndName nodeToOrgAndName) {
super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy, super(context, credentialStore, images, sizes, locations, listNodesStrategy, getNodeMetadataStrategy,
runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy, runNodesAndAddToSetStrategy, rebootNodeStrategy, destroyNodeStrategy, resumeNodeStrategy,
suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated, suspendNodeStrategy, templateBuilderProvider, templateOptionsProvider, nodeRunning, nodeTerminated,

View File

@ -64,7 +64,7 @@ public class ImageForVCloudExpressVAppTemplate implements Function<VAppTemplate,
builder.location(findLocationForResource.apply(checkNotNull(parent, "parent"))); builder.location(findLocationForResource.apply(checkNotNull(parent, "parent")));
builder.description(from.getDescription() != null ? from.getDescription() : from.getName()); builder.description(from.getDescription() != null ? from.getDescription() : from.getName());
builder.operatingSystem(osParser.apply(from.getName())); builder.operatingSystem(osParser.apply(from.getName()));
builder.defaultCredentials(credentialsProvider.execute(from)); builder.defaultCredentials(credentialsProvider.apply(from));
return builder.build(); return builder.build();
} }
} }

View File

@ -40,6 +40,7 @@ import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.util.ComputeServiceUtils; import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.domain.LoginCredentials;
import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeClient; import org.jclouds.trmk.vcloud_0_8.compute.TerremarkVCloudComputeClient;
import org.jclouds.trmk.vcloud_0_8.compute.domain.KeyPairCredentials; 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.domain.OrgAndName;
@ -105,27 +106,18 @@ public class VAppToNodeMetadata implements Function<VApp, NodeMetadata> {
builder.privateAddresses(computeClient.getPrivateAddresses(from.getHref())); builder.privateAddresses(computeClient.getPrivateAddresses(from.getHref()));
String group = parseGroupFromName(from.getName()); String group = parseGroupFromName(from.getName());
builder.group(group); builder.group(group);
// node-specific credentials override those from cache based on group // node-specific credentials override those from cache based on group
if (group != null && !credentialStore.containsKey("node#" + from.getHref().toASCIIString())) { 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);
} else { if (credentialsMap.containsKey(orgAndName)) {
builder.credentials(credentialStore.get("node#" + from.getHref().toASCIIString())); builder.credentials(LoginCredentials.builder(credentialsMap.get(orgAndName)).build());
} }
return builder.build(); } else {
builder.credentials(LoginCredentials.builder(credentialStore.get("node#" + from.getHref().toASCIIString()))
.build());
} }
protected void installCredentialsFromCache(URI nodeId, URI orgId, String group, NodeMetadataBuilder builder) { return builder.build();
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);
}
} }
} }

View File

@ -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.size;
import static com.google.common.collect.Iterables.transform; import static com.google.common.collect.Iterables.transform;
import static org.jclouds.compute.predicates.NodePredicates.TERMINATED; 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.inGroup;
import static org.jclouds.compute.predicates.NodePredicates.parentLocationId;
import java.util.Map; import java.util.Map;
@ -61,11 +61,8 @@ public class CleanupOrphanKeys {
} }
public void execute(Iterable<? extends NodeMetadata> deadOnes) { public void execute(Iterable<? extends NodeMetadata> deadOnes) {
// TODO refactor so that admin passwords are cached properly, probably as a list value in the
// credentialStore
for (NodeMetadata node : deadOnes){ for (NodeMetadata node : deadOnes){
credentialStore.remove("node#" + node.getId()); credentialStore.remove("node#" + node.getId());
credentialStore.remove("node#" + node.getId() + "#adminPassword");
} }
Iterable<OrgAndName> orgGroups = filter(transform(deadOnes, nodeToOrgAndName), notNull()); Iterable<OrgAndName> orgGroups = filter(transform(deadOnes, nodeToOrgAndName), notNull());
for (OrgAndName orgGroup : orgGroups) { for (OrgAndName orgGroup : orgGroups) {

View File

@ -66,7 +66,7 @@ public class ParseVAppTemplateDescriptionToGetDefaultLoginCredentials extends Re
} else { } else {
Matcher matcher = USER_PASSWORD_PATTERN.matcher(search); Matcher matcher = USER_PASSWORD_PATTERN.matcher(search);
if (matcher.find()) { 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 { } else {
logger.warn("could not parse username/password for image: " + template.getHref() + "\n" + search); logger.warn("could not parse username/password for image: " + template.getHref() + "\n" + search);
return null; return null;

View File

@ -65,15 +65,8 @@ public class StartVAppWithGroupEncodedIntoName implements CreateNodeWithGroupEnc
.getImage().getId()), name, options, template.getOptions().getInboundPorts()); .getImage().getId()), name, options, template.getOptions().getInboundPorts());
NodeMetadata node = vAppToNodeMetadata.apply(vApp); NodeMetadata node = vAppToNodeMetadata.apply(vApp);
NodeMetadataBuilder builder = NodeMetadataBuilder.fromNodeMetadata(node); NodeMetadataBuilder builder = NodeMetadataBuilder.fromNodeMetadata(node);
// TODO refactor this so that it is automatic in any provider if (template.getImage().getDefaultCredentials() != null)
if (template.getImage().getAdminPassword() != null) { credentialStore.put("node#" + node.getId(), template.getImage().getDefaultCredentials());
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()));
}
return builder.build(); return builder.build();
} }

View File

@ -31,7 +31,6 @@ import javax.inject.Singleton;
import org.jclouds.collect.Memoized; import org.jclouds.collect.Memoized;
import org.jclouds.compute.domain.Image; import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.ImageBuilder;
import org.jclouds.compute.reference.ComputeServiceConstants; import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.domain.Location; import org.jclouds.domain.Location;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -71,23 +70,6 @@ public class VAppTemplatesInOrgs implements Supplier<Set<? extends Image>> {
@Override @Override
public Set<? extends Image> get() { public Set<? extends Image> get() {
logger.debug(">> providing vAppTemplates"); logger.debug(">> providing vAppTemplates");
return newLinkedHashSet(transform( return newLinkedHashSet(concat(transform(organizatonsForLocations.apply(locations.get()), imagesInOrg)));
concat(transform(organizatonsForLocations.apply(locations.get()), imagesInOrg)),
new Function<Image, Image>() {
@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();
}
}));
} }
} }

View File

@ -20,8 +20,8 @@ package org.jclouds.trmk.ecloud;
import static org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.Builder.processorCount; import static org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions.Builder.processorCount;
import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import java.util.Map.Entry;
import org.jclouds.domain.Credentials; import org.jclouds.domain.Credentials;
import org.jclouds.net.IPSocket; 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.domain.VApp;
import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions; import org.jclouds.trmk.vcloud_0_8.options.InstantiateVAppTemplateOptions;
import org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants; import org.jclouds.trmk.vcloud_0_8.reference.VCloudConstants;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test; import org.testng.annotations.Test;
/** /**
@ -66,7 +65,7 @@ public class TerremarkECloudClientLiveTest extends TerremarkClientLiveTest {
@Override @Override
protected SshClient getConnectionFor(IPSocket socket) { protected SshClient getConnectionFor(IPSocket socket) {
return sshFactory.create(socket, new Credentials("ecloud", "TmrkCl0ud1s#1!")); return sshFactory.create(socket, new Credentials("ecloud", "$Ep455l0ud!2"));
} }
@Override @Override