use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class DirectOpenstackDownload method download.
public void download(OpsTarget target, File targetPath, OpenstackCredentials credentials, String containerName, String objectPath) throws OpsException {
RemoteCurlOpenstackSession session = new RemoteCurlOpenstackSession(target);
session.authenticate(credentials, false);
OpenstackStorageClient storageClient = session.getStorageClient();
RequestBuilder request = storageClient.root().containers().id(containerName).objects().id(objectPath).buildDownloadRequest();
CurlRequest curlRequest = session.toCurlRequest(request);
curlRequest.bareRequest = true;
Command curlCommand = curlRequest.toCommand();
curlCommand.addLiteral(">");
curlCommand.addFile(targetPath);
ProcessExecution execution = target.executeCommand(curlCommand);
// CurlResult curlResult = curlRequest.parseResponse(execution);
//
// int httpResult = curlResult.getHttpResult();
// switch (httpResult) {
// case 200:
// break;
// case 201:
// break;
// default:
// throw new OpsException("Unexpected result code while downloading file: " + httpResult + " Result=" +
// curlResult);
// }
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class MountCgroups method handler.
@Handler
public void handler() throws OpsException, IOException {
// TODO: Only if not installed
OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
File cgroupsFile = new File("/cgroup");
FilesystemInfo info = target.getFilesystemInfoFile(cgroupsFile);
if (info != null) {
// TODO: Better idempotency
return;
}
String fstabLine = "\ncgroup\t/cgroup\tcgroup\tdefaults\t0\t0";
File fstabFile = new File("/etc/fstab");
String fstab = target.readTextFile(fstabFile);
fstab += fstabLine;
FileUpload.upload(target, fstabFile, fstab);
target.mkdir(cgroupsFile);
Command mountCommand = Command.build("mount cgroup");
target.executeCommand(mountCommand);
// mkdir /cgroup
// echo -e "cgroup\t/cgroup\tcgroup\tdefaults\t0\t0" >> /etc/fstab
// mount cgroup
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class NetworkBridge method addChildren.
@Override
protected void addChildren() throws OpsException {
// We would need proxy_arp if they were on the same IPV4 network
// Do we need proxy_ndp ???
// echo 1 > /proc/sys/net/ipv6/conf/eth0/proxy_ndp
addChild(SysctlSetting.build("net.ipv4.ip_forward", "1"));
addChild(SysctlSetting.build("net.ipv6.conf.all.forwarding", "1"));
addChild(SysctlSetting.build("net.ipv6.conf.all.proxy_ndp", "1"));
{
File scriptPath = new File("/etc/network/if-up.d/nat-for-bridge");
TemplatedFile nat = addChild(TemplatedFile.build(template, scriptPath));
nat.setFileMode("0755");
// Simulate an ifup run
Command command = Command.build(scriptPath);
CommandEnvironment env = new CommandEnvironment();
env.put("IFACE", template.getPublicInterface());
env.put("MODE", "start");
env.put("ADDRFAM", "inet");
command.setEnvironment(env);
nat.setUpdateAction(command);
}
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class ManagedKvmInstance method buildKvmCommand.
private Command buildKvmCommand() {
Command command = Command.build("/usr/bin/kvm");
if (this.vnc != null) {
InetSocketAddress vnc = this.vnc.get();
if (vnc != null) {
int port = vnc.getPort();
int vncPort = port - 5900;
command.addLiteral("-vnc");
InetAddress address = vnc.getAddress();
if (!address.isAnyLocalAddress()) {
command.addQuoted(address.getHostAddress() + ":" + vncPort);
} else {
command.addQuoted("0.0.0.0:" + vncPort);
}
}
}
command.addLiteral("-m").addQuoted(Integer.toString(memoryMb));
command.addLiteral("-smp").addQuoted(Integer.toString(vcpus));
command.addLiteral("-name").addQuoted(id);
// command.addLiteral("-nodefconfig");
command.addLiteral("-nodefaults");
command.addLiteral("-vga").addQuoted("cirrus");
command.addLiteral("-usb");
command.addLiteral("-readconfig").addFile(getDeviceConfigPath());
if (!disableKvm) {
command.addLiteral("-enable-kvm");
}
return command;
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class NetworkTunDevice method handler.
@Handler
public void handler(OpsTarget target) throws OpsException {
if (OpsContext.isConfigure()) {
Command findCommand = Command.build("/sbin/ifconfig {0}", interfaceName);
boolean found = false;
try {
target.executeCommand(findCommand);
found = true;
} catch (ProcessExecutionException e) {
ProcessExecution execution = e.getExecution();
if (execution.getExitCode() == 1 && execution.getStdErr().contains("Device not found")) {
found = false;
} else {
throw new OpsException("Error checking for interface", e);
}
}
if (!found) {
// This is actually idempotent, but I think it's scary to rely on it being so
Command command = Command.build("/usr/sbin/tunctl -t {0}", interfaceName);
target.executeCommand(command);
}
{
// TODO: Safe to re-run?
Command command = Command.build("ifconfig {0} up", interfaceName);
target.executeCommand(command);
}
if (bridgeName != null) {
// TODO: Safe to re-run?
Command command = Command.build("brctl addif {0} {1}", bridgeName.get(), interfaceName);
try {
target.executeCommand(command);
} catch (ProcessExecutionException e) {
ProcessExecution execution = e.getExecution();
if (execution.getExitCode() == 1 && execution.getStdErr().contains("already a member of a bridge")) {
// OK
// TODO: Check that the bridge is bridgeName
} else {
throw new OpsException("Error attaching interface to bridge", e);
}
}
}
}
if (OpsContext.isDelete()) {
// TODO: Implement
log.warn("NetworkTunDevice delete not implemented");
}
}
Aggregations