Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
workload container registeration fix, sdk upgrade to 0.12.0, test fix…
…ed and re-ran
  • Loading branch information
Akshay Neema committed Jun 22, 2021
commit 3b9c3c07d0d71d2b9fde5ac8e36dc3ee7e731caa
3 changes: 2 additions & 1 deletion azure-cli2017.pyproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<CommandLineArguments>
</CommandLineArguments>
<IsWindowsApplication>False</IsWindowsApplication>
<TestFramework>Pytest</TestFramework>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'" />
<PropertyGroup Condition="'$(Configuration)' == 'Release'" />
Expand Down Expand Up @@ -1488,4 +1489,4 @@
</Interpreter>
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />
</Project>
</Project>
2 changes: 1 addition & 1 deletion src/azure-cli/azure/cli/command_modules/backup/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ def restore_disks(cmd, client, resource_group_name, vault_name, container_name,
# Trigger restore
result = client.trigger(vault_name, resource_group_name, fabric_name,
container_uri, item_uri, rp_name,
trigger_restore_request, raw=True)
trigger_restore_request, raw=True, polling=False).result()
return _track_backup_job(cmd.cli_ctx, result, vault_name, resource_group_name)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ def restore_AzureFileShare(cmd, client, resource_group_name, vault_name, rp_name

result = client.trigger(vault_name, resource_group_name, fabric_name,
container_uri, item_uri, rp_name,
trigger_restore_request, raw=True)
trigger_restore_request, raw=True, polling=False).result()

return helper.track_backup_job(cmd.cli_ctx, result, vault_name, resource_group_name)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ def is_json(content):


def get_protection_container_uri_from_id(arm_id):
m = re.search('(?<=protectionContainers/)[^/]+', arm_id)
m = re.search('(?<=/protectionContainers/)[^/]+', arm_id)
return m.group(0)


Expand All @@ -356,7 +356,7 @@ def get_vm_name_from_vm_id(arm_id):


def get_resource_group_from_id(arm_id):
m = re.search('(?<=resourceGroups/)[^/]+', arm_id)
m = re.search('(?<=/resourceGroups/)[^/]+', arm_id)
return m.group(0)


Expand All @@ -366,7 +366,7 @@ def get_operation_id_from_header(header):


def get_vault_from_arm_id(arm_id):
m = re.search('(?<=vaults/)[^/]+', arm_id)
m = re.search('(?<=/vaults/)[^/]+', arm_id)
return m.group(0)


Expand Down
64 changes: 45 additions & 19 deletions src/azure-cli/azure/cli/command_modules/backup/custom_wl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
protectable_containers_cf, backup_protection_containers_cf, backup_protected_items_cf, recovery_points_crr_cf
import azure.cli.command_modules.backup.custom_help as cust_help
import azure.cli.command_modules.backup.custom_common as common
from azure.cli.core.azclierror import InvalidArgumentValueError, RequiredArgumentMissingError, ValidationError
from azure.cli.core.azclierror import InvalidArgumentValueError, RequiredArgumentMissingError, ValidationError, \
ResourceNotFoundError


fabric_name = "Azure"
Expand Down Expand Up @@ -101,20 +102,18 @@ def register_wl_container(cmd, client, vault_name, resource_group_name, workload
""")

workload_type = _check_map(workload_type, workload_type_map)
container_name = resource_id.split('/')[-1]
container_name = _get_protectable_container_name(cmd, resource_group_name, vault_name, resource_id)

containers = list_protectable_containers(cmd, resource_group_name, vault_name)

for container in containers:
if cust_help.get_resource_id(container.properties.container_id) == cust_help.get_resource_id(resource_id):
container_name = container.name
break
if container_name is None or not cust_help.is_native_name(container_name):
# refresh containers and try to get the protectable container object again
client.refresh(vault_name, resource_group_name, fabric_name)
container_name = _get_protectable_container_name(cmd, resource_group_name, vault_name, resource_id)

if not cust_help.is_native_name(container_name):
raise CLIError(
"""
Container unavailable or already registered.
""")
if container_name is None or not cust_help.is_native_name(container_name):
raise ResourceNotFoundError(
"""
Container unavailable or already registered.
""")

properties = AzureVMAppContainerProtectionContainer(backup_management_type=container_type,
source_resource_id=resource_id,
Expand Down Expand Up @@ -547,6 +546,16 @@ def restore_azure_wl(cmd, client, resource_group_name, vault_name, recovery_conf
trigger_restore_properties = _get_restore_request_instance(item_type, log_point_in_time)
trigger_restore_properties.recovery_type = restore_mode

# Get target vm id
if container_id is not None:
target_container_name = cust_help.get_protection_container_uri_from_id(container_id)
target_resource_group = cust_help.get_resource_group_from_id(container_id)
target_vault_name = cust_help.get_vault_from_arm_id(container_id)
target_container = common.show_container(cmd, backup_protection_containers_cf(cmd.cli_ctx),
target_container_name, target_resource_group, target_vault_name,
'AzureWorkload')
setattr(trigger_restore_properties, 'target_virtual_machine_id', target_container.properties.source_resource_id)

if restore_mode == 'AlternateLocation':
if recovery_mode != "FileRecovery":
setattr(trigger_restore_properties, 'source_resource_id', source_resource_id)
Expand Down Expand Up @@ -574,7 +583,7 @@ def restore_azure_wl(cmd, client, resource_group_name, vault_name, recovery_conf
trigger_restore_request = RestoreRequestResource(properties=trigger_restore_properties)
# Trigger restore and wait for completion
result = client.trigger(vault_name, resource_group_name, fabric_name, container_uri,
item_uri, recovery_point_id, trigger_restore_request, raw=True)
item_uri, recovery_point_id, trigger_restore_request, raw=True, polling=False).result()
return cust_help.track_backup_job(cmd.cli_ctx, result, vault_name, resource_group_name)


Expand All @@ -585,11 +594,7 @@ def show_recovery_config(cmd, client, resource_group_name, vault_name, restore_m
datetime_type(log_point_in_time)

if restore_mode == 'AlternateWorkloadRestore':
if target_item is None:
raise CLIError(
"""
Target Item must be provided.
""")
_check_none_and_many(target_item, "Target Item")

protectable_item_type = target_item.properties.protectable_item_type
if protectable_item_type.lower() not in ["sqlinstance", "saphanasystem"]:
Expand Down Expand Up @@ -729,3 +734,24 @@ def _check_map(item_type, item_type_map):
az_error = InvalidArgumentValueError(error_text)
az_error.set_recommendation(recommendation_text)
raise az_error


def _get_protectable_container_name(cmd, resource_group_name, vault_name, resource_id):
containers = list_protectable_containers(cmd, resource_group_name, vault_name)
container_name = None
for container in containers:
container_resource_id = cust_help.get_resource_id(container.properties.container_id)
if container_resource_id.lower() == cust_help.get_resource_id(resource_id).lower():
container_name = container.name
break
return container_name

def _check_none_and_many(item, item_name):
if item is None:
error_text = "{} must be provided.".format(item_name)
az_error = ResourceNotFoundError(error_text)
raise az_error
if isinstance(item, list):
error_text = "Multiple {}s found. Please check if you have given correct target server type.".format(item_name)
az_error = InvalidArgumentValueError(error_text)
raise az_error
Loading