parent
427aab95ea
commit
81ad30c03a
@ -0,0 +1,8 @@
|
|||||||
|
#ifndef JSON_SEND_H
|
||||||
|
#define JSON_SEND_H
|
||||||
|
#include <Arduino.h>
|
||||||
|
void restartVM(String node, int vmid);
|
||||||
|
void restartContainer(String node, int containerid);
|
||||||
|
void restartNode(String node);
|
||||||
|
|
||||||
|
#endif /* JSON_SEND_H */
|
||||||
@ -0,0 +1,5 @@
|
|||||||
|
#ifndef MANAGE_H
|
||||||
|
#define MANAGE_H
|
||||||
|
|
||||||
|
|
||||||
|
#endif /* MANAGE_H */
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
#include <ArduinoJson.h>
|
||||||
|
#include <HTTPClient.h>
|
||||||
|
#include <server.h>
|
||||||
|
#include <utils.h>
|
||||||
|
#include <json/retrieve.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
void restartVM(String node, int vmid)
|
||||||
|
{
|
||||||
|
HTTPClient http;
|
||||||
|
String apiAddress = PROXMOX_ADDRESS + "/api2/json/nodes/" + node + "/qemu/" + vmid + "/status/reboot";
|
||||||
|
String auth = "PVEAPIToken=" + PROXMOX_TOKEN_USER + "!" + PROXMOX_TOKEN_NAME + "=" + PROXMOX_TOKEN_SECRET;
|
||||||
|
char authc[auth.length() + 1];
|
||||||
|
auth.toCharArray(authc, auth.length() + 1);
|
||||||
|
http.begin(apiAddress);
|
||||||
|
http.setAuthorization(authc);
|
||||||
|
int httpCode = http.POST("");
|
||||||
|
http.end();
|
||||||
|
|
||||||
|
if(httpCode == 0) {
|
||||||
|
throw std::runtime_error("Can't restart VM. Error code: " + httpCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void restartContainer(String node, int containerid)
|
||||||
|
{
|
||||||
|
HTTPClient http;
|
||||||
|
String apiAddress = PROXMOX_ADDRESS + "/api2/json/nodes/" + node + "/lxc/" + containerid + "/status/reboot";
|
||||||
|
String auth = "PVEAPIToken=" + PROXMOX_TOKEN_USER + "!" + PROXMOX_TOKEN_NAME + "=" + PROXMOX_TOKEN_SECRET;
|
||||||
|
char authc[auth.length() + 1];
|
||||||
|
auth.toCharArray(authc, auth.length() + 1);
|
||||||
|
http.begin(apiAddress);
|
||||||
|
http.setAuthorization(authc);
|
||||||
|
int httpCode = http.POST("");
|
||||||
|
http.end();
|
||||||
|
|
||||||
|
if(httpCode == 0) {
|
||||||
|
throw std::runtime_error("Can't restart container. Error code: " + httpCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void restartNode(String node)
|
||||||
|
{
|
||||||
|
HTTPClient http;
|
||||||
|
String apiAddress = PROXMOX_ADDRESS + "/api2/json/nodes/" + node + "/status/reboot";
|
||||||
|
String auth = "PVEAPIToken=" + PROXMOX_TOKEN_USER + "!" + PROXMOX_TOKEN_NAME + "=" + PROXMOX_TOKEN_SECRET;
|
||||||
|
char authc[auth.length() + 1];
|
||||||
|
auth.toCharArray(authc, auth.length() + 1);
|
||||||
|
http.begin(apiAddress);
|
||||||
|
http.setAuthorization(authc);
|
||||||
|
int httpCode = http.POST("");
|
||||||
|
http.end();
|
||||||
|
|
||||||
|
if(httpCode == 0) {
|
||||||
|
throw std::runtime_error("Can't restart container. Error code: " + httpCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,159 @@
|
|||||||
|
#include <json/retrieve.h>
|
||||||
|
#include <json/utils.h>
|
||||||
|
#include <json/send.h>
|
||||||
|
#include <global.h>
|
||||||
|
#include <menu.h>
|
||||||
|
#include <odroid_go.h>
|
||||||
|
#include <utils.h>
|
||||||
|
|
||||||
|
void nodeRestart()
|
||||||
|
{
|
||||||
|
Serial.println("node restart");
|
||||||
|
selectedItem = 0;
|
||||||
|
|
||||||
|
restartNode(selectedNode);
|
||||||
|
|
||||||
|
GO.lcd.clearDisplay();
|
||||||
|
GO.lcd.println("done");
|
||||||
|
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void vmRestart()
|
||||||
|
{
|
||||||
|
Serial.println("vm restart");
|
||||||
|
selectedItem = 0;
|
||||||
|
int numVMs;
|
||||||
|
VM *vms = getVMInfo(&numVMs, selectedNode);
|
||||||
|
if (vms != NULL)
|
||||||
|
{
|
||||||
|
listVMs(vms, numVMs);
|
||||||
|
|
||||||
|
restartVM(selectedNode, selectedVM);
|
||||||
|
|
||||||
|
GO.lcd.clearDisplay();
|
||||||
|
GO.lcd.println("done");
|
||||||
|
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void containerRestart()
|
||||||
|
{
|
||||||
|
Serial.println("lxc restart");
|
||||||
|
selectedItem = 0;
|
||||||
|
int numContainers;
|
||||||
|
Container *containers = getContainerInfo(&numContainers, selectedNode);
|
||||||
|
if (containers != NULL)
|
||||||
|
{
|
||||||
|
listContainers(containers, numContainers);
|
||||||
|
|
||||||
|
restartContainer(selectedNode, selectedLXC);
|
||||||
|
GO.lcd.clearDisplay();
|
||||||
|
GO.lcd.println("done");
|
||||||
|
|
||||||
|
delay(2000);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// void nodeStart()
|
||||||
|
// {
|
||||||
|
// Serial.println("node start");
|
||||||
|
// selectedItem = 0;
|
||||||
|
|
||||||
|
// startNode(selectedNode);
|
||||||
|
|
||||||
|
// GO.lcd.clearDisplay();
|
||||||
|
// GO.lcd.println("done");
|
||||||
|
|
||||||
|
// delay(2000);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void vmStart()
|
||||||
|
// {
|
||||||
|
// Serial.println("vm start");
|
||||||
|
// selectedItem = 0;
|
||||||
|
// int numVMs;
|
||||||
|
// VM *vms = getVMInfo(&numVMs, selectedNode);
|
||||||
|
// if (vms != NULL)
|
||||||
|
// {
|
||||||
|
// listVMs(vms, numVMs);
|
||||||
|
|
||||||
|
// startVM(selectedNode, selectedVM);
|
||||||
|
|
||||||
|
// GO.lcd.clearDisplay();
|
||||||
|
// GO.lcd.println("done");
|
||||||
|
|
||||||
|
// delay(2000);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void containerStart()
|
||||||
|
// {
|
||||||
|
// Serial.println("lxc start");
|
||||||
|
// selectedItem = 0;
|
||||||
|
// int numContainers;
|
||||||
|
// Container *containers = getContainerInfo(&numContainers, selectedNode);
|
||||||
|
// if (containers != NULL)
|
||||||
|
// {
|
||||||
|
// listContainers(containers, numContainers);
|
||||||
|
|
||||||
|
// startContainer(selectedNode, selectedLXC);
|
||||||
|
// GO.lcd.clearDisplay();
|
||||||
|
// GO.lcd.println("done");
|
||||||
|
|
||||||
|
// delay(2000);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
// void nodeStop()
|
||||||
|
// {
|
||||||
|
// Serial.println("node stop");
|
||||||
|
// selectedItem = 0;
|
||||||
|
|
||||||
|
// stopNode(selectedNode);
|
||||||
|
|
||||||
|
// GO.lcd.clearDisplay();
|
||||||
|
// GO.lcd.println("done");
|
||||||
|
|
||||||
|
// delay(2000);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void vmStop()
|
||||||
|
// {
|
||||||
|
// Serial.println("vm stop");
|
||||||
|
// selectedItem = 0;
|
||||||
|
// int numVMs;
|
||||||
|
// VM *vms = getVMInfo(&numVMs, selectedNode);
|
||||||
|
// if (vms != NULL)
|
||||||
|
// {
|
||||||
|
// listVMs(vms, numVMs);
|
||||||
|
|
||||||
|
// stopVM(selectedNode, selectedVM);
|
||||||
|
|
||||||
|
// GO.lcd.clearDisplay();
|
||||||
|
// GO.lcd.println("done");
|
||||||
|
|
||||||
|
// delay(2000);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void containerStop()
|
||||||
|
// {
|
||||||
|
// Serial.println("lxc stop");
|
||||||
|
// selectedItem = 0;
|
||||||
|
// int numContainers;
|
||||||
|
// Container *containers = getContainerInfo(&numContainers, selectedNode);
|
||||||
|
// if (containers != NULL)
|
||||||
|
// {
|
||||||
|
// listContainers(containers, numContainers);
|
||||||
|
|
||||||
|
// stopContainer(selectedNode, selectedLXC);
|
||||||
|
// GO.lcd.clearDisplay();
|
||||||
|
// GO.lcd.println("done");
|
||||||
|
|
||||||
|
// delay(2000);
|
||||||
|
// }
|
||||||
|
// }
|
||||||
Loading…
Reference in new issue