Skip to content

Improve vbox-adapter-check #679

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

Conversation

Ana06
Copy link
Member

@Ana06 Ana06 commented Apr 17, 2025

This PR includes the following improvements in vbox-adapter-check:

  • Verify the nic has been modified in the disable_adapter function as the VBoxManage command may return 0 even if it fails to set the adapter.
  • Set hostonlyadapter after running VBoxManage modifyvm --nic to ensure it has a name, fixing the bug that prevented the VM to start after disabling the NIC.
  • Fix disabling nic in VMs in aborted state.
  • Refactor get_vm_uuids, including giving it a name that better reflects its functionality and including the curly braces in the UUID for consistency with the rest of the code.
  • Move the logic to disable the nic adapter to the new function disable_adapter.
  • Only send notification if an adapter is actually modified.
  • Improve printed information, using a consistent format and adding emojis for better readability.
  • Add list_to_str function to improve readability of invalid NICs.
  • Remove unneeded exception re-raising.
  • Improve the documentation.

I plan to send a PR after this one has been merged to provide automation via GH actions to generate a linux binary for vbox-adapter-check and vbox-remove-snapshots.

$ ~/github/flare-vm/virtualbox/vbox-adapter-check.py
VM {2bc66f50-9ecb-4b10-a4dd-0cc329bc383d} ⚠️  FLARE-VM.testing is connected to the internet on adapter(s): 1
VM {a23c0c37-2062-4cf0-882b-9e9747dd33b6} ✅ REMnux.20241217.dynamic network configuration is ok
VM {fa0b3733-50cb-43fd-8428-745d0e9159cb} ✅ FLARE-VM.Win10.20250211.dynamic network configuration is ok
VM {e5f509ed-cbc8-4abc-b052-664246207e89} ⚠️  FLARE-VM.Win10.20250211.full.dynamic is connected to the internet on adapter(s): 1, 2
VM {e5f509ed-cbc8-4abc-b052-664246207e89} ⚙️  FLARE-VM.Win10.20250211.full.dynamic set adapter 1 to hostonly
VM {e5f509ed-cbc8-4abc-b052-664246207e89} ⚙️  FLARE-VM.Win10.20250211.full.dynamic set adapter 2 to hostonly

vbox-adapter-check_notification

Ana06 added 10 commits April 14, 2025 13:20
The changes include the following enhancement to the `get_vm_uuids`
function:

- Rename the function to `get_vms` to reflect that it returns both the
  name and UUID.
- Include the `{` and `}` in the matched UUID for consistency with the
  function `get_vm_uuid` and the rest of printed information.
- Remove unneeded exception re-raising.
- Improve the function documentation.
- Simplifying the conditional logic for filtering dynamic VMs. The
  condition is now inverted for better readability.
Move the logic to disable the nic adapter to the new function
`disable_adapter` implementing the following enhacements:
- Use `DISABLED_ADAPTER_TYPE` instead of its value (`"hostonly"`).
- Add the string `nic` directly in the commands instead of in every of
  the elements of the `nics_with_internet` list.
Refactor the `change_network_adapters_to_hostonly` function including
the following enhancements:
- Rename the function `verify_network_adapters` to better reflect its
  main purpose.
- Replace exception re-raising with a print that includes the error.
- Improve printed information, using a consistent format and adding
  emojis for better readability.
- Improve the function documentation.
Remove the unnecessary try-except block in the main function. Errors
during VM verification are already handled within
`verify_network_adapters`.

Improve warning message for no VMs found.
Only send notification if an adapter is actually modified.

Improve documentation to clarify the script's behavior and options,
including when notifications are shown.
Add `list_to_str` function to improve readability of invalid NICs.
Verify the nic has been modified in `disable_adapter` as the command may
return 0 even if it fails to set the adapter. Move logic to get
configured network interfaces to a new function `get_nics` to avoid
duplicating the code.
VMs in state `aborted` are also not running and running `VBoxManage
controlvm` fails.
The `VBoxManage modifyvm --nic` command does not set the hostonly
adapter. This change explicitly sets the hostonly adapter after
disabling the NIC to prevent errors when starting the VM.
Improve documentation to reflect latest changes.
@Ana06 Ana06 added 💎 enhancement It is working, but it could be better 🖥️ virtualbox labels Apr 17, 2025
@Ana06 Ana06 self-assigned this Apr 17, 2025
@Ana06 Ana06 added this to the FLARE-VM 2025 Q2 milestone Apr 28, 2025
@Ana06 Ana06 requested a review from emtuls May 6, 2025 14:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🖥️ virtualbox 💎 enhancement It is working, but it could be better
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant