Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def load_command_table(self, _):

with self.command_group('group', resource_group_sdk, resource_type=ResourceType.MGMT_RESOURCE_RESOURCES) as g:
g.command('delete', 'begin_delete', supports_no_wait=True, confirmation=True)
g.show_command('show', 'get')
g.custom_show_command('show', 'get_resource_group')
g.command('exists', 'check_existence')
g.custom_command('list', 'list_resource_groups', table_transformer=transform_resource_group_list)
g.custom_command('create', 'create_resource_group')
Expand Down
11 changes: 11 additions & 0 deletions src/azure-cli/azure/cli/command_modules/resource/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,17 @@ def update_resource_group(instance, tags=None):
return instance


def get_resource_group(cmd, resource_group_name):
from azure.core.exceptions import ResourceNotFoundError
try:
rcf = _resource_client_factory(cmd.cli_ctx)
return rcf.resource_groups.get(resource_group_name=resource_group_name)
except ResourceNotFoundError:
subscription_id = get_subscription_id(cmd.cli_ctx)
raise ResourceNotFoundError("Resource group '{}' could not be found in subscription '{}'."
.format(resource_group_name, subscription_id))


def export_group_as_template(
cmd, resource_group_name, include_comments=False, include_parameter_default_value=False, resource_ids=None, skip_resource_name_params=False, skip_all_params=False):
"""Captures a resource group as a template.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- group show
Connection:
- keep-alive
ParameterSetName:
- -n
User-Agent:
- AZURECLI/2.39.0 azsdk-python-azure-mgmt-resource/21.1.0b1 Python/3.8.0 (Windows-10-10.0.19041-SP0)
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/not_exist_group_000001?api-version=2021-04-01
response:
body:
string: '{"error":{"code":"ResourceGroupNotFound","message":"Resource group
''not_exist_group_000001'' could not be found."}}'
headers:
cache-control:
- no-cache
content-length:
- '114'
content-type:
- application/json; charset=utf-8
date:
- Thu, 11 Aug 2022 09:48:53 GMT
expires:
- '-1'
pragma:
- no-cache
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-ms-failure-cause:
- gateway
status:
code: 404
message: Not Found
version: 1
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,18 @@ def test_resource_group_force_deletion_type(self, resource_group):

self.cmd('group delete -n testrg -f Microsoft.Compute/virtualMachines --yes')
self.cmd('group exists -n testrg',
checks=self.check('@', False))
checks=self.check('@', False))

def test_show_not_existing_resource_group(self):
self.kwargs.update({
'group': self.create_random_name('not_exist_group_', 30)
})
subscriptionId = self.get_subscription_id()
from azure.core.exceptions import ResourceNotFoundError
message = "Resource group '{}' could not be found in subscription '{}'." \
.format(self.kwargs['group'], subscriptionId)
with self.assertRaisesRegex(ResourceNotFoundError, message):
self.cmd('group show -n {group}')


class ResourceGroupNoWaitScenarioTest(ScenarioTest):
Expand Down
Loading