/// @brief This is a function to send data to the API. Used for commands such as restarting. It also supports including a post payload to send additional information the API.
/// @param apiPath Refrence to a string which holds the appropriate path on the API to send data.
/// @param post Reference to a string which contains a payload to send to the API.
/// @brief Function to retrieve a specific node. Retrieves an array of the nodes and uses a for loop to check the name of each one until it finds one that matches the provided name.
/// @param name A reference to a string containing the name of the node being searched for.
/// @return The node which matches the name provided.
NodegetNode(constString&name)
{
intnumNodes;
Node*nodes=getNodeInfo(&numNodes);
Node*nodes=getNodeInfo(numNodes);
for(inti=0;i<numNodes;i++)
{
if(nodes[i].name==name)
{
returnnodes[i];
Nodenode=nodes[i];
delete[]nodes;
returnnode;
}
}
throwstd::runtime_error("Can't find the requested node in the array");
}
ContainergetContainer(intid,Stringnode)
/// @brief Function to retrieve a specific container. Retrieves an array of the containers and uses a for loop to check the id of each one until it finds one that matches the provided id.
/// @param id A reference to an integer which contains the id of the container being searched for.
/// @param node A reference to a string which contains the name of the node being searched on.
/// @return A container that matches the id provided.
throwstd::runtime_error("Can't find the requested container in the array");
}
VMgetVM(intid,Stringnode)
/// @brief Function to retrieve a specific VM. Retrieves an array of the VMs and uses a for loop to check the id of each one until it finds one that matches the provided id.
/// @param id A reference to an integer which contains the id of the VM being searched for.
/// @param node A reference to a string which contains the name of the node being searched on.
/// @return A VM that matches the id provided.
VMgetVM(constint&id,constString&node)
{
intnumVMs;
VM*vms=getVMInfo(&numVMs,node);
VM*vms=getVMInfo(numVMs,node);
for(inti=0;i<numVMs;i++)
{
if(vms[i].id==id)
@ -51,11 +66,15 @@ VM getVM(int id, String node)
throwstd::runtime_error("Can't find the requested vm in the array");
}
DiskgetDisk(Stringdevpath,Stringnode)
/// @brief Function to retrieve a specific disk. Retrieves an array of the containers and uses a for loop to check the devpath (e.g /dev/sda) of each one until it finds one that matches the provided devpath.
/// @param devpath A reference to a string which contains the devpath of the container being searched for.
/// @param node A reference to a string which contains the name of the node being searched on.
/// @return A disk that matches the devpath provided.
DiskgetDisk(constString&devpath,constString&node)
{
intnumDisks;
Disk*disks=getDiskInfo(&numDisks,node);
Disk*disks=getDiskInfo(numDisks,node);
for(inti=0;i<numDisks;i++)
{
if(disks[i].devpath==devpath)
@ -67,11 +86,15 @@ Disk getDisk(String devpath, String node)
throwstd::runtime_error("Can't find the requested disk in the array");
}
PoolgetPool(Stringname,Stringnode)
/// @brief Function to retrieve a specific ZFS pool. Retrieves an array of the pools and uses a for loop to check the name of each one until it finds one that matches the provided name.
/// @param name A reference to a string which contains the name of the pool being searched for.
/// @param node A reference to a string which contains the name of the node being searched on.
/// @return A pool that matches the name provided.
/// @brief User interface function to restart a VM. Retrieves an array of all VMs on the selected node, calls the list function to allow the user to pick a VM and then calls the restartVM() function on that VM to send the request to the API. Returns to the manage VM menu afterwards.
voidvmRestart()
{
Serial.println("vm restart");
selectedItem=0;
selectedVM=0;
intnumVMs;
VM*vms=getVMInfo(&numVMs,selectedNode);
VM*vms=getVMInfo(numVMs,selectedNode);
listVMs(vms,numVMs);
delete[]vms;
if(selectedVM>0)
@ -26,13 +27,14 @@ void vmRestart()
manageVMMenu();
}
/// @brief User interface function to restart a container. Retrieves an array of all containers on the selected node, calls the list function to allow the user to pick a container and then calls the restartContainer() function on that container to send the request to the API. Returns to the manage container menu afterwards.
/// @brief User interface function to start a VM. Retrieves an array of all VMs on the selected node, calls the list function to allow the user to pick a VM and then calls the startVM() function on that VM to send the request to the API. Returns to the manage VM menu afterwards.
voidvmStart()
{
Serial.println("vm start");
selectedItem=0;
selectedVM=0;
intnumVMs;
VM*vms=getVMInfo(&numVMs,selectedNode);
VM*vms=getVMInfo(numVMs,selectedNode);
listVMs(vms,numVMs);
delete[]vms;
if(selectedVM>0)
@ -71,13 +73,14 @@ void vmStart()
manageVMMenu();
}
/// @brief User interface function to start a container. Retrieves an array of all containers on the selected node, calls the list function to allow the user to pick a container and then calls the startContainer() function on that container to send the request to the API. Returns to the manage container menu afterwards.
/// @brief User interface function to stop a VM. Retrieves an array of all VMs on the selected node, calls the list function to allow the user to pick a VM and then calls the startVM() function on that VM to send the request to the API. Returns to the manage VM menu afterwards.
voidvmStop()
{
Serial.println("vm stop");
selectedItem=0;
selectedVM=0;
intnumVMs;
VM*vms=getVMInfo(&numVMs,selectedNode);
VM*vms=getVMInfo(numVMs,selectedNode);
listVMs(vms,numVMs);
delete[]vms;
if(selectedVM>0)
@ -114,13 +119,14 @@ void vmStop()
manageVMMenu();
}
/// @brief User interface function to stop a container. Retrieves an array of all containers on the selected node, calls the list function to allow the user to pick a container and then calls the stopContainer() function on that container to send the request to the API. Returns to the manage container menu afterwards.
// Initializing variables which hold the selections.
intselectedItem=0;
intselectedPage=0;
StringselectedNode="";
@ -31,20 +32,24 @@ MenuItem mainMenuItems[] = {
{"Manage VM",&manageVMMenu},
{"Manage Container",&manageContainerMenu}};
// Array of the VM managment menu items.
MenuItemmanageVMItems[]={
{"Restart",&vmRestart},
{"Start",&vmStart},
{"Stop",&vmStop},
};
// Array of the container management menu items.
MenuItemmanageContainerItems[]={
{"Restart",&containerRestart},
{"Start",&containerStart},
{"Stop",&containerStop},
};
intbuttonListener(intnumItems)
/// @brief Function to listen for button presses. Once called it will loop until a button is pressed. For the directional pad the selected page or item is changed and 0 is returned. For the A/B buttons 1/2 is returned to indicate that the user wants to select something or go back.
/// @param numItems A reference an integer which holds the number of items for the user to pick from in the menu.
/// @return An integer indicating what action was taken. 1 for the A button, 2 for the B button, 0 for any other input.
intbuttonListener(constint&numItems)
{
delay(300);
while(true)
@ -91,7 +96,15 @@ int buttonListener(int numItems)