mirror of https://github.com/apache/jclouds.git
Issue 587:workaround clouds who do not have sftp enabled
This commit is contained in:
parent
ac698c33ec
commit
e1b8110b12
|
@ -32,13 +32,17 @@ import org.jclouds.compute.options.RunScriptOptions;
|
||||||
import org.jclouds.compute.reference.ComputeServiceConstants;
|
import org.jclouds.compute.reference.ComputeServiceConstants;
|
||||||
import org.jclouds.logging.Logger;
|
import org.jclouds.logging.Logger;
|
||||||
import org.jclouds.scriptbuilder.InitBuilder;
|
import org.jclouds.scriptbuilder.InitBuilder;
|
||||||
|
import org.jclouds.scriptbuilder.domain.AppendFile;
|
||||||
import org.jclouds.scriptbuilder.domain.OsFamily;
|
import org.jclouds.scriptbuilder.domain.OsFamily;
|
||||||
import org.jclouds.scriptbuilder.domain.Statement;
|
import org.jclouds.scriptbuilder.domain.Statement;
|
||||||
|
import org.jclouds.scriptbuilder.domain.Statements;
|
||||||
import org.jclouds.ssh.SshClient;
|
import org.jclouds.ssh.SshClient;
|
||||||
|
|
||||||
import com.google.common.annotations.VisibleForTesting;
|
import com.google.common.annotations.VisibleForTesting;
|
||||||
import com.google.common.base.Function;
|
import com.google.common.base.Function;
|
||||||
import com.google.common.base.Objects;
|
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.Assisted;
|
||||||
import com.google.inject.assistedinject.AssistedInject;
|
import com.google.inject.assistedinject.AssistedInject;
|
||||||
|
|
||||||
|
@ -47,6 +51,7 @@ import com.google.inject.assistedinject.AssistedInject;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class RunScriptOnNodeAsInitScriptUsingSsh implements RunScriptOnNode {
|
public class RunScriptOnNodeAsInitScriptUsingSsh implements RunScriptOnNode {
|
||||||
|
public static final String PROPERTY_PUSH_INIT_SCRIPT_VIA_SFTP = "jclouds.compute.push-init-script-via-sftp";
|
||||||
@Resource
|
@Resource
|
||||||
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
@Named(ComputeServiceConstants.COMPUTE_LOGGER)
|
||||||
protected Logger logger = Logger.NULL;
|
protected Logger logger = Logger.NULL;
|
||||||
|
@ -59,6 +64,14 @@ public class RunScriptOnNodeAsInitScriptUsingSsh implements RunScriptOnNode {
|
||||||
|
|
||||||
protected SshClient ssh;
|
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
|
@AssistedInject
|
||||||
public RunScriptOnNodeAsInitScriptUsingSsh(Function<NodeMetadata, SshClient> sshFactory,
|
public RunScriptOnNodeAsInitScriptUsingSsh(Function<NodeMetadata, SshClient> sshFactory,
|
||||||
@Assisted NodeMetadata node, @Assisted Statement script, @Assisted RunScriptOptions options) {
|
@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.
|
* ssh client is initialized through this call.
|
||||||
*/
|
*/
|
||||||
protected ExecResponse doCall() {
|
protected ExecResponse doCall() {
|
||||||
|
if (pushInitViaSftp) {
|
||||||
ssh.put(name, init.render(OsFamily.UNIX));
|
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);
|
ssh.exec("chmod 755 " + name);
|
||||||
runAction("init");
|
runAction("init");
|
||||||
return runAction("start");
|
return runAction("start");
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.jclouds.vcloud.terremark;
|
||||||
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
import static org.jclouds.Constants.PROPERTY_API_VERSION;
|
||||||
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
import static org.jclouds.Constants.PROPERTY_ENDPOINT;
|
||||||
import static org.jclouds.Constants.PROPERTY_ISO3166_CODES;
|
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.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_NAME;
|
||||||
import static org.jclouds.vcloud.terremark.reference.TerremarkConstants.PROPERTY_TERREMARK_EXTENSION_VERSION;
|
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_ENDPOINT, "https://services.enterprisecloud.terremark.com/api");
|
||||||
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "eCloudExtensions");
|
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_NAME, "eCloudExtensions");
|
||||||
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.7");
|
properties.setProperty(PROPERTY_TERREMARK_EXTENSION_VERSION, "2.7");
|
||||||
// for some reason the centos template is very slow to deploy
|
// default for ubuntu
|
||||||
properties.setProperty(PROPERTY_VCLOUD_TIMEOUT_TASK_COMPLETED, 720l * 1000l + "");
|
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;
|
return properties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -39,13 +39,20 @@ import com.google.common.collect.Maps;
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class AppendFile implements Statement {
|
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 String path;
|
||||||
final Iterable<String> lines;
|
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.path = checkNotNull(path, "path");
|
||||||
this.lines = checkNotNull(lines, "lines");
|
this.lines = checkNotNull(lines, "lines");
|
||||||
|
this.marker = checkNotNull(marker, "marker");
|
||||||
checkState(Iterables.size(lines) > 0, "you must pass something to execute");
|
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) {
|
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) {
|
for (String line : lines) {
|
||||||
builder.append(line).append("\n");
|
builder.append(line).append("\n");
|
||||||
}
|
}
|
||||||
builder.append(MARKER).append("\n");
|
builder.append(marker).append("\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
private Statement appendToFile(String line, String path, OsFamily family) {
|
private Statement appendToFile(String line, String path, OsFamily family) {
|
||||||
|
|
|
@ -67,6 +67,10 @@ public class Statements {
|
||||||
return new AppendFile(path, lines);
|
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,
|
public static Statement createRunScript(String instanceName, Iterable<String> exports, String pwd,
|
||||||
Iterable<Statement> statements) {// TODO: convert so
|
Iterable<Statement> statements) {// TODO: convert so
|
||||||
// that
|
// that
|
||||||
|
|
Loading…
Reference in New Issue