Commit Graph

109 Commits (cf9577a40edd7c3f8bebcf02aaccb7ef441e7dac)

Author SHA1 Message Date
Roberto Hueso Gomez f56065a438 Fix reboot and poweroff threads args 2020-04-13 15:16:52 +02:00
Roberto Hueso Gomez 4f03c31f85 Add mode selection for ogClient 2020-04-08 13:31:45 +02:00
OpenGnSys Support Team d69841ed97 rename getURI to get_uri in restRequest 2020-03-09 18:10:57 +01:00
OpenGnSys Support Team 5964e48df9 rename execcmd to shellrun 2020-03-09 18:10:54 +01:00
Roberto Hueso Gómez 4e1ad0f949 Put state to IDLE after run/schedule 2020-03-03 14:13:10 +01:00
Roberto Hueso Gómez b53f8d0f8f Send complete HTTP header when response has no body 2020-03-02 09:32:40 +01:00
OpenGnSys Support Team a85c113ee7 Rename operation to method
As defined by the HTTP standard.
2020-02-26 17:58:15 +01:00
Alvaro Neira Ayuso 6f7ba325b8 Modify way to close PID process
With our client disconnection, we hid that the ogClient process will be
closed too. This new way only close the subprocess keeping the ogClient
still working.
2020-02-24 09:35:24 +01:00
Alvaro Neira Ayuso 583057bd69 Use state machine to avoid race condition problems
This patch allows us to control the thread using a state machine. This state
machine controls if the client is busy or not. This new way to control the
threads give us more control for avoiding race condition problems.
2020-02-23 20:04:47 +01:00
OpenGnSys Support Team 3917c3675f pep-0008 cleanup
From pep-0008: Method Names and Instance Variables

Use the function naming rules: lowercase with words separated by underscores as
necessary to improve readability.
2020-02-21 12:57:54 +01:00
Roberto Hueso Gómez 1fd9f2e07c Use 'with' keyword for file reading
This is applied to /software and /hardware file reads.
We should use 'with' instead of opening and closing a file since this prevents
that files stay open after an exception is raised.
2020-02-05 16:49:42 +01:00
Roberto Hueso Gómez fe4236dcd8 Fix /image/restore execution and response 2020-02-05 13:42:10 +01:00
Roberto Hueso Gómez 680214317e Fix /image/create execution and response 2020-02-05 13:41:54 +01:00
Roberto Hueso Gómez 2934773d88 Fix /setup execution and response 2020-02-03 10:15:54 +01:00
Roberto Hueso Gómez e96e187825 Fix parseGetConf(...) configuration parsing
This patch also reformats the response to the /refresh command.
2020-02-03 10:15:49 +01:00
OpenGnSys Support Team f86999da0c add space after Content-Length and Content-Type
ogAdmServer needs this space to work fine.
2020-01-28 09:14:13 +01:00
Roberto Hueso Gómez dabc7ebf83 Change POST /refresh to GET /refresh
This patch changes the HTTP method for /refresh and cleans up the implementation
of the /refresh Linux operator.
2020-01-21 17:33:05 +01:00
Roberto Hueso Gómez ca0a62f9c6 Fix /software command Linux operation
This patch runs the script InventarioSoftware with the right arguments.
This also increases the recv buffer size for the test server.
2020-01-21 17:32:57 +01:00
Roberto Hueso Gómez 9890d60300 Fix /shell/run commands splitting
This patch splits shell commands either with ';' or '\n'.
2020-01-21 17:32:48 +01:00
Roberto Hueso Gómez 96c2ddea2d Fix /hardware command Linux operation
This patch runs the script InventarioHardware with the right arguments.
2020-01-21 17:32:42 +01:00
Alvaro Neira Ayuso 2e806531a0 (Clean-Up) Rename all the functions in ogRest to new ones more clears 2020-01-19 20:18:14 +01:00
Alvaro Neira Ayuso e39fe2fc52 (Clean-Up) Rename HTTPParser file to restRequest 2020-01-19 20:18:14 +01:00
Alvaro Neira Ayuso 86eb703964 (Clean-Up) Modify restResponse to get the response using constructor and get function 2020-01-19 20:18:07 +01:00
Alvaro Neira Ayuso 8fc251eff3 (Clean-Up) Rename HTTPParser to restRequest 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 8e54420dfd (Clean-Up) Rename cmd function/variables to use "run" syntax 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 5603a280ef Improve /image/create command response
With this new patch, the image/create command will create a response message
with more information for the server. The new format is:

{"disk" : "1", "partition" : "1", "code" : "1", "id" : "1", "name" : "test",
"repository" : "192.168.2.4", "software" : "xyz"}

"xyz" will be the output saved during the execution of InventarioSoftware in
a specific path.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso b5e182f7dd Add Refresh command
This patch allows us to execute refresh command using ogClient. This command
gets all the configuration in our machine and send this information to the
server. The format of the message that ogClient will send to the server will be:

{"disk": "1", "partition_setup": [{"partition": "1", "code": "LINUX",
"filesystem": "NTFS", "size": "498688", "format": "0"}, {"partition": "2",
"code": "LINUX", "filesystem": "NTFS", "size": "498688", "format": "0"},
{"partition": "3", "code": "LINUX", "filesystem": "NTFS", "size": "498688",
"format": "0"}]}
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso b2fd0b5fff Add image/create command for creating a new image
This patch allows us to use a new support for creating images using ogClient.
ogClient receives from the server a message which json body must be:

{"disk" : "1", "partition" : "1", "code" : "1", "id" : "1", "name" : "test",
"repository" : "192.168.2.4" }

ogClient returns to the server the software inventory executed before
create the image. The message for the server is:

{ "disk" : "0", "partition" : "1", "software" : "xyz" }

    "xyz" will be the output saved during the execution of InventarioSoftware in
    a specific path.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso fdd4ba59c7 (BUG) Include client parameter in restore command 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 05b1088827 Include License header 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso d5dca0f756 Add stop command
This patch includes a new support for stopping all the process running on
the ogClient.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 230bdca0ea Execute cmd command using thread
This patch prepares the code for future stop command.
2020-01-19 19:50:44 +01:00
Roberto Hueso Gómez b9c33f2c83 Fix echo check for process_shellrun in ogRest 2020-01-19 19:50:44 +01:00
Roberto Hueso Gómez 9c34a8e69f Change /probe from GET to POST in ogClient 2020-01-19 19:50:44 +01:00
Roberto Hueso Gómez 3a44e48e4b Adapt client responses to the server's
Header parameters need to be sorted for the test server.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso a9d81adb1f Include echo option for returning shell output
This patch adds a new echo option in /shell/run command. In case that the option
is set up to true, the server will receive in the response a json with the shell
output. Otherwise, the server will receive a response message without json
body.

A side effect of this change is that the command /shell/output/ disapears.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 336b02371d Send OPG (opengnsys) status when a probe command is received 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 38b57c4ae4 Improve setup command response
This patch adds a new response support. This way allows us to send a new
response message with more information about the partitions already set up.
The format of the response is:

{ "disk" : "1", "cache" : "1", "cache_size" : "0",
"partition_setup": [{"partition": "1", "code": "LINUX", "filesystem": "EMPTY",
"size": "498688", "format": "0"}...]
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso a306b8b9d8 Catch execution errors during restore image command
This patch allows us to send feedback to the server in case of error during
the execution of the command. In case of error, ogClient will send an
"Internal Error" http message.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 1ced3dd069 Improve hardware command response behavior
This patch give us a better support in case of error or success execution.
In error cases, the new behavior is to send an Internal Error http message (500).
Otherwise, the server will receive a message with a json with this format:

    { "hardware" : "xyz" }

"xyz" is the output saved in a specific path during the execution of
InventarioHardware.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 683afa6465 Improve software command response behavior
During our tests, we found some limitation during the execution of the software
command. We don't manage errors during the execution of this command. Moreover,
the server needs some information in case that everything is OK.

This patch modified the code for controlling the errors during the execution,
returning an "Internal Error" http message (500). Moreover, in case that
everything is OK, ogClient sends a message with this json body:

    { "disk" : "0", "partition" : "1", "software" : "xyz" }

"xyz" will be the output saved during the execution of InventarioSoftware in
a specific path.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 0f32b9ca88 Catch execution errors during init session command
This patch allows us to catch an exception when something wrong is happening
executing the init session command. In error cases, ogClient sends an internal
error http message to the server. Otherwise, an OK http message.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 2e342b50c8 Modify methods to use less arguments
Now, all the arguments are received from httpparser. Those arguments convert
the function in long lines of codes. Passing directly the httpparser, all the
function will have less arguments and will be more clear the code.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso cc11d8f38f Add restore/image command for restoring images on the machine
ogAdmClient has a support to restore image on the machine. This new command
allows the new ogClient to execute the same script to restore the images
on the machine. The json format sent from the server must be:

{ "disk" : "1", "partition" : "1", "name" : "test",\
 "repository" : "192.168.56.10", "type" : "UNICAST", "profile": "1", "id": "1"}
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso efbe8a7960 Add setup command for configuring the machine
ogAdmClient has a support to configure the machines. This new command allows
the new ogClient to execute the same script to configure the machine.
The json format sent from the server must be:

{ "disk" : "1", "cache" : "0", "cache_size" : "70000000",\
"partition_setup": [{"partition": "1", "code": "NTFS", "filesystem": "NTFS",\
 "size": "11000000", "format": "0"}]}
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 9fd8f2dbd0 Add schedule command
No action executed. This command only return a 200 OK message.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 261a5edf7c Add hardware command to inventory the machine hardware
ogAdmClient has a support to inventory the hardware in a machine. This new
command allows the new ogClient to execute the same script to inventory the hw.
No arguments needed for executing the command
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 6d1e79b8eb Add software command to inventory the machine software
ogAdmClient has a support to inventory the software in a machine. This new
command allows the new ogClient to execute the same script to inventory the sw.
The arguments will be received from the server as a json message. Format:

{ "disk" : "0", "partition" : "1"}
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 2fa8aa4ff7 Add session command to init the opengnsys session
ogAdmClient has a support for initializing the session in the machine. This new
command allows the new ogClient to execute the same script to init the session.
The arguments will be received from the server as a json message. Format:

{ "disk" : "0", "partition" : "1"}
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 7c26c55074 Create new object for creating dynamic json messages 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso e6eba4b91f (BUG) Handling command error
This patch adds support for handling the error when the command is wrong formed.
Now, if we send a shell/run command and the shell command is incomplete,
the program crashes.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso af903503a2 Modify Thread methods names
This patch modifies the method names to use names more clear.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso b571f40482 Blocks the program execution until a command is processing
This patch changes the command process blocking the execution until is processing.
Moreover, the response will be OK (200) instead of IN_PROGRESS (202).
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 59a28237f1 Create ogThread class to move all thread functions
Right now, all the thread functions are declared inside the processor function.
Those functions were created for execute specific commands in the machine
(poweroff, reboot, etc). Creating this new class we are cleaning up the code.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso d065e1998d Execute command received using Threads
Now we are blocking the execution when we apply a command sent from the server.
This behavior is unacceptable for our client.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 6764fc44e1 Split the commands taking into account GET/POST operations 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso e20daf639d Add shell run and output commands
Opengnsys needs a support to execute commands on the machine. This patch adds
the support for executing two new commands "shell/run" and "shell/output". The
first one, give us the support for executing a command in the machine and keep
save in a queue the output. The second one, give us the support for sending the
output from the command executed.
2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso dfc97ffedb Merge ogRest and ogProcess to have only one class 2020-01-19 19:50:44 +01:00
Alvaro Neira Ayuso 694bc492a2 Add ogRest class to generate API Rest Responses
This class now, allow us to generate API Rest responses. In the future, the idea
is to complete this class with get and post messages if it's needed.
2020-01-19 19:50:44 +01:00