use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class DownloadImage method handler.
@Handler
public void handler(OpsTarget target) throws OpsException {
if (target.getFilesystemInfoFile(imageFile) == null) {
DirectCloud cloud = OpsContext.get().getInstance(DirectCloud.class);
if (cloud == null) {
throw new IllegalStateException("Cloud instance not found");
}
ImageStore imageStore = cloudHelpers.getImageStore(cloud);
MachineProvider machineProvider = providers.toInterface(cloud, MachineProvider.class);
CloudImage imageInfo = imageFactory.getOrCreateImageId(machineProvider, imageFormats, recipeKey);
if (imageStore == null) {
throw new OpsException("Image store not configured");
}
String fileName = imageInfo.getId() + ".image." + imageInfo.getFormat().name();
// TODO: We don't need rawImage; delete or just request a read-only version
File rawImage = new File(IMAGES_DIR, fileName);
target.mkdir(IMAGES_DIR);
// TODO: Caching / reuse ... need to check md5 though
imageStore.bringToMachine(imageInfo.getId(), target, rawImage);
ImageFormat imageFormat = imageInfo.getFormat();
switch(imageFormat) {
case Tar:
{
target.mkdir(imageFile);
target.executeCommand(Command.build("cd {0}; tar jxf {1}", imageFile, rawImage).setTimeout(TimeSpan.FIVE_MINUTES));
break;
}
case DiskRaw:
{
Command expand = Command.build("gunzip -c {0} | cp --sparse=always /proc/self/fd/0 {1}", rawImage, imageFile);
target.executeCommand(expand.setTimeout(TimeSpan.FIVE_MINUTES));
break;
}
case DiskQcow2:
{
Command expand = Command.build("cp {0} {1}", rawImage, imageFile);
target.executeCommand(expand.setTimeout(TimeSpan.FIVE_MINUTES));
break;
}
default:
throw new OpsException("Unknown image format: " + imageFormat);
}
}
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class InstanceScript method configure.
// public void configure(ManagedSupervisordInstance instance) {
// SupervisorProcessConfig sup = new SupervisorProcessConfig(key);
// Map<String, String> properties = sup.getProperties();
//
// Command command = Command.build(filePath.getAbsolutePath());
// properties.put("command", command.buildCommandString());
//
// instance.config = Providers.of(sup);
// }
public void configure(ItemBase owner, StandardService service) {
Command command = Command.build(filePath.getAbsolutePath());
service.command = OpsProvider.of(command);
service.key = key;
service.owner = owner.getKey();
// Map<String, String> env = template.getEnvironment();
// service.environment = Providers.of(env);
//
// service.instanceDir = instanceDir;
// service.key = template.getServiceKey();
//
// service.owner = template.getModel().getKey();
//
// service.matchExecutableName = template.getMatchExecutableName();
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class ShellBackupClient method doBackup.
public void doBackup(DirectoryBackup request) throws OpsException {
File tempDir = request.target.createTempDir();
File excludeFile = new File(tempDir, "exclude.txt");
if (request.objectName == null) {
request.objectName = UUID.randomUUID().toString();
}
request.objectName += ".tgz";
// TODO: Set content type?
FileUpload.upload(request.target, excludeFile, Joiner.on("\n").join(request.exclude));
Command tarCommand = Command.build("tar zcf - -X {0} {1}", excludeFile, request.rootDirectory);
log.info("Backing up " + request.rootDirectory);
uploadStream(request, tarCommand);
request.target.rmdir(tempDir);
log.info("Backup complete");
}
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
}
Aggregations