Compare commits

..

No commits in common. '678c2874a25e4918abdbeb85a0410275b36f6ebf' and '3dc9b97d1ec377a2fca7506316b4204aca0f588e' have entirely different histories.

@ -1,63 +0,0 @@
package fr.sixthemes.beans;
import java.util.HashMap;
import java.util.Map;
public class CTConf {
protected SysConf systemConfiguration;
protected NetConf inet4Configuration;
protected NetConf6 inet6Configuration;
public CTConf() {
this.systemConfiguration = new SysConf();
this.inet4Configuration = new NetConf();
this.inet6Configuration = new NetConf6();
}
public CTConf(SysConf system, NetConf inet4, NetConf6 inet6) {
this.systemConfiguration = system;
this.inet4Configuration = inet4;
this.inet6Configuration = inet6;
}
public Map<String, String> getParameters() {
Map<String, String> parameters = new HashMap<>();
parameters.put("unprivileged", "1");
parameters.put("features", "nesting=1");
// TODO : Remove hardcoded password
parameters.put("password", "12345");
parameters.putAll(systemConfiguration.getParameters());
parameters.putAll(inet4Configuration.getParameters());
return parameters;
}
public SysConf getSystemConfiguration() {
return this.systemConfiguration;
}
public NetConf getInet4Configuration() {
return this.inet4Configuration;
}
public NetConf6 getInet6Configuration() {
return this.inet6Configuration;
}
public void setSystemConfiguration(SysConf systemConfiguration) {
this.systemConfiguration = systemConfiguration;
}
public void setInet4Configuration(NetConf inet4Configuration) {
this.inet4Configuration = inet4Configuration;
}
public void setInet6Configuration(NetConf6 inet6Configuration) {
this.inet6Configuration = inet6Configuration;
}
}

@ -1,66 +0,0 @@
package fr.sixthemes.beans;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URLEncoder;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.util.Map;
public class CTCreationRequest {
protected String targetClusterURL;
protected String apiID;
protected String apiKey;
public CTCreationRequest() {
// TODO : Get default credentials from user session or docker env
this.targetClusterURL = "https://example.com";
}
public CTCreationRequest(String targetClusterURL, String apiID, String apiKey) {
this.targetClusterURL = targetClusterURL;
this.apiID = apiID;
this.apiKey = apiKey;
}
public String sendRequest(CTConf ctConfiguration) {
try {
String postData = this.getPostDataFor(ctConfiguration);
// TODO : remove hardcoded parameters
postData += "&ostemplate=local%3Avztmpl%2Fdebian-11-standard_11.6-1_amd64.tar.zst&vmid=8000";
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(this.targetClusterURL + "?" + postData))
.header("Authorization", "PVEAPIToken=" + this.apiID + "=" + this.apiKey)
.method("POST", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = HttpClient.newHttpClient().send(request, HttpResponse.BodyHandlers.ofString());
return response.body();
}
catch(Exception e) {
return e.getStackTrace().toString();
}
}
public String getPostDataFor(CTConf conf) throws UnsupportedEncodingException {
StringBuilder builder = new StringBuilder();
for (Map.Entry<String, String> entry : conf.getParameters().entrySet()) {
builder.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
builder.append("=");
builder.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
builder.append("&");
}
String resultString = builder.toString();
return resultString.length() > 0
? resultString.substring(0, resultString.length() - 1)
: resultString;
}
}

@ -1,7 +1,5 @@
package fr.sixthemes.beans; package fr.sixthemes.beans;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
@ -64,14 +62,6 @@ public class NetConf {
return builder.toString(); return builder.toString();
} }
public Map<String, String> getParameters() {
Map<String, String> parameters = new HashMap<>();
parameters.put("net0", "name=eth0,bridge=" + this.network + ",ip=" + (this.ipAddress.isEmpty() ? "dhcp" : this.ipAddress + ",gw=" + this.gateway));
return parameters;
}
/* /*
* *
* GETTERS * GETTERS

@ -1,8 +1,5 @@
package fr.sixthemes.beans; package fr.sixthemes.beans;
import java.util.HashMap;
import java.util.Map;
import fr.sixthemes.utils.Utils; import fr.sixthemes.utils.Utils;
public class SysConf { public class SysConf {
@ -38,16 +35,6 @@ public class SysConf {
this.setDisk(disk); this.setDisk(disk);
} }
public Map<String, String> getParameters() {
Map<String, String> parameters = new HashMap<>();
parameters.put("hostname", this.hostname);
parameters.put("cores", this.cores);
parameters.put("rootfs", "local-zfs:" + this.disk);
return parameters;
}
/* /*
* *
* GETTERS * GETTERS

@ -8,7 +8,6 @@ import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import fr.sixthemes.beans.CTConf;
import fr.sixthemes.beans.NetConf; import fr.sixthemes.beans.NetConf;
import fr.sixthemes.beans.NetConf6; import fr.sixthemes.beans.NetConf6;
import fr.sixthemes.beans.SysConf; import fr.sixthemes.beans.SysConf;
@ -51,9 +50,6 @@ public class CreateCTHandler extends HttpServlet {
NetConf6 netconf6 = new NetConf6(ipaddress6, gateway6, network, ipconf6); NetConf6 netconf6 = new NetConf6(ipaddress6, gateway6, network, ipconf6);
req.setAttribute("netconf6", netconf6); req.setAttribute("netconf6", netconf6);
CTConf conf = new CTConf(sysconf, netconf4, netconf6);
req.getSession().setAttribute("conf", conf);
// -------------------- // --------------------
this.getServletContext().getRequestDispatcher("/WEB-INF/createct.jsp").forward(req, resp); this.getServletContext().getRequestDispatcher("/WEB-INF/createct.jsp").forward(req, resp);

@ -1,40 +0,0 @@
package fr.sixthemes.servlets;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import fr.sixthemes.beans.CTConf;
import fr.sixthemes.beans.CTCreationRequest;
@WebServlet(urlPatterns = "/process")
public class RequestProcessor extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
CTConf conf = (CTConf) req.getSession().getAttribute("conf");
String targetUrl = req.getParameter("target");
String tokenID = req.getParameter("tokenid");
String tokenKey = req.getParameter("tokenkey");
CTCreationRequest request = new CTCreationRequest(targetUrl, tokenID, tokenKey);
String response = request.sendRequest(conf);
PrintWriter out = resp.getWriter();
out.println(response);
// out.println(request.getPostDataFor(conf));
}
}

@ -16,42 +16,17 @@
<body> <body>
<div class="container"> <div class="container">
<h1>6-Deploy</h1> <h1>6-Deploy</h1>
<h2>Résumé</h2> <h2>CT creation</h2>
<ul>
<div class="row"> <li><strong>Hostname : </strong>${sysconf.hostname}</li>
<div class="three columns"> <li><strong>Cores : </strong>${sysconf.cores}</li>
<h3>Système</h3> <li><strong>RAM : </strong>${sysconf.ram}</li>
<ul> <li><strong>Disk (in GB) : </strong>${sysconf.disk}</li>
<li><strong>Nom d'hôte : </strong>${sysconf.hostname}</li> </ul>
<li><strong>Nombre de coeurs : </strong>${sysconf.cores}</li> <h3>IPv4 :</h3>
<li><strong>RAM (en Mo) : </strong>${sysconf.ram}</li> <%= netconf4.toHTML() %>
<li><strong>Stockage (en Go) : </strong>${sysconf.disk}</li> <h3>IPv6</h3>
</ul> <%= netconf6.toHTML() %>
</div>
<div class="three columns">
<h3>IPv4 :</h3>
<%= netconf4.toHTML() %>
</div>
<div class="six columns">
<h3>IPv6</h3>
<%= netconf6.toHTML() %>
</div>
</div>
<hr>
<div class="row">
<h2>Déploiement</h2>
<div class="six columns offset-by-three">
<form action="/process" method="post">
<label for="target">URL du cluster cible</label>
<input class="u-full-width" name="target" type="text" placeholder="ex : https://prox.exemple.com" />
<label for="tokenid">Identifiant du token d'API</label>
<input class="u-full-width" name="tokenid" type="text" placeholder="ex : root@pam!ApiToken" />
<label for="tokenkey">Clé du token d'API</label>
<input class="u-full-width" name="tokenkey" type="text" placeholder="0aa00a00-0000-00aa-aaa0-a0aaa000000a" />
<input class="u-full-width" type="submit" value="Valider" />
</form>
</div>
</div>
</div> </div>
</body> </body>
</html> </html>
Loading…
Cancel
Save