Search in sources :

Example 26 with Command

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);
}
Also used : Command(org.platformlayer.ops.Command) Handler(org.platformlayer.ops.Handler)

Example 27 with Command

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;
}
Also used : Command(org.platformlayer.ops.Command) File(java.io.File) Handler(org.platformlayer.ops.Handler)

Example 28 with Command

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);
        }
    }
}
Also used : DirectCloud(org.platformlayer.service.cloud.direct.model.DirectCloud) MachineProvider(org.platformlayer.ops.machines.MachineProvider) OpsException(org.platformlayer.ops.OpsException) Command(org.platformlayer.ops.Command) CloudImage(org.platformlayer.ops.images.CloudImage) File(java.io.File) ImageStore(org.platformlayer.ops.images.ImageStore) ImageFormat(org.platformlayer.ops.images.ImageFormat) Handler(org.platformlayer.ops.Handler)

Example 29 with Command

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();
}
Also used : Command(org.platformlayer.ops.Command)

Example 30 with Command

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");
}
Also used : Command(org.platformlayer.ops.Command) File(java.io.File)

Aggregations

Command (org.platformlayer.ops.Command)72 File (java.io.File)21 Handler (org.platformlayer.ops.Handler)17 OpsException (org.platformlayer.ops.OpsException)16 ProcessExecution (org.platformlayer.ops.process.ProcessExecution)16 CommandEnvironment (org.platformlayer.ops.CommandEnvironment)11 OpsTarget (org.platformlayer.ops.OpsTarget)9 InetAddress (java.net.InetAddress)4 CurlRequest (org.platformlayer.ops.helpers.CurlRequest)4 Md5Hash (com.fathomdb.hash.Md5Hash)3 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 Map (java.util.Map)3 FilesystemInfo (org.platformlayer.ops.filesystem.FilesystemInfo)3 ImageFormat (org.platformlayer.ops.images.ImageFormat)3 List (java.util.List)2 Properties (java.util.Properties)2 RequestBuilder (org.openstack.client.common.RequestBuilder)2 AddressModel (org.platformlayer.core.model.AddressModel)2 Tag (org.platformlayer.core.model.Tag)2