-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Quickstart for Track 2 preview management libraries and update root readme for track 2 #11384
Changes from 5 commits
15da20b
51650b8
fb204a8
4012010
7299074
11a0b25
e45d6c2
18363a2
1c3fcab
f4c4efd
e85994e
b73ea95
8f960b0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shall we also have something about "Preview Versions" (I mean our bx versions)? And perhaps in general "preview versions" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is covered in "Management: New Releases" section on this page |
||
|
||
|
||
### Management | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section should be deleted and content merged with the sections above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yep! |
||
|
||
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-<service name>` convention for their package names. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,138 @@ | ||
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 <https://azure.github.io/azure-sdk/releases/latest/#python>`__ | ||
|
||
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 | ||
|
||
- **Subscription ID** | ||
- **Client ID** | ||
- **Client Secret** | ||
- **Tenant ID** | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was also thinking that we could add alternative of using Azure CLI as well. Maybe simpler for some users. Just "az login" and the same examples should work considering we use default credentials? |
||
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 / Client Secret / Tenant ID | ||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
For information on how to get Client ID, Client Secret, and Tenant ID, please refer to `this document <https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal>`__ | ||
|
||
nickzhums marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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: | ||
|
||
Windows (Note: Administrator access is required) | ||
|
||
1. Open the Control Panel | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this can be also done in command line: however maybe via control panel is better as it will be persistent. |
||
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 | ||
:: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the instructions are different depending on OS, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, good point, instructions added for Windows |
||
|
||
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 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 | ||
**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: | ||
|
||
:: | ||
|
||
import azure.mgmt.resource | ||
import azure.mgmt.network | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. for simplicity of example, we probably don't need network and compute here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
import azure.mgmt.compute | ||
from azure.identity import DefaultAzureCredential; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove ; |
||
... | ||
subscription_id = os.environ.get("AZURE_SUBSCRIPTION_ID") | ||
credentials = DefaultAzureCredential() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. shoudl use the singular form for clarity |
||
resource_client = azure.mgmt.resource.ResourceManagementClient(credential=credentials, subscription_id=subscription_id) | ||
|
||
More information and different authentication approaches using Azure Identity can be found in | ||
`this document <https://docs.microsoft.com/en-us/python/api/overview/azure/identity-readme?view=azure-python>`__ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Recommendation is to always remove the "en-us" part of the URL, so the url can be localized depending of customer country automatically There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. good point |
||
|
||
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 | ||
|
||
**Create a resource group** | ||
|
||
:: | ||
|
||
location = "mylocation" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i would change "mylocation" to some real location for instance "westus2" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yep, good point |
||
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** | ||
|
||
:: | ||
|
||
# | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why an empty # ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed |
||
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.wd | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wd? guess wait() ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes, should be copy paste error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'll also have to update the links in the Packages Available to point to these sections instead (L20-22)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, strange, I thought I updated these, thanks for spotting :)