|
6 | 6 | from azure.cli.command_modules.backup import custom |
7 | 7 | from azure.cli.command_modules.backup import custom_afs |
8 | 8 | from azure.cli.command_modules.backup import custom_help |
9 | | -import azure.cli.command_modules.backup.custom_common as common |
10 | 9 | from azure.cli.command_modules.backup import custom_wl |
| 10 | +import azure.cli.command_modules.backup.custom_common as common |
| 11 | +from azure.cli.command_modules.backup._validators import validate_reconfigure_cli_parameters |
11 | 12 | from azure.cli.command_modules.backup._client_factory import protection_policies_cf, backup_protected_items_cf, \ |
12 | 13 | backup_protection_containers_cf, backup_protectable_items_cf, registered_identities_cf, vaults_cf |
13 | 14 | from azure.cli.core.azclierror import ValidationError, RequiredArgumentMissingError, InvalidArgumentValueError, \ |
|
19 | 20 | fabric_name = "Azure" |
20 | 21 |
|
21 | 22 |
|
| 23 | +def reconfigure_backup_protection(cmd, client, resource_group_name, vault_name, container_name, item_name, |
| 24 | + new_vault_name, new_vault_resource_group, |
| 25 | + new_policy_name, backup_management_type, workload_type=None, |
| 26 | + retain_as_per_policy=False, tenant_id=None): |
| 27 | + """Entry point for reconfiguring backup protection across vaults. |
| 28 | +
|
| 29 | + This function performs common validation and dispatches to workload specific implementations |
| 30 | + in custom.py (VM), custom_afs.py (AFS) and custom_wl.py (Workload).""" |
| 31 | + |
| 32 | + # Common CLI-level validation (different vaults, workload type rules etc.) |
| 33 | + validate_reconfigure_cli_parameters(vault_name, resource_group_name, |
| 34 | + new_vault_name, new_vault_resource_group, |
| 35 | + backup_management_type, workload_type) |
| 36 | + |
| 37 | + # Fetch the protected item from old vault (use existing show_item logic) |
| 38 | + item = show_item(cmd, client, resource_group_name, vault_name, |
| 39 | + container_name, item_name, backup_management_type, workload_type) |
| 40 | + custom_help.validate_item(item) |
| 41 | + if isinstance(item, list): # Ambiguous friendly name |
| 42 | + raise ValidationError("Multiple items found. Please use native container and item names.") |
| 43 | + |
| 44 | + # Item-level validation (state, workload specifics) |
| 45 | + from azure.mgmt.recoveryservicesbackup.activestamp.models import ProtectionState |
| 46 | + if item.properties.protection_state not in [ProtectionState.protected, |
| 47 | + ProtectionState.protection_stopped]: |
| 48 | + raise ValidationError(f"Reconfiguration only supported for items in states: Protected or " |
| 49 | + f"ProtectionStopped. Current state: " |
| 50 | + f"{item.properties.protection_state}") |
| 51 | + |
| 52 | + # Dispatch by backup management type |
| 53 | + dispatch_type = backup_management_type.lower() |
| 54 | + if dispatch_type == 'azureiaasvm': |
| 55 | + return custom.reconfigure_vm_protection(cmd, item, vault_name, resource_group_name, |
| 56 | + new_vault_name, new_vault_resource_group, |
| 57 | + new_policy_name, retain_as_per_policy, tenant_id) |
| 58 | + if dispatch_type == 'azurestorage': |
| 59 | + return custom_afs.reconfigure_afs_protection(cmd, item, vault_name, resource_group_name, |
| 60 | + new_vault_name, new_vault_resource_group, |
| 61 | + new_policy_name, retain_as_per_policy, tenant_id) |
| 62 | + if dispatch_type == 'azureworkload': |
| 63 | + return custom_wl.reconfigure_wl_protection(cmd, item, vault_name, resource_group_name, |
| 64 | + new_vault_name, new_vault_resource_group, |
| 65 | + new_policy_name, workload_type, retain_as_per_policy, tenant_id) |
| 66 | + |
| 67 | + |
22 | 68 | def show_container(cmd, client, name, resource_group_name, vault_name, backup_management_type=None, |
23 | 69 | status="Registered", use_secondary_region=None): |
24 | 70 | return common.show_container(cmd, client, name, resource_group_name, vault_name, backup_management_type, status, |
|
0 commit comments