Skip to content

Commit 672a42f

Browse files
authored
[BACKUP] az backup protectable-item list: Add protectable-item-type as an optional argument (Azure#16765)
1 parent 9f4939a commit 672a42f

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

linter_exclusions.yml

+5
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,11 @@ backup protectable-item show:
695695
protectable_item_type:
696696
rule_exclusions:
697697
- option_length_too_long
698+
backup protectable-item list:
699+
parameters:
700+
protectable_item_type:
701+
rule_exclusions:
702+
- option_length_too_long
698703
backup protection auto-enable-for-azurewl:
699704
parameters:
700705
protectable_item_name:

src/azure-cli/azure/cli/command_modules/backup/_params.py

+3
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,9 @@ def load_arguments(self, _):
244244
c.argument('server_name', options_list=['--server-name'], help='Parent Server name of the item.')
245245
c.argument('protectable_item_type', protectable_item_type)
246246

247+
with self.argument_context('backup protectable-item list') as c:
248+
c.argument('protectable_item_type', protectable_item_type)
249+
247250
# Restore
248251
# TODO: Need to use recovery_point.id once https://github.com/Azure/msrestazure-for-python/issues/80 is fixed.
249252
with self.argument_context('backup restore') as c:

src/azure-cli/azure/cli/command_modules/backup/custom_base.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,8 @@ def list_associated_items_for_policy(client, resource_group_name, vault_name, na
196196
backup_management_type)
197197

198198

199-
def list_protectable_items(cmd, client, resource_group_name, vault_name, workload_type, container_name=None):
199+
def list_protectable_items(cmd, client, resource_group_name, vault_name, workload_type, container_name=None,
200+
protectable_item_type=None):
200201
container_uri = None
201202
if container_name:
202203
if custom_help.is_native_name(container_name):
@@ -211,7 +212,8 @@ def list_protectable_items(cmd, client, resource_group_name, vault_name, workloa
211212
Multiple containers with same Friendly Name found. Please give native names instead.
212213
""")
213214
container_uri = container.name
214-
return custom_wl.list_protectable_items(client, resource_group_name, vault_name, workload_type, container_uri)
215+
return custom_wl.list_protectable_items(client, resource_group_name, vault_name, workload_type, container_uri,
216+
protectable_item_type)
215217

216218

217219
def show_protectable_item(cmd, client, resource_group_name, vault_name, name, server_name, protectable_item_type,

src/azure-cli/azure/cli/command_modules/backup/custom_wl.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,11 @@ def show_protectable_instance(items, server_name, protectable_item_type):
283283
return cust_help.get_none_one_or_many(filtered_items)
284284

285285

286-
def list_protectable_items(client, resource_group_name, vault_name, workload_type, container_uri=None):
286+
def list_protectable_items(client, resource_group_name, vault_name, workload_type, container_uri=None,
287+
protectable_item_type=None):
287288
workload_type = _check_map(workload_type, workload_type_map)
289+
if protectable_item_type is not None:
290+
protectable_item_type = _check_map(protectable_item_type, protectable_item_type_map)
288291

289292
filter_string = cust_help.get_filter_string({
290293
'backupManagementType': "AzureWorkload",
@@ -293,9 +296,15 @@ def list_protectable_items(client, resource_group_name, vault_name, workload_typ
293296
# Items list
294297
items = client.list(vault_name, resource_group_name, filter_string)
295298
paged_items = cust_help.get_list_from_paged_response(items)
299+
300+
if protectable_item_type is not None:
301+
# Protectable Item Type filter
302+
paged_items = [item for item in paged_items if
303+
item.properties.protectable_item_type.lower() == protectable_item_type.lower()]
296304
if container_uri:
297305
return [item for item in paged_items if
298306
cust_help.get_protection_container_uri_from_id(item.id).lower() == container_uri.lower()]
307+
299308
return paged_items
300309

301310

0 commit comments

Comments
 (0)