-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Self-Help Commands Init Onboarding (#6242)
* generated self-help commands * update names of parameters to shorter name. * working az cli self-help * adding live tests and recordings * adding myself as extension owner * adding entry service_name.json * update name in codeowners * add examples * add readme and examples
- Loading branch information
1 parent
a719103
commit 6237593
Showing
31 changed files
with
2,165 additions
and
1 deletion.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
.. :changelog: | ||
Release History | ||
=============== | ||
|
||
0.1.0 | ||
++++++ | ||
* Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Azure CLI SelfHelp Extension | ||
|
||
This is an extension to Azure CLI to manage SelfHelp resources. | ||
|
||
## How to use | ||
|
||
Install this extension using the below CLI command. For details on each command, use `-h` or `--help`. | ||
|
||
``` | ||
az extension add --name self-help | ||
``` | ||
|
||
## Included Commands | ||
|
||
### _"Discovery-Solution"_ commands | ||
|
||
- #### List DiscoverySolutions | ||
|
||
_Examples:_ | ||
|
||
``` | ||
# Gets list of solution metadata for an azure resource. | ||
az self-help discovery-solution list --scope {scope} | ||
``` | ||
|
||
### _"Diagnostic"_ commands | ||
|
||
- #### Create Diagnostic for a resource | ||
|
||
_Examples:_ | ||
|
||
``` | ||
# Creates a diagnostic for a resource | ||
az self-help diagnostic create --diagnostic-name {diagnostic-name} --insights [{solutionId:Demo2InsightV2}] --scope {scope} | ||
``` | ||
|
||
- #### Show Diagnostic for a resource | ||
|
||
_Examples:_ | ||
|
||
``` | ||
# Show diagnostic for a resource. | ||
az self-help diagnostic show --diagnostic-name {diagnostic-name} --scope {scope} | ||
``` | ||
|
||
### _"Check-Name-Availability"_ commands | ||
|
||
- #### CheckName Availabiliity | ||
|
||
_Examples:_ | ||
|
||
``` | ||
# Checks name available of a diagnostic resource. | ||
az self-help check-name-availability --scope subscriptionId/{subId} --name {diagnostic-name} --type 'Microsoft.Help/diagnostics' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# | ||
# Code generated by aaz-dev-tools | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
from azure.cli.core import AzCommandsLoader | ||
from azext_self_help._help import helps # pylint: disable=unused-import | ||
|
||
|
||
class SelfHelpCommandsLoader(AzCommandsLoader): | ||
|
||
def __init__(self, cli_ctx=None): | ||
from azure.cli.core.commands import CliCommandType | ||
custom_command_type = CliCommandType( | ||
operations_tmpl='azext_self_help.custom#{}') | ||
super().__init__(cli_ctx=cli_ctx, | ||
custom_command_type=custom_command_type) | ||
|
||
def load_command_table(self, args): | ||
from azext_self_help.commands import load_command_table | ||
from azure.cli.core.aaz import load_aaz_command_table | ||
try: | ||
from . import aaz | ||
except ImportError: | ||
aaz = None | ||
if aaz: | ||
load_aaz_command_table( | ||
loader=self, | ||
aaz_pkg_name=aaz.__name__, | ||
args=args | ||
) | ||
load_command_table(self, args) | ||
return self.command_table | ||
|
||
def load_arguments(self, command): | ||
from azext_self_help._params import load_arguments | ||
load_arguments(self, command) | ||
|
||
|
||
COMMAND_LOADER_CLS = SelfHelpCommandsLoader |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# | ||
# Code generated by aaz-dev-tools | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: disable=line-too-long | ||
# pylint: disable=too-many-lines | ||
|
||
from knack.help_files import helps # pylint: disable=unused-import |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# | ||
# Code generated by aaz-dev-tools | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: disable=too-many-lines | ||
# pylint: disable=too-many-statements | ||
|
||
|
||
def load_arguments(self, _): # pylint: disable=unused-argument | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# | ||
# Code generated by aaz-dev-tools | ||
# -------------------------------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# | ||
# Code generated by aaz-dev-tools | ||
# -------------------------------------------------------------------------------------------- |
24 changes: 24 additions & 0 deletions
24
src/self-help/azext_self_help/aaz/latest/self_help/__cmd_group.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# | ||
# Code generated by aaz-dev-tools | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: skip-file | ||
# flake8: noqa | ||
|
||
from azure.cli.core.aaz import * | ||
|
||
|
||
@register_command_group( | ||
"self-help", | ||
is_preview=True, | ||
) | ||
class __CMDGroup(AAZCommandGroup): | ||
"""Azure SelfHelp will help you troubleshoot issues with Azure resources. | ||
""" | ||
pass | ||
|
||
|
||
__all__ = ["__CMDGroup"] |
12 changes: 12 additions & 0 deletions
12
src/self-help/azext_self_help/aaz/latest/self_help/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# | ||
# Code generated by aaz-dev-tools | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: skip-file | ||
# flake8: noqa | ||
|
||
from .__cmd_group import * | ||
from ._check_name_availability import * |
188 changes: 188 additions & 0 deletions
188
src/self-help/azext_self_help/aaz/latest/self_help/_check_name_availability.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
# -------------------------------------------------------------------------------------------- | ||
# Copyright (c) Microsoft Corporation. All rights reserved. | ||
# Licensed under the MIT License. See License.txt in the project root for license information. | ||
# | ||
# Code generated by aaz-dev-tools | ||
# -------------------------------------------------------------------------------------------- | ||
|
||
# pylint: skip-file | ||
# flake8: noqa | ||
|
||
from azure.cli.core.aaz import * | ||
|
||
|
||
@register_command( | ||
"self-help check-name-availability", | ||
is_preview=True, | ||
) | ||
class CheckNameAvailability(AAZCommand): | ||
"""This API is used to check the uniqueness of a resource name used for a diagnostic check. | ||
:example: Check Diagnostic Resource Uniqueness | ||
az self-help check-name-availability --scope subscriptionId/{subId} --name {diagnostic-name} --type 'Microsoft.Help/diagnostics' | ||
""" | ||
|
||
_aaz_info = { | ||
"version": "2023-01-01-preview", | ||
"resources": [ | ||
["mgmt-plane", "/{scope}/providers/microsoft.help/checknameavailability", "2023-01-01-preview"], | ||
] | ||
} | ||
|
||
def _handler(self, command_args): | ||
super()._handler(command_args) | ||
self._execute_operations() | ||
return self._output() | ||
|
||
_args_schema = None | ||
|
||
@classmethod | ||
def _build_arguments_schema(cls, *args, **kwargs): | ||
if cls._args_schema is not None: | ||
return cls._args_schema | ||
cls._args_schema = super()._build_arguments_schema(*args, **kwargs) | ||
|
||
# define Arg Group "" | ||
|
||
_args_schema = cls._args_schema | ||
_args_schema.scope = AAZStrArg( | ||
options=["--scope"], | ||
help="This is an extension resource provider and only resource level extension is supported at the moment.", | ||
required=True, | ||
) | ||
|
||
# define Arg Group "CheckNameAvailabilityRequest" | ||
|
||
_args_schema = cls._args_schema | ||
_args_schema.name = AAZStrArg( | ||
options=["--name"], | ||
arg_group="CheckNameAvailabilityRequest", | ||
help="The name of the resource for which availability needs to be checked.", | ||
) | ||
_args_schema.type = AAZStrArg( | ||
options=["--type"], | ||
arg_group="CheckNameAvailabilityRequest", | ||
help="The resource type.", | ||
) | ||
return cls._args_schema | ||
|
||
def _execute_operations(self): | ||
self.pre_operations() | ||
self.DiagnosticsCheckNameAvailability(ctx=self.ctx)() | ||
self.post_operations() | ||
|
||
@register_callback | ||
def pre_operations(self): | ||
pass | ||
|
||
@register_callback | ||
def post_operations(self): | ||
pass | ||
|
||
def _output(self, *args, **kwargs): | ||
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True) | ||
return result | ||
|
||
class DiagnosticsCheckNameAvailability(AAZHttpOperation): | ||
CLIENT_TYPE = "MgmtClient" | ||
|
||
def __call__(self, *args, **kwargs): | ||
request = self.make_request() | ||
session = self.client.send_request(request=request, stream=False, **kwargs) | ||
if session.http_response.status_code in [200]: | ||
return self.on_200(session) | ||
|
||
return self.on_error(session.http_response) | ||
|
||
@property | ||
def url(self): | ||
return self.client.format_url( | ||
"/{scope}/providers/Microsoft.Help/checkNameAvailability", | ||
**self.url_parameters | ||
) | ||
|
||
@property | ||
def method(self): | ||
return "POST" | ||
|
||
@property | ||
def error_format(self): | ||
return "MgmtErrorFormat" | ||
|
||
@property | ||
def url_parameters(self): | ||
parameters = { | ||
**self.serialize_url_param( | ||
"scope", self.ctx.args.scope, | ||
skip_quote=True, | ||
required=True, | ||
), | ||
} | ||
return parameters | ||
|
||
@property | ||
def query_parameters(self): | ||
parameters = { | ||
**self.serialize_query_param( | ||
"api-version", "2023-01-01-preview", | ||
required=True, | ||
), | ||
} | ||
return parameters | ||
|
||
@property | ||
def header_parameters(self): | ||
parameters = { | ||
**self.serialize_header_param( | ||
"Content-Type", "application/json", | ||
), | ||
**self.serialize_header_param( | ||
"Accept", "application/json", | ||
), | ||
} | ||
return parameters | ||
|
||
@property | ||
def content(self): | ||
_content_value, _builder = self.new_content_builder( | ||
self.ctx.args, | ||
typ=AAZObjectType, | ||
typ_kwargs={"flags": {"client_flatten": True}} | ||
) | ||
_builder.set_prop("name", AAZStrType, ".name") | ||
_builder.set_prop("type", AAZStrType, ".type") | ||
|
||
return self.serialize_content(_content_value) | ||
|
||
def on_200(self, session): | ||
data = self.deserialize_http_content(session) | ||
self.ctx.set_var( | ||
"instance", | ||
data, | ||
schema_builder=self._build_schema_on_200 | ||
) | ||
|
||
_schema_on_200 = None | ||
|
||
@classmethod | ||
def _build_schema_on_200(cls): | ||
if cls._schema_on_200 is not None: | ||
return cls._schema_on_200 | ||
|
||
cls._schema_on_200 = AAZObjectType() | ||
|
||
_schema_on_200 = cls._schema_on_200 | ||
_schema_on_200.message = AAZStrType() | ||
_schema_on_200.name_available = AAZBoolType( | ||
serialized_name="nameAvailable", | ||
) | ||
_schema_on_200.reason = AAZStrType() | ||
|
||
return cls._schema_on_200 | ||
|
||
|
||
class _CheckNameAvailabilityHelper: | ||
"""Helper class for CheckNameAvailability""" | ||
|
||
|
||
__all__ = ["CheckNameAvailability"] |
Oops, something went wrong.