Skip to content

Commit f0d5df5

Browse files
committed
Improve the error message of the conflict between tag and other filter conditions for az resource list command
1 parent 6ce5bba commit f0d5df5

File tree

7 files changed

+111
-183
lines changed

7 files changed

+111
-183
lines changed

src/azure-cli/HISTORY.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Release History
1919

2020
* Fix issue #11658: `az group export` command does not support `--query` and `--output` parameters
2121
* Fix issue #10279: The exit code of `az group deployment validate` is 0 when the verification fails
22+
* Add new parameter `--managed-by` to support adding managedBy information for command `az group create`.
2223

2324
**IoT Central**
2425

src/azure-cli/azure/cli/command_modules/resource/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ class ResourceCommandsLoader(AzCommandsLoader):
1313
def __init__(self, cli_ctx=None):
1414
from azure.cli.core.commands import CliCommandType
1515
from azure.cli.core import ModExtensionSuppress
16+
from azure.cli.core.profiles import ResourceType
1617
resource_custom = CliCommandType(operations_tmpl='azure.cli.command_modules.resource.custom#{}')
1718
super(ResourceCommandsLoader, self).__init__(cli_ctx=cli_ctx,
19+
resource_type=ResourceType.MGMT_RESOURCE_RESOURCES,
1820
custom_command_type=resource_custom,
1921
suppress_extension=ModExtensionSuppress(
2022
__name__, 'managementgroups', '0.1.0',

src/azure-cli/azure/cli/command_modules/resource/_params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ def load_arguments(self, _):
221221

222222
with self.argument_context('group create') as c:
223223
c.argument('rg_name', options_list=['--name', '--resource-group', '-n', '-g'], help='name of the new resource group', completer=None)
224+
c.argument('managed_by', min_api='2016-09-01', help='The ID of the resource that manages this resource group.')
224225

225226
with self.argument_context('tag') as c:
226227
c.argument('tag_name', options_list=['--name', '-n'])

src/azure-cli/azure/cli/command_modules/resource/custom.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,7 @@ def list_resource_groups(cmd, tag=None): # pylint: disable=no-self-use
716716
return list(groups)
717717

718718

719-
def create_resource_group(cmd, rg_name, location, tags=None):
719+
def create_resource_group(cmd, rg_name, location, tags=None, managed_by=None):
720720
""" Create a new resource group.
721721
:param str resource_group_name:the desired resource group name
722722
:param str location:the resource group location
@@ -729,6 +729,10 @@ def create_resource_group(cmd, rg_name, location, tags=None):
729729
location=location,
730730
tags=tags
731731
)
732+
733+
if cmd.supported_api_version(min_api='2016-09-01'):
734+
parameters.managed_by = managed_by
735+
732736
return rcf.resource_groups.create_or_update(rg_name, parameters)
733737

734738

src/azure-cli/azure/cli/command_modules/resource/tests/latest/recordings/test_resource_group.yaml

Lines changed: 59 additions & 97 deletions
Large diffs are not rendered by default.

src/azure-cli/azure/cli/command_modules/resource/tests/latest/recordings/test_resource_group_no_wait.yaml

Lines changed: 36 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ interactions:
1515
ParameterSetName:
1616
- -n --no-wait --yes
1717
User-Agent:
18-
- python/3.7.4 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
19-
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.75
18+
- python/3.8.0 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
19+
azure-mgmt-resource/6.0.0 Azure-SDK-For-Python AZURECLI/2.0.79
2020
accept-language:
2121
- en-US
2222
method: DELETE
@@ -30,19 +30,19 @@ interactions:
3030
content-length:
3131
- '0'
3232
date:
33-
- Mon, 21 Oct 2019 05:11:56 GMT
33+
- Wed, 08 Jan 2020 02:37:51 GMT
3434
expires:
3535
- '-1'
3636
location:
37-
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/operationresults/eyJqb2JJZCI6IlJFU09VUkNFR1JPVVBERUxFVElPTkpPQi1DTEk6NUZSRzo1Rk5PV0FJVDo1RlRFU1Q1UlRDS1hMRFNZVVNIQ0hCUDZMTExDSnw1NkE3Qzk0NkM4QzFGRkFGLVdFU1RVUyIsImpvYkxvY2F0aW9uIjoid2VzdHVzIn0?api-version=2019-07-01
37+
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/operationresults/eyJqb2JJZCI6IlJFU09VUkNFR1JPVVBERUxFVElPTkpPQi1DTEk6NUZSRzo1Rk5PV0FJVDo1RlRFU1RLT1pNRE81REdVNVhXM1hFMlhES0hZQXxENEFGOTlENTNERjhDNjAyLVdFU1RVUyIsImpvYkxvY2F0aW9uIjoid2VzdHVzIn0?api-version=2019-07-01
3838
pragma:
3939
- no-cache
4040
strict-transport-security:
4141
- max-age=31536000; includeSubDomains
4242
x-content-type-options:
4343
- nosniff
4444
x-ms-ratelimit-remaining-subscription-deletes:
45-
- '14999'
45+
- '14998'
4646
status:
4747
code: 202
4848
message: Accepted
@@ -60,15 +60,15 @@ interactions:
6060
ParameterSetName:
6161
- --deleted -n
6262
User-Agent:
63-
- python/3.7.4 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
64-
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.75
63+
- python/3.8.0 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
64+
azure-mgmt-resource/6.0.0 Azure-SDK-For-Python AZURECLI/2.0.79
6565
accept-language:
6666
- en-US
6767
method: GET
6868
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_rg_nowait_test000001?api-version=2019-07-01
6969
response:
7070
body:
71-
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_rg_nowait_test000001","name":"cli_rg_nowait_test000001","type":"Microsoft.Resources/resourceGroups","location":"westus","tags":{"product":"azurecli","cause":"automation","date":"2019-10-21T05:11:40Z"},"properties":{"provisioningState":"Deleting"}}'
71+
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_rg_nowait_test000001","name":"cli_rg_nowait_test000001","type":"Microsoft.Resources/resourceGroups","location":"westus","tags":{"product":"azurecli","cause":"automation","date":"2020-01-08T02:37:41Z"},"properties":{"provisioningState":"Deleting"}}'
7272
headers:
7373
cache-control:
7474
- no-cache
@@ -77,7 +77,7 @@ interactions:
7777
content-type:
7878
- application/json; charset=utf-8
7979
date:
80-
- Mon, 21 Oct 2019 05:11:56 GMT
80+
- Wed, 08 Jan 2020 02:37:52 GMT
8181
expires:
8282
- '-1'
8383
pragma:
@@ -105,15 +105,15 @@ interactions:
105105
ParameterSetName:
106106
- --deleted -n
107107
User-Agent:
108-
- python/3.7.4 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
109-
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.75
108+
- python/3.8.0 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
109+
azure-mgmt-resource/6.0.0 Azure-SDK-For-Python AZURECLI/2.0.79
110110
accept-language:
111111
- en-US
112112
method: GET
113113
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_rg_nowait_test000001?api-version=2019-07-01
114114
response:
115115
body:
116-
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_rg_nowait_test000001","name":"cli_rg_nowait_test000001","type":"Microsoft.Resources/resourceGroups","location":"westus","tags":{"product":"azurecli","cause":"automation","date":"2019-10-21T05:11:40Z"},"properties":{"provisioningState":"Deleting"}}'
116+
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_rg_nowait_test000001","name":"cli_rg_nowait_test000001","type":"Microsoft.Resources/resourceGroups","location":"westus","tags":{"product":"azurecli","cause":"automation","date":"2020-01-08T02:37:41Z"},"properties":{"provisioningState":"Deleting"}}'
117117
headers:
118118
cache-control:
119119
- no-cache
@@ -122,7 +122,7 @@ interactions:
122122
content-type:
123123
- application/json; charset=utf-8
124124
date:
125-
- Mon, 21 Oct 2019 05:12:26 GMT
125+
- Wed, 08 Jan 2020 02:38:22 GMT
126126
expires:
127127
- '-1'
128128
pragma:
@@ -150,53 +150,8 @@ interactions:
150150
ParameterSetName:
151151
- --deleted -n
152152
User-Agent:
153-
- python/3.7.4 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
154-
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.75
155-
accept-language:
156-
- en-US
157-
method: GET
158-
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_rg_nowait_test000001?api-version=2019-07-01
159-
response:
160-
body:
161-
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_rg_nowait_test000001","name":"cli_rg_nowait_test000001","type":"Microsoft.Resources/resourceGroups","location":"westus","tags":{"product":"azurecli","cause":"automation","date":"2019-10-21T05:11:40Z"},"properties":{"provisioningState":"Deleting"}}'
162-
headers:
163-
cache-control:
164-
- no-cache
165-
content-length:
166-
- '427'
167-
content-type:
168-
- application/json; charset=utf-8
169-
date:
170-
- Mon, 21 Oct 2019 05:12:56 GMT
171-
expires:
172-
- '-1'
173-
pragma:
174-
- no-cache
175-
strict-transport-security:
176-
- max-age=31536000; includeSubDomains
177-
vary:
178-
- Accept-Encoding
179-
x-content-type-options:
180-
- nosniff
181-
status:
182-
code: 200
183-
message: OK
184-
- request:
185-
body: null
186-
headers:
187-
Accept:
188-
- application/json
189-
Accept-Encoding:
190-
- gzip, deflate
191-
CommandName:
192-
- group wait
193-
Connection:
194-
- keep-alive
195-
ParameterSetName:
196-
- --deleted -n
197-
User-Agent:
198-
- python/3.7.4 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
199-
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.75
153+
- python/3.8.0 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
154+
azure-mgmt-resource/6.0.0 Azure-SDK-For-Python AZURECLI/2.0.79
200155
accept-language:
201156
- en-US
202157
method: GET
@@ -213,7 +168,7 @@ interactions:
213168
content-type:
214169
- application/json; charset=utf-8
215170
date:
216-
- Mon, 21 Oct 2019 05:13:27 GMT
171+
- Wed, 08 Jan 2020 02:38:52 GMT
217172
expires:
218173
- '-1'
219174
pragma:
@@ -241,8 +196,8 @@ interactions:
241196
ParameterSetName:
242197
- -n
243198
User-Agent:
244-
- python/3.7.4 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
245-
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.75
199+
- python/3.8.0 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
200+
azure-mgmt-resource/6.0.0 Azure-SDK-For-Python AZURECLI/2.0.79
246201
accept-language:
247202
- en-US
248203
method: HEAD
@@ -258,7 +213,7 @@ interactions:
258213
content-type:
259214
- application/json; charset=utf-8
260215
date:
261-
- Mon, 21 Oct 2019 05:13:27 GMT
216+
- Wed, 08 Jan 2020 02:38:53 GMT
262217
expires:
263218
- '-1'
264219
pragma:
@@ -273,7 +228,7 @@ interactions:
273228
code: 404
274229
message: Not Found
275230
- request:
276-
body: '{"location": "westus"}'
231+
body: '{"location": "westus", "managedBy": "test_admin"}'
277232
headers:
278233
Accept:
279234
- application/json
@@ -284,30 +239,30 @@ interactions:
284239
Connection:
285240
- keep-alive
286241
Content-Length:
287-
- '22'
242+
- '49'
288243
Content-Type:
289244
- application/json; charset=utf-8
290245
ParameterSetName:
291-
- -n -l
246+
- -n -l --managed-by
292247
User-Agent:
293-
- python/3.7.4 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
294-
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.75
248+
- python/3.8.0 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
249+
azure-mgmt-resource/6.0.0 Azure-SDK-For-Python AZURECLI/2.0.79
295250
accept-language:
296251
- en-US
297252
method: PUT
298253
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_rg_nowait_test000001?api-version=2019-07-01
299254
response:
300255
body:
301-
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_rg_nowait_test000001","name":"cli_rg_nowait_test000001","type":"Microsoft.Resources/resourceGroups","location":"westus","properties":{"provisioningState":"Succeeded"}}'
256+
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_rg_nowait_test000001","name":"cli_rg_nowait_test000001","type":"Microsoft.Resources/resourceGroups","location":"westus","managedBy":"test_admin","properties":{"provisioningState":"Succeeded"}}'
302257
headers:
303258
cache-control:
304259
- no-cache
305260
content-length:
306-
- '347'
261+
- '372'
307262
content-type:
308263
- application/json; charset=utf-8
309264
date:
310-
- Mon, 21 Oct 2019 05:13:30 GMT
265+
- Wed, 08 Jan 2020 02:38:59 GMT
311266
expires:
312267
- '-1'
313268
pragma:
@@ -317,7 +272,7 @@ interactions:
317272
x-content-type-options:
318273
- nosniff
319274
x-ms-ratelimit-remaining-subscription-writes:
320-
- '1191'
275+
- '1198'
321276
status:
322277
code: 201
323278
message: Created
@@ -335,8 +290,8 @@ interactions:
335290
ParameterSetName:
336291
- -n
337292
User-Agent:
338-
- python/3.7.4 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
339-
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.75
293+
- python/3.8.0 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
294+
azure-mgmt-resource/6.0.0 Azure-SDK-For-Python AZURECLI/2.0.79
340295
accept-language:
341296
- en-US
342297
method: HEAD
@@ -350,7 +305,7 @@ interactions:
350305
content-length:
351306
- '0'
352307
date:
353-
- Mon, 21 Oct 2019 05:13:30 GMT
308+
- Wed, 08 Jan 2020 02:39:00 GMT
354309
expires:
355310
- '-1'
356311
pragma:
@@ -376,24 +331,24 @@ interactions:
376331
ParameterSetName:
377332
- --exists -n
378333
User-Agent:
379-
- python/3.7.4 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
380-
azure-mgmt-resource/4.0.0 Azure-SDK-For-Python AZURECLI/2.0.75
334+
- python/3.8.0 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2
335+
azure-mgmt-resource/6.0.0 Azure-SDK-For-Python AZURECLI/2.0.79
381336
accept-language:
382337
- en-US
383338
method: GET
384339
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_rg_nowait_test000001?api-version=2019-07-01
385340
response:
386341
body:
387-
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_rg_nowait_test000001","name":"cli_rg_nowait_test000001","type":"Microsoft.Resources/resourceGroups","location":"westus","properties":{"provisioningState":"Succeeded"}}'
342+
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_rg_nowait_test000001","name":"cli_rg_nowait_test000001","type":"Microsoft.Resources/resourceGroups","location":"westus","managedBy":"test_admin","properties":{"provisioningState":"Succeeded"}}'
388343
headers:
389344
cache-control:
390345
- no-cache
391346
content-length:
392-
- '347'
347+
- '372'
393348
content-type:
394349
- application/json; charset=utf-8
395350
date:
396-
- Mon, 21 Oct 2019 05:13:31 GMT
351+
- Wed, 08 Jan 2020 02:39:00 GMT
397352
expires:
398353
- '-1'
399354
pragma:

src/azure-cli/azure/cli/command_modules/resource/tests/latest/test_resource.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,10 @@ def test_resource_group(self, resource_group):
2525
self.cmd('group exists -n {rg}',
2626
checks=self.check('@', False))
2727

28-
self.cmd('group create -n {rg} -l westus --tag a=b c', checks=[
28+
self.cmd('group create -n {rg} -l westus --tag a=b c --managed-by test_admin', checks=[
2929
self.check('name', '{rg}'),
30-
self.check('tags', {'a': 'b', 'c': ''})
30+
self.check('tags', {'a': 'b', 'c': ''}),
31+
self.check('managedBy', 'test_admin')
3132
])
3233
self.cmd('group exists -n {rg}',
3334
checks=self.check('@', True))
@@ -64,8 +65,10 @@ def test_resource_group_no_wait(self, resource_group):
6465
checks=self.is_empty())
6566
self.cmd('group exists -n {rg}',
6667
checks=self.check('@', False))
67-
self.cmd('group create -n {rg} -l westus',
68-
checks=self.check('name', '{rg}'))
68+
self.cmd('group create -n {rg} -l westus --managed-by test_admin', checks=[
69+
self.check('name', '{rg}'),
70+
self.check('managedBy', 'test_admin')
71+
])
6972
self.cmd('group exists -n {rg}',
7073
checks=self.check('@', True))
7174
self.cmd('group wait --exists -n {rg}',

0 commit comments

Comments
 (0)