Search in sources :

Example 1 with ScriptBuilder

use of org.platformlayer.ops.networks.ScriptBuilder in project platformlayer by platformlayer.

the class InstanceScript method getContentsBytes.

@Override
protected byte[] getContentsBytes() throws OpsException {
    ScriptBuilder sb = new ScriptBuilder();
    addIpNeighborProxy(sb);
    sb.add(launchInstanceCommand);
    String script = sb.toString();
    return Utf8.getBytes(script);
}
Also used : ScriptBuilder(org.platformlayer.ops.networks.ScriptBuilder)

Example 2 with ScriptBuilder

use of org.platformlayer.ops.networks.ScriptBuilder in project platformlayer by platformlayer.

the class IpTablesFirewallManager method configureAddRule.

@Override
public void configureAddRule(OpsTarget target, FirewallRecord add) throws OpsException {
    // OpsServer server = smartGetServer(true);
    Command command = IpTablesManager.buildCommandAddFirewallRule(target, add);
    String fileName = Sanitizer.forFileName().clean(add.buildKey());
    File scriptDirectory = new File("/etc/iptables/eth0");
    File transportDirectory;
    switch(add.getTransport()) {
        case Ipv4:
            transportDirectory = new File(scriptDirectory, "inet");
            break;
        case Ipv6:
            transportDirectory = new File(scriptDirectory, "inet6");
            break;
        default:
            throw new IllegalStateException();
    }
    File scriptFile = new File(transportDirectory, fileName);
    ScriptBuilder sb = new ScriptBuilder();
    sb.add(command);
    String script = sb.toString();
    String existing = target.readTextFile(scriptFile);
    boolean shouldUpload = true;
    if (existing != null) {
        if (Objects.equal(existing, script)) {
            shouldUpload = false;
        } else {
            // TODO: Put a UUID in there, check the UUID is the same??
            throw new OpsException("Script has changed: " + scriptFile);
        }
    }
    if (shouldUpload) {
        target.mkdir(transportDirectory);
        FileUpload upload = FileUpload.build(script);
        upload.path = scriptFile;
        upload.mode = "0755";
        target.doUpload(upload);
    }
    Command executeScript = Command.build("{0}", scriptFile);
    target.executeCommand(executeScript);
// getCurrentFirewallState(operation).state.add(add);
}
Also used : OpsException(org.platformlayer.ops.OpsException) Command(org.platformlayer.ops.Command) ScriptBuilder(org.platformlayer.ops.networks.ScriptBuilder) File(java.io.File) FileUpload(org.platformlayer.ops.FileUpload)

Example 3 with ScriptBuilder

use of org.platformlayer.ops.networks.ScriptBuilder in project platformlayer by platformlayer.

the class IpTablesRuleScript method getContentsBytes.

@Override
protected byte[] getContentsBytes() throws OpsException {
    Command command = buildIptablesAddCommand();
    ScriptBuilder sb = new ScriptBuilder();
    sb.addMetadata("key", ruleKey);
    sb.add(command);
    return sb.getBytes();
}
Also used : Command(org.platformlayer.ops.Command) ScriptBuilder(org.platformlayer.ops.networks.ScriptBuilder)

Aggregations

ScriptBuilder (org.platformlayer.ops.networks.ScriptBuilder)3 Command (org.platformlayer.ops.Command)2 File (java.io.File)1 FileUpload (org.platformlayer.ops.FileUpload)1 OpsException (org.platformlayer.ops.OpsException)1