From 15da20b0f958f9cce28db1d2baafd5918e734188 Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Tue, 12 May 2020 17:40:04 +0800 Subject: [PATCH 01/13] Quickstart for Track 2 preview management libraries --- doc/sphinx/mgmt_preview_quickstart.rst | 151 +++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100644 doc/sphinx/mgmt_preview_quickstart.rst diff --git a/doc/sphinx/mgmt_preview_quickstart.rst b/doc/sphinx/mgmt_preview_quickstart.rst new file mode 100644 index 00000000000..f534b118819 --- /dev/null +++ b/doc/sphinx/mgmt_preview_quickstart.rst @@ -0,0 +1,151 @@ +Quickstart Tutorial - Resource Management (Preview Libraries) +=============================================================== + +We are excited to announce that a new set of management libraries are now in Public Preview. +Those packages share a number of new features such as Azure Identity support, +HTTP pipeline, error-handling.,etc, and they also follow the new Azure SDK guidelines which +create easy-to-use APIs that are idiomatic, compatible, and dependable. + +You can find the details of those new libraries `here `__ + +In this basic quickstart guide, we will walk you through how to +authenticate to Azure using the preview libraries and start interacting with +Azure resources. There are several possible approaches to +authentication. This document illustrates the most common scenario + +Prerequisites +------------- + +| You will need the following values to authenticate to Azure +- **Client ID** +- **Client Secret** +- **Tenant ID** +- **Subscription ID** + +These values can be obtained from the portal, here's the instructions: + +Get Subscription ID +^^^^^^^^^^^^^^^^^^^ + +1. Login into your azure account +2. Select Subscriptions in the left sidebar +3. Select whichever subscription is needed +4. Click on overview +5. Copy the Subscription ID + +Get Client ID +^^^^^^^^^^^^^ + +1. Login into your azure account +2. Select azure active directory in the left sidebar +3. Click "App Registrations" +4. Select the application which you have created +5. Copy "Application (client) ID" + +Get Client Secret +^^^^^^^^^^^^^^^^^ + +1. Login into your azure account +2. Select azure active directory in the left sidebar +3. Click "App Registrations" in the left sidebar +4. Click "Certificates & Secrets" +5. Click "+ New client secret" +6. Type description and click "Add" +7. Copy and store the key value. You won’t be able to retrieve it after + you leave this page. + +Get Tenant ID +^^^^^^^^^^^^^ + +1. Login into your azure account +2. Select azure active directory in the left sidebar +3. Click "App Registrations" in the left sidebar +4. Select the application which you have created +5. Copy "Directory (tenant) ID" + +Setting Environment Variables +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +After you obtained the values, you need to set the following values as +your environment variables + +- ``AZURE_CLIENT_ID`` +- ``AZURE_CLIENT_SECRET`` +- ``AZURE_TENANT_ID`` +- ``AZURE_SUBSCRIPTION_ID`` + +To set the following environment variables on your development system: + +:: + + export AZURE_CLIENT_ID="__CLIENT_ID__" + export AZURE_CLIENT_SECRET="__CLIENT_SECRET__" + export AZURE_TENANT_ID="__TENANT_ID__" + export AZURE_SUBSCRIPTION_ID="__SUBSCRIPTION_ID__" + +Authentication and Creating REST Client +--------------------------------------- + +Now that the environment is setup, all you need to do is to create an +authenticated client. Our default option is to use +**DefaultAzureCredentials** and in this guide we have picked +**Resource** as our target service. To authenticate to Azure and create +a REST client, simply do the following: + +:: + + import azure.mgmt.resource + import azure.mgmt.network + import azure.mgmt.compute + from azure.identity import DefaultAzureCredential; + ... + subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID") + credentials = DefaultAzureCredential() + resource_client = azure.mgmt.resource.ResourceManagementClient(credential=credentials, subscription_id=subscription_id) + +More information and different authentication approaches using Azure Identity can be found at +`here `__ + +Managing Resources +------------------ + +Now that we are authenticated, we can use our REST client to make API +calls. Let's create a resource group and demostrate REST client's usage + +**Create a resource group** + +:: + + location = "mylocation" + group_name = "my_resource_group_name" + group = resource_client.resource_groups.create_or_update( + group_name, + {'location': location} + ) + +**Update a resource group** + +:: + + group_name = "my_resource_group_name" + group.tags = { + "environment":"test", + "department":"tech" + } + updated_group = resource_client.resource_groups.create_or_update(group_name, group) + +**List all resource groups** + +:: + + # + group_list = self.resource_client.resource_groups.list() + for g in group_list: + print_resource_group(g) + +**Delete a resource group** + +:: + + delete_async_op = resource_client.resource_groups.begin_delete(group_name) + delete_async_op.wait() From 51650b8dc93e6ecdba8987381a8b03d4fb0606d9 Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Thu, 14 May 2020 16:59:11 +0800 Subject: [PATCH 02/13] Update quickstart document based on comments --- doc/sphinx/mgmt_preview_quickstart.rst | 71 +++++++++++--------------- 1 file changed, 29 insertions(+), 42 deletions(-) diff --git a/doc/sphinx/mgmt_preview_quickstart.rst b/doc/sphinx/mgmt_preview_quickstart.rst index f534b118819..c5b47557094 100644 --- a/doc/sphinx/mgmt_preview_quickstart.rst +++ b/doc/sphinx/mgmt_preview_quickstart.rst @@ -16,52 +16,28 @@ authentication. This document illustrates the most common scenario Prerequisites ------------- -| You will need the following values to authenticate to Azure +| You will need the following values to authenticate to Azure + +- **Subscription ID** - **Client ID** - **Client Secret** - **Tenant ID** -- **Subscription ID** These values can be obtained from the portal, here's the instructions: Get Subscription ID ^^^^^^^^^^^^^^^^^^^ -1. Login into your azure account +1. Login into your Azure account 2. Select Subscriptions in the left sidebar 3. Select whichever subscription is needed -4. Click on overview +4. Click on Overview 5. Copy the Subscription ID -Get Client ID -^^^^^^^^^^^^^ - -1. Login into your azure account -2. Select azure active directory in the left sidebar -3. Click "App Registrations" -4. Select the application which you have created -5. Copy "Application (client) ID" - -Get Client Secret -^^^^^^^^^^^^^^^^^ - -1. Login into your azure account -2. Select azure active directory in the left sidebar -3. Click "App Registrations" in the left sidebar -4. Click "Certificates & Secrets" -5. Click "+ New client secret" -6. Type description and click "Add" -7. Copy and store the key value. You won’t be able to retrieve it after - you leave this page. +Get Client ID / Client Secret / Tenant ID +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -Get Tenant ID -^^^^^^^^^^^^^ - -1. Login into your azure account -2. Select azure active directory in the left sidebar -3. Click "App Registrations" in the left sidebar -4. Select the application which you have created -5. Copy "Directory (tenant) ID" +For information on how to get Client ID, Client Secret, and Tenant ID, please refer to `this document `__ Setting Environment Variables ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -76,6 +52,15 @@ your environment variables To set the following environment variables on your development system: +Windows (Note: Administrator access is required) + +1. Open the Control Panel +2. Click System Security, then System +3. Click Advanced system settings on the left +4. Inside the System Properties window, click the Environment Variables… button. +5. Click on the property you would like to change, then click the Edit… button. If the property name is not listed, then click the New… button. + +Linux-based OS :: export AZURE_CLIENT_ID="__CLIENT_ID__" @@ -83,14 +68,16 @@ To set the following environment variables on your development system: export AZURE_TENANT_ID="__TENANT_ID__" export AZURE_SUBSCRIPTION_ID="__SUBSCRIPTION_ID__" -Authentication and Creating REST Client ---------------------------------------- +Authentication and Creating Resource Management Client +------------------------------------------------------ Now that the environment is setup, all you need to do is to create an authenticated client. Our default option is to use -**DefaultAzureCredentials** and in this guide we have picked -**Resource** as our target service. To authenticate to Azure and create -a REST client, simply do the following: +**DefaultAzureCredential** and in this guide we have picked +**Resources** as our target service, but you can set it up similarly for any other service that you are using. + +To authenticate to Azure and create +a management client, simply do the following: :: @@ -103,14 +90,14 @@ a REST client, simply do the following: credentials = DefaultAzureCredential() resource_client = azure.mgmt.resource.ResourceManagementClient(credential=credentials, subscription_id=subscription_id) -More information and different authentication approaches using Azure Identity can be found at -`here `__ +More information and different authentication approaches using Azure Identity can be found in +`this document `__ Managing Resources ------------------ -Now that we are authenticated, we can use our REST client to make API -calls. Let's create a resource group and demostrate REST client's usage +Now that we are authenticated, we can use our management client to make API +calls. Let's create a resource group and demonstrate management client's usage **Create a resource group** @@ -148,4 +135,4 @@ calls. Let's create a resource group and demostrate REST client's usage :: delete_async_op = resource_client.resource_groups.begin_delete(group_name) - delete_async_op.wait() + delete_async_op.wd From fb204a868014ea095dd4b955b7eaef0b318e6978 Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Thu, 14 May 2020 17:14:29 +0800 Subject: [PATCH 03/13] Update index.rst --- doc/sphinx/index.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/sphinx/index.rst b/doc/sphinx/index.rst index cdca4ef41e7..a3f01093d32 100644 --- a/doc/sphinx/index.rst +++ b/doc/sphinx/index.rst @@ -65,6 +65,7 @@ section of the project. installation quickstart_authentication + mgmt_preview_quickstart multicloud exceptions Service Management (Legacy) From 401201049e39dc626504de9740d43039cadd73b0 Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Thu, 14 May 2020 17:15:12 +0800 Subject: [PATCH 04/13] Update index.rst and add Track 2 quickstart to menu From 729907462d1b2d5b4d8bc82ad3e4ffa5299b6c08 Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Thu, 14 May 2020 17:22:53 +0800 Subject: [PATCH 05/13] Update root readme to reflect track 2 mgmt libraries --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index 02ceb87cbea..2c0fef89f9c 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,17 @@ You can find the [most up to date list of all of the new packages on our page](h Last stable versions of packages that have been provided for usage with Azure and are production-ready. These libraries provide you with similar functionalities to the Preview ones as they allow you to use and consume existing resources and interact with them, for example: upload a blob. They might not implement the [guidelines](https://azure.github.io/azure-sdk/python_introduction.html) or have the same feature set as the Novemeber releases. They do however offer wider coverage of services. +### Management: New Releases +A new set of management libraries that follow the [Azure SDK Design Guidelines for Python](https://azure.github.io/azure-sdk/python/guidelines/) are now in Public Preview. These new libraries provide a number of core capabilities that are shared amongst all Azure SDKs, including the intuitive Azure Identity library, an HTTP Pipeline with custom policies, error-handling, distributed tracing, and much more. +You can find the list of new packages [on this page](https://azure.github.io/azure-sdk/releases/latest/python.html). Documentation and code samples for these new libraries can be found [here](https://azure.github.io/azure-sdk-for-python) + +> NOTE: If you need to ensure your code is ready for production use one of the stable, non-preview libraries. + +### Management: Previous Versions +For a complete list of management libraries which enable you to provision and manage Azure resources, please check [here](https://azure.github.io/azure-sdk/releases/latest/all/python.html). They might not have the same feature set as the new releases but they do offer wider coverage of services. +Management libraries can be identified by namespaces that start with `azure-mgmt-`, e.g. `azure-mgmt-compute` + + ### Management Libraries which enable you to provision specific resources. They are responsible for directly mirroring and consuming Azure service's REST endpoints. The management libraries use the `azure-mgmt-` convention for their package names. From 11a0b25e63de113a359935c9ac5c9fd6a996fa48 Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Sat, 16 May 2020 14:02:53 +0800 Subject: [PATCH 06/13] Update root readme for track 2 mgmt plane libraries Remove extra section Add pointer to new sections --- README.md | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 2c0fef89f9c..d36e27f3ea2 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,8 @@ The client libraries are supported on Python 2.7 and 3.5.3 or later. Each service might have a number of libraries available from each of the following categories: * [Client - New Releases](#Client-New-Releases) * [Client - Previous Versions](#Client-Previous-Versions) -* [Management](#Management) +* [Management - New Releases](#Management-New-Releases) +* [Management - Previous Versions](#Management-Previous-Versions) ### Client: New Releases @@ -43,11 +44,6 @@ You can find the list of new packages [on this page](https://azure.github.io/azu For a complete list of management libraries which enable you to provision and manage Azure resources, please check [here](https://azure.github.io/azure-sdk/releases/latest/all/python.html). They might not have the same feature set as the new releases but they do offer wider coverage of services. Management libraries can be identified by namespaces that start with `azure-mgmt-`, e.g. `azure-mgmt-compute` - -### Management - -Libraries which enable you to provision specific resources. They are responsible for directly mirroring and consuming Azure service's REST endpoints. The management libraries use the `azure-mgmt-` convention for their package names. - ## Need help? * For detailed documentation visit our [Azure SDK for Python documentation](https://aka.ms/python-docs) From e45d6c285a5841d084f9505cd9195272f0fa928a Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Sat, 16 May 2020 14:44:17 +0800 Subject: [PATCH 07/13] Update mgmt preview quickstart based on review comments --- doc/sphinx/mgmt_preview_quickstart.rst | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/doc/sphinx/mgmt_preview_quickstart.rst b/doc/sphinx/mgmt_preview_quickstart.rst index c5b47557094..630c5f4557b 100644 --- a/doc/sphinx/mgmt_preview_quickstart.rst +++ b/doc/sphinx/mgmt_preview_quickstart.rst @@ -84,7 +84,7 @@ a management client, simply do the following: import azure.mgmt.resource import azure.mgmt.network import azure.mgmt.compute - from azure.identity import DefaultAzureCredential; + from azure.identity import DefaultAzureCredential ... subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID") credentials = DefaultAzureCredential() @@ -125,7 +125,6 @@ calls. Let's create a resource group and demonstrate management client's usage :: - # group_list = self.resource_client.resource_groups.list() for g in group_list: print_resource_group(g) @@ -135,4 +134,15 @@ calls. Let's create a resource group and demonstrate management client's usage :: delete_async_op = resource_client.resource_groups.begin_delete(group_name) - delete_async_op.wd + delete_async_op.wait() + + +Contributing +------------ +For details on contributing to this repository, see the contributing guide. + +This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.microsoft.com. + +When you submit a pull request, a CLA-bot will automatically determine whether you need to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the instructions provided by the bot. You will only need to do this once across all repositories using our CLA. + +This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments. From 18363a2e8c503861863e8e3f48eec3d80fdad66b Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Sat, 16 May 2020 14:48:18 +0800 Subject: [PATCH 08/13] Update mgmt quickstart based on authentication --- doc/sphinx/mgmt_preview_quickstart.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/sphinx/mgmt_preview_quickstart.rst b/doc/sphinx/mgmt_preview_quickstart.rst index 630c5f4557b..ab7d9dee865 100644 --- a/doc/sphinx/mgmt_preview_quickstart.rst +++ b/doc/sphinx/mgmt_preview_quickstart.rst @@ -37,7 +37,7 @@ Get Subscription ID Get Client ID / Client Secret / Tenant ID ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -For information on how to get Client ID, Client Secret, and Tenant ID, please refer to `this document `__ +For information on how to get Client ID, Client Secret, and Tenant ID, please refer to `this document `__ Setting Environment Variables ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -87,11 +87,11 @@ a management client, simply do the following: from azure.identity import DefaultAzureCredential ... subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID") - credentials = DefaultAzureCredential() - resource_client = azure.mgmt.resource.ResourceManagementClient(credential=credentials, subscription_id=subscription_id) + credential = DefaultAzureCredential() + resource_client = azure.mgmt.resource.ResourceManagementClient(credential=credential, subscription_id=subscription_id) More information and different authentication approaches using Azure Identity can be found in -`this document `__ +`this document `__ Managing Resources ------------------ From 1c3fcabf6b822c7f2f50fcb04e84e0ceb2868612 Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Sat, 16 May 2020 15:21:51 +0800 Subject: [PATCH 09/13] Update quickstart docs based on review comments Add troubleshooting and contributing sections --- doc/sphinx/mgmt_preview_quickstart.rst | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/doc/sphinx/mgmt_preview_quickstart.rst b/doc/sphinx/mgmt_preview_quickstart.rst index ab7d9dee865..1bba970be0f 100644 --- a/doc/sphinx/mgmt_preview_quickstart.rst +++ b/doc/sphinx/mgmt_preview_quickstart.rst @@ -135,8 +135,13 @@ calls. Let's create a resource group and demonstrate management client's usage delete_async_op = resource_client.resource_groups.begin_delete(group_name) delete_async_op.wait() - - + +Need help? +---------- +- For detailed documentation visit our Azure SDK for `Python documentation `__ +- File an issue via `Github Issues `__ +- Check `previous questions `__ or ask new ones on StackOverflow using azure and python tags. + Contributing ------------ For details on contributing to this repository, see the contributing guide. From f4c4efd306623eefbbfecf964cb47a3b7c91d2b7 Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Sat, 16 May 2020 15:24:09 +0800 Subject: [PATCH 10/13] Update quickstart based on review comments Update troubleshooting sections --- doc/sphinx/mgmt_preview_quickstart.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/doc/sphinx/mgmt_preview_quickstart.rst b/doc/sphinx/mgmt_preview_quickstart.rst index 1bba970be0f..a13d57e0cf1 100644 --- a/doc/sphinx/mgmt_preview_quickstart.rst +++ b/doc/sphinx/mgmt_preview_quickstart.rst @@ -138,8 +138,7 @@ calls. Let's create a resource group and demonstrate management client's usage Need help? ---------- -- For detailed documentation visit our Azure SDK for `Python documentation `__ -- File an issue via `Github Issues `__ +- File an issue via `Github Issues `__ and make sure you add the "Preview" label to the issue - Check `previous questions `__ or ask new ones on StackOverflow using azure and python tags. Contributing From e85994e94d7c2588aa1a1349ef06a6690d929530 Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Wed, 3 Jun 2020 14:27:18 +0800 Subject: [PATCH 11/13] Update quickstart --- doc/sphinx/mgmt_preview_quickstart.rst | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/doc/sphinx/mgmt_preview_quickstart.rst b/doc/sphinx/mgmt_preview_quickstart.rst index a13d57e0cf1..79b7ddffb4b 100644 --- a/doc/sphinx/mgmt_preview_quickstart.rst +++ b/doc/sphinx/mgmt_preview_quickstart.rst @@ -80,10 +80,6 @@ To authenticate to Azure and create a management client, simply do the following: :: - - import azure.mgmt.resource - import azure.mgmt.network - import azure.mgmt.compute from azure.identity import DefaultAzureCredential ... subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID") @@ -103,7 +99,7 @@ calls. Let's create a resource group and demonstrate management client's usage :: - location = "mylocation" + location = "westus2" group_name = "my_resource_group_name" group = resource_client.resource_groups.create_or_update( group_name, From b73ea95d42fd9272bc769763f6f538694d1ad4ec Mon Sep 17 00:00:00 2001 From: nickzhums <56864335+nickzhums@users.noreply.github.com> Date: Fri, 5 Jun 2020 16:23:07 +0800 Subject: [PATCH 12/13] Update quickstart with network sample --- doc/sphinx/mgmt_preview_quickstart.rst | 77 +++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/doc/sphinx/mgmt_preview_quickstart.rst b/doc/sphinx/mgmt_preview_quickstart.rst index 79b7ddffb4b..50fb906732b 100644 --- a/doc/sphinx/mgmt_preview_quickstart.rst +++ b/doc/sphinx/mgmt_preview_quickstart.rst @@ -68,7 +68,7 @@ Linux-based OS export AZURE_TENANT_ID="__TENANT_ID__" export AZURE_SUBSCRIPTION_ID="__SUBSCRIPTION_ID__" -Authentication and Creating Resource Management Client +Authentication and Creating Management Client ------------------------------------------------------ Now that the environment is setup, all you need to do is to create an @@ -80,11 +80,15 @@ To authenticate to Azure and create a management client, simply do the following: :: + + import azure.mgmt.resource + import azure.mgmt.network from azure.identity import DefaultAzureCredential ... subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID") credential = DefaultAzureCredential() resource_client = azure.mgmt.resource.ResourceManagementClient(credential=credential, subscription_id=subscription_id) + network_client = azure.mgmt.network.NetworkManagementClient(credential=credential, subscription_id=subscription_id) More information and different authentication approaches using Azure Identity can be found in `this document `__ @@ -92,8 +96,7 @@ More information and different authentication approaches using Azure Identity ca Managing Resources ------------------ -Now that we are authenticated, we can use our management client to make API -calls. Let's create a resource group and demonstrate management client's usage +Now that we are authenticated, we can use the Resource client (azure.mgmt.resource.ResourceManagementClient) we have created to perform operations on Resource Group. In this example, we will show to manage Resource Groups. **Create a resource group** @@ -132,6 +135,74 @@ calls. Let's create a resource group and demonstrate management client's usage delete_async_op = resource_client.resource_groups.begin_delete(group_name) delete_async_op.wait() +Managing Network +------------------ +We can use the Network client (azure.mgmt.resource.NetworkManagementClient) we have created to perform operations on Network related resources. In this example, we will show how to manage Public IP Addresses. + +**Create a Network Public IP Address** + +:: + + GROUP_NAME = "testgroup" + PUBLIC_IP_ADDRESS = "public_ip_address_name" + + # Create Resource Group + resource_client.resource_groups.create_or_update( + GROUP_NAME, + {"location": "eastus"} + ) + + # Create Public IP Address + public_ip_address = network_client.public_ip_addresses.begin_create_or_update( + GROUP_NAME, + PUBLIC_IP_ADDRESS, + { + "location": "eastus" + } + ).result() + print("Create Public IP Address:\n{}".format(public_ip_address)) + +**Update a Network Public IP Address** + +:: + + public_ip_address = network_client.public_ip_addresses.get( + GROUP_NAME, + PUBLIC_IP_ADDRESS + ) + print("Get Public IP Address:\n{}".format(public_ip_address)) + +**List all Network Public IP Address** + +:: + + # Update Public IP Address + public_ip_address = network_client.public_ip_addresses.update_tags( + GROUP_NAME, + PUBLIC_IP_ADDRESS, + { + "tags": { + "tag1": "value1", + "tag2": "value2" + } + } + ) + print("Updated Public IP Address \n{}".format(public_ip_address)) + +**Delete a Network Public IP Address** + +:: + + # Delete Public IP Address + public_ip_address = network_client.public_ip_addresses.begin_delete( + GROUP_NAME, + PUBLIC_IP_ADDRESS + ).result() + print("Delete Public IP Address.\n") + + + + Need help? ---------- - File an issue via `Github Issues `__ and make sure you add the "Preview" label to the issue From 8f960b0668b8d3ee2c912817e97cfd8ce001a20d Mon Sep 17 00:00:00 2001 From: Kerwin Sun Date: Wed, 10 Jun 2020 16:15:33 +0800 Subject: [PATCH 13/13] Add async description in quickstart (#11943) * [doc] add description about asynchronous client. * update description. --- doc/sphinx/mgmt_preview_quickstart.rst | 46 ++++++++++++++++++++++++-- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/doc/sphinx/mgmt_preview_quickstart.rst b/doc/sphinx/mgmt_preview_quickstart.rst index 50fb906732b..1bcb2085869 100644 --- a/doc/sphinx/mgmt_preview_quickstart.rst +++ b/doc/sphinx/mgmt_preview_quickstart.rst @@ -162,7 +162,7 @@ We can use the Network client (azure.mgmt.resource.NetworkManagementClient) we h ).result() print("Create Public IP Address:\n{}".format(public_ip_address)) -**Update a Network Public IP Address** +**Get a Network Public IP Address** :: @@ -172,7 +172,7 @@ We can use the Network client (azure.mgmt.resource.NetworkManagementClient) we h ) print("Get Public IP Address:\n{}".format(public_ip_address)) -**List all Network Public IP Address** +**Update tags in Network Public IP Address** :: @@ -200,8 +200,50 @@ We can use the Network client (azure.mgmt.resource.NetworkManagementClient) we h ).result() print("Delete Public IP Address.\n") +Async and sync operations +------------------------- +In python>=3.5, Azure Python SDK provides the choice for user to use the asynchronous client for asynchronous programming. +**Create Management Client in async** +:: + + from azure.identity.aio import DefaultAzureCredential + from azure.mgmt.network.aio import NetworkManagementClient + from azure.mgmt.resource.resources.aio import ResourceManagementClient + + SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) + credential = DefaultAzureCredential() + resource_client = ResourceManagementClient( + credential=credential, + subscription_id=SUBSCRIPTION_ID + ) + network_client = NetworkManagementClient( + credential=credential, + subscription_id=SUBSCRIPTION_ID + ) + +**Create a Network Public IP Address** +:: + + GROUP_NAME = "testgroup" + PUBLIC_IP_ADDRESS = "public_ip_address_name" + # Create Resource Group + await resource_client.resource_groups.create_or_update( + GROUP_NAME, + {"location": "eastus"} + ) + + # Create Public IP Address + async_poller = await network_client.public_ip_addresses.begin_create_or_update( + GROUP_NAME, + PUBLIC_IP_ADDRESS, + { + "location": "eastus" + } + ) + public_ip_address = await async_poller.result() + print("Create Public IP Address:\n{}".format(public_ip_address)) Need help? ----------