Skip to content
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
2 changes: 0 additions & 2 deletions doc/extensions/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ What is an Extension?
- Currently, we support one extension type, a [Python Wheel](http://pythonwheels.com/).
- All extension documentation here refers to this type of extension.

> Extensions should be built with wheel `0.29.0` or `0.30.0` until [#6441](https://github.com/Azure/azure-cli/issues/6441) is resolved


What an Extension is not
------------------------
Expand Down
25 changes: 21 additions & 4 deletions src/azure-cli/azure/cli/command_modules/resource/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -1025,11 +1025,14 @@ def update_resource_group(instance, tags=None):


def export_group_as_template(
cmd, resource_group_name, include_comments=False, include_parameter_default_value=False):
cmd, resource_group_name, include_comments=False, include_parameter_default_value=False, resource_ids=None, skip_resource_name_params=False, skip_all_params=False):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we register all new arguments in _params.py? Especially for --resource-ids, which should be an array, right?

@jorgecotillo Jorge Cotillo (jorgecotillo) May 27, 2020

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, had to add nargs to the param.

"""Captures a resource group as a template.
:param str resource_group_name:the name of the resoruce group.
:param bool include_comments:export template with comments.
:param str resource_group_name: the name of the resource group.
:param str resource_ids: a string containing space-separated resource ids to filter the export by. To export all resources, do not specify this argument or supply "*".
:param bool include_comments: export template with comments.
:param bool include_parameter_default_value: export template parameter with default value.
:param bool skip_resource_name_params: export template and skip resource name parameterization.
:param bool skip_all_params: export template parameter and skip all parameterization.
Comment on lines +1041 to +1042

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For these parameters, I will recommend you to add them as storage_true and give short name for them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.

"""
rcf = _resource_client_factory(cmd.cli_ctx)

Expand All @@ -1038,10 +1041,24 @@ def export_group_as_template(
export_options.append('IncludeComments')
if include_parameter_default_value:
export_options.append('IncludeParameterDefaultValue')
if skip_resource_name_params:
export_options.append('SkipResourceNameParameterization')
if skip_all_params:
export_options.append('SkipAllParameterization')

resources = []
if resource_ids is None or resource_ids == "*":

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

resource_ids [](start = 31, length = 12)

just to confirm here if it should be resource_ids[0] == "*"?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated the code.

resources = ["*"]
else:
for i in resource_ids.split():
if is_valid_resource_id(i):
resources.append(i)
else:
raise CLIError('az resource: error: argument --resource-ids: invalid ResourceId value: \'%s\'' % i)

options = ','.join(export_options) if export_options else None

result = rcf.resource_groups.export_template(resource_group_name, ['*'], options=options)
result = rcf.resource_groups.export_template(resource_group_name, resources, options=options)

# pylint: disable=no-member
# On error, server still returns 200, with details in the error attribute
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,339 @@
interactions:
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- network vnet create
Connection:
- keep-alive
ParameterSetName:
- -g -n
User-Agent:
- python/3.7.7 (Windows-10-10.0.18362-SP0) msrest/0.6.9 msrest_azure/0.6.3 azure-mgmt-resource/9.0.0
Azure-SDK-For-Python AZURECLI/2.5.1
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_test_rg_scenario000001?api-version=2019-07-01
response:
body:
string: '{"id":"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_rg_scenario000001","name":"cli_test_rg_scenario000001","type":"Microsoft.Resources/resourceGroups","location":"westus","tags":{"product":"azurecli","cause":"automation","date":"2020-05-22T18:17:08Z","StorageType":"testStrogae"},"properties":{"provisioningState":"Succeeded"}}'
headers:
cache-control:
- no-cache
content-length:
- '456'
content-type:
- application/json; charset=utf-8
date:
- Fri, 22 May 2020 18:17:12 GMT
expires:
- '-1'
pragma:
- no-cache
strict-transport-security:
- max-age=31536000; includeSubDomains
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
status:
code: 200
message: OK
- request:
body: '{"location": "westus", "tags": {}, "properties": {"addressSpace": {"addressPrefixes":
["10.0.0.0/16"]}, "dhcpOptions": {}}}'
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- network vnet create
Connection:
- keep-alive
Content-Length:
- '123'
Content-Type:
- application/json; charset=utf-8
ParameterSetName:
- -g -n
User-Agent:
- python/3.7.7 (Windows-10-10.0.18362-SP0) msrest/0.6.9 msrest_azure/0.6.3 azure-mgmt-network/10.1.0
Azure-SDK-For-Python AZURECLI/2.5.1
accept-language:
- en-US
method: PUT
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_rg_scenario000001/providers/Microsoft.Network/virtualNetworks/vnet1?api-version=2020-04-01
response:
body:
string: "{\r\n \"name\": \"vnet1\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_rg_scenario000001/providers/Microsoft.Network/virtualNetworks/vnet1\",\r\n
\ \"etag\": \"W/\\\"3f095d9a-b7cf-486d-b644-7099c50dcc97\\\"\",\r\n \"type\":
\"Microsoft.Network/virtualNetworks\",\r\n \"location\": \"westus\",\r\n
\ \"tags\": {\r\n \"costCenter\": \"Contoso/IT/PROD/123456\"\r\n },\r\n
\ \"properties\": {\r\n \"provisioningState\": \"Updating\",\r\n \"resourceGuid\":
\"0d5b7728-2038-42d5-b9dd-c21e75ce962c\",\r\n \"addressSpace\": {\r\n \"addressPrefixes\":
[\r\n \"10.0.0.0/16\"\r\n ]\r\n },\r\n \"dhcpOptions\":
{\r\n \"dnsServers\": []\r\n },\r\n \"subnets\": [],\r\n \"virtualNetworkPeerings\":
[],\r\n \"enableDdosProtection\": false,\r\n \"enableVmProtection\":
false\r\n }\r\n}"
headers:
azure-asyncnotification:
- Enabled
azure-asyncoperation:
- https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Network/locations/westus/operations/14df1e47-c541-4d5e-af7d-2f785e0e6c8d?api-version=2020-04-01
cache-control:
- no-cache
content-length:
- '814'
content-type:
- application/json; charset=utf-8
date:
- Fri, 22 May 2020 18:17:13 GMT
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-HTTPAPI/2.0
- Microsoft-HTTPAPI/2.0
strict-transport-security:
- max-age=31536000; includeSubDomains
x-content-type-options:
- nosniff
x-ms-arm-service-request-id:
- 04d1546b-34c7-4ce8-80a7-c24e72f0cb2d
x-ms-ratelimit-remaining-subscription-writes:
- '1199'
status:
code: 201
message: Created
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- network vnet create
Connection:
- keep-alive
ParameterSetName:
- -g -n
User-Agent:
- python/3.7.7 (Windows-10-10.0.18362-SP0) msrest/0.6.9 msrest_azure/0.6.3 azure-mgmt-network/10.1.0
Azure-SDK-For-Python AZURECLI/2.5.1
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/providers/Microsoft.Network/locations/westus/operations/14df1e47-c541-4d5e-af7d-2f785e0e6c8d?api-version=2020-04-01
response:
body:
string: "{\r\n \"status\": \"Succeeded\"\r\n}"
headers:
cache-control:
- no-cache
content-length:
- '29'
content-type:
- application/json; charset=utf-8
date:
- Fri, 22 May 2020 18:17:16 GMT
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-HTTPAPI/2.0
- Microsoft-HTTPAPI/2.0
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
x-ms-arm-service-request-id:
- aeb586d8-c43b-47f6-ab07-b47b279ff40c
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- network vnet create
Connection:
- keep-alive
ParameterSetName:
- -g -n
User-Agent:
- python/3.7.7 (Windows-10-10.0.18362-SP0) msrest/0.6.9 msrest_azure/0.6.3 azure-mgmt-network/10.1.0
Azure-SDK-For-Python AZURECLI/2.5.1
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_rg_scenario000001/providers/Microsoft.Network/virtualNetworks/vnet1?api-version=2020-04-01
response:
body:
string: "{\r\n \"name\": \"vnet1\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_rg_scenario000001/providers/Microsoft.Network/virtualNetworks/vnet1\",\r\n
\ \"etag\": \"W/\\\"b91ba743-3872-4739-978b-7fc25edcc7ad\\\"\",\r\n \"type\":
\"Microsoft.Network/virtualNetworks\",\r\n \"location\": \"westus\",\r\n
\ \"tags\": {\r\n \"costCenter\": \"Contoso/IT/PROD/123456\"\r\n },\r\n
\ \"properties\": {\r\n \"provisioningState\": \"Succeeded\",\r\n \"resourceGuid\":
\"0d5b7728-2038-42d5-b9dd-c21e75ce962c\",\r\n \"addressSpace\": {\r\n \"addressPrefixes\":
[\r\n \"10.0.0.0/16\"\r\n ]\r\n },\r\n \"dhcpOptions\":
{\r\n \"dnsServers\": []\r\n },\r\n \"subnets\": [],\r\n \"virtualNetworkPeerings\":
[],\r\n \"enableDdosProtection\": false,\r\n \"enableVmProtection\":
false\r\n }\r\n}"
headers:
cache-control:
- no-cache
content-length:
- '815'
content-type:
- application/json; charset=utf-8
date:
- Fri, 22 May 2020 18:17:17 GMT
etag:
- W/"b91ba743-3872-4739-978b-7fc25edcc7ad"
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-HTTPAPI/2.0
- Microsoft-HTTPAPI/2.0
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
x-ms-arm-service-request-id:
- 19d437a8-19cd-45af-b63e-acf3cdd07908
status:
code: 200
message: OK
- request:
body: null
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- network vnet show
Connection:
- keep-alive
ParameterSetName:
- -g -n
User-Agent:
- python/3.7.7 (Windows-10-10.0.18362-SP0) msrest/0.6.9 msrest_azure/0.6.3 azure-mgmt-network/10.1.0
Azure-SDK-For-Python AZURECLI/2.5.1
accept-language:
- en-US
method: GET
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_rg_scenario000001/providers/Microsoft.Network/virtualNetworks/vnet1?api-version=2020-04-01
response:
body:
string: "{\r\n \"name\": \"vnet1\",\r\n \"id\": \"/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_rg_scenario000001/providers/Microsoft.Network/virtualNetworks/vnet1\",\r\n
\ \"etag\": \"W/\\\"b91ba743-3872-4739-978b-7fc25edcc7ad\\\"\",\r\n \"type\":
\"Microsoft.Network/virtualNetworks\",\r\n \"location\": \"westus\",\r\n
\ \"tags\": {\r\n \"costCenter\": \"Contoso/IT/PROD/123456\"\r\n },\r\n
\ \"properties\": {\r\n \"provisioningState\": \"Succeeded\",\r\n \"resourceGuid\":
\"0d5b7728-2038-42d5-b9dd-c21e75ce962c\",\r\n \"addressSpace\": {\r\n \"addressPrefixes\":
[\r\n \"10.0.0.0/16\"\r\n ]\r\n },\r\n \"dhcpOptions\":
{\r\n \"dnsServers\": []\r\n },\r\n \"subnets\": [],\r\n \"virtualNetworkPeerings\":
[],\r\n \"enableDdosProtection\": false,\r\n \"enableVmProtection\":
false\r\n }\r\n}"
headers:
cache-control:
- no-cache
content-length:
- '815'
content-type:
- application/json; charset=utf-8
date:
- Fri, 22 May 2020 18:17:17 GMT
etag:
- W/"b91ba743-3872-4739-978b-7fc25edcc7ad"
expires:
- '-1'
pragma:
- no-cache
server:
- Microsoft-HTTPAPI/2.0
- Microsoft-HTTPAPI/2.0
strict-transport-security:
- max-age=31536000; includeSubDomains
transfer-encoding:
- chunked
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
x-ms-arm-service-request-id:
- 656853f2-0df3-4712-aedc-375b95f51af8
status:
code: 200
message: OK
- request:
body: 'b''{"resources": ["/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/cli_test_rg_scenario000001/providers/Microsoft.Network/virtualNetworks/vnet1"],
"options": "SkipAllParameterization"}'''
headers:
Accept:
- application/json
Accept-Encoding:
- gzip, deflate
CommandName:
- group export
Connection:
- keep-alive
Content-Length:
- '249'
Content-Type:
- application/json; charset=utf-8
ParameterSetName:
- --name --resource-ids --skip-all-params --query
User-Agent:
- python/3.7.7 (Windows-10-10.0.18362-SP0) msrest/0.6.9 msrest_azure/0.6.3 azure-mgmt-resource/9.0.0
Azure-SDK-For-Python AZURECLI/2.5.1
accept-language:
- en-US
method: POST
uri: https://management.azure.com/subscriptions/00000000-0000-0000-0000-000000000000/resourcegroups/cli_test_rg_scenario000001/exportTemplate?api-version=2019-07-01
response:
body:
string: '{"template":{"$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#","contentVersion":"1.0.0.0","parameters":{},"variables":{},"resources":[{"type":"Microsoft.Network/virtualNetworks","apiVersion":"2020-04-01","name":"vnet1","location":"westus","tags":{"costCenter":"Contoso/IT/PROD/123456"},"properties":{"addressSpace":{"addressPrefixes":["10.0.0.0/16"]},"dhcpOptions":{"dnsServers":[]},"subnets":[],"virtualNetworkPeerings":[],"enableDdosProtection":false,"enableVmProtection":false}}]}}'
headers:
cache-control:
- no-cache
content-length:
- '526'
content-type:
- application/json; charset=utf-8
date:
- Fri, 22 May 2020 18:17:18 GMT
expires:
- '-1'
pragma:
- no-cache
strict-transport-security:
- max-age=31536000; includeSubDomains
vary:
- Accept-Encoding
x-content-type-options:
- nosniff
status:
code: 200
message: OK
version: 1
Loading