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);
}
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);
}
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();
}
Aggregations