Issue 587:workaround clouds who do not have sftp enabled

This commit is contained in:
Adrian Cole 2011-06-01 12:03:19 -07:00
parent ac698c33ec
commit e1b8110b12
4 changed files with 40 additions and 7 deletions

View File

@ -32,13 +32,17 @@ import org.jclouds.compute.options.RunScriptOptions;
import org.jclouds.compute.reference.ComputeServiceConstants;
import org.jclouds.logging.Logger;
import org.jclouds.scriptbuilder.InitBuilder;
import org.jclouds.scriptbuilder.domain.AppendFile;
import org.jclouds.scriptbuilder.domain.OsFamily;
import org.jclouds.scriptbuilder.domain.Statement;
import org.jclouds.scriptbuilder.domain.Statements;
import org.jclouds.ssh.SshClient;
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Function;
import com.google.common.base.Objects;
import com.google.common.base.Splitter;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;
import com.google.inject.assistedinject.AssistedInject;
@ -47,6 +51,7 @@ import com.google.inject.assistedinject.AssistedInject;
* @author Adrian Cole
*/
public class RunScriptOnNodeAsInitScriptUsingSsh implements RunScriptOnNode {
public static final String PROPERTY_PUSH_INIT_SCRIPT_VIA_SFTP = "jclouds.compute.push-init-script-via-sftp";
@Resource
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
protected Logger logger = Logger.NULL;
@ -59,6 +64,14 @@ public class RunScriptOnNodeAsInitScriptUsingSsh implements RunScriptOnNode {
protected SshClient ssh;
/**
* true to use sftp, false to use ssh. If there's a problem with the sftp configuration, setting
* this to false will help.
*/
@Inject(optional = true)
@Named(PROPERTY_PUSH_INIT_SCRIPT_VIA_SFTP)
private boolean pushInitViaSftp = true;
@AssistedInject
public RunScriptOnNodeAsInitScriptUsingSsh(Function<NodeMetadata, SshClient> sshFactory,
@Assisted NodeMetadata node, @Assisted Statement script, @Assisted RunScriptOptions options) {
@ -104,7 +117,13 @@ public class RunScriptOnNodeAsInitScriptUsingSsh implements RunScriptOnNode {
* ssh client is initialized through this call.
*/
protected ExecResponse doCall() {
ssh.put(name, init.render(OsFamily.UNIX));
if (pushInitViaSftp) {
ssh.put(name, init.render(OsFamily.UNIX));
} else {
ssh.exec("rm " + name);
ssh.exec(Statements.appendFile(name, Splitter.on('\n').split(init.render(OsFamily.UNIX)),
AppendFile.MARKER + "_" + name).render(OsFamily.UNIX));
}
ssh.exec("chmod 755 " + name);
runAction("init");
return runAction("start");

View File

@ -21,6 +21,7 @@ package org.jclouds.vcloud.terremark;
import static org.jclouds.Constants.PROPERTY_API_VERSION;
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
import static org.jclouds.compute.callables.RunScriptOnNodeAsInitScriptUsingSsh.PROPERTY_PUSH_INIT_SCRIPT_VIA_SFTP;
import static org.jclouds.vcloud.reference.VCloudConstants.PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED;
import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_NAME;
import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION;
@ -41,8 +42,10 @@ public class TerremarkECloudPropertiesBuilder extends TerremarkVCloudPropertiesB
properties.setProperty(PROPERTY_ENDPOINT, "https://services.enterprisecloud.terremark.com/api");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "eCloudExtensions");
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.7");
// for some reason the centos template is very slow to deploy
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 720l * 1000l + "");
// default for ubuntu
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 360l * 1000l + "");
// ubuntu image has a problem with sftp
properties.setProperty(PROPERTY_PUSH_INIT_SCRIPT_VIA_SFTP, "false");
return properties;
}

View File

@ -39,13 +39,20 @@ import com.google.common.collect.Maps;
* @author Adrian Cole
*/
public class AppendFile implements Statement {
public final static String MARKER = "END_OF_FILE";
public static final String MARKER = "END_OF_FILE";
final String path;
final Iterable<String> lines;
final String marker;
public AppendFile(String path, Iterable<String> lines) {// TODO: convert so
public AppendFile(String path, Iterable<String> lines) {
this(path, lines, MARKER);
}
public AppendFile(String path, Iterable<String> lines, String marker) {
this.path = checkNotNull(path, "path");
this.lines = checkNotNull(lines, "lines");
this.marker = checkNotNull(marker, "marker");
checkState(Iterables.size(lines) > 0, "you must pass something to execute");
}
@ -84,11 +91,11 @@ public class AppendFile implements Statement {
}
private void hereFile(String path, StringBuilder builder) {
builder.append("cat >> ").append(path).append(" <<'").append(MARKER).append("'\n");
builder.append("cat >> ").append(path).append(" <<'").append(marker).append("'\n");
for (String line : lines) {
builder.append(line).append("\n");
}
builder.append(MARKER).append("\n");
builder.append(marker).append("\n");
}
private Statement appendToFile(String line, String path, OsFamily family) {

View File

@ -67,6 +67,10 @@ public class Statements {
return new AppendFile(path, lines);
}
public static Statement appendFile(String path, Iterable<String> lines, String marker) {
return new AppendFile(path, lines, marker);
}
public static Statement createRunScript(String instanceName, Iterable<String> exports, String pwd,
Iterable<Statement> statements) {// TODO: convert so
// that