[
https://issues.apache.org/jira/browse/JCLOUDS-861?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14532802#comment-14532802
]
Stuart Hendren commented on JCLOUDS-861:
----------------------------------------
The following example, based on the jclouds example (stripped down), shows the
problem.
You need to provide the service account email address and path to the pem file,
as you would expect.
The centos-7 instance is created but fails to authenticate the generated key.
Swapping to the commented debian-7-wheezy image works.
{code:title=CreateServerErrorExample.java|borderStyle=solid}
package com.example;
import static java.util.concurrent.TimeUnit.SECONDS;
import static
org.jclouds.compute.config.ComputeServiceProperties.POLL_INITIAL_PERIOD;
import static
org.jclouds.compute.config.ComputeServiceProperties.POLL_MAX_PERIOD;
import java.io.Closeable;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.TimeoutException;
import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.RunNodesException;
import org.jclouds.compute.domain.Hardware;
import org.jclouds.compute.domain.Image;
import org.jclouds.compute.domain.NodeMetadata;
import org.jclouds.compute.domain.Template;
import org.jclouds.sshj.config.SshjSshClientModule;
import com.google.common.collect.ImmutableSet;
import com.google.common.io.Closeables;
import com.google.common.io.Files;
import com.google.inject.Module;
public class CreateServerErrorExample implements Closeable {
private static final String PROVIDER = "google-compute-engine";
private static final String ZONE = "europe-west1-b";
private static final String PROFILE = "f1-micro";
// private static final String IMAGE = "debian-7-wheezy";
private static final String IMAGE = "centos-7";
private static final String NAME = "jclouds-example";
private static final String POLL_PERIOD_TWENTY_SECONDS =
String.valueOf(SECONDS.toMillis(20));
private final ComputeService computeService;
public static void main(final String[] args) {
String serviceAccountEmailAddress = args[0];
String serviceAccountKey = null;
try {
serviceAccountKey = Files.toString(new File(args[1]),
Charset.defaultCharset());
} catch (IOException e) {
System.err.println("Cannot open service account private
key PEM file: " + args[1] + "\n" + e.getMessage());
System.exit(1);
}
CreateServerErrorExample createServer = new
CreateServerErrorExample(serviceAccountEmailAddress,
serviceAccountKey);
try {
createServer.createServer();
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
createServer.close();
} catch (IOException e) {
e.printStackTrace();
System.exit(1);
}
}
}
public CreateServerErrorExample(final String
serviceAccountEmailAddress, final String serviceAccountKey) {
Properties overrides = new Properties();
overrides.setProperty(POLL_INITIAL_PERIOD,
POLL_PERIOD_TWENTY_SECONDS);
overrides.setProperty(POLL_MAX_PERIOD,
POLL_PERIOD_TWENTY_SECONDS);
Iterable<Module> modules = ImmutableSet.<Module> of(new
SshjSshClientModule());
ComputeServiceContext context =
ContextBuilder.newBuilder(PROVIDER)
.credentials(serviceAccountEmailAddress,
serviceAccountKey)
.modules(modules)
.overrides(overrides)
.buildView(ComputeServiceContext.class);
computeService = context.getComputeService();
}
private void createServer()
throws RunNodesException, TimeoutException, IOException
{
Template template = computeService.templateBuilder()
.locationId(ZONE)
.hardwareId(getHardware().getId())
.imageId(getImage().getId())
.build();
Set<? extends NodeMetadata> nodes =
computeService.createNodesInGroup(NAME, 1, template);
NodeMetadata nodeMetadata = nodes.iterator().next();
String publicAddress =
nodeMetadata.getPublicAddresses().iterator().next();
System.out.format(" %s%n", nodeMetadata);
System.out.format(" Instance %s started with IP %s%n",
nodeMetadata.getName(), publicAddress);
System.out.format(" Username %s",
nodeMetadata.getCredentials().identity);
System.out.format(" Key %s ",
nodeMetadata.getCredentials().credential);
}
private Hardware getHardware() {
for (Hardware profile : computeService.listHardwareProfiles()) {
if (ZONE.equals(profile.getLocation().getId()) &&
PROFILE.equals(profile.getName())) {
return profile;
}
}
return null;
}
private Image getImage() {
for (Image image : computeService.listImages()) {
if (image.getName().startsWith(IMAGE)) {
return image;
}
}
return null;
}
@Override
public final void close() throws IOException {
Closeables.close(computeService.getContext(), true);
}
}
{code}
> node creation fails due to ssh failure
> --------------------------------------
>
> Key: JCLOUDS-861
> URL: https://issues.apache.org/jira/browse/JCLOUDS-861
> Project: jclouds
> Issue Type: Bug
> Components: jclouds-labs-google
> Reporter: Yaron Rosenbaum
> Priority: Blocker
>
> I am creating CoreOS nodes, and using cloud-init with them. The cloud-init
> takes a while to process.
> 11:42:32.780 [user thread 3] ERROR jclouds.ssh - <<
> (core:rsa[ssh-agent]@1….2) error acquiring {hostAndPort=1…2:22,
> loginUser=core, ssh=null, connectTimeout=60000, sessionTimeout=60000} (not
> retryable): Exhausted available authentication methods
> net.schmizz.sshj.userauth.UserAuthException: Exhausted available
> authentication methods
> I’ve set the following overrides:
>
> overrides.setProperty(ComputeServiceProperties.POLL_INITIAL_PERIOD,
> TWENTY_SECONDS);
> overrides.setProperty(ComputeServiceProperties.POLL_MAX_PERIOD,
> TWENTY_SECONDS);
> // 18 retries of 15 seconds --> 4.5 min
> overrides.setProperty(Constants.PROPERTY_MAX_RETRIES, "6");
> overrides.setProperty(Constants.PROPERTY_RETRY_DELAY_START, "15");
> These overrides had no effect.
> overrides.setProperty("jclouds.ssh.max-retries", "100");
> overrides.setProperty("jclouds.ssh.retry-auth", "true");
> These overrides worked - ssh retries for 100 times, but: the sleep time
> between retries is 2s (which should be exponential backoff, and configurable)
> and - eventually locks down the ssh agent for "too many retries"
> (the ssh agent is up, it's only that the ssh key was not installed yet...)
> My workaround is to install ssh keys as part of cloud-init, and then
> everything works ok, but this is a serious bug, and this workaround will not
> work in all cases.
> This MAY be related to:
> https://github.com/jclouds/jclouds-labs-google/pull/118
> PS.
> I setup cloud-init by setting user metadata “user-data”=<the content of the
> cloud-init.yaml file>.
> cloud-init works, node IS accessible via ssh, and my unit files are up and
> running.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)