Search in sources :

Example 51 with Command

use of org.platformlayer.ops.Command in project platformlayer by platformlayer.

the class ZookeeperUtils method sendCommand.

public static ZookeeperResponse sendCommand(OpsTarget target, InetSocketAddress socketAddress, String zkCommand) throws OpsException {
    Command command = Command.build("echo {0} | nc {1} {2}", zkCommand, socketAddress.getAddress().getHostAddress(), socketAddress.getPort());
    ProcessExecution execution = target.executeCommand(command);
    return new ZookeeperResponse(execution.getStdOut());
}
Also used : Command(org.platformlayer.ops.Command) ProcessExecution(org.platformlayer.ops.process.ProcessExecution)

Example 52 with Command

use of org.platformlayer.ops.Command in project platformlayer by platformlayer.

the class PosixUser method doOperation.

@Handler
public void doOperation() throws OpsException {
    OpsTarget target = OpsContext.get().getInstance(OpsTarget.class);
    // TODO: Only if user not found
    {
        Command command = Command.build("adduser");
        command.addLiteral("--system");
        command.addLiteral("--no-create-home");
        if (shell != null) {
            command.addLiteral("--shell").addFile(shell);
        }
        if (!Strings.isNullOrEmpty(primaryGroup)) {
            command.addLiteral("--ingroup");
            command.addQuoted(primaryGroup);
        }
        command.addQuoted(userName);
        target.executeCommand(command);
    }
    for (String secondaryGroup : secondaryGroups) {
        Command command = Command.build("adduser");
        command.addQuoted(userName);
        command.addQuoted(secondaryGroup);
        target.executeCommand(command);
    }
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) Command(org.platformlayer.ops.Command) Handler(org.platformlayer.ops.Handler)

Example 53 with Command

use of org.platformlayer.ops.Command in project platformlayer by platformlayer.

the class DownloadFileByHash method uploadFile.

@Override
protected void uploadFile(OpsTarget target, File remoteFilePath) throws IOException, OpsException {
    target.mkdir(remoteFilePath.getParentFile());
    Md5Hash resolved = getResolved(target);
    CasStoreObject casObject;
    CasStoreMap casStoreMap = cas.getCasStoreMap(target);
    try {
        casObject = casStoreMap.findArtifact(new OpsCasTarget(target), resolved);
    } catch (Exception e) {
        throw new OpsException("Error while resolving artifact:" + getHumanName(), e);
    }
    if (url != null && casObject == null) {
        target.mkdir(remoteFilePath.getParentFile());
        CurlRequest curlRequest = new CurlRequest(url);
        curlRequest.bareRequest = true;
        CommandEnvironment commandEnvironment = httpProxies.getHttpProxyEnvironment(target, Usage.General, url);
        Command curlCommand = curlRequest.toCommand();
        curlCommand.addLiteral(">");
        curlCommand.addFile(remoteFilePath);
        curlCommand.setEnvironment(commandEnvironment);
        curlCommand.setTimeout(TimeSpan.FIVE_MINUTES);
        // TODO: Can we cache into CAS instead??
        log.info("Not found in CAS system; downloading directly: " + url);
        target.executeCommand(curlCommand);
    } else {
        if (casObject == null) {
            throw new OpsException("Unable to find artifact: " + getHumanName());
        }
        log.info("Doing a CAS copy from " + casObject + " to target");
        cas.copyObject(casStoreMap, casObject, new OpsCasTarget(target), remoteFilePath, true);
    }
}
Also used : CasStoreMap(org.platformlayer.cas.CasStoreMap) OpsException(org.platformlayer.ops.OpsException) CasStoreObject(org.platformlayer.cas.CasStoreObject) Command(org.platformlayer.ops.Command) CurlRequest(org.platformlayer.ops.helpers.CurlRequest) CommandEnvironment(org.platformlayer.ops.CommandEnvironment) Md5Hash(com.fathomdb.hash.Md5Hash) OpsCasTarget(org.platformlayer.ops.cas.OpsCasTarget) URISyntaxException(java.net.URISyntaxException) OpsException(org.platformlayer.ops.OpsException) IOException(java.io.IOException)

Example 54 with Command

use of org.platformlayer.ops.Command in project platformlayer by platformlayer.

the class PackageRemoval method handler.

@Handler
public void handler(OpsTarget target) throws OpsException {
    // Make sure openssh-server is manually installed (i.e. not through task-ssh-server)
    target.executeCommand("apt-get install openssh-server");
    // Only for wheezy? Squeeze has a depencency of install-info -> findutils
    Command command = Command.build("apt-get remove --yes aptitude tasksel tasksel-data man-db manpages libxapian22 libboost-iostreams1.49.0 info ");
    target.executeCommand(command);
    // Maybe:
    command = Command.build("apt-get remove --yes groff-base consolekit sane-utils  exim4-config installation-report");
    target.executeCommand(command);
    // Replace netcat with netcat6
    target.executeCommand("apt-get install netcat6");
    target.executeCommand("apt-get remove netcat-traditional");
    // We just want headless...
    command = Command.build("apt-get remove --yes dbus openjdk-7-jdk openjdk-7-jre  icedtea-7-jre-cacao icedtea-7-jre-jamvm");
    target.executeCommand(command);
    // Do we need python?? Does it still get installed??
    // apt-get remove python
    // Warnings??
    // apt-get remove install-info
    //
    // Squeeze:
    // apt-get remove aptitude tasksel tasksel-data man-db manpages libxapian22 info
    target.executeCommand("apt-get autoremove");
}
Also used : Command(org.platformlayer.ops.Command) Handler(org.platformlayer.ops.Handler)

Example 55 with Command

use of org.platformlayer.ops.Command in project platformlayer by platformlayer.

the class PersistIptablesScripts method addChildren.

@Override
protected void addChildren() throws OpsException {
    addChild(ManagedDirectory.build(BASE_DIR, "0644"));
    addChild(SimpleFile.build(getClass(), new File("/etc/network/if-pre-up.d/iptables-lockdown")).setFileMode("755").setUpdateAction(new FilesystemAction() {

        @Override
        public void execute(OpsTarget target, ManagedFilesystemItem managedFilesystemItem) throws OpsException {
            if (managedFilesystemItem.getNewFileWasCreated()) {
                // Set the parameters the ifup sets
                CommandEnvironment env = new CommandEnvironment();
                env.put("MODE", "start");
                env.put("IFACE", "--all");
                env.put("ADDRFAM", "meta");
                Command runLockdown = Command.build("/etc/network/if-pre-up.d/iptables-lockdown");
                runLockdown.setEnvironment(env);
                target.executeCommand(runLockdown);
            }
        }
    }));
    addChild(SimpleFile.build(getClass(), new File("/etc/network/if-up.d/iptables-ifup")).setFileMode("755"));
}
Also used : OpsTarget(org.platformlayer.ops.OpsTarget) Command(org.platformlayer.ops.Command) CommandEnvironment(org.platformlayer.ops.CommandEnvironment) ManagedFilesystemItem(org.platformlayer.ops.filesystem.ManagedFilesystemItem) File(java.io.File) SimpleFile(org.platformlayer.ops.filesystem.SimpleFile) FilesystemAction(org.platformlayer.ops.filesystem.FilesystemAction)

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