Skip to content

Refactoring#6

Merged
chikatetsu merged 23 commits intomasterfrom
refacto/migration
Jul 16, 2025
Merged

Refactoring#6
chikatetsu merged 23 commits intomasterfrom
refacto/migration

Conversation

@chikatetsu
Copy link
Contributor

@chikatetsu chikatetsu commented Jul 16, 2025

Summary by CodeRabbit

  • New Features

    • Added commands and scripts to list all servers from a vCenter instance, including a new Python module and Bash script for this functionality.
    • Introduced new event types and enhanced event handling for VM and server operations, supporting more detailed migration and restart workflows.
    • Added support for configurable UPS grace periods for shutdown and restart via updated YAML configuration and logic.
  • Improvements

    • Enhanced error handling and status reporting for VM and host operations, including more specific messages for unreachable hosts and disallowed migrations.
    • Updated migration and restart logic to follow clearer, sequential steps with improved event recording and rollback support.
    • Improved process management in automation scripts to prevent concurrent runs and ensure clean transitions between migration and restart plans.
  • Documentation

    • Greatly expanded and restructured the README with detailed setup, usage instructions, and configuration examples.
    • Updated help texts and documentation across scripts to clarify that all operations target vCenter servers exclusively.
  • Configuration

    • Simplified and clarified the migration plan YAML structure, centralizing grace period settings and streamlining server definitions.

@chikatetsu chikatetsu requested a review from jabibamman July 16, 2025 09:55
@chikatetsu chikatetsu self-assigned this Jul 16, 2025
@chikatetsu chikatetsu added the enhancement New feature or request label Jul 16, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jul 16, 2025

Walkthrough

This update introduces new features and refactors for VMware vCenter orchestration scripts, including enhanced event handling, improved YAML migration plan structure, new server listing functionality, and more precise error handling. The documentation is extensively rewritten for clarity, and several scripts and modules are updated to align with the new configuration and workflow.

Changes

Files / Scripts / Modules Change Summary
README.md Expanded and restructured with detailed features, setup, usage, and configuration documentation.
data_retriever/dto.py Added servers_list_info function; server_info now includes moid field.
data_retriever/event_queue.py Added grace_shutdown method to EventQueue.
data_retriever/migration_event.py Added VMStartedEvent; modified VMShutdownEvent and ServerShutdownEvent dataclasses; updated EVENT_CLASSES.
data_retriever/vm_ware_connection.py Refactored VM collection logic; added get_all_hosts method.
data_retriever/yaml_parser.py Replaced nested shutdown/restart dataclasses with flat vm_order and new UpsGrace dataclass; updated YAML parsing logic and error handling.
list_server.py, list_server.sh New Python module and Bash script to list all vCenter servers with CLI and environment validation.
list_vm.py, server_info.py, server_metrics.py, vm_metrics.py, vm_stop.py, vm_start.py, vm_migration.py Updated docstrings and CLI help texts to clarify exclusive vCenter usage; no logic changes except in vm_migration.py and vm_start.py (see below).
vm_migration.py Disallows migration of powered-on VMs; improved error handling; updated migration workflow to explicitly stop, migrate, and start VMs.
vm_start.py Enhanced error handling for host faults; clarified docstrings and messages.
migration_plan.py, restart_plan.py Updated function signatures to accept ups_grace; refactored shutdown/restart logic for new event types and delays; reordered event handling.
migration_plan.sh, restart_plan.sh Added process checks and delays to prevent concurrent execution and coordinate shutdown/restart grace periods.
plans/migration-example.yml Updated plan structure: added ups section for grace periods; flattened server VM order configuration.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant BashScript
    participant PythonScript
    participant VMwareConnection
    participant vCenter
    participant Redis

    User->>BashScript: Run migration_plan.sh / restart_plan.sh
    BashScript->>BashScript: Check for running processes / delays
    BashScript->>PythonScript: Run migration_plan.py or restart_plan.py
    PythonScript->>VMwareConnection: Connect to vCenter
    PythonScript->>vCenter: Retrieve servers/VMs
    PythonScript->>Redis: Push event (shutdown, migration, start, etc.)
    PythonScript->>VMwareConnection: Perform action (stop VM, migrate, start VM, etc.)
    PythonScript->>Redis: Update event state
    PythonScript->>VMwareConnection: Disconnect
    PythonScript->>User: Output result
Loading
sequenceDiagram
    participant User
    participant list_server.sh
    participant list_server.py
    participant VMwareConnection
    participant vCenter

    User->>list_server.sh: Run with connection parameters
    list_server.sh->>list_server.py: Validate and execute
    list_server.py->>VMwareConnection: Connect to vCenter
    VMwareConnection->>vCenter: Retrieve all hosts
    VMwareConnection->>list_server.py: Return hosts
    list_server.py->>User: Output JSON server list
Loading

Possibly related PRs

  • Migrate VMs #3: Related to VMware host and VM data retrieval refactoring and VM migration functions, sharing context on VMware connection handling and data structures.

Suggested reviewers

  • jabibamman

Poem

In the warren of scripts, a new path appears,
With servers and VMs now handled with cheers!
YAML plans are simpler, events queue with grace,
No more confusion—just one rabbit's pace.
From shutdown to restart, the flow is so neat,
🐇 Hopping through vCenter, automation's a treat!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (9)
migration_plan.sh (1)

5-9: Improve process detection pattern specificity.

The current pgrep pattern "python.*migration_plan\.py$" may match unintended processes or miss edge cases. Consider using more specific patterns or additional verification.

-PID=$(pgrep -f "python.*migration_plan\.py$")
+PID=$(pgrep -f "python.*migration_plan\.py$" | head -1)

Also consider adding the current script's PID to avoid false positives if the script name contains similar patterns.

plans/migration-example.yml (1)

7-9: Good centralization of grace period configuration.

The new ups section centralizes grace period settings, which improves maintainability and clarity. The structure aligns well with the described parser changes.

Consider adding comments to clarify the units (presumably seconds):

 ups:
+  # Grace periods in seconds
   shutdownGrace: 60
   restartGrace: 60
list_server.py (1)

34-34: Fix copy-paste error in CLI description.

The description mentions "Lister les VM d'un serveur" (List VMs of a server) but should describe server listing instead.

-    parser = ArgumentParser(description="Lister les VM d'un serveur")
+    parser = ArgumentParser(description="Lister les serveurs d'un vCenter")
list_server.sh (1)

35-39: Consider security improvement for command execution.

While the current implementation works, using eval with user input could be a security concern. Consider using arrays for safer command construction.

-CMD="python list_server.py --ip \"$IP\" --user \"$USER\" --password \"$PASSWORD\""
-if [[ -n "$PORT" ]]; then
-    CMD+=" --port \"$PORT\""
-fi
-eval "$CMD"
+CMD_ARGS=("python" "list_server.py" "--ip" "$IP" "--user" "$USER" "--password" "$PASSWORD")
+if [[ -n "$PORT" ]]; then
+    CMD_ARGS+=("--port" "$PORT")
+fi
+"${CMD_ARGS[@]}"
vm_start.py (1)

50-50: Consider using actual VM name instead of MOID.

The function now accepts a name parameter for better logging, but moid is being passed instead of the actual VM name. Consider retrieving the VM name for more meaningful logging.

-return vm_start(vm, moid)
+return vm_start(vm, vm.name if vm else moid)
data_retriever/vm_ware_connection.py (1)

66-89: LGTM! Well-implemented host collection method with optimization opportunity.

The new get_all_hosts method follows the same pattern as get_all_vms and properly handles recursive folder traversal. However, the conditional logic for ComputeResource and ClusterComputeResource can be simplified.

Apply this diff to address the static analysis hint:

-                if isinstance(entity, vim.ComputeResource):
-                    hosts.extend(entity.host)
-                elif isinstance(entity, vim.ClusterComputeResource):
-                    hosts.extend(entity.host)
+                if isinstance(entity, (vim.ComputeResource, vim.ClusterComputeResource)):
+                    hosts.extend(entity.host)
vm_migration.py (1)

31-32: Breaking change: Explicit VM power state management required

The function now rejects migration of powered-on VMs instead of automatically powering them off. This is safer but may break existing workflows that relied on automatic power-off behavior.

Consider documenting this breaking change prominently in release notes or migration guides.

data_retriever/yaml_parser.py (1)

63-63: Use dictionary .get() method for cleaner code

Static analysis correctly suggests using .get() for optional dictionary keys.

-            port=data['vCenter']['port'] if 'port' in data['vCenter'] else 443,
+            port=data['vCenter'].get('port', 443),
-            destination = server['server']['destination'] if 'destination' in server['server'] else None
+            destination = server['server'].get('destination')

Also applies to: 74-74

README.md (1)

13-13: Minor language improvements

Consider these style improvements for better readability.

-- Store migration events in Redis in order to roll back the operations afterwards.
+- Store migration events in Redis to roll back the operations afterward.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d5d02dd and cc3cb5f.

📒 Files selected for processing (20)
  • README.md (1 hunks)
  • data_retriever/dto.py (1 hunks)
  • data_retriever/event_queue.py (1 hunks)
  • data_retriever/migration_event.py (1 hunks)
  • data_retriever/vm_ware_connection.py (2 hunks)
  • data_retriever/yaml_parser.py (2 hunks)
  • list_server.py (1 hunks)
  • list_server.sh (1 hunks)
  • list_vm.py (2 hunks)
  • migration_plan.py (4 hunks)
  • migration_plan.sh (1 hunks)
  • plans/migration-example.yml (2 hunks)
  • restart_plan.py (2 hunks)
  • restart_plan.sh (1 hunks)
  • server_info.py (2 hunks)
  • server_metrics.py (2 hunks)
  • vm_metrics.py (2 hunks)
  • vm_migration.py (5 hunks)
  • vm_start.py (3 hunks)
  • vm_stop.py (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (4)
list_server.py (2)
data_retriever/dto.py (3)
  • result_message (14-28)
  • output (5-11)
  • servers_list_info (101-112)
data_retriever/vm_ware_connection.py (4)
  • VMwareConnection (6-142)
  • connect (11-29)
  • get_all_hosts (66-89)
  • disconnect (31-36)
restart_plan.py (7)
data_retriever/migration_event.py (4)
  • VMMigrationEvent (6-8)
  • VMShutdownEvent (11-13)
  • ServerShutdownEvent (21-25)
  • VMStartedEvent (16-18)
data_retriever/vm_ware_connection.py (4)
  • VMwareConnection (6-142)
  • connect (11-29)
  • get_vm (91-118)
  • get_host_system (120-142)
data_retriever/yaml_parser.py (3)
  • VCenter (28-32)
  • load_plan_from_yaml (40-100)
  • UpsGrace (35-37)
vm_migration.py (1)
  • vm_migration (11-46)
vm_start.py (1)
  • vm_start (9-30)
vm_stop.py (1)
  • vm_stop (9-29)
data_retriever/event_queue.py (4)
  • EventQueue (9-74)
  • start_restart (61-66)
  • get_event_list (28-38)
  • finish_restart (68-74)
vm_migration.py (3)
vm_start.py (1)
  • vm_start (9-30)
vm_stop.py (1)
  • vm_stop (9-29)
data_retriever/dto.py (1)
  • result_message (14-28)
vm_start.py (1)
data_retriever/dto.py (1)
  • result_message (14-28)
🪛 Ruff (0.12.2)
data_retriever/vm_ware_connection.py

75-78: Combine if branches using logical or operator

Combine if branches

(SIM114)

data_retriever/yaml_parser.py

63-63: Use data['vCenter'].get('port', 443) instead of an if block

Replace with data['vCenter'].get('port', 443)

(SIM401)


74-74: Use server['server'].get('destination', None) instead of an if block

Replace with server['server'].get('destination', None)

(SIM401)

🪛 LanguageTool
README.md

[style] ~13-~13: Consider a more concise word here.
Context: ...YAML. - Store migration events in Redis in order to roll back the operations afterwards. - ...

(IN_ORDER_TO_PREMIUM)


[locale-violation] ~13-~13: In American English, ‘afterward’ is the preferred variant. ‘Afterwards’ is more commonly used in British English and other dialects.
Context: ...is in order to roll back the operations afterwards. - Convenience shell scripts that wrap ...

(AFTERWARDS_US)

🪛 markdownlint-cli2 (0.17.2)
README.md

18-18: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

🔇 Additional comments (43)
data_retriever/event_queue.py (1)

40-45: Well-implemented method following established patterns.

The grace_shutdown method correctly follows the same pattern as other state management methods in the class. The error handling is consistent, and the state value is descriptive and appropriate for the shutdown grace period workflow.

vm_stop.py (2)

34-40: Good documentation clarification.

The updated docstring correctly specifies that the connection is to a vCenter server, improving clarity for users and aligning with the broader standardization effort across the codebase.


62-65: Consistent CLI help text improvements.

The updated help text correctly specifies vCenter parameters, providing better guidance to users about the expected connection target.

plans/migration-example.yml (1)

27-30: Simplified VM order structure improves readability.

Moving vmOrder directly under the server configuration eliminates unnecessary nesting and makes the configuration cleaner and more intuitive.

server_info.py (2)

10-10: Consistent documentation improvements.

The updated docstring correctly specifies vCenter connections, maintaining consistency with the broader standardization effort across the VMware orchestration scripts.

Also applies to: 13-16


40-43: Clear CLI help text updates.

The updated help text provides better guidance to users by explicitly specifying that connection parameters are for the vCenter server.

list_vm.py (2)

12-15: LGTM: Clear documentation improvement.

The docstring clarification specifying "VCenter" instead of generic server improves API documentation consistency across the codebase.


35-38: LGTM: Consistent CLI help text improvements.

The French help text clarifications align with the codebase-wide standardization on vCenter-specific connection parameters.

restart_plan.sh (3)

5-9: LGTM: Good concurrency protection.

The process check prevents multiple instances from running simultaneously, which is essential for restart plan operations.


11-15: LGTM: Proper configuration validation.

The config file existence check ensures graceful failure if the migration plan is missing.


23-24: LGTM: Configuration-driven grace period.

The sleep mechanism using the extracted grace period value provides configurable timing control.

data_retriever/dto.py (2)

101-112: LGTM: Well-structured server listing function.

The function correctly follows the established pattern from vms_list_info, reusing the existing server_info function for consistency.


125-125: LGTM: Consistent data enrichment.

Adding the managed object ID (moid) to server data provides consistency with VM data structures and enables unique identification of hosts.

list_server.py (2)

8-30: LGTM: Well-structured server listing implementation.

The function correctly follows the established pattern from list_vm.py, with proper error handling and resource cleanup.


35-38: LGTM: Consistent CLI parameter definitions.

The CLI arguments follow the established pattern with proper French help text and consistent defaults.

server_metrics.py (2)

10-10: LGTM: Clear documentation improvement.

The docstring clarification specifying "VCenter" improves API documentation consistency and aligns with the broader refactoring effort.

Also applies to: 13-16


40-43: LGTM: Consistent CLI help text improvements.

The French help text clarifications maintain consistency with other modules in the codebase.

vm_metrics.py (2)

10-16: LGTM! Documentation clarity improvements.

The updated docstring clearly specifies that connections are to vCenter servers, which aligns with the broader refactoring effort to clarify VMware infrastructure terminology throughout the codebase.


39-43: LGTM! Consistent CLI help text improvements.

The argument parser help texts have been updated to consistently specify "vCenter" connections, maintaining consistency with the docstring changes and improving user experience.

data_retriever/migration_event.py (3)

13-13: LGTM! Logical addition of server context.

Adding server_moid to VMShutdownEvent provides valuable context about which server the VM was running on, which is useful for tracking and orchestration purposes.


15-18: LGTM! Well-structured new event type.

The new VMStartedEvent dataclass follows the established pattern and structure of existing event types, maintaining consistency in the codebase.


28-28: LGTM! Proper event type registration.

The EVENT_CLASSES dictionary is correctly updated to include the new VMStartedEvent, ensuring proper serialization and deserialization support.

list_server.sh (3)

5-14: LGTM! Solid argument parsing implementation.

The argument parsing loop correctly handles the required parameters and follows bash best practices with proper shift operations.


16-20: LGTM! Proper validation of required parameters.

The validation correctly checks for required parameters and provides clear error messages with usage information.


22-33: LGTM! Comprehensive virtual environment validation.

The script performs thorough checks for virtual environment existence, activation success, and validates that the correct environment is activated. The error messages are clear and helpful.

vm_start.py (4)

26-26: LGTM! Improved success message with dynamic VM name.

The success message now includes the VM name, providing better feedback to users about which specific VM was started.


27-28: LGTM! Enhanced error handling for host-related issues.

The specific exception handling for host-related errors (NoCompatibleHost, InvalidHostState, HostNotConnected) provides better error categorization and user-friendly messages.


38-41: LGTM! Documentation clarity improvements.

The updated docstring clearly specifies vCenter connections, maintaining consistency with the broader refactoring effort.


63-66: LGTM! Consistent CLI help text improvements.

The argument parser help texts have been updated to consistently specify "vCenter" connections, improving user experience.

data_retriever/vm_ware_connection.py (2)

42-51: LGTM! Improved code organization with helper function.

The refactoring to use a helper function collect_vms_from_folder improves code readability and maintainability by separating the recursive logic.


63-63: LGTM! Consistent usage of refactored helper function.

The main VM collection logic now properly uses the new helper function, maintaining consistency.

restart_plan.py (4)

14-22: Good improvement: Configurable grace periods

The refactoring to use UpsGrace parameter instead of hardcoded delays improves flexibility and maintainability.


44-50: Correct rollback logic for migrated VMs

The VMStartedEvent handler correctly stops VMs that were started after migration during the shutdown process, properly restoring the original state.


57-58: Improved error handling for event queue cleanup

Moving finish_restart() inside the try block ensures the restart is only marked as complete on success, preventing incorrect state updates on failure.


71-73: Proper validation of required configuration

Good defensive programming by checking both v_center and ups_grace are loaded before proceeding with restart.

vm_migration.py (2)

43-44: Good addition: Specific exception handling

The new handler for InvalidHostState provides clearer error messages for host connectivity issues.


50-58: Clear documentation improvements

The updated docstrings correctly clarify that connections are made to vCenter servers, improving accuracy and reducing confusion.

data_retriever/yaml_parser.py (2)

34-38: Well-designed grace period abstraction

The UpsGrace dataclass provides a clean abstraction for grace period configuration, improving code organization.


94-94: Good simplification of VM order structure

The simplified vm_order list aligns well with the new global grace period configuration approach.

migration_plan.py (3)

50-57: Well-implemented grace period logic

The grace period implementation properly signals the shutdown state and waits for potential power restoration before proceeding with VM shutdown.


77-95: Excellent sequential VM lifecycle management

The new stop→migrate→start flow with event tracking for each step provides clear state management and enables proper rollback operations.


105-105: Consistent error handling improvement

Like in restart_plan.py, moving finish_shutdown() to the try block ensures shutdown is only marked complete on success.

README.md (1)

1-82: Excellent documentation overhaul

The comprehensive rewrite provides clear guidance on features, installation, and usage. The examples are particularly helpful.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (2)
migration_plan.sh (1)

11-30: Excellent process termination implementation.

The graceful termination logic properly implements the SIGTERM → wait → SIGKILL pattern for both restart_plan.py and restart_plan.sh. This addresses the previous review concern about robust process termination.

README.md (1)

85-117: YAML example correctly updated to match new structure.

The documentation example now properly reflects the new YAML format with the ups section and simplified vmOrder structure, addressing the previous review concern.

🧹 Nitpick comments (3)
data_retriever/yaml_parser.py (1)

70-70: Consider using dict.get() for cleaner code.

The static analysis tool suggests a more concise approach for optional field access.

-        destination = server['server']['destination'] if 'destination' in server['server'] else None
+        destination = server['server'].get('destination', None)
README.md (2)

13-13: Consider minor style improvements.

The documentation is comprehensive and well-written. A few minor style improvements could enhance readability.

-Store migration events in Redis in order to roll back the operations afterwards.
+Store migration events in Redis to roll back the operations afterward.

18-25: Add language specification to fenced code block.

The directory structure code block should specify the language for better syntax highlighting.

-```
+```text
 .
 ├── data_retriever/       # Connection helpers and data transfer objects
 ├── plans/                # Example migration plan in YAML
 ├── *.py                  # Command line utilities (server_start.py, vm_migration.py, ...)
 ├── *.sh                  # Shell wrappers for the Python tools
 └── requirements.txt      # Python dependencies

</blockquote></details>

</blockquote></details>

<details>
<summary>📜 Review details</summary>

**Configuration used: CodeRabbit UI**
**Review profile: CHILL**
**Plan: Pro**


<details>
<summary>📥 Commits</summary>

Reviewing files that changed from the base of the PR and between cc3cb5f53a5b51d7e92bd507d20dc3a86eb960fe and b38aa01b551c817f4c7ee5541c1d076c1ffaa013.

</details>

<details>
<summary>📒 Files selected for processing (7)</summary>

* `README.md` (1 hunks)
* `data_retriever/yaml_parser.py` (3 hunks)
* `migration_plan.py` (4 hunks)
* `migration_plan.sh` (1 hunks)
* `restart_plan.py` (2 hunks)
* `restart_plan.sh` (1 hunks)
* `vm_migration.py` (5 hunks)

</details>

<details>
<summary>🚧 Files skipped from review as they are similar to previous changes (3)</summary>

* restart_plan.sh
* vm_migration.py
* migration_plan.py

</details>

<details>
<summary>🧰 Additional context used</summary>

<details>
<summary>🪛 LanguageTool</summary>

<details>
<summary>README.md</summary>

[style] ~13-~13: Consider a more concise word here.
Context: ...YAML. - Store migration events in Redis in order to roll back the operations afterwards. - ...

(IN_ORDER_TO_PREMIUM)

---

[locale-violation] ~13-~13: In American English, ‘afterward’ is the preferred variant. ‘Afterwards’ is more commonly used in British English and other dialects.
Context: ...is in order to roll back the operations afterwards. - Convenience shell scripts that wrap ...

(AFTERWARDS_US)

</details>

</details>
<details>
<summary>🪛 markdownlint-cli2 (0.17.2)</summary>

<details>
<summary>README.md</summary>

18-18: Fenced code blocks should have a language specified

(MD040, fenced-code-language)

</details>

</details>
<details>
<summary>🪛 Ruff (0.12.2)</summary>

<details>
<summary>data_retriever/yaml_parser.py</summary>

70-70: Use `server['server'].get('destination', None)` instead of an `if` block

Replace with `server['server'].get('destination', None)`

(SIM401)

</details>

</details>

</details>

<details>
<summary>🔇 Additional comments (9)</summary><blockquote>

<details>
<summary>migration_plan.sh (1)</summary>

`5-9`: **Well-implemented concurrency control.**

The addition of this check prevents multiple migration plans from running simultaneously, which is essential for maintaining system consistency.

</details>
<details>
<summary>restart_plan.py (4)</summary>

`14-21`: **Function signature correctly updated for grace period configuration.**

The addition of the `ups_grace` parameter and its usage to replace hardcoded delays improves configurability and aligns with the new YAML structure.

---

`30-50`: **Event handling logic properly enhanced.**

The reordered event handling and addition of `VMStartedEvent` support creates a more comprehensive restart workflow. The consistent pattern of waiting for host connection before VM operations is well implemented.

---

`57-58`: **Improved completion logic placement.**

Moving the completion logic inside the try block ensures it only executes when all events are successfully processed, which is more robust than the previous finally block placement.

---

`71-75`: **Main function properly updated for new parameter structure.**

The updated main function correctly loads and passes the `ups_grace` parameter, maintaining consistency with the new YAML structure.

</details>
<details>
<summary>data_retriever/yaml_parser.py (3)</summary>

`34-37`: **Well-designed UpsGrace dataclass.**

The new `UpsGrace` dataclass properly centralizes grace period configuration, improving maintainability and reducing code duplication across the codebase.

---

`52-53`: **Improved error handling approach.**

Allowing exceptions to propagate instead of returning None values is actually better than the previous approach, as it ensures errors are handled explicitly by callers rather than potentially being silently ignored.

---

`90-90`: **Simplified VM order parsing is well-implemented.**

The direct parsing of `vmOrder` into a list of strings is much cleaner than the previous nested structure and aligns well with the new YAML format.

</details>
<details>
<summary>README.md (1)</summary>

`1-125`: **Excellent documentation overhaul.**

The complete rewrite transforms the README into a comprehensive user guide that clearly explains the project's purpose, features, installation, and usage. The structured approach with clear sections makes it very accessible to new users.

</details>

</blockquote></details>

</details>

<!-- This is an auto-generated comment by CodeRabbit for review status -->

@chikatetsu chikatetsu merged commit e7e3225 into master Jul 16, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant