Skip to content

Refactor#62

Open
t0kubetsu wants to merge 35 commits intomainfrom
refactor
Open

Refactor#62
t0kubetsu wants to merge 35 commits intomainfrom
refactor

Conversation

@t0kubetsu
Copy link
Copy Markdown

No description provided.

pparage added 18 commits March 19, 2026 09:48
closes #58)

Default unchanged: localhost/127.0.0.1/[::1] only.
Set CORS_ORIGIN_REGEX env var to allow additional origins, e.g.:
  CORS_ORIGIN_REGEX=^https?://(localhost|127\.0\.0\.1|\[::1\]|192\.168\.42\.\d+)(:\d+)?$
New endpoint: ws://host:8000/ws/vm-status?node=X&api_host=X&token_id=X&token_secret=X

- Polls Proxmox API directly via httpx (fast, no Ansible overhead)
- Sends full VM state on first connect
- Sends only diffs (status/CPU changes) on subsequent updates
- Filters out templates
- 5-second poll interval
- Auto-cleanup on disconnect
WebSocket endpoint now reads API host, token ID, and token secret from
the backend's own inventory/hosts.yml file. Frontend only needs to
connect to ws://backend/ws/vm-status — no credentials in the browser.
Add 9 consolidated schema files under app/schemas/:
- base.py: ProxmoxBaseRequest added
- vms.py: VM list, create, delete, clone, action, mass ops
- vm_config.py: VM config get/set (full, cdrom, cpu, ram, tag)
- snapshots.py: Snapshot CRUD (create, delete, list, revert)
- firewall.py: Rules, aliases, enable/disable at DC/node/VM
- network.py: Node and VM network interface operations
- storage.py: Storage list, download ISO, list ISO/templates
- bundles/__init__.py: Ubuntu + Proxmox default VM bundles
- debug/__init__.py: Debug/ping schemas

All old class names preserved as backward-compatible aliases.
Old files kept in place (cleanup deferred to Task 1.8).
35 new tests in tests/test_schemas.py — all 57 tests pass.
Replace the deeply nested app/routes/v0/ directory tree (86 files) with
10 flat domain-grouped modules under app/routes/:

- vms.py        — VM list, lifecycle (start/stop/pause/resume), management (create/delete/clone), mass operations
- vm_config.py  — VM configuration (get config, cdrom, cpu, ram, set tag)
- snapshots.py  — Snapshot CRUD (list, create, delete, revert)
- firewall.py   — Firewall aliases, rules, VM/node/DC enable/disable
- network.py    — VM and node network interface management
- storage.py    — Storage list, ISO download, ISO/template listing
- bundles.py    — Core Ubuntu bundles + Proxmox create/start/stop/delete/snapshot bundles
- runner.py     — Dynamic bundle and scenario runner
- debug.py      — Ping and test function endpoints
- ws_status.py  — WebSocket VM status (unchanged)

Each domain file uses shared helpers to eliminate the duplicated
request_checks/reply_processing/run pattern. The __init__.py wires
all routers with their original prefixes.

All 80 route paths, HTTP methods, tags, and response models are
preserved exactly as before — verified by the golden reference test.
Delete 120+ old route/schema/core files that are fully replaced by the
new consolidated domain modules from Tasks 1.3-1.7. Update all imports
in the new route files to point to app.core.runner, app.core.extractor,
and the flat app.schemas.* modules instead of the old deeply nested paths.

Deleted:
- app/routes/v0/ (entire deeply nested route tree)
- app/routes/admin_proxmox.py, admin_run.py, admin_run_bundles_core.py, admin_debug.py
- app/schemas/proxmox/ (old nested schema tree)
- app/schemas/bundles/core/ (old nested bundle schemas)
- app/schemas/debug/ping.py (old debug schema)
- app/vault/ (replaced by app/core/vault.py)
- app/runner.py (replaced by app/core/runner.py)
- app/extract_actions.py (replaced by app/core/extractor.py)

All 59 tests pass before and after deletion.
@t0kubetsu
Copy link
Copy Markdown
Author

t0kubetsu commented Mar 23, 2026

This PR is not ready for merge — the following are still missing:

  • README documentation covering the code
  • Unit tests covering the code

pparage added 6 commits March 23, 2026 16:32
…ic v2 fixes

Merges origin/refactor (format, slim base image, pydantic v2 deprecation fixes)
with local branch (unused import removals, CodeQL findings, implementation plan).
…cket helpers

- test_checks_inventory.py: inventory name validation and path traversal
- test_checks_playbooks.py: playbook path validation and traversal detection
- test_runner_internals.py: _build_envvars, _build_cmdline, _setup_temp_dir
- test_ws_helpers.py: compute_diff and load_proxmox_credentials
Mocks run_playbook_core to verify route handlers parse requests
correctly, call the runner with right arguments, and return
appropriate HTTP responses without needing Ansible/Proxmox.
@t0kubetsu
Copy link
Copy Markdown
Author

t0kubetsu commented Mar 24, 2026

Tests directory has to follow the structure of the fastapi app directory:

./tests
  core
  routes
  schemas
  utils

In the readme, we could add commands to display the covering of the tests.

We can also remove the 3 _*.sh scripts and the start.sh script.

Rename the requirements.yml, at the root,used by ansible to ansible_requirements.yml

We can also move inventory and playbooks to a ansible directory with the requirements.yml (like that we don't rename it but put it in a ansible directory).

Also, is pytest.ini really useful ?

We have also to take care of curl_utils scripts, are they useful ? Currently they don't take args so we have, to use it, to modify by hands the value to make them work. Is a python cli utility not better ?

@pparage
Copy link
Copy Markdown
Member

pparage commented Mar 25, 2026

@hyde-repo Regarding the curl scripts what was the intend?

@hyde-repo
Copy link
Copy Markdown
Member

@pparage @t0kubetsu

Yes, please feel free to remove those files as they are temporary scripts that were not intended for long-term use.

pparage and others added 4 commits March 25, 2026 09:07
- Pin python:3.12-slim, remove unused sshpass and start.sh copy
- Move pytest/setuptools/wheel to requirements-dev.txt
- Add SSH key mount to docker-compose for Ansible access
Clean up Docker production image and split dev dependencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants