2424from azure .mgmt .recoveryservicesbackup .activestamp import RecoveryServicesBackupClient
2525from azure .cli .core .commands .client_factory import get_mgmt_service_client
2626
27+ from knack .log import get_logger
28+ logger = get_logger (__name__ )
29+
2730fabric_name = "Azure"
2831backup_management_type = "AzureStorage"
2932workload_type = "AzureFileShare"
@@ -245,9 +248,9 @@ def list_recovery_points(cmd, client, resource_group_name, vault_name, item, sta
245248 Please either remove the flag or query for any other backup-management-type.
246249 """ )
247250
248- if is_ready_for_move is not None or target_tier is not None or tier is not None :
251+ if is_ready_for_move is not None or target_tier is not None :
249252 raise ArgumentUsageError ("""Invalid argument has been passed. --is-ready-for-move true, --target-tier
250- and --tier flags are not supported for --backup-management-type AzureStorage.""" )
253+ are not supported for --backup-management-type AzureStorage.""" )
251254
252255 if recommended_for_archive is not None :
253256 raise ArgumentUsageError ("""--recommended-for-archive is supported by AzureIaasVM backup management
@@ -270,11 +273,57 @@ def list_recovery_points(cmd, client, resource_group_name, vault_name, item, sta
270273 recovery_points = client .list (vault_name , resource_group_name , fabric_name , container_uri , item_uri , filter_string )
271274 paged_recovery_points = helper .get_list_from_paged_response (recovery_points )
272275
276+ if tier :
277+ filtered_recovery_points = []
278+
279+ for rp in paged_recovery_points :
280+ # Prepare to collect tier types
281+ rp_tier_types = []
282+
283+ # Safely grab additional_properties
284+ additional_props = getattr (rp .properties , 'additional_properties' , {})
285+ if not isinstance (additional_props , dict ):
286+ continue
287+
288+ # Get details list
289+ tier_details_list = additional_props .get ("recoveryPointTierDetails" , [])
290+ if not isinstance (tier_details_list , list ):
291+ continue
292+
293+ for detail in tier_details_list :
294+ if not isinstance (detail , dict ):
295+ continue
296+ rp_type = detail .get ("type" )
297+ if rp_type :
298+ rp_tier_types .append (rp_type )
299+
300+ # Map types to a tier
301+ if 'InstantRP' in rp_tier_types and 'HardenedRP' in rp_tier_types :
302+ rp_tier = 'SnapshotAndVaultStandard'
303+ elif 'InstantRP' in rp_tier_types :
304+ rp_tier = 'Snapshot'
305+ elif 'HardenedRP' in rp_tier_types :
306+ rp_tier = 'VaultStandard'
307+ else :
308+ logger .warning (
309+ "Warning: Unrecognized Recovery Point tier received."
310+ "If you see this message, please contact Microsoft Support."
311+ "The recognized tiers for AzureFileShare are: 'Snapshot', 'VaultStandard', or "
312+ "'SnapshotAndVaultStandard'."
313+ )
314+ rp_tier = None
315+
316+ # Filter by matching tier
317+ if rp_tier == tier :
318+ filtered_recovery_points .append (rp )
319+
320+ return filtered_recovery_points
321+
273322 return paged_recovery_points
274323
275324
276325def update_policy_for_item (cmd , client , resource_group_name , vault_name , item , policy , tenant_id = None ,
277- is_critical_operation = False ):
326+ is_critical_operation = False , yes = False ):
278327 if item .properties .backup_management_type != policy .properties .backup_management_type :
279328 raise CLIError (
280329 """
@@ -302,6 +351,13 @@ def update_policy_for_item(cmd, client, resource_group_name, vault_name, item, p
302351 aux_tenants = [tenant_id ]).protected_items
303352 afs_item .properties .resource_guard_operation_requests = [helper .get_resource_guard_operation_request (
304353 cmd .cli_ctx , resource_group_name , vault_name , "updateProtection" )]
354+
355+ # Validate existing & new policy
356+ existing_policy_name = item .properties .policy_id .split ('/' )[- 1 ]
357+ existing_policy = common .show_policy (protection_policies_cf (cmd .cli_ctx ), resource_group_name , vault_name ,
358+ existing_policy_name )
359+ helper .validate_update_policy_request (existing_policy , policy , yes )
360+
305361 # Update policy
306362 result = client .create_or_update (vault_name , resource_group_name , fabric_name ,
307363 container_uri , item_uri , afs_item , cls = helper .get_pipeline_response )
@@ -365,7 +421,7 @@ def _get_storage_account_id(cli_ctx, storage_account_name, storage_account_rg):
365421
366422
367423def set_policy (cmd , client , resource_group_name , vault_name , policy , policy_name , tenant_id = None ,
368- is_critical_operation = False ):
424+ is_critical_operation = False , yes = False ):
369425 if policy_name is None :
370426 raise CLIError (
371427 """
@@ -375,7 +431,8 @@ def set_policy(cmd, client, resource_group_name, vault_name, policy, policy_name
375431 policy_object = helper .get_policy_from_json (client , policy )
376432 policy_object .properties .work_load_type = workload_type
377433 existing_policy = common .show_policy (client , resource_group_name , vault_name , policy_name )
378- helper .validate_update_policy_request (existing_policy , policy_object )
434+
435+ helper .validate_update_policy_request (existing_policy , policy_object , yes )
379436 if is_critical_operation :
380437 if helper .is_retention_duration_decreased (existing_policy , policy_object , "AzureStorage" ):
381438 # update the payload with critical operation and add auxiliary header for cross tenant case
0 commit comments