Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Self-Help] Feature self-help 2023-09-01-preview #6872

Merged
6 changes: 5 additions & 1 deletion src/self-help/HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,8 @@ Release History

0.1.0
++++++
* Initial release.
* Initial release.

0.2.0
++++++
* Added new commands troubleshooter and solution from public preview version v2023-09-01-preview. Updated contracts for responses.
90 changes: 84 additions & 6 deletions src/self-help/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ az extension add --name self-help

```
# Gets list of solution metadata for an azure resource.
az self-help discovery-solution list --scope {scope}
az self-help discovery-solution list --filter "ProblemClassificationId eq '00000000-0000-0000-0000-000000000000'" --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
kairu-ms marked this conversation as resolved.
Show resolved Hide resolved
```

### _"Diagnostic"_ commands
Expand All @@ -31,16 +31,92 @@ az extension add --name self-help

```
# Creates a diagnostic for a resource
az self-help diagnostic create --diagnostic-name {diagnostic-name} --insights [{solutionId:Demo2InsightV2}] --scope {scope}
az self-help diagnostic create --diagnostic-name diagnostic-name --insights [{solutionId:Demo2InsightV2}] --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
```

- #### Show Diagnostic for a resource

_Examples:_

```
# Show diagnostic for a resource.
az self-help diagnostic show --diagnostic-name {diagnostic-name} --scope {scope}
# Shows diagnostic for a resource.
az self-help diagnostic show --diagnostic-name diagnostic-name --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
```

### _"Solution"_ commands

- #### Create Solution for a resource

_Examples:_

```
# Creates a solution for a resource
az self-help solution create --solution-name solution-name --trigger-criteria [{name:solutionid,value:Demo2InsightV2}] --parameters {} --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
```

- #### Show Solution for a resource

_Examples:_

```
# Shows solution for a resource.
az elf-help solution show --solution-name solution-name --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
```

- #### Update Solution for a resource

_Examples:_

```
# Updates solution for a resource.
az self-help solution update --solution-name solution-name --trigger-criteria [{name:ReplacementKey,value:<!--56ee7509-92e1-4b9e-97c2-dda53065294c-->}] --parameters {SearchText:CanNotRDP,SymptomId:KeyVaultVaultNotFoundInsight} --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
```

### _"Troubleshooter"_ commands

- #### Create Troubleshooter for a resource

_Examples:_

```
# Creates a troubleshooter for a resource
az self-help troubleshooter create --troubleshooter-name 12345678-BBBb-cCCCC-0000-123456789012 --solution-id e104dbdf-9e14-4c9f-bc78-21ac90382231 --parameters {ResourceUri:'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'} --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
```

- #### Show troubleshooter for a resource

_Examples:_

```
# Show troubleshooter for a resource.
az self-help troubleshooter show --troubleshooter-name 12345678-BBBb-cCCCC-0000-123456789012 --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
```

- #### Restart troubleshooter for a resource

_Examples:_

```
# Restarts troubleshooter for a resource.
az self-help troubleshooter restart --troubleshooter-name 12345678-BBBb-cCCCC-0000-123456789012 --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
```

- #### End troubleshooter for a resource

_Examples:_

```
# Ends troubleshooter for a resource.
az self-help troubleshooter end --troubleshooter-name 12345678-BBBb-cCCCC-0000-123456789012 --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
```

- #### Continue troubleshooter for a resource

_Examples:_

```
# Continues troubleshooter for a resource.
az self-help troubleshooter continue --troubleshooter-name 12345678-BBBb-cCCCC-0000-123456789012 --step-id step-id --responses [] --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
```

### _"Check-Name-Availability"_ commands
Expand All @@ -50,6 +126,8 @@ az extension add --name self-help
_Examples:_

```
# Checks name available of a diagnostic resource.
az self-help check-name-availability --scope subscriptionId/{subId} --name {diagnostic-name} --type 'Microsoft.Help/diagnostics'
# Check Resource Uniqueness
az self-help check-name-availability --scope subscriptions/12345678-BBBb-cCCCC-0000-123456789012 --name diagnostic-name --type 'Microsoft.Help/diagnostics'
az self-help check-name-availability --scope subscriptions/12345678-BBBb-cCCCC-0000-123456789012 --name solution-name --type 'Microsoft.Help/solutions'
az self-help check-name-availability --scope subscriptions/12345678-BBBb-cCCCC-0000-123456789012 --name abf168ed-1b54-454a-86f6-e4b62253d3b1 --type 'Microsoft.Help/troubleshooters'
```
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@
is_preview=True,
)
class CheckNameAvailability(AAZCommand):
"""This API is used to check the uniqueness of a resource name used for a diagnostic check.
"""This API is used to check the uniqueness of a resource name used for a diagnostic, troubleshooter or solutions

:example: Check Diagnostic Resource Uniqueness
az self-help check-name-availability --scope subscriptionId/{subId} --name {diagnostic-name} --type 'Microsoft.Help/diagnostics'
:example: Check Resource Uniqueness
az self-help check-name-availability --scope subscriptions/12345678-BBBb-cCCCC-0000-123456789012 --name diagnostic-name --type 'Microsoft.Help/diagnostics'
az self-help check-name-availability --scope subscriptions/12345678-BBBb-cCCCC-0000-123456789012 --name solution-name --type 'Microsoft.Help/solutions'
az self-help check-name-availability --scope subscriptions/12345678-BBBb-cCCCC-0000-123456789012 --name abf168ed-1b54-454a-86f6-e4b62253d3b1 --type 'Microsoft.Help/troubleshooters'
"""

_aaz_info = {
"version": "2023-01-01-preview",
"version": "2023-09-01-preview",
"resources": [
["mgmt-plane", "/{scope}/providers/microsoft.help/checknameavailability", "2023-01-01-preview"],
["mgmt-plane", "/{scope}/providers/microsoft.help/checknameavailability", "2023-09-01-preview"],
]
}

Expand Down Expand Up @@ -68,7 +70,7 @@ def _build_arguments_schema(cls, *args, **kwargs):

def _execute_operations(self):
self.pre_operations()
self.DiagnosticsCheckNameAvailability(ctx=self.ctx)()
self.CheckNameAvailabilityPost(ctx=self.ctx)()
self.post_operations()

@register_callback
Expand All @@ -83,7 +85,7 @@ def _output(self, *args, **kwargs):
result = self.deserialize_output(self.ctx.vars.instance, client_flatten=True)
return result

class DiagnosticsCheckNameAvailability(AAZHttpOperation):
class CheckNameAvailabilityPost(AAZHttpOperation):
CLIENT_TYPE = "MgmtClient"

def __call__(self, *args, **kwargs):
Expand Down Expand Up @@ -124,7 +126,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2023-01-01-preview",
"api-version", "2023-09-01-preview",
required=True,
),
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class Create(AAZCommand):
"""Creates a diagnostics that will help you troubleshoot an issue with your azure resource.

:example: Create Diagnostic at Resource Level
az self-help diagnostic create --diagnostic-name {diagnostic-name} --insights [{solutionId:Demo2InsightV2}] --scope {scope}
az self-help diagnostic create --diagnostic-name diagnostic-name --insights [{solutionId:Demo2InsightV2}] --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
"""

_aaz_info = {
"version": "2023-01-01-preview",
"version": "2023-09-01-preview",
"resources": [
["mgmt-plane", "/{scope}/providers/microsoft.help/diagnostics/{}", "2023-01-01-preview"],
["mgmt-plane", "/{scope}/providers/microsoft.help/diagnostics/{}", "2023-09-01-preview"],
]
}

Expand All @@ -48,7 +48,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
_args_schema = cls._args_schema
_args_schema.diagnostic_name = AAZStrArg(
options=["--diagnostic-name"],
help="unique resource name for diagnostic proxy resources.",
help="Unique resource name for insight resources",
required=True,
fmt=AAZStrArgFormat(
pattern="^[A-Za-z0-9-+@()_]+$",
Expand Down Expand Up @@ -123,16 +123,16 @@ def __call__(self, *args, **kwargs):
return self.client.build_lro_polling(
self.ctx.args.no_wait,
session,
self.on_201,
self.on_200_201,
self.on_error,
lro_options={"final-state-via": "azure-async-operation"},
path_format_arguments=self.url_parameters,
)
if session.http_response.status_code in [201]:
if session.http_response.status_code in [200, 201]:
return self.client.build_lro_polling(
self.ctx.args.no_wait,
session,
self.on_201,
self.on_200_201,
self.on_error,
lro_options={"final-state-via": "azure-async-operation"},
path_format_arguments=self.url_parameters,
Expand Down Expand Up @@ -174,7 +174,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2023-01-01-preview",
"api-version", "2023-09-01-preview",
required=True,
),
}
Expand Down Expand Up @@ -225,42 +225,42 @@ def content(self):

return self.serialize_content(_content_value)

def on_201(self, session):
def on_200_201(self, session):
data = self.deserialize_http_content(session)
self.ctx.set_var(
"instance",
data,
schema_builder=self._build_schema_on_201
schema_builder=self._build_schema_on_200_201
)

_schema_on_201 = None
_schema_on_200_201 = None

@classmethod
def _build_schema_on_201(cls):
if cls._schema_on_201 is not None:
return cls._schema_on_201
def _build_schema_on_200_201(cls):
if cls._schema_on_200_201 is not None:
return cls._schema_on_200_201

cls._schema_on_201 = AAZObjectType()
cls._schema_on_200_201 = AAZObjectType()

_schema_on_201 = cls._schema_on_201
_schema_on_201.id = AAZStrType(
_schema_on_200_201 = cls._schema_on_200_201
_schema_on_200_201.id = AAZStrType(
flags={"read_only": True},
)
_schema_on_201.name = AAZStrType(
_schema_on_200_201.name = AAZStrType(
flags={"read_only": True},
)
_schema_on_201.properties = AAZObjectType(
_schema_on_200_201.properties = AAZObjectType(
flags={"client_flatten": True},
)
_schema_on_201.system_data = AAZObjectType(
_schema_on_200_201.system_data = AAZObjectType(
serialized_name="systemData",
flags={"read_only": True},
)
_schema_on_201.type = AAZStrType(
_schema_on_200_201.type = AAZStrType(
flags={"read_only": True},
)

properties = cls._schema_on_201.properties
properties = cls._schema_on_200_201.properties
properties.accepted_at = AAZStrType(
serialized_name="acceptedAt",
flags={"read_only": True},
Expand All @@ -277,10 +277,10 @@ def _build_schema_on_201(cls):
flags={"read_only": True},
)

diagnostics = cls._schema_on_201.properties.diagnostics
diagnostics = cls._schema_on_200_201.properties.diagnostics
diagnostics.Element = AAZObjectType()

_element = cls._schema_on_201.properties.diagnostics.Element
_element = cls._schema_on_200_201.properties.diagnostics.Element
_element.error = AAZObjectType()
_CreateHelper._build_schema_error_read(_element.error)
_element.insights = AAZListType()
Expand All @@ -289,35 +289,35 @@ def _build_schema_on_201(cls):
)
_element.status = AAZStrType()

insights = cls._schema_on_201.properties.diagnostics.Element.insights
insights = cls._schema_on_200_201.properties.diagnostics.Element.insights
insights.Element = AAZObjectType()

_element = cls._schema_on_201.properties.diagnostics.Element.insights.Element
_element = cls._schema_on_200_201.properties.diagnostics.Element.insights.Element
_element.id = AAZStrType()
_element.importance_level = AAZStrType(
serialized_name="importanceLevel",
)
_element.results = AAZStrType()
_element.title = AAZStrType()

global_parameters = cls._schema_on_201.properties.global_parameters
global_parameters = cls._schema_on_200_201.properties.global_parameters
global_parameters.Element = AAZStrType()

insights = cls._schema_on_201.properties.insights
insights = cls._schema_on_200_201.properties.insights
insights.Element = AAZObjectType()

_element = cls._schema_on_201.properties.insights.Element
_element = cls._schema_on_200_201.properties.insights.Element
_element.additional_parameters = AAZDictType(
serialized_name="additionalParameters",
)
_element.solution_id = AAZStrType(
serialized_name="solutionId",
)

additional_parameters = cls._schema_on_201.properties.insights.Element.additional_parameters
additional_parameters = cls._schema_on_200_201.properties.insights.Element.additional_parameters
additional_parameters.Element = AAZStrType()

system_data = cls._schema_on_201.system_data
system_data = cls._schema_on_200_201.system_data
system_data.created_at = AAZStrType(
serialized_name="createdAt",
)
Expand All @@ -337,7 +337,7 @@ def _build_schema_on_201(cls):
serialized_name="lastModifiedByType",
)

return cls._schema_on_201
return cls._schema_on_200_201


class _CreateHelper:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class Show(AAZCommand):
"""Get the diagnostics using the 'diagnosticsResourceName' you chose while creating the diagnostic.

:example: Show Diagnostic at Resource Level
az self-help diagnostic show --diagnostic-name {diagnostic-name} --scope {scope}
az self-help diagnostic show --diagnostic-name diagnostic-name --scope 'subscriptions/0d0fcd2e-c4fd-4349-8497-200edb3923c6/resourceGroups/myresourceGroup/providers/Microsoft.KeyVault/vaults/test-keyvault-non-read'
"""

_aaz_info = {
"version": "2023-01-01-preview",
"version": "2023-09-01-preview",
"resources": [
["mgmt-plane", "/{scope}/providers/microsoft.help/diagnostics/{}", "2023-01-01-preview"],
["mgmt-plane", "/{scope}/providers/microsoft.help/diagnostics/{}", "2023-09-01-preview"],
]
}

Expand All @@ -47,7 +47,7 @@ def _build_arguments_schema(cls, *args, **kwargs):
_args_schema = cls._args_schema
_args_schema.diagnostic_name = AAZStrArg(
options=["--diagnostic-name"],
help="unique resource name for diagnostic proxy resources",
help="Unique resource name for insight resources",
required=True,
fmt=AAZStrArgFormat(
pattern="^[A-Za-z0-9-+@()_]+$",
Expand Down Expand Up @@ -124,7 +124,7 @@ def url_parameters(self):
def query_parameters(self):
parameters = {
**self.serialize_query_param(
"api-version", "2023-01-01-preview",
"api-version", "2023-09-01-preview",
required=True,
),
}
Expand Down
Loading