use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class GreTunnel method handler.
@Handler
public void handler(OpsTarget target) throws OpsException {
// ip tunnel add netb mode gre remote 184.173.172.26 local 209.105.243.38 ttl 255
Command addTunnel = Command.build("ip tunnel add {0} mode gre remote {1} local {2} ttl 255", tunnelName, remoteTunnelAddress, localTunnelAddress);
target.executeCommand(addTunnel);
// ip addr add fdfd:fdfd:fdfd:1::/64 dev netb
Command tunnelAddAddress = Command.build("ip addr add {0} dev {1}", localPrivateAddress, tunnelName);
target.executeCommand(tunnelAddAddress);
// ip route add fdfd:fdfd:fdfd:1::/64 dev netb
Command tunnelAddRoute = Command.build("ip route add {0} dev {1}", remotePrivateNetwork, tunnelName);
target.executeCommand(tunnelAddRoute);
Command tunnelUp = Command.build("ip link set {0} up", tunnelName);
target.executeCommand(tunnelUp);
}
use of org.platformlayer.ops.Command in project platformlayer by platformlayer.
the class GerritBootstrap method handler.
@Handler
public void handler(OpsTarget target) throws OpsException, IOException {
File canary = new File(template.getDataDir(), "bin/gerrit.sh");
if (target.getFilesystemInfoFile(canary) == null) {
if (OpsContext.isConfigure()) {
File dataDir = template.getDataDir();
Command command = Command.build("java");
command.addLiteral("-jar").addFile(template.getInstallWarFile());
command.addLiteral("init");
command.addLiteral("--no-auto-start");
command.addLiteral("--batch");
command.addLiteral("-d").addFile(dataDir);
target.executeCommand(command);
}
}
// DROP TABLE contributor_agreements;
// DROP TABLE account_agreements;
// DROP TABLE account_group_agreements;
// ALTER TABLE accounts DROP COLUMN display_patch_sets_in_reverse_order;
// ALTER TABLE accounts DROP COLUMN display_person_name_in_review_category;
// ALTER TABLE tracking_ids DROP COLUMN tracking_id;
// ALTER TABLE account_groups DROP COLUMN owner_group_id;
// ALTER TABLE account_groups DROP COLUMN external_name;
}
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");
}
Aggregations