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.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<OrgAndName, KeyPairCredentials> 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,

View File

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

View File

@ -40,6 +40,7 @@ import org.jclouds.compute.domain.OperatingSystem;
import org.jclouds.compute.util.ComputeServiceUtils;
import org.jclouds.domain.Credentials;
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.domain.KeyPairCredentials;
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()));
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);
}
}
}

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.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<? extends NodeMetadata> 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<OrgAndName> orgGroups = filter(transform(deadOnes, nodeToOrgAndName), notNull());
for (OrgAndName orgGroup : orgGroups) {

View File

@ -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;

View File

@ -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();
}

View File

@ -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<Set<? extends Image>> {
@Override
public Set<? extends Image> get() {
logger.debug(">> providing vAppTemplates");
return newLinkedHashSet(transform(
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();
}
}));
return newLinkedHashSet(concat(transform(organizatonsForLocations.apply(locations.get()), imagesInOrg)));
}
}

View File

@ -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