summaryrefslogtreecommitdiffstats
path: root/src/ogRest.py
Commit message (Collapse)AuthorAgeFilesLines
* src: remove unused legacy software inventory codeJose M. Guisado2023-05-171-11/+7
| | | | | | | | | | | | | Remove unnecessary InventarioSoftware invocation inside image_create operation. Software inventory is executed after image creation (see ogRest.py). Remove legacy 'path' parameter. This parameter was used to specify the path of a text file in which legacy bash scripts wrote the software inventory of the client (something like "Csft-{ip}..."). Fixes: 04bb35bd86b58c ("live: rewrite software inventory") Fixes: 2e3d47b7b8db69 ("Avoid writting /software output to a file")
* live: rewrite hardware inventory commandJose M. Guisado2023-04-181-6/+4
| | | | | | | | | | | | | | | | Replace legacy shell script InventarioHardware for helper functions from hw_inventory.py Use get_hardware_inventory to obtain a HardwareInventory object with the hardware information. Map the HardwareInventory object to a legacy response string with the legacy_list_hardware_inventory function. Remove "Chrd-*" file reading logic, it's no longer needed. Legacy shell script InventarioHardware uses that file. Expect a change in the structure of hardware inventory response payload in the future. This patch does not address the HTTP response containing the hardware inventory as a '\n' separated string of hardware elements.
* ogRest: improve error logging when executing operationsv1.2.6Jose M. Guisado2023-03-101-32/+23
| | | | | | | | | | | | | Capture all possible Python exceptions in the try/except block of every opengnsys operation. Create an error handling function to deduplicate code in the except block. The error handling function resets the ogRest state to IDLE and sends the corresponding 500 Internal Server Error. This *does not cover* every possible error. There are functions inside ogThread which contain code that may raise errors that are not covered by any try/except block.
* ogRest: remove root logger constantJose M. Guisado2023-03-101-7/+6
| | | | | | | | | | | | | | | | Remove unnecesary root logger constant: LOGGER The root logger is used by default when executing: logging.debug() logging.info() logging.warning() ... There is no point in doing: LOGGER = logging.getLogger() # Get root logger LOGGER.debug() # Use root logger
* legacy: rewrite ogGetImageInfoJose M. Guisado2023-03-021-4/+4
| | | | | | | | | | | | | | | | | | | | Rewrites this legacy script behavior using native Python code, using subprocess module when executing programs like partclone.info or lzop ogGetImageInfo is a bash script that retrieves information regarding an OpenGnsys partition image, specifically: - clonator - compressor - filesystem - datasize (size of the partition image) This rewrite only supports partclone and lzop compressed images. This is standard behavior, we have no reports of other programs or compression algorithms in use. Keep this legacy function with hungarian notation to emphasize this is still a legacy component that may be replaced in the future.
* src: improve loggingJose M. Guisado2022-06-081-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | 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 Add event datagram socketJose M. Guisado2021-11-291-0/+3
| | | | | | | | | | 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 Add windows modeJose M. Guisado2021-11-181-1/+3
| | | | | | | | | | | | 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 Use logging module instead of syslogJose M. Guisado2021-11-181-14/+13
| | | | | | | | | | | | | | | | | | | | | | | | We can't use syslog if we want to execute ogClient in the Windows platform. Use the native logging library so we can attach different handlers depending on the mode ogClient is executing. Logging configuration is done via a python dict. There is a different dict for linux and windows. These dicts define the configuration of the root logger, handlers and formatters used. As of now, it is only expected to use the root logger for everything logging related. The root logger is obtained via: LOGGER = logging.getLogger() More info about handlers, formatters and loggers: https://docs.python.org/3/howto/logging.html Logging configuration is done at startup, just after parsing the json (knowing ogclient mode). If json parsing goes bad, ogclient will only print a message to stdout.
* #1065 src: add linux modeJose M. Guisado2021-11-151-0/+3
| | | | | | | | | | | | | | | | | | | | | 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", ... }
* ogClient is AGPLv3+OpenGnSys Support Team2021-05-141-3/+3
| | | | Update license header in files.
* #995 Add link speed in probe responsesJose M. Guisado2021-05-041-5/+9
| | | | | | | | Separates probe method into separate ogclient modes (virtual, vdi) so future supported OS can easily have a tailored probe responses. Link speed is retrieved using a minimal ethtool command sent using fcntl module from python.
* Rename 'linux' folder and operations to 'live'Jose M. Guisado2020-12-031-2/+2
| | | | | | | | | | | ogLive related operations are named inside a 'Linux' folder, also its python class is named OgLinuxOperations. Rename every 'linux' occurrence with live to further clarify this folder and operations. - OgLinuxOperations -> OgLiveOperations - src/linux/ -> src/live/ Fixes: 1377acee ('Rename 'linux' mode to 'live' mode')
* #1010 Change POST /software to GETJavier Sánchez Parra2020-12-021-2/+2
| | | | | | | ogClient /software gets a representation of the target resource’s state. GET method is more appropriate than POST. Change /software method from POST to GET.
* #1000 ogRest: set idle state after processing bad requestJose M. Guisado2020-12-011-0/+3
| | | | | | | | | | | | Before this patch the ogRest would hang indifinitely in a BUSY state when a bad request was received. Fix this by returning ogRest state to IDLE once the corresponding bad request response has been sent. This accounts for the following cases: - Unknown GET action - Unknown POST action - Unknown HTTP verb
* #1004 Send datasize in bytesJavier Sánchez Parra2020-09-291-1/+4
| | | | | | | Image datasize is expressed in kibibytes but the existing REST API field represent data in bytes. This commit changes ogClient to send datasize in bytes.
* #1004 Add new fields to /image/create responseJavier Sánchez Parra2020-09-101-1/+7
| | | | | | | | | | | | | | | | | | | | | | | | Extend ogClient to include more information about the image that has been created. This patch modifies ogClient to read an info file created by image creation script, add this info to the JSON response and then remove the file. Example of new /image/create response: { "disk": "1", "partition": "1", "code": "131", "id": "1", "name": "ubuntu", "repository": "192.168.56.10", "software": "Ubuntu 18.04.5 LTS \naccountsservice 0.6.45\n...", "clonator": "PARTCLONE", "compressor": "LZOP", "filesystem": "EXTFS", "datasize": 2100000 } New fields are "clonator", "compressor", "filesystem" and "datasize".
* #999 Fix ogClient session commandJavier Sánchez Parra2020-08-211-1/+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.
* Add Virtual statusJavier Sánchez Parra2020-06-261-1/+4
| | | | | Since version 1.2.0, OpenGnsys supports ogVDI hypervisor OS. This commit a new status which indicates that clients are running ogVDI
* Add syslog logs for HTTP requests and responsesRoberto Hueso Gómez2020-06-261-0/+21
| | | | | | | | | | This is useful for debuging and getting information on the processes that are being executed in ogclient. syslog outputs are something similar to: Jun 26 10:36:40 ogAdministrator /ogclient: GET refresh HTTP/1.1 Jun 26 10:36:40 ogAdministrator /ogclient: HTTP/1.0 500 Internal Server Err
* Import OgLinuxOperations only when necessaryRoberto Hueso Gómez2020-06-081-2/+1
| | | | | This fixes a circular import error produced by the import of ogClient inside of OgLinuxOperations.
* Rename 'linux' mode to 'live' modeRoberto Hueso Gómez2020-06-051-1/+1
| | | | 'linux' represents ogLive mode that is the reason for the rename.
* Move check_vm_state_loop() into OgVirtualOperationsRoberto Hueso Gómez2020-05-261-14/+3
| | | | | | Improves code encapsulation by moving check_vm_state_loop method into OgVirtualOperations class. This also fixes import error when running ogclient in 'linux' mode.
* Only import virtual functions when needed.Javier Sánchez Parra2020-05-201-1/+2
| | | | | | | | | ogClient may runs on an OS that do not have all the dependencies needed to use virtual functions. This commit change the behaviour to only import virtual functions when the ogClient has to work with Virtual Machines. This way ogClient works on environments which do not need virtual functions.
* Adapt ogLinuxOperation to work with json config fileJavier Sánchez Parra2020-05-181-1/+1
| | | | | | | ogClient changed its config file format to json. This patch adapts ogLinuxOperation to use new config file. Co-authored-by: Roberto Hueso <rhueso@soleta.eu>
* Wait before polling QMP for host poweroffRoberto Hueso Gómez2020-05-141-2/+2
| | | | | This patch waits before polling qemu with QMP so that it has time to be ready for requests. It also increases wait time in case the host machine is slow.
* Rename operation 'execCMD' to 'shellrun'Roberto Hueso Gómez2020-05-131-1/+1
| | | | This patch also ignores calls to shellrun when virtual mode is activated.
* Switch config file to jsonRoberto Hueso Gómez2020-05-131-4/+5
| | | | | This patch makes configuration parsing easier as well as making the full configuration available in many subclasses.
* Poweroff when no VM and no jobs are runningRoberto Hueso Gómez2020-05-111-1/+14
| | | | | | This patch calls poweroff in virtual mode when no VM is running and no jobs are being executed. This is useful when the guest OS shutdowns so that the host OS does not continue to run.
* Avoid killing ogclient in virtual modeRoberto Hueso Gómez2020-04-201-8/+8
|
* Avoid writting /software output to a fileRoberto Hueso Gómez2020-04-171-5/+4
|
* Use samba for create and restore virtual partitionsRoberto Hueso Gómez2020-04-171-1/+2
| | | | This requires to configure user and password for samba repositories.
* Fix reboot and poweroff threads argsRoberto Hueso Gomez2020-04-131-2/+2
|
* Add mode selection for ogClientRoberto Hueso Gomez2020-04-081-17/+25
|
* rename getURI to get_uri in restRequestOpenGnSys Support Team2020-03-091-1/+1
|
* rename execcmd to shellrunOpenGnSys Support Team2020-03-091-2/+2
|
* Put state to IDLE after run/scheduleRoberto Hueso Gómez2020-03-031-0/+1
|
* Send complete HTTP header when response has no bodyRoberto Hueso Gómez2020-03-021-1/+2
|
* Rename operation to methodOpenGnSys Support Team2020-02-261-4/+4
| | | | As defined by the HTTP standard.
* Modify way to close PID processAlvaro Neira Ayuso2020-02-241-12/+17
| | | | | | 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.
* Use state machine to avoid race condition problemsAlvaro Neira Ayuso2020-02-231-11/+63
| | | | | | 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.
* pep-0008 cleanupOpenGnSys Support Team2020-02-211-38/+38
| | | | | | | From pep-0008: Method Names and Instance Variables Use the function naming rules: lowercase with words separated by underscores as necessary to improve readability.
* Use 'with' keyword for file readingRoberto Hueso Gómez2020-02-051-9/+4
| | | | | | 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.
* Fix /image/restore execution and responseRoberto Hueso Gómez2020-02-051-0/+5
|
* Fix /image/create execution and responseRoberto Hueso Gómez2020-02-051-5/+2
|
* Fix /setup execution and responseRoberto Hueso Gómez2020-02-031-8/+2
|
* Fix parseGetConf(...) configuration parsingRoberto Hueso Gómez2020-02-031-5/+6
| | | | This patch also reformats the response to the /refresh command.
* add space after Content-Length and Content-TypeOpenGnSys Support Team2020-01-281-2/+2
| | | | ogAdmServer needs this space to work fine.
* Change POST /refresh to GET /refreshRoberto Hueso Gómez2020-01-211-2/+2
| | | | | This patch changes the HTTP method for /refresh and cleans up the implementation of the /refresh Linux operator.
* Fix /software command Linux operationRoberto Hueso Gómez2020-01-211-3/+3
| | | | | This patch runs the script InventarioSoftware with the right arguments. This also increases the recv buffer size for the test server.