summaryrefslogtreecommitdiffstats
path: root/src/ogClient.py
Commit message (Collapse)AuthorAgeFilesLines
* ogclient: remove external referenceOpenGnSys Support Team2024-08-061-1/+0
|
* src: log backtrace in unhandled error casesAlejandro Sirgo Rica2024-04-031-2/+3
| | | | | | | | | | | | | | | | | | | Log an error message in known error cases and log a backtrace otherwise. Define a new error type OgError to be used in all the 'raise' blocks to define the error message to log. The exception propagates until it reaches send_internal_server_error() where the exception type is checked. If the type is OgError we log the exception message. Logs the backtrace for other types. The initial error implementation printed a backtrace everytime an error ocurred. The next iteration changed it to only print a backtrace in a very particular case but ended up omiting too much information such as syntax errors or unknown error context. The actual implementation only logs the cases we already cover in the codebase and logs a bracktrace in the others, enabling a better debugging experience.
* ogclient: consolidate logging in client coreAlejandro Sirgo Rica2024-03-211-3/+2
| | | | | | | | | The main function must be able to handle the login of critical error in the main ogClient class instance. Add a try except block to the ogCLient run logic and move the relevant error logs into the except block. Delegate the error messages to the exception message. This is the first step towards error message deduplication.
* ogclient: add support for X-Sequence headerv1.3.0Jose M. Guisado2023-06-141-0/+3
| | | | | | | | | | | | | | | Enable parsing of "X-Sequence" HTTP headers from incoming requests. Add "seq" field in restRequest class. Enable adding "X-Sequence" to outgoing responses. Add "seq" field inside restResponse class. Store current client sequence number inside ogClient class. Ideally, the restRequest object should be used to retrieve the sequence number but not all processing functions inside ogRest.py receive the request as parameter (eg: process_refresh). In the other hand, all processing functions receive the ogClient object.
* src: improve loggingJose M. Guisado2022-06-081-8/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | Adds new logging handler redirecting messages to the log file located in the Samba shared directory (applies to live mode clients, i.e: ogLive) Parses log level configuration from ogclient.json. See: { "opengnsys": { ... "log": "INFO", ... } ... } Adds --debug option to set root logger level to DEBUG when starting ogClient. Overrides log level from config file. In addition: - Replaces any occurence of print with a corresponding logging function. - Unsets log level for handlers, use root logger level instead. - Default level for root logger is INFO. - Replaces level from response log messages to debug (ogRest)
* #1065 Init event socket according to modeJose M. Guisado2022-02-021-1/+3
| | | | | | | Commit 700aa89ea99 introduced the use of getattr when getting event socket to avoid errors in case it was not initialized. Prefer to initialize accordingly inside the ogClient class constructor.
* #1065 Use getattr when retrieving event socketJose M. Guisado2022-02-011-1/+1
| | | | | | | | | | | | | | If ogClient does not run on windows or linux mode, it does not create a datagram event socket. If ogClient runs in virtual or live mode this will cause an error when calling get_event_socket because the class instance has no member "event_sock". Use getattr when retrieving the event socket from ogClient class, if there is no event socket, then return None. Fixes 2465ef25b741 (Add event datagram socket)
* #1065 Init config_path according to platformJose M. Guisado2021-12-101-5/+1
| | | | | | | | | | Commit 2dbcd18c06dd breaks interfaceAdm path for live operations. Keep OG_PATH to the value prior to commit 2dbcd18c06dd. Check platform before reading config file. If platform is different from linux then look for cfg/ogclient.json in current folder and do not use OG_PATH.
* #1065 Add event datagram socketJose M. Guisado2021-11-291-1/+29
| | | | | | | | | | ogClient can receive events via a datagram socket opened at 55885. This socket is only opened when in windows or linux mode, for event reporting from within the system. Events reported this way are sent back to ogServer via a 103 Early Hints HTTP message. Information regarding the event is sent in the response's payload.
* #1065 Fix windows not reattempting refused connectionsJose M. Guisado2021-11-231-1/+5
| | | | | | | | | Windows does not report a refused connection the same way as Linux. Unsuccesful connect socket will be kept in the exceptfds, and won't be in the readable nor writable fds. The socket in this state will have SO_ERROR set to ECONNREFUSED. On the other hand, Linux does not use exceptfds for such case.
* #1065 revisit config_path initializationJose M. Guisado2021-11-181-1/+4
| | | | | | | If current platform is Linux (either live, virtual or linux) expect /opt/opengnsys/ogclient/cfg/ to contain ogclient.json. If current platform is not Linux then we fallback to current directory.
* #1065 Add windows modeJose M. Guisado2021-11-181-1/+1
| | | | | | | | | | | | Add agent mode for windows platform. Subprocess module for shell/run is cross-platform an no change was needed. The subprocess will run with the same privilege as its parent, ogclient. TODO: Provide a windows installer. As of now, an administrator needs to install python and required libraries for this mode to be usable.
* #1065 src: add linux modeJose M. Guisado2021-11-151-1/+1
| | | | | | | | | | | | | | | | | | | | | ogClient can run in "linux" mode. In addition to live or virtual. Serves as a substitute to the legacy ogagent, which has not received any updates since 2020/07/23. Linux mode initially supports remote reboot and poweroff. Requires updated ogServer with the Linux ogclient state. ogClient can be set up to run in linux mode by specifying it in ogclient.json: { "opengnsys": { "ip": "192.168.56.10", "port": 8889, "log": "DEBUG", "mode": "linux", ... }
* #1056 stop thread if connection with server is lostOpenGnSys Support Team2021-11-111-0/+1
| | | | | | | | | | | | | | | | Abort command if the connection with the server is lost. Otherwise, a race condition that leaves ogServer and ogClient out-of-sync might occur: 1. ogClient is busy running a command (on the worker thread), for example, image/restore. 2. ogServer is stopped OR ogClient loses connection with ogServer (due to transient network problem). 3. ogClient reconnects and ogServer sends a refresh command. 4. ogClient worker thread finishes and it sends a reply to image/restore. 5. ogServer gets confused because it expects a reply to the refresh command, not the old image/restore.
* #1056 stop request processing on connection closureOpenGnSys Support Team2021-07-151-1/+1
| | | | | | If server closes the connection, close the socket, reconnect and stop processing. self.connect() already cleans up the internal state, including the socket state.
* #1056 add cleanup method and use itOpenGnSys Support Team2021-07-151-10/+8
| | | | add method to clean up interval socket state and use it
* #1000 Fix HTTP request header length parsingJavier Sánchez Parra2021-07-131-3/+4
| | | | | | | | | | | | | | | | | | | OgClient miscalculates the body size of the request. ogServer delimits HTTP headers with "\r\n\r\n" to comply with RFC 2616. But ogClient searches for the first "\r\n" delimiter, hence, ogClient stops at the first HTTP header field instead of at the end of the header. Hence, it incorrectly assumes the body starts after the first "\r\n". This commit updates ogClient to search for the "\r\n\r\n" delimiter. Example: POST /shell/run HTTP/1.1\r\n <-- ogClient considers body starts here (WRONG!) Content-Length: 952\r\n Content-Type: application/json\r\n \r\n <-- Here is where the body starts {"json-body":...}
* ogClient is AGPLv3+OpenGnSys Support Team2021-05-141-3/+3
| | | | Update license header in files.
* #980 Broken TCP connection times out after 120 seconds through keepaliveOpenGnSys Support Team2021-04-231-0/+5
| | | | | Enable TCP keepalive to detect if the ogServer is gone (hard reset). If no reply after 120 seconds, then release the connection to the server.
* #1000 Fix ogClient HTTP length handlingJavier Sánchez Parra2020-08-251-4/+9
| | | | | | | | | | | | | | | | | | | | Irina reports that "Partition assistant"/"Asistente de particionado" is not working. This is happening because ogClient is not reading the full data ogServer sends when the entire HTTP PDU is larger than 1024. However, ogClient should read the whole message, reading until read data length is greater or equal to "Content-Length" header value. ogClient fails to obtain "Content-Length" value because is looking for "content-length", be aware of the case sensitivity. It also needs to take into account the header length because read data length also includes headers. This patch updates ogClient to: 1) look for "Content-Length instead of "content-length". 2) compare read date length with content length plus headers length.
* #999 Fix ogClient session commandJavier Sánchez Parra2020-08-211-0/+1
| | | | | | | | | Disconnect gracefully from ogServer after booting OS, the script to start the OS calls kexec, so everything is gone after it. For Windows, this results in a reboot. This commit also improves the disconnect function to make sure the disconnection is synchronous.
* Rename 'linux' mode to 'live' modeRoberto Hueso Gómez2020-06-051-1/+1
| | | | 'linux' represents ogLive mode that is the reason for the rename.
* Delete ogConfig.pyRoberto Hueso Gómez2020-06-051-0/+2
| | | | | This file is only used for its OG_PATH variable, this variable is now in ogClient.
* remove platform checkOpenGnSys Support Team2020-05-131-3/+0
|
* Switch config file to jsonRoberto Hueso Gómez2020-05-131-10/+15
| | | | | This patch makes configuration parsing easier as well as making the full configuration available in many subclasses.
* Use samba for create and restore virtual partitionsRoberto Hueso Gómez2020-04-171-2/+7
| | | | This requires to configure user and password for samba repositories.
* wait for 1 second if connection is refusedOpenGnSys Support Team2020-04-141-18/+6
|
* Sleep 1 second to avoid high CPU loadRoberto Hueso Gomez2020-04-141-0/+1
|
* Avoid connection status infinite print loopRoberto Hueso Gomez2020-04-141-7/+17
| | | | This patch avoids infinite writting of connection status messages to the log.
* Add mode selection for ogClientRoberto Hueso Gomez2020-04-081-2/+6
|
* Rename operation to methodOpenGnSys Support Team2020-02-261-1/+1
| | | | As defined by the HTTP standard.
* (Clean-Up) Rename HTTPParser to restRequestAlvaro Neira Ayuso2020-01-191-4/+4
|
* Include License headerAlvaro Neira Ayuso2020-01-191-0/+8
|
* Fix ogClient socket.error typoRoberto Hueso Gómez2020-01-191-1/+2
|
* Change ogClient.py encoding from dos to unixRoberto Hueso gomez2020-01-191-123/+123
|
* Add session command to init the opengnsys sessionAlvaro Neira Ayuso2020-01-191-1/+1
| | | | | | | | 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"}
* Add shell run and output commandsAlvaro Neira Ayuso2020-01-191-2/+2
| | | | | | | | 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.
* Merge ogRest and ogProcess to have only one classAlvaro Neira Ayuso2020-01-191-3/+3
|
* Include disconnect and send function on client sideAlvaro Neira Ayuso2020-01-191-2/+9
| | | | | | | | | To disconnect the socket or send a message we use in different parts of the code the attribute socket which is declared inside of the client. This way will create us important problem in the future if we want to change the behavior in our client sockets. This patch adds two new methods inside the client and we can use them in other classes giving us the easy way to send messages and disconnect the client.
* Add ogRest class to generate API Rest ResponsesAlvaro Neira Ayuso2020-01-191-4/+5
| | | | | 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.
* Port program to Python 3Alvaro Neira Ayuso2020-01-191-15/+17
| | | | | Python 2.7 will be deprecated in January of 2020. So, we need to have the program with a supported api.
* Remove unneeded logsAlvaro Neira Ayuso2020-01-191-3/+0
|
* Send bad request when the APIRest operation is not supportedAlvaro Neira Ayuso2020-01-191-3/+4
| | | | | | | | | | | | | | Our program sends always the HTTP message: HTTP/1.0 200 OK but if the operation sent is not supported, we are sending the same correct message. This patch add the support to check if the message is supported. If the message is not supported, we are going to send: HTTP/1.0 400 Bad request\r\n\r\n Otherwise, in operations supported: HTTP/1.0 200 OK
* Execute socket loop on run socket functionAlvaro Neira Ayuso2020-01-191-0/+20
| | | | Ported code from main function to a client function for clearing the main loop.
* Add ogProcess and ogOperation for linuxAlvaro Neira Ayuso2020-01-191-0/+5
| | | | | Thoses new classes allows us to process and execute commands from server side sent using HTTP format.
* Add HTTP parser supportAlvaro Neira Ayuso2020-01-191-11/+4
| | | | | | The new OpenGnsys support to communicate server and client side will be HTTP. This new class allows us the support for parsing all the message received from the server in HTTP format.
* Modify Client state to use enumAlvaro Neira Ayuso2020-01-191-6/+8
| | | | | | | | | During our connections, we are using states to control the Client Socket. We defined using global variables. In case that we modify this global variable, we need to change it in serveral parts of the code. Using enums and declaring a new class, we can redefine the values or create new states without changing the same code in differents python files.
* Create new ogClientAlvaro Neira Ayuso2020-01-191-0/+95
This commit init the new ogClient. The new ogClient has support for configuring and for connecting with the ogAdminServer.