Skip to content

Commit

Permalink
[Azure Red Hat OpenShift] Add monitor subgroup to manage Log Analyt…
Browse files Browse the repository at this point in the history
…ics monitoring in Azure Red Hat OpensShift cluster (#11904)
  • Loading branch information
Olga Mirensky authored Jan 29, 2020
1 parent 3b133db commit 3c86814
Show file tree
Hide file tree
Showing 7 changed files with 989 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/azure-cli/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ Release History
* Fix issue #11658: `az group export` command does not support `--query` and `--output` parameters
* Fix issue #10279: The exit code of `az group deployment validate` is 0 when the verification fails

**Azure Red Hat OpenShift**

* Add `monitor` subgroup to manage Log Analytics monitoring in Azure Red Hat OpensShift cluster

**IoT**

* Deprecated 'IoT hub Job' commands.
Expand Down
23 changes: 23 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -959,3 +959,26 @@
text: |-
az openshift wait -g MyResourceGroup -n MyManagedCluster --updated --interval 60 --timeout 1800
"""

helps['openshift monitor'] = """
type: group
short-summary: Commands to manage Log Analytics monitoring. Requires "--workspace-id".
"""

helps['openshift monitor enable'] = """
type: command
short-summary: Enable Log Analytics monitoring. Requires "--workspace-id".
examples:
- name: Enable Log Analytics in a managed OpenShift cluster.
text: |-
az openshift monitor enable -g MyResourceGroup -n MyManagedCluster --workspace-id "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/MyResourceGroup/providers/Microsoft.OperationalInsights/workspaces/{workspace-id}"
"""

helps['openshift monitor disable'] = """
type: command
short-summary: Disable Log Analytics monitoring.
examples:
- name: Disable Log Analytics monitoring.
text: |-
az openshift monitor disable -g MyResourceGroup -n MyManagedCluster
"""
3 changes: 3 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,9 @@ def load_arguments(self, _):
c.argument('customer_admin_group_id', options_list=['--customer-admin-group-id'])
c.argument('workspace_id')

with self.argument_context('openshift monitor enable') as c:
c.argument('workspace_id', help='The resource ID of an existing Log Analytics Workspace to use for storing monitoring data.')


def _get_default_install_location(exe_name):
system = platform.system()
Expand Down
6 changes: 6 additions & 0 deletions src/azure-cli/azure/cli/command_modules/acs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,3 +124,9 @@ def load_command_table(self, _):
g.custom_show_command('show', 'openshift_show')
g.custom_command('list', 'osa_list', table_transformer=osa_list_table_format)
g.wait_command('wait')

# OSA monitor subgroup
with self.command_group('openshift monitor', openshift_managed_clusters_sdk,
client_factory=cf_openshift_managed_clusters) as g:
g.custom_command('enable', 'openshift_monitor_enable', supports_no_wait=True)
g.custom_command('disable', 'openshift_monitor_disable', supports_no_wait=True)
31 changes: 26 additions & 5 deletions src/azure-cli/azure/cli/command_modules/acs/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -3113,6 +3113,15 @@ def osa_list(cmd, client, resource_group_name=None):
return _remove_osa_nulls(list(managed_clusters))


def _format_workspace_id(workspace_id):
workspace_id = workspace_id.strip()
if not workspace_id.startswith('/'):
workspace_id = '/' + workspace_id
if workspace_id.endswith('/'):
workspace_id = workspace_id.rstrip('/')
return workspace_id


def openshift_create(cmd, client, resource_group_name, name, # pylint: disable=too-many-locals
location=None,
compute_vm_size="Standard_D4s_v3",
Expand Down Expand Up @@ -3197,11 +3206,7 @@ def openshift_create(cmd, client, resource_group_name, name, # pylint: disable=
name=vnet_peer
)
if workspace_id is not None:
workspace_id = workspace_id.strip()
if not workspace_id.startswith('/'):
workspace_id = '/' + workspace_id
if workspace_id.endswith('/'):
workspace_id = workspace_id.rstrip('/')
workspace_id = _format_workspace_id(workspace_id)
monitor_profile = OpenShiftManagedClusterMonitorProfile(enabled=True, workspace_resource_id=workspace_id) # pylint: disable=line-too-long
else:
monitor_profile = None
Expand Down Expand Up @@ -3259,6 +3264,22 @@ def openshift_scale(cmd, client, resource_group_name, name, compute_count, no_wa
return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance)


def openshift_monitor_enable(cmd, client, resource_group_name, name, workspace_id, no_wait=False):
instance = client.get(resource_group_name, name)
workspace_id = _format_workspace_id(workspace_id)
monitor_profile = OpenShiftManagedClusterMonitorProfile(enabled=True, workspace_resource_id=workspace_id) # pylint: disable=line-too-long
instance.monitor_profile = monitor_profile

return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance)


def openshift_monitor_disable(cmd, client, resource_group_name, name, no_wait=False):
instance = client.get(resource_group_name, name)
monitor_profile = OpenShiftManagedClusterMonitorProfile(enabled=False, workspace_resource_id=None) # pylint: disable=line-too-long
instance.monitor_profile = monitor_profile
return sdk_no_wait(no_wait, client.create_or_update, resource_group_name, name, instance)


def _get_load_balancer_outbound_ips(load_balancer_outbound_ips):
"""parse load balancer profile outbound IP ids and return an array of references to the outbound IP resources"""
load_balancer_outbound_ip_resources = None
Expand Down
Loading

0 comments on commit 3c86814

Please sign in to comment.