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
Prev Previous commit
Next Next commit
address comments and rerun tests
  • Loading branch information
Myron committed Apr 26, 2020
commit 1052c51fd1c42cb49c13666c1a4f410fdc57ad3c
10 changes: 5 additions & 5 deletions src/azure-cli/azure/cli/command_modules/monitor/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -1105,7 +1105,7 @@

helps['monitor log-analytics workspace linked-storage'] = """
type: group
short-summary: Manage linked storage for log analytics workspace.
short-summary: Manage linked storage account for log analytics workspace.
"""

helps['monitor log-analytics workspace linked-storage create'] = """
Expand All @@ -1126,17 +1126,17 @@

helps['monitor log-analytics workspace linked-storage add'] = """
type: command
short-summary: Add linked storages for log analytics workspace.
short-summary: Add some linked storages with specific data source type for log analytics workspace.
examples:
- name: Add a linked storage for a log analytics workspace
- name: Add two linked storage for a log analytics workspace
text: az monitor log-analytics workspace linked-storage add --type AzureWatson -g MyResourceGroup --workspace-name MyWorkspace --storage-accounts SA1 SA2
"""

helps['monitor log-analytics workspace linked-storage remove'] = """
type: command
short-summary: Remove all linked storages with specific data source type for log analytics workspace
short-summary: Remove some linked storages with specific data source type for log analytics workspace
examples:
- name: Remove a linked storage for a log analytics workspace
- name: Remove two linked storage for a log analytics workspace
text: az monitor log-analytics workspace linked-storage remove --type AzureWatson -g MyResourceGroup --workspace-name MyWorkspace --storage-accounts SA1 SA2.
"""

Expand Down
16 changes: 8 additions & 8 deletions src/azure-cli/azure/cli/command_modules/monitor/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def load_command_table(self, _):
g.command('enable', 'enable')
g.command('disable', 'disable')

with self.command_group('monitor log-analytics workspace linked-service', log_analytics_workspace_linked_service_sdk, custom_command_type=log_analytics_workspace_linked_service_custom) as g:
with self.command_group('monitor log-analytics workspace linked-service', log_analytics_workspace_linked_service_sdk, custom_command_type=log_analytics_workspace_linked_service_custom, is_preview=True) as g:
g.custom_command('create', 'create_log_analytics_workspace_linked_service', supports_no_wait=True)
g.generic_update_command('update', custom_func_name='update_log_analytics_workspace_linked_service', supports_no_wait=True)
g.show_command('show', 'get')
Expand All @@ -377,32 +377,32 @@ def load_command_table(self, _):
g.command('create', 'create_or_update')
g.custom_command('add', 'add_log_analytics_workspace_linked_storage_accounts')
g.custom_command('remove', 'remove_log_analytics_workspace_linked_storage_accounts')
g.command('delete', 'delete')
g.command('delete', 'delete', confirmation=True)
g.show_command('show', 'get')
g.command('list', 'list_by_workspace')

with self.command_group('monitor', metric_alert_sdk, custom_command_type=monitor_general_custom, is_preview=True) as g:
g.custom_command('clone', 'clone_existed_settings')
with self.command_group('monitor', metric_alert_sdk, custom_command_type=monitor_general_custom) as g:
g.custom_command('clone', 'clone_existed_settings', is_preview=True)

with self.command_group('monitor private-link-scope', private_link_scopes_sdk, custom_command_type=private_link_scope_custom) as g:
with self.command_group('monitor private-link-scope', private_link_scopes_sdk, custom_command_type=private_link_scope_custom, is_preview=True) as g:
g.custom_show_command('show', 'show_private_link_scope')
g.custom_command('list', 'list_private_link_scope')
g.custom_command('create', 'create_private_link_scope')
g.custom_command('update', 'update_private_link_scope')
g.custom_command('delete', 'delete_private_link_scope', confirmation=True)

with self.command_group('monitor private-link-scope scoped-resource', private_link_scoped_resources_sdk, custom_command_type=private_link_scope_custom) as g:
with self.command_group('monitor private-link-scope scoped-resource', private_link_scoped_resources_sdk, custom_command_type=private_link_scope_custom, is_preview=True) as g:
g.custom_show_command('show', 'show_private_link_scope_resource', client_factory=cf_private_link_scoped_resources)
g.custom_command('list', 'list_private_link_scope_resource', client_factory=cf_private_link_scoped_resources)
g.custom_command('create', 'create_private_link_scope_resource', client_factory=cf_private_link_scoped_resources)
g.custom_command('delete', 'delete_private_link_scope_resource', client_factory=cf_private_link_scoped_resources, confirmation=True)

with self.command_group('monitor private-link-scope private-link-resource', private_link_resources_sdk, custom_command_type=private_link_scope_custom) as g:
with self.command_group('monitor private-link-scope private-link-resource', private_link_resources_sdk, custom_command_type=private_link_scope_custom, is_preview=True) as g:
g.custom_show_command('show', 'show_private_link_resource', client_factory=cf_private_link_resources)
from azure.cli.core.commands.transform import gen_dict_to_list_transform
g.custom_command('list', 'list_private_link_resource', client_factory=cf_private_link_resources, transform=gen_dict_to_list_transform(key="value"))

with self.command_group('monitor private-link-scope private-endpoint-connection', private_endpoint_connections_sdk, custom_command_type=private_link_scope_custom) as g:
with self.command_group('monitor private-link-scope private-endpoint-connection', private_endpoint_connections_sdk, custom_command_type=private_link_scope_custom, is_preview=True) as g:
g.custom_show_command('show', 'show_private_endpoint_connection', client_factory=cf_private_endpoint_connections,
validator=validate_private_endpoint_connection_id)
g.custom_command('list', 'list_private_endpoint_connection', client_factory=cf_private_endpoint_connections)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@ def remove_log_analytics_workspace_linked_storage_accounts(client, resource_grou
linked_storage_accounts = client.get(resource_group_name=resource_group_name,
workspace_name=workspace_name,
data_source_type=data_source_type)
existed_storage_account_ids_set = set(linked_storage_accounts.storage_account_ids)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about write code as follows,

    if storage_account_id.lower() in [existing_storage_acocunt_id.lower() for existing_storage_acocunt_id in linked_storage_accounts.storage_account_ids]:
        linked_storage_accounts.storage_account_ids.remove(storage_account_id)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

each iteration we need a list generation, which is quite resource consuming. But I change the logic to generate set.

storage_account_ids_set = set()
for storage_account_id in storage_account_ids:
if storage_account_id in linked_storage_accounts.storage_account_ids:
linked_storage_accounts.storage_account_ids.remove(storage_account_id)
storage_account_ids_set.add(str.lower(storage_account_id))
for existed_storage_account_id in existed_storage_account_ids_set:
if str.lower(existed_storage_account_id) in storage_account_ids_set:
linked_storage_accounts.storage_account_ids.remove(existed_storage_account_id)
return client.create_or_update(resource_group_name=resource_group_name,
workspace_name=workspace_name,
data_source_type=data_source_type,
Expand Down
Loading