Commit Graph

161 Commits (6503d0ffe7eac8a1cd2cb77582719552114af398)

Author SHA1 Message Date
OpenGnSys Support Team 6503d0ffe7 live: call wipefs if partition or format fails
wipe disk if partition or format fails to leave the disk in consistent state.
2025-02-14 15:48:13 +01:00
Alejandro Sirgo Rica 0ca16bc46c live: remove unused variable in cache_delete()
Remove unused variable delted_images in the function cache_delete()
2025-02-14 13:15:27 +01:00
Alejandro Sirgo Rica bd190f8d44 live: send refresh payload in image restore
Send the refresh payload after a completed image restore operation.

The fields sent to ogServer are not enough to update the status of
the client and the OS installed in a partition does not appear in
the database.
2025-02-13 12:40:53 +01:00
Alejandro Sirgo Rica 72406a7d89 live: configure OS on first disk only
Call configure_os only for first disk, any other disks are only
supported to restore data images by now.

Call os_probe only for disk 1 in refresh.
2025-02-11 11:06:29 +01:00
Alejandro Sirgo Rica c260534534 live: remove unneeded string formatting in image_create
Replace f-string wf'{image_path}' with the variable image_path.
2025-02-03 11:27:18 +01:00
Alejandro Sirgo Rica 40e4545bb7 live: fix image restore backtrace
import the missing function is_hibernation_enabled() into
ogOperations.py to prevent a backtrace in each restore operation.
2025-01-07 15:02:10 +01:00
Alejandro Sirgo Rica d29b601f17 uefi: remove dependency with probe.py
Reduce interdependency between imports by checking the correct OS for
copy_windows_efi_bootloader() from the code invoking the operation.

Break circular dependency where:
probe.py imports from winreg.py
winreg.py imports from uefi.py
uefi.py imports from probe.py
2025-01-07 15:02:04 +01:00
Alejandro Sirgo Rica 203f3e5533 live: add additional error checks for shell run
Add checks for invalid arguments and permission errors.
2024-12-12 11:20:23 +01:00
OpenGnSys Support Team 62b52ff364 src: update license header 2024-11-28 16:45:56 +01:00
Alejandro Sirgo Rica e4be5c34eb src: add support for direct command execution
Update live shell run mode for the new REST API interface.
Evaluate the "inline" field to diferentiate between execution of
script in /opt/opengnsys/shell/ and a cmd execution.

Remove usage of echo argument of the API REST.

Update Windows and Linux mode for direct command execution.
Set OutputEncoding environment variable to 'utf-8' in Windows to
unify the encoding of stdout for the invoked programs.

Decode stdout to utf-8-sig to remove potential BOM.

While at this, remove strange legacy ;|\n\r terminator.
2024-11-27 13:53:19 +01:00
Alejandro Sirgo Rica a36c4daa23 src: add user session detection implementation
Detect user login and logout for Linux and Windows.

Report an active interactive session through the /refresh response
so a new ogserver instance can update the session status.

Poll the session change in 5 second intervals in a thread. Use the
same event socket previously used by the old session detection
mechanism to notify a session change.

Use the method check_interactive_session_change in each
ogOperations.py to report the session status.
Return values:
	None: no session changes are found
	True: login
	False: logout

Windows
Verify if psutil.users() has any value.

Linux
Verify all the psutil.users() asociated to a terminal.
2024-11-26 13:02:45 +01:00
OpenGnSys Support Team 90a9ba9543 live: bogus error in logs when connecting to ogserver
This error is bogus:

 (2024-11-14 09:05:37) ogClient: [ERROR] - Partition query error for /dev/sdb: No medium found

skip if device cannot be opened instead.
2024-11-14 18:12:56 +01:00
Alejandro Sirgo Rica a440b9da47 live: fix error report in partition and format
Fix error codepath and properly mark the operation as failed.
2024-11-05 11:20:59 +01:00
OpenGnSys Support Team 7874323d46 live: use reboot --force --force to make a hard reboot in new live
this is a workaround for the new live system to make a hardware reboot
that allows UEFI to pick up, otherwise it performs a kernel reboot instead.
2024-10-24 17:46:37 +02:00
Alejandro Sirgo Rica 569caa733f cache: add code to cache the oglive boot files
Add update_live_cache() implementing the legacy script
updateBootCache()

Copy the ogvmlinuz and oginitrd.img files into cache after
a partition and format command with an available cache partition.
2024-10-24 10:52:33 +02:00
OpenGnSys Support Team fc21cd988f live: always enable wol when launching ogclient
no need to wait for reboot/poweroff to enable wake-on-lan.
2024-10-24 10:46:44 +02:00
Alejandro Sirgo Rica e8ddbbd075 src: isolate libfdisk operations to enable mount operations
python-libfdisk does not close file descriptor until the cxt
object goes out of scope.

Define get_partition_data and get_disk_data functions to isolate
the python-libfdisk logic and return the data as an object.

Improve error handling of libfdisk operaions in refresh.
2024-10-08 10:07:45 +02:00
Alejandro Sirgo Rica 97c836e0e4 live: improve part not found log in image_create
Report the partition number of the missing partition.
2024-10-08 10:07:45 +02:00
Alejandro Sirgo Rica f942b19eae src: fix cache mount in new ogLive
Mount cache in image_create() image_restore() and cache_fetch().

Remove init_cache() and ensure /opt/opengnsys/images/ exists
within the cache mountpoint if it does not exists in cache_mount().
2024-10-08 10:07:45 +02:00
OpenGnSys Support Team fe960010a0 live: remove useless check in compute_md5
this never returns -1 on error, an exception is rised instead
2024-10-05 08:40:55 +02:00
Alejandro Sirgo Rica 0f167cf29f src: consolidate compute_md5 functions
Add compute_md5 function in src/utils/fs.py

Remove identical md5 functions from src/live/ogOperations.py and
src/utils/tiptorrent.py

Move error checks from ogOperations.py into compute_md5 function in
src/utils/fs.py
2024-10-02 14:50:14 +02:00
Alejandro Sirgo Rica cc70274079 src: check if the system is hibernated before /image/create
Mount the system partition in readonly mode and check for the
hiberfil.sys file if the target system is a Windows.

Fail the image creation process if the target system is hibernated.
2024-10-02 14:25:04 +02:00
OpenGnSys Support Team f1b1532f78 live: refactor poweroff and reboot
- enable WoL
- check for poweroff and reboot before checking for busybox.
- call new shutdown method
2024-10-01 22:12:17 +02:00
OpenGnSys Support Team cf9e1c96fd live: fix EBUSY error in newer kernels with mkfs
python-libfdisk does not close file descriptor to /dev/sda after completing
partitioning. This results EBUSY errors when formatting partitions with mkfs
in newer kernels. Encapsulate code to partition in method so python garbage
collection knows ctx objects can be release then close file descritor to
/dev/sda.

ogRest is not accessible from _partition(), remove check to ogRest.terminated,
actually no need to terminate inmediately when formatting is ongoing, better
leave things in consistent state when stop command is received.
2024-10-01 17:02:49 +02:00
Alejandro Sirgo Rica f0953c969a live: report correct partition size unit in setup() log
Log the correct partition size unit. Use MiB instead of MB.
2024-10-01 16:49:58 +02:00
Alejandro Sirgo Rica e30e934272 src: replace DEVICE env variable with get_ethernet_interface()
Use a python function to obtain the main net interface. Detect
the first ethernet inferface in use.
Stop using the DEVICE environment variable.
2024-10-01 15:32:54 +02:00
OpenGnSys Support Team 8f437bb954 live: remove unused probe
unused since ogserver's commit 87be2ce08 #980 Change initial probe to refresh
2024-09-30 14:42:29 +02:00
OpenGnSys Support Team 9c18ef7392 live: use busybox otherwise poweroff/reboot commands 2024-09-30 14:42:29 +02:00
Alejandro Sirgo Rica 9c2ae873f2 live: disable browser operations if the binary is missing
Add shutils.which checks before every browser operations to
skip the subprocess call if the binary is missing.
2024-09-27 14:27:00 +02:00
Alejandro Sirgo Rica 8754c21694 src: report used and free partition data in bytes
Add "used_size" and "free_size" to the partition data and the
cache data.

Old response from ogClient for /cache/delete, /cache/fetch
and /image/restore:
{
  'cache': [
    {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'},
    {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'}
  ]
}

New response:
{
  'cache': {
    'used_size': 4520232322423,
    'free_size': 48273465287452945,
    'images': [
      {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'},
      {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'}
    ]
  }
}
2024-09-25 14:35:41 +02:00
Alejandro Sirgo Rica 51258613cc src: verify the fields of the efibootmgr json in /refresh
Don't send the efi data in the /refresh payload if efibootmgr
is missing any of the json keys.

Log the missing keys in case of missing some.
2024-09-25 14:35:41 +02:00
Alejandro Sirgo Rica 595770163a live: add boot entries into /refresh payload
Add 'efi' key into the refresh payload. The value for that key
has the following structure:

'efi': {
  'entries': [
    {
      "order": 0,
      "name": "Boot0000",
      "active": false,
      "description": "grub"
    },
    {
      "order": 1,
      "name": "Boot0001",
      "active": true,
      "description": "UEFI: PXE IP4 Realtek PCIe GBE Family Controller"
    }
  ]
}

If the client is not a EFI system it won't add the 'efi' field.
If an entry is not in the boot order it won't have the 'order' field.
2024-09-10 17:23:18 +02:00
OpenGnSys Support Team 084650e4b1 live: use correct variable name in restore unicast cache
fe40f9c5 ('src: add POST cache/fetch method') broke unicast cache restore.

(2024-09-09 10:05:22) ogClient: [ERROR] - name 'image_name' is not defined
Traceback (most recent call last):
File "/opt/opengnsys/ogClient/src/ogRest.py", line 175, in image_restore
payload = ogRest.operations.image_restore(request, ogRest)
File "/opt/opengnsys/ogClient/src/live/ogOperations.py", line 520, in image_restore
self._restore_image_unicast(repo, name, partdev, cache)
File "/opt/opengnsys/ogClient/src/live/ogOperations.py", line 242, in _restore_image_unicast
image_path = f'{OG_CACHE_IMAGE_PATH}{image_name}.img'
NameError: name 'image_name' is not defined
2024-09-09 12:23:00 +02:00
OpenGnSys Support Team 05b7a576b0 live: incorrect indentation
f2a2f53074 ('live: remove file from cache with no checksum file') broke
indentation which breaks ogClient.
2024-09-03 19:44:43 +02:00
Alejandro Sirgo Rica 6704abc620 live: add disk index bounds check
Add disk index bounds checks for setup() and image_create().
Prevent backtrace logging when an invalid disk index is used.
2024-09-02 14:25:54 +02:00
OpenGnSys Support Team f2a2f53074 live: remove file from cache with no checksum file
Maybe result of a partial download? then, remove it to leave cache in consistent
state.
2024-09-02 13:59:36 +02:00
OpenGnSys Support Team 9270a6c58f src: append .img to log that report image fetching 2024-08-29 13:10:50 +02:00
OpenGnSys Support Team 3d47b5069a src: use logging.warning()
logging.warn() is deprecated since 3.3.

And use .error() instead when command is unsupported or client is busy, that
should not ever happen.
2024-08-27 12:44:13 +02:00
OpenGnSys Support Team 8839950758 live: report that up-to-date image already exists in cache 2024-08-21 09:28:01 +02:00
OpenGnSys Support Team 1ca3992f71 src: remove call to restoreImageCustom script
remove call to custom version of legacy script, display warning.
2024-08-21 09:21:53 +02:00
Alejandro Sirgo Rica 9fa4a5f651 live: clean files after a failed cache image copy
Remove image files after a failed image copy operation.
2024-08-09 11:05:02 +02:00
Alejandro Sirgo Rica fe40f9c5d6 src: add POST cache/fetch method
Add API REST method to fetch an image.
Consolidate image fetch loging for cache/fetch and image/restore.

Resquest payload structure:
{
    'image': 'linux.img'
    'type': 'TIPTORRENT'
    'repository': '12.141.10.2'
}

The client will try to fetch'image' from 'repository' into cache.

Resquest response structure:
{
    'cache': [
        {'name': 'windows.img', 'size': 2432370213, checksum: '5d4dcc677bc19f40a647d0002f4ade90'},
        {'name': 'linux.img', 'size': 243234534213, checksum: '3eb22f888f88a55ad954f55644e1192e'}
    ]
}
2024-08-09 11:04:56 +02:00
OpenGnSys Support Team 9ee5f4adaa live: move filesystem expansion out of OS configuration
just a clean up.
2024-08-06 18:39:37 +02:00
OpenGnSys Support Team 1011957bb7 live: use correct loglevel when reporting issues with listing cache contents
instead of using info to report errors.
2024-07-31 22:29:29 +02:00
OpenGnSys Support Team 1329c0955b live: validate checksum only once if image is already in cache
if image already exists in the cache, skip a second checksum validation.

log shows duplicated entries:

	Verifying checksum for example.img, please wait...
	Checksum is OK for example.img
	Verifying checksum for example.img, please wait...
	Checksum is OK for example.img

because tip_check_csum() is called twice in this case.
2024-07-30 16:19:03 +02:00
OpenGnSys Support Team 1376b1900d live: remove old image and checksum file on download
Restoring an updated image file (with different checksum) could fail while the
old checksum file could remain in place.

Remove image and checksum file before fetching the new files.
2024-07-30 16:11:43 +02:00
OpenGnSys Support Team a846d5e343 live: unicast-direct does not validate checksum
this restore method is unreliable, add warning to the logs.
2024-07-30 00:51:37 +02:00
OpenGnSys Support Team 8395982244 live: validate file existence and checksum for unicast cache
after copying file to cache, validate that file exists in cache and checksum
correct.
2024-07-30 00:51:37 +02:00
Alejandro Sirgo Rica 567fea276e utils: add postinstall.py
Replace ConfigureOs script by native calls to:

- update BCD via hivex using bcd.py and winreg.py infrastructure.
- restore efi bootloader restore_windows_efi_bootloader().

Call legacy scripts for remaining postinstall procedures to
replace them incrementally.

Define variable CONFIGUREOS_LEGACY_ENABLED as False by default.
Run legacy configureOs when CONFIGUREOS_LEGACY_ENABLED = True.
This serves as a auxiliar method to keep the restoration functional
in case of problems with the new configure_os logic.
2024-07-29 15:07:22 +02:00
Alejandro Sirgo Rica e20cda122b utils: rename ogExtendFs to extend_filesystem
Use a more consistent name format for the ogExtendFs function.
2024-07-29 15:07:22 +02:00