diff --git a/html/images/sprite_invader_vm_failed.png b/html/images/sprite_invader_vm_failed.png
new file mode 100644
index 0000000..f1af99c
Binary files /dev/null and b/html/images/sprite_invader_vm_failed.png differ
diff --git a/html/images/sprite_invader_vm_paused.png b/html/images/sprite_invader_vm_paused.png
new file mode 100644
index 0000000..f1af99c
Binary files /dev/null and b/html/images/sprite_invader_vm_paused.png differ
diff --git a/html/images/sprite_invader_vm_starting.png b/html/images/sprite_invader_vm_starting.png
new file mode 100644
index 0000000..f1af99c
Binary files /dev/null and b/html/images/sprite_invader_vm_starting.png differ
diff --git a/html/images/sprite_invader_vm_stopped.png b/html/images/sprite_invader_vm_stopped.png
new file mode 100644
index 0000000..f1af99c
Binary files /dev/null and b/html/images/sprite_invader_vm_stopped.png differ
diff --git a/html/index.html b/html/index.html
index 6d53f18..85d993d 100644
--- a/html/index.html
+++ b/html/index.html
@@ -697,7 +697,7 @@ k8s_jobs:

-
version: 2024-12-25 10:23:42
+
version: 2024-12-29 17:50:52
diff --git a/html/js/kubeinvaders.js b/html/js/kubeinvaders.js
index 759123e..612e067 100644
--- a/html/js/kubeinvaders.js
+++ b/html/js/kubeinvaders.js
@@ -336,6 +336,16 @@ function startChaosNode(node_name) {
oReq.send();
}
+function rebootVirtualMachine(vm_name) {
+ var oReq = new XMLHttpRequest();
+ oReq.onload = function () {
+ $('#alert_placeholder').replaceWith(alert_div + 'Latest action: Prepareing reboot virtual machine ' + vm_name + '');
+ };;
+ $('#alert_placeholder').replaceWith(alert_div + 'Latest action: Reboot virtual machine ' + vm_name + '');
+ oReq.open("GET", k8s_url + "/kube/chaos/vm_reboot?vm_name=" + vm_name + "&namespace=" + namespace);
+ oReq.send();
+}
+
function deletePods(pod_name) {
var oReq = new XMLHttpRequest();
oReq.onload = function () {
@@ -356,8 +366,6 @@ function addNodeAndVMstoPods() {
return pods;
}
-
-
function getPods() {
if (chaos_pods) {
var oReq = new XMLHttpRequest();
@@ -405,7 +413,7 @@ function getVMs() {
virtualMachines = [];
Array.from(jsonData.items).forEach(vm => {
const name = vm.metadata.name; // Nome della VM
- const status = vm.status.printableStatus; // Stato della VM
+ const status = vm.status.printableStatus.toLowerCase(); // Stato della VM
virtualMachines.push({ name: name, status: status });
});
};;
@@ -537,9 +545,9 @@ function drawAlien(alienX, alienY, name, status) {
ctx.fillText(name.substring(0, 10) + '..', alienX, alienY + 50);
}
else if (virtualMachines.some((vm) => vm.name == name)) {
- image.src = './images/k8s_node.png';
+ image.src = `./images/sprite_invader_vm_${status}.png`;
ctx.font = '10px pixel';
- ctx.drawImage(image, alienX, alienY, 30, 40);
+ ctx.drawImage(image, alienX, alienY, 40, 40);
ctx.fillText(name.substring(0, 10) + '..', alienX, alienY + 50);
}
else {
@@ -578,6 +586,10 @@ function checkRocketAlienCollision() {
aliens[i]["active"] = false;
startChaosNode(aliens[i]["name"]);
}
+ else if (virtualMachines.some((vm) => vm.name == aliens[i]["name"])) {
+ aliens[i]["active"] = false;
+ rebootVirtualMachine(aliens[i]["name"]);
+ }
else {
deletePods(aliens[i]["name"]);
}
@@ -851,10 +863,10 @@ window.setInterval(function setAliens() {
}, 1000)
window.setInterval(function backgroundTasks() {
- console.log("Nodes:", nodes);
- console.log("Virtual Machines:", virtualMachines);
- console.log("chaos_vms flag:", chaos_vms);
- console.log("Pods:", pods);
+ // console.log("Nodes:", nodes);
+ // console.log("Virtual Machines:", virtualMachines);
+ // console.log("chaos_vms flag:", chaos_vms);
+ // console.log("Pods:", pods);
if (!codename_configured) {
chaosProgram = $('#chaosProgramTextArea').val();
diff --git a/scripts/vm_reboot.lua b/scripts/vm_reboot.lua
new file mode 100644
index 0000000..0044cd4
--- /dev/null
+++ b/scripts/vm_reboot.lua
@@ -0,0 +1,47 @@
+local https = require "ssl.https"
+local ltn12 = require "ltn12"
+local json = require 'lunajson'
+local redis = require "resty.redis"
+local http = require("resty.http")
+
+local k8s_url = ""
+
+if os.getenv("KUBERNETES_SERVICE_HOST") then
+ k8s_url = "https://" .. os.getenv("KUBERNETES_SERVICE_HOST") .. ":" .. os.getenv("KUBERNETES_SERVICE_PORT_HTTPS")
+else
+ k8s_url = os.getenv("ENDPOINT")
+end
+
+local token = os.getenv("TOKEN")
+local arg = ngx.req.get_uri_args()
+local namespace = arg["namespace"]
+local vm_name = arg["vm_name"]
+local url = k8s_url .. "/apis/kubevirt.io/v1/namespaces/" .. namespace .. "/virtualmachines/" .. vm_name .. "/restart"
+local decoded = nil
+
+ngx.header['Access-Control-Allow-Origin'] = '*'
+ngx.header['Access-Control-Allow-Methods'] = 'GET, POST, OPTIONS'
+ngx.header['Access-Control-Allow-Headers'] = 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range'
+ngx.header['Access-Control-Expose-Headers'] = 'Content-Length,Content-Range';
+
+ngx.log(ngx.INFO, "Requesting nodes using this url: " .. url)
+
+local httpc = http.new()
+
+-- Esegui la richiesta
+local res, err = httpc:request_uri(url, {
+ method = "GET",
+ ssl_verify = false, -- TODO: use a valid certificate
+ headers = {
+ ["Accept"] = "application/json",
+ ["Content-Type"] = "application/json",
+ ["Authorization"] = "Bearer " .. token
+ }
+})
+
+if not res then
+ ngx.log(ngx.ERR, "Errore durante la richiesta HTTP: ", err)
+ return
+end
+
+ngx.say(res.body)
\ No newline at end of file