Search in sources :

Example 1 with FilesystemAction

use of org.platformlayer.ops.filesystem.FilesystemAction 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

File (java.io.File)1 Command (org.platformlayer.ops.Command)1 CommandEnvironment (org.platformlayer.ops.CommandEnvironment)1 OpsTarget (org.platformlayer.ops.OpsTarget)1 FilesystemAction (org.platformlayer.ops.filesystem.FilesystemAction)1 ManagedFilesystemItem (org.platformlayer.ops.filesystem.ManagedFilesystemItem)1 SimpleFile (org.platformlayer.ops.filesystem.SimpleFile)1