|
| 1 | +## Scenarios |
| 2 | + |
| 3 | +### Setup |
| 4 | + |
| 5 | +Example: |
| 6 | +```python |
| 7 | + config_file = Path(__file__).parent / "scenarios_configs.yaml" |
| 8 | + scenarios_config = ConfigLoader(file_path=config_file) |
| 9 | + backend_name = scenarios_config.get("API.backend", "https") |
| 10 | + register_backends(backend_name) |
| 11 | + ext_api = ProxmoxAPI(backend_name=backend_name, backend_type="sync") |
| 12 | + with ext_api as api: |
| 13 | + node_tasks = NodeTasksSync(api=api) # Pass the api instance to NodeTasksAsync |
| 14 | + for v in scenarios_config.get("Scenarios").values(): |
| 15 | + scenario_file = v.get("file") |
| 16 | + config = v.get("config") |
| 17 | + # Create scenario instance using the factory |
| 18 | + scenario = ScenarioFactory.create_scenario(scenario_file, config) |
| 19 | + # Run the scenario |
| 20 | + scenario.run(node_tasks) |
| 21 | +``` |
| 22 | + |
| 23 | +### Config |
| 24 | +#### Folder tree |
| 25 | + |
| 26 | +```bash |
| 27 | +cluster_tasks |
| 28 | +├── scenarios_configs.yaml |
| 29 | +├── scenarios |
| 30 | +│ ├── clone_template_vm_async.py (class ScenarioCloneTemplateVmAsync) |
| 31 | +│ ├── clone_template_vm_sync.py (class ScenarioCloneTemplateVmSync) |
| 32 | +```` |
| 33 | +#### Scenarios config `scenarios_configs.yaml` |
| 34 | +```yaml |
| 35 | +API: |
| 36 | + backend: "https" |
| 37 | +Scenarios: |
| 38 | + CloneTemplateVM: |
| 39 | + file: "clone_template_vm" |
| 40 | + config: |
| 41 | + node: "c01" |
| 42 | + vmid: 1004 |
| 43 | + newid: 201 |
| 44 | + name: "Cloned01" |
| 45 | + full: 1 |
| 46 | +``` |
| 47 | + |
| 48 | +#### Result |
| 49 | +<details> |
| 50 | +<summary>src/cluster_tasks/controller_sync.py</summary> |
| 51 | + |
| 52 | +``` pycon |
| 53 | +python /src/cluster_tasks/controller_sync.py |
| 54 | +DEBUG: Scenarios config: <config.config.ConfigLoader object at 0x10fd0b350> |
| 55 | +DEBUG: Creating backend: https of type: sync |
| 56 | +Running Scenario Template VM Clone: ScenarioCloneTemplateVmSync |
| 57 | +DEBUG: Generated a new task ID: 036b0cf8-c506-42ae-bb16-41f79d8708d2 |
| 58 | +DEBUG: Formatted endpoint: /api2/json/nodes/c01/qemu/201/status/current |
| 59 | +INFO: VM 201 already exists - Deleting... |
| 60 | +DEBUG: Generated a new task ID: d851e29d-11b9-49f0-ac48-b4be53f66a47 |
| 61 | +DEBUG: Formatted endpoint: /api2/json/nodes/c01/qemu/201 |
| 62 | +DEBUG: Generated a new task ID: fb7e60d4-9f45-490b-ba48-c2b7c408f297 |
| 63 | +DEBUG: Formatted endpoint: /api2/json/nodes/c01/tasks/UPID:c01:002DC36D:045F99E0:677A9183:qmdestroy:201:api_user@pam!cluster_helper:/status |
| 64 | +INFO: Waiting for task to finish... [ 0:00:00 / 0:01:00 ] |
| 65 | +DEBUG: Generated a new task ID: cb281c02-d5de-4f5e-9362-11f83e261250 |
| 66 | +DEBUG: Formatted endpoint: /api2/json/nodes/c01/tasks/UPID:c01:002DC36D:045F99E0:677A9183:qmdestroy:201:api_user@pam!cluster_helper:/status |
| 67 | +INFO: VM 201 deleted successfully |
| 68 | +DEBUG: Generated a new task ID: 1f3ce5b8-2ac1-4889-b43c-5ddfc76b949a |
| 69 | +DEBUG: Formatted endpoint: /api2/json/nodes/c01/qemu/1004/clone |
| 70 | +DEBUG: Generated a new task ID: 2bb19080-44ab-43ce-9b30-a3d8c4d0c51f |
| 71 | +DEBUG: Formatted endpoint: /api2/json/nodes/c01/tasks/UPID:c01:002DC388:045F9AE2:677A9185:qmclone:1004:api_user@pam!cluster_helper:/status |
| 72 | +INFO: Waiting for task to finish... [ 0:00:00 / 0:01:00 ] |
| 73 | +DEBUG: Generated a new task ID: 3398e65b-ddad-427b-af86-ee2735e54907 |
| 74 | +DEBUG: Formatted endpoint: /api2/json/nodes/c01/tasks/UPID:c01:002DC388:045F9AE2:677A9185:qmclone:1004:api_user@pam!cluster_helper:/status |
| 75 | +INFO: Waiting for task to finish... [ 0:00:02 / 0:01:00 ] |
| 76 | +DEBUG: Generated a new task ID: 6cafba81-fa97-48a8-9b51-c11df3bbe1d8 |
| 77 | +DEBUG: Formatted endpoint: /api2/json/nodes/c01/tasks/UPID:c01:002DC388:045F9AE2:677A9185:qmclone:1004:api_user@pam!cluster_helper:/status |
| 78 | +INFO: Waiting for task to finish... [ 0:00:04 / 0:01:00 ] |
| 79 | +DEBUG: Generated a new task ID: 507cb3aa-7a72-4b01-b1f0-9a52a8f92b99 |
| 80 | +DEBUG: Formatted endpoint: /api2/json/nodes/c01/tasks/UPID:c01:002DC388:045F9AE2:677A9185:qmclone:1004:api_user@pam!cluster_helper:/status |
| 81 | +INFO: Waiting for task to finish... [ 0:00:06 / 0:01:00 ] |
| 82 | +DEBUG: Generated a new task ID: f4cb2983-3d06-49d0-b221-6336da330ce1 |
| 83 | +DEBUG: Formatted endpoint: /api2/json/nodes/c01/tasks/UPID:c01:002DC388:045F9AE2:677A9185:qmclone:1004:api_user@pam!cluster_helper:/status |
| 84 | +INFO: VM 201 cloned successfully |
| 85 | +
|
| 86 | +Process finished with exit code 0 |
| 87 | +``` |
| 88 | +</details> |
| 89 | + |
| 90 | +### ScenarioFactory |
| 91 | + |
| 92 | +```python |
| 93 | +scenario = ScenarioFactory.create_scenario(scenario_file, config) |
| 94 | +``` |
| 95 | + |
| 96 | + |
| 97 | +### ScenarioBase |
| 98 | + |
| 99 | + |
| 100 | + |
| 101 | + |
| 102 | + |
| 103 | +[README](../README.md) |
0 commit comments