summaryrefslogtreecommitdiffstats
path: root/src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java
diff options
context:
space:
mode:
authorSimon Rettberg2014-06-03 16:47:36 +0200
committerSimon Rettberg2014-06-03 16:47:36 +0200
commit32dc5354e2916387a2c62eadae0a4568023f1151 (patch)
tree7fd9a0173d6073e86d1d48e545646b1bc8c1a5eb /src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java
downloadtmlite-bwlp-32dc5354e2916387a2c62eadae0a4568023f1151.tar.gz
tmlite-bwlp-32dc5354e2916387a2c62eadae0a4568023f1151.tar.xz
tmlite-bwlp-32dc5354e2916387a2c62eadae0a4568023f1151.zip
Initial commit
Diffstat (limited to 'src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java')
-rw-r--r--src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java83
1 files changed, 83 insertions, 0 deletions
diff --git a/src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java b/src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java
new file mode 100644
index 0000000..c0534c7
--- /dev/null
+++ b/src/main/java/org/openslx/taskmanager/tasks/CompileIPxe.java
@@ -0,0 +1,83 @@
+package org.openslx.taskmanager.tasks;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+
+import org.apache.commons.io.FileUtils;
+import org.openslx.taskmanager.api.AbstractTask;
+
+import com.google.gson.annotations.Expose;
+
+public class CompileIPxe extends AbstractTask
+{
+
+ @Expose
+ private String ip = null;
+ @Expose
+ private String defaultentry = null;
+ @Expose
+ private int timeout = 0;
+ @Expose
+ private String custom = null;
+
+ private Output status = new Output();
+
+ @Override
+ protected boolean initTask()
+ {
+ this.setStatusObject( this.status );
+ if ( this.ip == null ) {
+ status.error = "No IP address set.";
+ return false;
+ }
+ if ( this.defaultentry == null )
+ this.defaultentry = "net";
+ if ( this.custom == null )
+ this.custom = "";
+ return true;
+ }
+
+ @Override
+ protected boolean execute()
+ {
+ // Prepare menu
+ String template;
+ try {
+ template = FileUtils.readFileToString( new File( "./data/pxemenu.template" ), StandardCharsets.UTF_8 );
+ } catch ( IOException e ) {
+ status.error = e.toString();
+ return false;
+ }
+ // Substitutions
+ template = template.replaceAll( "%ip%", this.ip );
+ template = template.replaceAll( "%timeout%", Integer.toString( this.timeout * 10 ) );
+ template = template.replaceAll( "%totaltimeout%", Integer.toString( this.timeout * 40 ) );
+ template = template.replaceAll( "%default%", this.defaultentry );
+ template = template.replaceAll( "%custom%", this.custom );
+ // Default selection net
+ if ( this.defaultentry.equals( "net" ) )
+ template = template.replaceAll( "%default-net%", "MENU DEFAULT" );
+ else
+ template = template.replaceAll( "%default-net%", "" );
+ // Default selection hdd
+ if ( this.defaultentry.equals( "hdd" ) )
+ template = template.replaceAll( "%default-hdd%", "MENU DEFAULT" );
+ else
+ template = template.replaceAll( "%default-hdd%", "" );
+ // Write out
+ try {
+ FileUtils.writeStringToFile( new File( "/srv/openslx/tftp/pxelinux.cfg/default" ), template, StandardCharsets.UTF_8 );
+ } catch ( IOException e ) {
+ status.error = e.toString();
+ return false;
+ }
+ return true;
+ }
+
+ class Output
+ {
+ protected String error = null;
+ }
+
+}