8
8
from datetime import datetime , timedelta , timezone
9
9
# pylint: disable=too-many-lines
10
10
from knack .log import get_logger
11
+ from knack .prompting import prompt_y_n
11
12
from azure .mgmt .core .tools import is_valid_resource_id
12
13
13
14
from azure .mgmt .recoveryservicesbackup .activestamp import RecoveryServicesBackupClient
126
127
os_linux = 'Linux'
127
128
password_offset = 33
128
129
password_length = 15
130
+ vm_policy_type_map = {
131
+ 'v2' : 'enhanced' ,
132
+ 'v1' : 'standard'
133
+ }
134
+ enhanced_policy_type = "v2"
135
+ standard_policy_type = "v1"
129
136
# pylint: disable=too-many-function-args
130
137
131
138
@@ -173,9 +180,9 @@ def create_vault(client, vault_name, resource_group_name, location, tags=None,
173
180
"to their default values. It is recommended to use az backup vault update instead." )
174
181
175
182
# If the vault exists, we move to the update flow instead
176
- update_vault (client , vault_name , resource_group_name , tags , public_network_access ,
177
- immutability_state , cross_subscription_restore_state , classic_alerts ,
178
- azure_monitor_alerts_for_job_failures )
183
+ return update_vault (client , vault_name , resource_group_name , tags , public_network_access ,
184
+ immutability_state , cross_subscription_restore_state , classic_alerts ,
185
+ azure_monitor_alerts_for_job_failures )
179
186
except CoreResourceNotFoundError :
180
187
vault_properties = VaultProperties ()
181
188
@@ -983,7 +990,7 @@ def list_items(cmd, client, resource_group_name, vault_name, container_name=None
983
990
984
991
985
992
def update_policy_for_item (cmd , client , resource_group_name , vault_name , item , policy , tenant_id = None ,
986
- is_critical_operation = False ):
993
+ is_critical_operation = False , yes = False ):
987
994
if item .properties .backup_management_type != policy .properties .backup_management_type :
988
995
raise CLIError (
989
996
"""
@@ -1004,16 +1011,33 @@ def update_policy_for_item(cmd, client, resource_group_name, vault_name, item, p
1004
1011
vm_item_properties .policy_id = policy .id
1005
1012
vm_item_properties .source_resource_id = item .properties .source_resource_id
1006
1013
vm_item = ProtectedItemResource (properties = vm_item_properties )
1014
+ existing_policy = common .show_policy (protection_policies_cf (cmd .cli_ctx ), resource_group_name , vault_name ,
1015
+ item .properties .policy_name )
1016
+
1007
1017
if is_critical_operation :
1008
- existing_policy = common .show_policy (protection_policies_cf (cmd .cli_ctx ), resource_group_name , vault_name ,
1009
- item .properties .policy_name )
1010
1018
if cust_help .is_retention_duration_decreased (existing_policy , policy , "AzureIaasVM" ):
1011
1019
# update the payload with critical operation and add auxiliary header for cross tenant case
1012
1020
if tenant_id is not None :
1013
1021
client = get_mgmt_service_client (cmd .cli_ctx , RecoveryServicesBackupClient ,
1014
1022
aux_tenants = [tenant_id ]).protected_items
1015
1023
vm_item .properties .resource_guard_operation_requests = [cust_help .get_resource_guard_operation_request (
1016
1024
cmd .cli_ctx , resource_group_name , vault_name , "updateProtection" )]
1025
+
1026
+ # Raise warning for standard->enhanced policy
1027
+ try :
1028
+ existing_policy_type = existing_policy .properties .policy_type .lower ()
1029
+ new_policy_type = policy .properties .policy_type .lower ()
1030
+ if (not yes and
1031
+ new_policy_type in vm_policy_type_map and vm_policy_type_map [new_policy_type ] == 'enhanced' and
1032
+ existing_policy_type in vm_policy_type_map and vm_policy_type_map [existing_policy_type ] == 'standard' ):
1033
+ warning_prompt = ('Upgrading to enhanced policy can incur additional charges. Once upgraded to the enhanced '
1034
+ 'policy, it is not possible to revert back to the standard policy. Do you want to continue?' )
1035
+ if not prompt_y_n (warning_prompt ):
1036
+ logger .warning ('Cancelling policy update operation' )
1037
+ return None
1038
+ except (AttributeError ):
1039
+ logger .warning ("Unable to fetch policy type for either existing or new policy. Proceeding with update." )
1040
+
1017
1041
# Update policy
1018
1042
result = client .create_or_update (vault_name , resource_group_name , fabric_name ,
1019
1043
container_uri , item_uri , vm_item , cls = cust_help .get_pipeline_response )
0 commit comments