def enable_for_AzureFileShare(cmd, client, resource_group_name, vault_name, afs_name, storage_account_name, policy_name): # get registered storage accounts storage_account = None containers_client = backup_protection_containers_cf(cmd.cli_ctx) registered_containers = common.list_containers(containers_client, resource_group_name, vault_name, "AzureStorage") storage_account = _get_storage_account_from_list(registered_containers, storage_account_name) # get unregistered storage accounts if storage_account is None: unregistered_containers = list_protectable_containers(cmd.cli_ctx, resource_group_name, vault_name) storage_account = _get_storage_account_from_list(unregistered_containers, storage_account_name) if storage_account is None: # refresh containers in the vault protection_containers_client = protection_containers_cf(cmd.cli_ctx) filter_string = helper.get_filter_string({'backupManagementType': "AzureStorage"}) refresh_result = protection_containers_client.refresh(vault_name, resource_group_name, fabric_name, filter=filter_string, raw=True) helper.track_refresh_operation(cmd.cli_ctx, refresh_result, vault_name, resource_group_name) # refetch the protectable containers after refresh unregistered_containers = list_protectable_containers(cmd.cli_ctx, resource_group_name, vault_name) storage_account = _get_storage_account_from_list(unregistered_containers, storage_account_name) if storage_account is None: raise CLIError("Storage account not found or not supported.") # register storage account protection_containers_client = protection_containers_cf(cmd.cli_ctx) properties = AzureStorageContainer(backup_management_type="AzureStorage", source_resource_id=storage_account.properties.container_id, workload_type="AzureFileShare") param = ProtectionContainerResource(properties=properties) result = protection_containers_client.register(vault_name, resource_group_name, fabric_name, storage_account.name, param, raw=True) helper.track_register_operation(cmd.cli_ctx, result, vault_name, resource_group_name, storage_account.name) policy = common.show_policy(protection_policies_cf(cmd.cli_ctx), resource_group_name, vault_name, policy_name) helper.validate_policy(policy) protectable_item = _get_protectable_item_for_afs(cmd.cli_ctx, vault_name, resource_group_name, afs_name, storage_account) helper.validate_azurefileshare_item(protectable_item) container_uri = helper.get_protection_container_uri_from_id(protectable_item.id) item_uri = helper.get_protectable_item_uri_from_id(protectable_item.id) item_properties = AzureFileshareProtectedItem() item_properties.policy_id = policy.id item_properties.source_resource_id = protectable_item.properties.parent_container_fabric_id item = ProtectedItemResource(properties=item_properties) result = client.create_or_update(vault_name, resource_group_name, fabric_name, container_uri, item_uri, item, raw=True) return helper.track_backup_job(cmd.cli_ctx, result, vault_name, resource_group_name)
def register_wl_container(cmd, client, vault_name, resource_group_name, workload_type, resource_id, container_type): if not cust_help.is_id(resource_id): raise CLIError( """ Resource ID is not a valid one. """) workload_type = workload_type_map[workload_type] container_name = resource_id.split('/')[-1] 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 not cust_help.is_native_name(container_name): raise CLIError( """ Container unavailable or already registered. """) properties = AzureVMAppContainerProtectionContainer(backup_management_type=container_type, source_resource_id=resource_id, workload_type=workload_type) param = ProtectionContainerResource(properties=properties) # Trigger register and wait for completion result = sdk_no_wait(True, client.register, vault_name, resource_group_name, fabric_name, container_name, param) return cust_help.track_register_operation(cmd.cli_ctx, result, vault_name, resource_group_name, container_name)
def re_register_wl_container(cmd, client, vault_name, resource_group_name, workload_type, container_name, container_type): workload_type = workload_type_map[workload_type] if not cust_help.is_native_name(container_name): raise CLIError( """ Container name passed cannot be a friendly name. Please pass a native container name. """) backup_cf = backup_protection_containers_cf(cmd.cli_ctx) containers = common.list_containers(backup_cf, resource_group_name, vault_name, container_type) source_resource_id = None for container in containers: if container.name == container_name: source_resource_id = container.properties.source_resource_id break if not source_resource_id: raise CLIError( """ No such registered container exists. """) properties = AzureVMAppContainerProtectionContainer(backup_management_type=container_type, workload_type=workload_type, operation_type='Reregister', source_resource_id=source_resource_id) param = ProtectionContainerResource(properties=properties) # Trigger register and wait for completion result = sdk_no_wait(True, client.register, vault_name, resource_group_name, fabric_name, container_name, param) return cust_help.track_register_operation(cmd.cli_ctx, result, vault_name, resource_group_name, container_name)
def register_wl_container(cmd, client, vault_name, resource_group_name, workload_type, resource_id, container_type): if not cust_help.is_id(resource_id): raise CLIError( """ Resource ID is not a valid one. """) workload_type = _check_map(workload_type, workload_type_map) container_name = _get_protectable_container_name(cmd, resource_group_name, vault_name, resource_id) if container_name is None or not cust_help.is_native_name(container_name): filter_string = cust_help.get_filter_string({'backupManagementType': "AzureWorkload"}) # refresh containers and try to get the protectable container object again refresh_result = client.refresh(vault_name, resource_group_name, fabric_name, filter=filter_string, cls=cust_help.get_pipeline_response) cust_help.track_refresh_operation(cmd.cli_ctx, refresh_result, vault_name, resource_group_name) container_name = _get_protectable_container_name(cmd, resource_group_name, vault_name, resource_id) 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, workload_type=workload_type) param = ProtectionContainerResource(properties=properties) # Trigger register and wait for completion result = client.register(vault_name, resource_group_name, fabric_name, container_name, param, cls=cust_help.get_pipeline_response) return cust_help.track_register_operation(cmd.cli_ctx, result, vault_name, resource_group_name, container_name)
def unregister_afs_container(cmd, client, vault_name, resource_group_name, container_name): result = client.unregister(vault_name, resource_group_name, fabric_name, container_name, raw=True) return helper.track_register_operation(cmd.cli_ctx, result, vault_name, resource_group_name, container_name)
def unregister_wl_container(cmd, client, vault_name, resource_group_name, container_name): if not cust_help.is_native_name(container_name): raise CLIError( """ Container name passed cannot be a friendly name. Please pass a native container name. """) # Trigger unregister and wait for completion result = client.unregister(vault_name, resource_group_name, fabric_name, container_name, raw=True) return cust_help.track_register_operation(cmd.cli_ctx, result, vault_name, resource_group_name, container_name)