├── .gitignore ├── .vscode └── settings.json ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── SECURITY.md ├── doc └── network-manage-loadbalancer │ ├── CONTRIBUTING.md │ ├── LICENSE │ ├── README.md │ ├── example_internal_load_balancer.py │ ├── example_public_load_balancer.py │ ├── load-balancer.svg │ └── requirements.txt ├── playground └── azure │ ├── createVM │ ├── env.sh │ ├── readme.md │ ├── track1.py │ ├── track1_requirements.txt │ ├── track2.py │ ├── track2_async.py │ └── track2_requirements.txt │ └── createVMWithMultiAPI │ └── track2.py └── samples ├── advisor ├── README.md ├── manage_configuration.py ├── manage_recommendation.py └── requirements.txt ├── apimanagement ├── README.md ├── manage_private_endpoint_list.py └── requirements.txt ├── appconfiguration ├── README.md ├── aio │ └── manage_app_configuration_store_async.py ├── manage_app_configuration_store.py └── requirements.txt ├── appservice ├── README.md ├── disable_manage_web_app_slot.py ├── manage_app_service_plan.py ├── manage_static_site.py ├── manage_web_app.py └── requirements.txt ├── authorization ├── README.md ├── manage_role_assignment.py ├── manage_role_management_policy.py └── requirements.txt ├── automanage ├── README.md ├── manage_configuration_profile_assignments.py ├── manage_configuration_profiles.py └── requirements.txt ├── automation ├── README.md ├── manage_account.py ├── manage_credential.py ├── manage_job.py ├── manage_jobschedule.py ├── manage_module.py ├── manage_runbook.py ├── manage_schedule.py ├── manage_variable.py ├── manage_webhook.py └── requirements.txt ├── batch ├── README.md ├── manage_application.py ├── manage_batch_account.py ├── manage_certificate.py ├── manage_pool.py └── requirements.txt ├── cdn ├── README.md ├── manage_cdn.py └── requirements.txt ├── cognitiveservices ├── README.md ├── manage_account.py └── requirements.txt ├── commerce ├── README.md ├── commerce_demo.py └── requirements.txt ├── communication ├── README.md ├── aio │ ├── manage_communication_async.py │ └── requirements.txt ├── manage_communication.py └── requirements.txt ├── compute ├── README.md ├── aio │ └── manage_virtual_machine_async.py ├── manage_availability_set.py ├── manage_dedicated_host.py ├── manage_disk.py ├── manage_disk_encryption_set.py ├── manage_galley.py ├── manage_proximity_placement_group.py ├── manage_snapshot.py ├── manage_virtual_machine.py ├── manage_virtual_machine_create_run_commands.py ├── manage_virtual_machine_cross_tenant.py ├── manage_virtual_machine_redeploy_vm.py ├── manage_virtual_machine_run_command.py ├── manage_virtual_machine_scale_set.py └── requirements.txt ├── consumption ├── README.md ├── manage_consumption.py └── requirements.txt ├── containerinstance ├── README.md ├── manage_container_group.py └── requirements.txt ├── containerregistry ├── README.md ├── manage_agent_pool.py ├── manage_pipline.py ├── manage_registry.py ├── manage_replication.py ├── manage_scope_map.py ├── manage_task.py ├── manage_task_run.py ├── manage_token.py ├── manage_webhook.py └── requirements.txt ├── containerservice ├── README.md ├── enable_monitoring_metrics.py ├── manage_agent_pool.py ├── manage_get_versions.py ├── manage_managed_clusters.py └── requirements.txt ├── cosmosdb ├── README.md ├── manage_cassandra_resource.py ├── manage_database.py ├── manage_database_account.py ├── manage_gremlin_resource.py ├── manage_mongo_db_resource.py ├── manage_sql_resource.py ├── manage_table_resource.py └── requirements.txt ├── costmanagement ├── README.md ├── manage_exports.py └── requirements.txt ├── datalakestore ├── README.md ├── manage_datalakestore.py └── requirements.txt ├── devtestlabs ├── README.md ├── manage_devtestlabs.py └── requirements.txt ├── eventgrid ├── README.md ├── manage_servicename.py └── requirements.txt ├── eventhub ├── README.md ├── aio │ └── manage_namespace_async.py ├── manage_consumer_groups.py ├── manage_disaster_recovery_config.py ├── manage_eventhub.py ├── manage_namespace.py └── requirements.txt ├── hdinsight ├── README.md ├── manage_hdinsignt.py └── requirements.txt ├── iothub ├── README.md ├── manage_resource.py └── requirements.txt ├── iothubprovisioningservices ├── README.md ├── manage_resource.py └── requirements.txt ├── keyvault ├── README.md ├── aio │ └── manage_vault_async.py ├── manage_vault.py └── requirements.txt ├── labservices ├── README.md ├── manage_labservices.py └── requirements.txt ├── loadtesting ├── README.md ├── manage_load_test_resource.py └── requirements.txt ├── loganalytics ├── README.md ├── manage_tables_list_by_workspace.py ├── manage_workspace.py ├── manage_workspace_with_gov_cloud.py └── requirements.txt ├── logic ├── README.md ├── manage_logic.py └── requirements.txt ├── machinelearningservices ├── README.md ├── manage_machinelearningservices.py └── requirements.txt ├── marketplaceordering ├── README.md ├── manage_marketplace_agreement.py └── requirements.txt ├── monitor ├── README.md ├── aio │ └── manage_log_profile_async.py ├── create_or_update_scheduled_query_rule.py ├── disable_manage_diagnostic_setting.py ├── disable_manage_scheduled_query_rule.py ├── manage_action_group.py ├── manage_activity_log_alert.py ├── manage_autoscale_setting.py ├── manage_log_profile.py ├── manage_metric_alerts.py ├── manage_metric_list.py └── requirements.txt ├── network ├── README.md ├── aio │ └── manage_virtual_network_async.py ├── ddos │ ├── manage_bastion_host.py │ └── manage_ddos_protection_plan.py ├── endpoint │ ├── manage_private_endpoint.py │ ├── manage_private_link_service.py │ ├── manage_service_endpoint_policy.py │ └── manage_service_endpoint_policy_definition.py ├── express_route │ ├── disable_manage_express_route_circuit_connection.py │ ├── manage_express_route_circuit.py │ ├── manage_express_route_circuit_authorization.py │ └── manage_express_route_circuit_peering.py ├── firewall │ ├── manage_azure_firewall.py │ ├── manage_firewall_policy.py │ ├── manage_firewall_policy_rule_group.py │ └── manage_web_application_firewall_policy.py ├── interface │ └── manage_network_interface.py ├── ip │ ├── manage_ip_group.py │ ├── manage_ip_prefix.py │ └── manage_public_ip_address.py ├── load_balancer │ ├── manage_inbound_nat_rule.py │ └── manage_load_balancer.py ├── nat │ └── manage_nat_gateway.py ├── raw_request_hook.py ├── raw_response_hook.py ├── requirements.txt ├── route │ ├── manage_route.py │ └── manage_route_table.py ├── route_filter │ ├── manage_route_filter.py │ └── manage_route_filter_rule.py ├── virtual_network │ ├── manage_local_network_gateway.py │ ├── manage_subnet.py │ ├── manage_virtual_network.py │ ├── manage_virtual_network_gateway.py │ ├── manage_virtual_network_gateway_connection.py │ ├── manage_virtual_network_gateway_root_certification.py │ └── manage_virtual_network_peering.py ├── virtual_wan │ ├── manage_security_partner_provider.py │ ├── manage_virtual_hub.py │ ├── manage_virtual_wan.py │ ├── manage_vpn_gateway.py │ └── manage_vpn_site.py └── watcher │ ├── manage_network_profile.py │ ├── manage_network_security_group.py │ ├── manage_network_watcher.py │ ├── manage_packet_capture.py │ └── manage_security_rule.py ├── notificationhubs ├── README.md ├── manage_namespace.py ├── manage_notification_hub.py └── requirements.txt ├── policyinsights ├── README.md ├── manage_remediation.py └── requirements.txt ├── quota ├── Group Quota Samples │ ├── README.md │ └── Sample.py ├── README.md ├── mamge_create_or_update.py └── requirements.txt ├── recoveryservices ├── README.md ├── manage_vault.py ├── manage_vault_extended_info.py └── requirements.txt ├── recoveryservicesbackup ├── README.md ├── backup_vm.py └── requirements.txt ├── redis ├── README.md ├── manage_firewall_rule.py ├── manage_patch_schedule.py ├── manage_redis.py └── requirements.txt ├── relay ├── README.md ├── manage_hybridconnection.py ├── manage_namespace.py ├── manage_wcfrelay.py └── requirements.txt ├── reservations ├── README.md ├── manage_reservations_list.py └── requirements.txt ├── resourceconnector ├── README.md ├── manage_create.py └── requirements.txt ├── resourcegraph ├── README.md ├── requirements.txt ├── resources_query.py └── resources_query_customed_response.py ├── resourcehealth ├── README.md ├── manage_availability_statuses_list_by_subscription_id.py ├── manage_availability_statuses_operations.py └── requirements.txt ├── resources ├── README.md ├── aio │ └── manage_resource_group_async.py ├── disable_manage_resource_deployment_script.py ├── manage_providers.py ├── manage_resource.py ├── manage_resource_application.py ├── manage_resource_check_exsistence.py ├── manage_resource_deployment.py ├── manage_resource_group.py ├── manage_resource_group_tag.py ├── manage_resource_link.py ├── manage_resource_lock_at_resource_group.py ├── manage_resource_policy.py ├── manage_resource_subscriptions.py ├── manage_resource_tags.py └── requirements.txt ├── scheduler ├── README.md ├── manage_job_collection.py └── requirements.txt ├── search ├── README.md ├── manage_query_key.py ├── manage_service.py └── requirements.txt ├── security ├── README.md ├── manage_advanced_threat_protection.py └── requirements.txt ├── servicebus ├── README.md ├── manage_disaster_recovery_config.py ├── manage_migration_config.py ├── manage_namespace.py ├── manage_queue.py ├── manage_topic.py └── requirements.txt ├── servicelinker ├── README.md ├── manage_service_linker.py └── requirements.txt ├── sql ├── README.md ├── manage_database.py ├── manage_elastic_pool.py ├── manage_failover_group.py ├── manage_firewall_rule.py ├── manage_job.py ├── manage_server.py ├── manage_server_communication_link.py ├── manage_server_dns_alias.py ├── manage_server_key.py ├── manage_sync.py ├── manage_virtual_network_rule.py ├── manage_vulnerability_assessment.py └── requirements.txt ├── storage ├── README.md ├── aio │ └── manage_storage_account_async.py ├── manage_blob_container.py ├── manage_encryption_scope.py ├── manage_file_share.py ├── manage_management_policy.py ├── manage_regenerate_key.py ├── manage_storage_account.py ├── manage_storage_account_public_access.py └── requirements.txt └── testbase ├── manage_package.py ├── manage_testbase_account.py ├── manage_testresult.py ├── readme.md ├── requirements.txt └── testbase_util.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | build/ 12 | develop-eggs/ 13 | dist/ 14 | downloads/ 15 | eggs/ 16 | .eggs/ 17 | lib/ 18 | lib64/ 19 | parts/ 20 | sdist/ 21 | var/ 22 | wheels/ 23 | pip-wheel-metadata/ 24 | share/python-wheels/ 25 | *.egg-info/ 26 | .installed.cfg 27 | *.egg 28 | MANIFEST 29 | 30 | # PyInstaller 31 | # Usually these files are written by a python script from a template 32 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 33 | *.manifest 34 | *.spec 35 | 36 | # Installer logs 37 | pip-log.txt 38 | pip-delete-this-directory.txt 39 | 40 | # Unit test / coverage reports 41 | htmlcov/ 42 | .tox/ 43 | .nox/ 44 | .coverage 45 | .coverage.* 46 | .cache 47 | nosetests.xml 48 | coverage.xml 49 | *.cover 50 | *.py,cover 51 | .hypothesis/ 52 | .pytest_cache/ 53 | 54 | # Translations 55 | *.mo 56 | *.pot 57 | 58 | # Django stuff: 59 | *.log 60 | local_settings.py 61 | db.sqlite3 62 | db.sqlite3-journal 63 | 64 | # Flask stuff: 65 | instance/ 66 | .webassets-cache 67 | 68 | # Scrapy stuff: 69 | .scrapy 70 | 71 | # Sphinx documentation 72 | docs/_build/ 73 | 74 | # PyBuilder 75 | target/ 76 | 77 | # Jupyter Notebook 78 | .ipynb_checkpoints 79 | 80 | # IPython 81 | profile_default/ 82 | ipython_config.py 83 | 84 | # pyenv 85 | .python-version 86 | 87 | # pipenv 88 | # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control. 89 | # However, in case of collaboration, if having platform-specific dependencies or dependencies 90 | # having no cross-platform support, pipenv may install dependencies that don't work, or not 91 | # install all needed dependencies. 92 | #Pipfile.lock 93 | 94 | # PEP 582; used by e.g. github.com/David-OConnor/pyflow 95 | __pypackages__/ 96 | 97 | # Celery stuff 98 | celerybeat-schedule 99 | celerybeat.pid 100 | 101 | # SageMath parsed files 102 | *.sage.py 103 | 104 | # Environments 105 | .env 106 | .venv 107 | env/ 108 | venv/ 109 | ENV/ 110 | env.bak/ 111 | venv.bak/ 112 | 113 | # Spyder project settings 114 | .spyderproject 115 | .spyproject 116 | 117 | # Rope project settings 118 | .ropeproject 119 | 120 | # mkdocs documentation 121 | /site 122 | 123 | # mypy 124 | .mypy_cache/ 125 | .dmypy.json 126 | dmypy.json 127 | 128 | # Pyre type checker 129 | .pyre/ 130 | 131 | .idea/ 132 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.formatting.provider": "black" 3 | } 4 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Microsoft Open Source Code of Conduct 2 | 3 | This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 4 | 5 | Resources: 6 | 7 | - [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) 8 | - [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) 9 | - Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns 10 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Microsoft Corporation. 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE 22 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Security 4 | 5 | Microsoft takes the security of our software products and services seriously, which includes all source code repositories managed through our GitHub organizations, which include [Microsoft](https://github.com/Microsoft), [Azure](https://github.com/Azure), [DotNet](https://github.com/dotnet), [AspNet](https://github.com/aspnet), [Xamarin](https://github.com/xamarin), and [our GitHub organizations](https://opensource.microsoft.com/). 6 | 7 | If you believe you have found a security vulnerability in any Microsoft-owned repository that meets [Microsoft's definition of a security vulnerability](https://docs.microsoft.com/en-us/previous-versions/tn-archive/cc751383(v=technet.10)), please report it to us as described below. 8 | 9 | ## Reporting Security Issues 10 | 11 | **Please do not report security vulnerabilities through public GitHub issues.** 12 | 13 | Instead, please report them to the Microsoft Security Response Center (MSRC) at [https://msrc.microsoft.com/create-report](https://msrc.microsoft.com/create-report). 14 | 15 | If you prefer to submit without logging in, send email to [secure@microsoft.com](mailto:secure@microsoft.com). If possible, encrypt your message with our PGP key; please download it from the [Microsoft Security Response Center PGP Key page](https://www.microsoft.com/en-us/msrc/pgp-key-msrc). 16 | 17 | You should receive a response within 24 hours. If for some reason you do not, please follow up via email to ensure we received your original message. Additional information can be found at [microsoft.com/msrc](https://www.microsoft.com/msrc). 18 | 19 | Please include the requested information listed below (as much as you can provide) to help us better understand the nature and scope of the possible issue: 20 | 21 | * Type of issue (e.g. buffer overflow, SQL injection, cross-site scripting, etc.) 22 | * Full paths of source file(s) related to the manifestation of the issue 23 | * The location of the affected source code (tag/branch/commit or direct URL) 24 | * Any special configuration required to reproduce the issue 25 | * Step-by-step instructions to reproduce the issue 26 | * Proof-of-concept or exploit code (if possible) 27 | * Impact of the issue, including how an attacker might exploit the issue 28 | 29 | This information will help us triage your report more quickly. 30 | 31 | If you are reporting for a bug bounty, more complete reports can contribute to a higher bounty award. Please visit our [Microsoft Bug Bounty Program](https://microsoft.com/msrc/bounty) page for more details about our active programs. 32 | 33 | ## Preferred Languages 34 | 35 | We prefer all communications to be in English. 36 | 37 | ## Policy 38 | 39 | Microsoft follows the principle of [Coordinated Vulnerability Disclosure](https://www.microsoft.com/en-us/msrc/cvd). 40 | 41 | -------------------------------------------------------------------------------- /doc/network-manage-loadbalancer/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing to Azure samples 2 | 3 | Thank you for your interest in contributing to Azure samples! 4 | 5 | ## Ways to contribute 6 | 7 | You can contribute to [Azure samples](https://azure.microsoft.com/documentation/samples/) in a few different ways: 8 | 9 | - Submit feedback on [this sample page](https://azure.microsoft.com/documentation/samples/network-python-manage-loadbalancer/) whether it was helpful or not. 10 | - Submit issues through [issue tracker](https://github.com/Azure-Samples/network-python-manage-loadbalancer/issues) on GitHub. We are actively monitoring the issues and improving our samples. 11 | - If you wish to make code changes to samples, or contribute something new, please follow the [GitHub Forks / Pull requests model](https://help.github.com/articles/fork-a-repo/): Fork the sample repo, make the change and propose it back by submitting a pull request. -------------------------------------------------------------------------------- /doc/network-manage-loadbalancer/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Microsoft Corporation 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /doc/network-manage-loadbalancer/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==18.0.0 3 | azure-mgmt-network==19.0.0 4 | azure-mgmt-compute==22.0.0 -------------------------------------------------------------------------------- /playground/azure/createVM/env.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export AZURE_TENANT_ID="" 4 | export AZURE_CLIENT_ID="" 5 | export AZURE_CLIENT_SECRET="" 6 | export SUBSCRIPTION_ID="" -------------------------------------------------------------------------------- /playground/azure/createVM/readme.md: -------------------------------------------------------------------------------- 1 | # How to run sample in track2 2 | 3 | ## 1. Install dependences for track2 4 | run `pip install -r track2_requirements.txt` 5 | 6 | ## 2. create env values 7 | We need put app registration information into env values. 8 | For example in linux: 9 | ```bash 10 | export AZURE_TENANT_ID="" 11 | export AZURE_CLIENT_ID="" 12 | export AZURE_CLIENT_SECRET="" 13 | export SUBSCRIPTION_ID="" 14 | ``` 15 | 16 | You can update env values in `env.sh` and run `source env.sh` to make it vailable in current shell. 17 | 18 | About how to create app registration, see here: https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app 19 | 20 | ## 3. test sample 21 | just run `track2.py` to test creating virtualmachine in track2 sdk. 22 | Atfter finish script, you can find your virtualmachine in azure portal. 23 | -------------------------------------------------------------------------------- /playground/azure/createVM/track1_requirements.txt: -------------------------------------------------------------------------------- 1 | azure-mgmt-compute 2 | azure-mgmt-resource 3 | azure-mgmt-network 4 | azure-common 5 | -------------------------------------------------------------------------------- /playground/azure/createVM/track2_requirements.txt: -------------------------------------------------------------------------------- 1 | azure-mgmt-compute=17.0.0b1 2 | azure-mgmt-resource=15.0.0b1 3 | azure-mgmt-network=16.0.0b1 4 | azure-identity 5 | -------------------------------------------------------------------------------- /samples/advisor/manage_configuration.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.advisor import AdvisorManagementClient 11 | from azure.mgmt.advisor.models import ConfigData 12 | from azure.mgmt.resource import ResourceManagementClient 13 | 14 | 15 | def main(): 16 | 17 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 18 | GROUP_NAME = "testgroupx" 19 | CONFIGURATION = "default" 20 | 21 | # Create client 22 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 23 | resource_client = ResourceManagementClient( 24 | credential=DefaultAzureCredential(), 25 | subscription_id=SUBSCRIPTION_ID 26 | ) 27 | advisor_client = AdvisorManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | 32 | # Create resource group 33 | resource_client.resource_groups.create_or_update( 34 | GROUP_NAME, 35 | {"location": "eastus"} 36 | ) 37 | 38 | # create a new configuration to update exclude to True 39 | input = ConfigData() 40 | input.exclude=True 41 | 42 | # Create configuration 43 | configuration = advisor_client.configurations.create_in_resource_group( 44 | configuration_name=CONFIGURATION, 45 | resource_group=GROUP_NAME, 46 | config_contract=input 47 | ) 48 | print("Create configuration:\n{}".format(configuration)) 49 | 50 | # Get configuration 51 | configurations = advisor_client.configurations.list_by_resource_group( 52 | resource_group=GROUP_NAME, 53 | ) 54 | print("Get configuration:\n{}".format(list(configurations)[0])) 55 | 56 | # Delete Group 57 | resource_client.resource_groups.begin_delete( 58 | GROUP_NAME 59 | ).result() 60 | 61 | 62 | if __name__ == "__main__": 63 | main() 64 | -------------------------------------------------------------------------------- /samples/advisor/manage_recommendation.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | import re 9 | 10 | from azure.identity import DefaultAzureCredential 11 | from azure.mgmt.advisor import AdvisorManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | RECOMMENDATION = "recommendationxxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | advisor_client = AdvisorManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | 27 | def call(response, *args, **kwargs): 28 | return response.http_response 29 | 30 | # Generate recommendation 31 | response = advisor_client.recommendations.generate(cls=call) 32 | 33 | location = response.headers['Location'] 34 | # extract the operation ID from the Location header 35 | operation_id = re.findall("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", location) 36 | 37 | # Get generate status 38 | recommendation = advisor_client.recommendations.get_generate_status( 39 | cls=call, 40 | operation_id=operation_id[0] 41 | ) 42 | print("Get recommendation status:\n{}".format(recommendation)) 43 | 44 | 45 | if __name__ == "__main__": 46 | main() 47 | -------------------------------------------------------------------------------- /samples/advisor/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-advisor==9.0.0b1 3 | azure-mgmt-resource==15.0.0 4 | -------------------------------------------------------------------------------- /samples/apimanagement/manage_private_endpoint_list.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from azure.identity import DefaultAzureCredential 4 | from azure.mgmt.resource import ResourceManagementClient 5 | from azure.mgmt.apimanagement import ApiManagementClient 6 | from azure.mgmt.apimanagement.models import ApiManagementServiceResource, ApiManagementServiceSkuProperties 7 | 8 | def main(): 9 | GROUP_NAME = 'testgroupx' 10 | LOCATION = 'eastus2' 11 | SERVICE_NAME = 'test-apimanager' 12 | PUBLISHER_NAME = 'foo' 13 | PUBLISHER_EMAIL = 'foo@foo.com' 14 | SUBSCRIPTION_ID = os.getenv('SUBSCRIPTION_ID') 15 | 16 | resource_client = ResourceManagementClient( 17 | DefaultAzureCredential(), 18 | subscription_id=SUBSCRIPTION_ID 19 | ) 20 | apimanagement_client = ApiManagementClient( 21 | DefaultAzureCredential(), 22 | subscription_id=SUBSCRIPTION_ID 23 | ) 24 | 25 | resource_group = resource_client.resource_groups.create_or_update(GROUP_NAME, {'location': LOCATION}) 26 | 27 | # create and update may take a long time 28 | apimanagement_parameters = ApiManagementServiceResource( 29 | sku=ApiManagementServiceSkuProperties(name="Developer", capacity=1), 30 | location=LOCATION, 31 | publisher_name=PUBLISHER_NAME, 32 | publisher_email=PUBLISHER_EMAIL, 33 | enable_client_certificate=True 34 | ) 35 | 36 | apimanagement_service = apimanagement_client.api_management_service.begin_create_or_update(GROUP_NAME, SERVICE_NAME, 37 | parameters=apimanagement_parameters).result() 38 | 39 | result = apimanagement_client.private_endpoint_connection.list_private_link_resources(GROUP_NAME, SERVICE_NAME) 40 | 41 | for i in result.value: 42 | print(i) 43 | 44 | apimanagement_client.api_management_service.begin_delete(GROUP_NAME, SERVICE_NAME) 45 | resource_client.resource_groups.begin_delete(GROUP_NAME) 46 | 47 | print('Finish') 48 | 49 | 50 | if __name__ == '__main__': 51 | main() 52 | -------------------------------------------------------------------------------- /samples/apimanagement/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-apimanagement==3.0.0 3 | azure-mgmt-resource==21.1.0 4 | -------------------------------------------------------------------------------- /samples/appconfiguration/manage_app_configuration_store.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.appconfiguration import AppConfigurationManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | CONFIG_STORE_NAME = "configstorexyz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | appconfig_client = AppConfigurationManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | resource_client = ResourceManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create appconfiguration store 37 | appconfig_store = appconfig_client.configuration_stores.begin_create( 38 | GROUP_NAME, 39 | CONFIG_STORE_NAME, 40 | { 41 | "location": "eastus", 42 | "sku": { 43 | "name": "Standard" 44 | } 45 | } 46 | ).result() 47 | print("Create appconfigruation store:\n{}".format(appconfig_store)) 48 | 49 | # Get appconfiguration store 50 | appconfig_store = appconfig_client.configuration_stores.get( 51 | GROUP_NAME, 52 | CONFIG_STORE_NAME 53 | ) 54 | print("Get appconfigruation store:\n{}".format(appconfig_store)) 55 | 56 | # Update appconfiguration store 57 | appconfig_store = appconfig_client.configuration_stores.begin_update( 58 | GROUP_NAME, 59 | CONFIG_STORE_NAME, 60 | { 61 | "tags": { 62 | "category": "Marketing" 63 | }, 64 | "sku": { 65 | "name": "Standard" 66 | } 67 | } 68 | ).result() 69 | print("Update appconfigruation store:\n{}".format(appconfig_store)) 70 | 71 | # Delete appconfiguration store 72 | appconfig_client.configuration_stores.begin_delete( 73 | GROUP_NAME, 74 | CONFIG_STORE_NAME 75 | ).result() 76 | print("Delete appconfiguration store") 77 | 78 | # Delete Group 79 | resource_client.resource_groups.begin_delete( 80 | GROUP_NAME 81 | ).result() 82 | 83 | if __name__ == "__main__": 84 | main() 85 | -------------------------------------------------------------------------------- /samples/appconfiguration/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-appconfiguration==1.0.0 3 | azure-mgmt-resource==15.0.0 4 | -------------------------------------------------------------------------------- /samples/appservice/manage_app_service_plan.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.web import WebSiteManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | APP_SERVICE_PLAN = "appserviceplanxxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | web_client = WebSiteManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create app service plan 38 | app_service_plan = web_client.app_service_plans.begin_create_or_update( 39 | GROUP_NAME, 40 | APP_SERVICE_PLAN, 41 | { 42 | "kind": "app", 43 | "location": "eastus", 44 | "sku": { 45 | "name": "P1", 46 | "tier": "Premium", 47 | "size": "P1", 48 | "family": "P", 49 | "capacity": "1" 50 | } 51 | } 52 | ).result() 53 | print("Create app service plan:\n{}".format(app_service_plan)) 54 | 55 | # Get app service plan 56 | app_service_plan = web_client.app_service_plans.get( 57 | GROUP_NAME, 58 | APP_SERVICE_PLAN 59 | ) 60 | print("Get app service plan:\n{}".format(app_service_plan)) 61 | 62 | # Update app service plan 63 | app_service_plan = web_client.app_service_plans.update( 64 | GROUP_NAME, 65 | APP_SERVICE_PLAN, 66 | { 67 | "kind": "app" 68 | } 69 | ) 70 | print("Update app service plan:\n{}".format(app_service_plan)) 71 | 72 | # Delete app service plan 73 | app_service_plan = web_client.app_service_plans.delete( 74 | GROUP_NAME, 75 | APP_SERVICE_PLAN 76 | ) 77 | print("Delete app service plan.\n") 78 | 79 | # Delete Group 80 | resource_client.resource_groups.begin_delete( 81 | GROUP_NAME 82 | ).result() 83 | 84 | 85 | if __name__ == "__main__": 86 | main() 87 | -------------------------------------------------------------------------------- /samples/appservice/manage_static_site.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.web import WebSiteManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GITHUB_TOKEN = os.environ.get("GITHUB_TOKEN", None) 18 | GROUP_NAME = "testgroupxx" 19 | STATIC_SITE = "staticsitexxyyzz" 20 | 21 | # Create client 22 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 23 | resource_client = ResourceManagementClient( 24 | credential=DefaultAzureCredential(), 25 | subscription_id=SUBSCRIPTION_ID 26 | ) 27 | web_client = WebSiteManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | 32 | # Create resource group 33 | resource_client.resource_groups.create_or_update( 34 | GROUP_NAME, 35 | {"location": "eastus2"} 36 | ) 37 | 38 | # Create static site 39 | static_site = web_client.static_sites.begin_create_or_update_static_site( 40 | GROUP_NAME, 41 | STATIC_SITE, 42 | { 43 | "location": "eastus2", 44 | "sku": { 45 | "name": "Free", 46 | }, 47 | "repository_url": "https://github.com/00Kai0/html-docs-hello-world", 48 | "branch": "master", 49 | "repository_token": GITHUB_TOKEN, 50 | "build_properties": { 51 | "app_location": "app", 52 | "api_location": "api", 53 | "app_artifact_location": "build" 54 | } 55 | } 56 | ) 57 | print("Create static site:\n{}".format(static_site)) 58 | 59 | # Get static site 60 | static_site = web_client.static_sites.get_static_site( 61 | GROUP_NAME, 62 | STATIC_SITE 63 | ) 64 | print("Get static site:\n{}".format(static_site)) 65 | 66 | # Delete static site 67 | static_site = web_client.static_sites.begin_delete_static_site( 68 | GROUP_NAME, 69 | STATIC_SITE 70 | ) 71 | print("Delete static site.\n") 72 | 73 | # Delete Group 74 | resource_client.resource_groups.begin_delete( 75 | GROUP_NAME 76 | ).result() 77 | 78 | 79 | if __name__ == "__main__": 80 | main() 81 | -------------------------------------------------------------------------------- /samples/appservice/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource>=15.0.0 3 | azure-mgmt-web==6.1.0 4 | -------------------------------------------------------------------------------- /samples/authorization/manage_role_assignment.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.authorization import AuthorizationManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | CLIENT_OID = os.environ.get("CLIENT_OID", None) 18 | GROUP_NAME = "testgroupx" 19 | ROLE_ASSIGNMENT = "88888888-7000-0000-0000-000000000003" 20 | ROLE_DEFINITION = "e078ab98-ef3a-4c9a-aba7-12f5172b45d0" 21 | SCOPE = "subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}".format( 22 | subscriptionId=SUBSCRIPTION_ID, 23 | resourceGroupName=GROUP_NAME 24 | ) 25 | 26 | # Create client 27 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 28 | resource_client = ResourceManagementClient( 29 | credential=DefaultAzureCredential(), 30 | subscription_id=SUBSCRIPTION_ID 31 | ) 32 | authorization_client = AuthorizationManagementClient( 33 | credential=DefaultAzureCredential(), 34 | subscription_id=SUBSCRIPTION_ID, 35 | api_version="2018-01-01-preview" 36 | ) 37 | 38 | # Create resource group 39 | resource_client.resource_groups.create_or_update( 40 | GROUP_NAME, 41 | {"location": "eastus"} 42 | ) 43 | 44 | # Create role assignment 45 | role_assignment = authorization_client.role_assignments.create( 46 | SCOPE, 47 | ROLE_ASSIGNMENT, 48 | { 49 | "role_definition_id": "/subscriptions/" + SUBSCRIPTION_ID + "/providers/Microsoft.Authorization/roleDefinitions/" + ROLE_DEFINITION, 50 | "principal_id": CLIENT_OID, 51 | } 52 | ) 53 | print("Create role assignment:\n{}".format(role_assignment)) 54 | 55 | # Get role assignment 56 | role_assignment = authorization_client.role_assignments.get( 57 | SCOPE, 58 | ROLE_ASSIGNMENT 59 | ) 60 | print("Get role assignment:\n{}".format(role_assignment)) 61 | 62 | # Delete role assignment 63 | role_assignment = authorization_client.role_assignments.delete( 64 | SCOPE, 65 | ROLE_ASSIGNMENT 66 | ) 67 | print("Delete role assignment.\n") 68 | 69 | # Delete Group 70 | resource_client.resource_groups.begin_delete( 71 | GROUP_NAME 72 | ).result() 73 | 74 | 75 | if __name__ == "__main__": 76 | main() 77 | -------------------------------------------------------------------------------- /samples/authorization/manage_role_management_policy.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | import json 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.authorization import AuthorizationManagementClient 11 | 12 | 13 | def main(): 14 | 15 | sub_id = os.environ.get("SUBSCRIPTION_ID", None) 16 | 17 | # Create client 18 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 19 | client = AuthorizationManagementClient( 20 | credential=DefaultAzureCredential(), 21 | subscription_id=sub_id, 22 | ) 23 | 24 | result = client.role_management_policies.list_for_scope( 25 | scope=f"providers/Microsoft.Subscription/subscriptions/{sub_id}" 26 | ) 27 | 28 | for item in result: 29 | print(json.dumps(item.serialize())) 30 | 31 | 32 | if __name__ == "__main__": 33 | main() 34 | -------------------------------------------------------------------------------- /samples/authorization/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-authorization==3.0.0 3 | azure-mgmt-resource==20.1.0 4 | -------------------------------------------------------------------------------- /samples/automanage/manage_configuration_profile_assignments.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from azure.identity import DefaultAzureCredential 4 | from azure.mgmt.automanage import AutomanageClient 5 | 6 | 7 | def main(): 8 | rg = "resourceGroupName" 9 | profile_name = "configurationProfileName" 10 | vm = "vmName" 11 | SUBSCRIPTION_ID = os.getenv('SUBSCRIPTION_ID') 12 | 13 | # Create Automanage Client 14 | credential = DefaultAzureCredential() 15 | client = AutomanageClient(credential, SUBSCRIPTION_ID) 16 | 17 | # Create Azure Best Practices assignment 18 | best_practices_assignment = { 19 | "properties": { 20 | "configurationProfile": "/providers/Microsoft.Automanage/bestPractices/AzureBestPracticesProduction", 21 | } 22 | } 23 | 24 | client.configuration_profile_assignments.create_or_update( 25 | "default", rg, vm, custom_profile_assignment) 26 | 27 | # Create custom profile assignment 28 | custom_profile_assignment = { 29 | "properties": { 30 | "configurationProfile": f"/subscriptions/{SUBSCRIPTION_ID}/resourceGroups/{rg}/providers/Microsoft.Automanage/configurationProfiles/{profile_name}" 31 | } 32 | } 33 | 34 | client.configuration_profile_assignments.create_or_update( 35 | "default", rg, vm, best_practices_assignment) 36 | 37 | # Get configuration profile assignment 38 | assignment = client.configuration_profile_assignments.get( 39 | rg, "default", vm) 40 | print(assignment) 41 | 42 | 43 | if __name__ == '__main__': 44 | main() 45 | -------------------------------------------------------------------------------- /samples/automanage/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-automanage -------------------------------------------------------------------------------- /samples/automation/manage_account.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.automation import AutomationClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | AUTOMATION_ACCOUNT = "automationaccountxxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | automation_client = AutomationClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create automation account 38 | automation_account = automation_client.automation_account.create_or_update( 39 | GROUP_NAME, 40 | AUTOMATION_ACCOUNT, 41 | { 42 | "sku": { 43 | "name": "Free" 44 | }, 45 | "name": AUTOMATION_ACCOUNT, 46 | "location": "East US 2" 47 | } 48 | ) 49 | print("Create automation account:\n{}".format(automation_account)) 50 | 51 | # Get automation account 52 | automation_account = automation_client.automation_account.get( 53 | GROUP_NAME, 54 | AUTOMATION_ACCOUNT 55 | ) 56 | print("Get automation account:\n{}".format(automation_account)) 57 | 58 | # Update automation account 59 | automation_account = automation_client.automation_account.update( 60 | GROUP_NAME, 61 | AUTOMATION_ACCOUNT, 62 | { 63 | "sku": { 64 | "name": "Free" 65 | }, 66 | "name": AUTOMATION_ACCOUNT, 67 | "location": "East US 2" 68 | } 69 | ) 70 | print("Update automation account:\n{}".format(automation_account)) 71 | 72 | # Delete automation account 73 | automation_account = automation_client.automation_account.delete( 74 | GROUP_NAME, 75 | AUTOMATION_ACCOUNT 76 | ) 77 | print("Delete automation account.\n") 78 | 79 | # Delete Group 80 | resource_client.resource_groups.begin_delete( 81 | GROUP_NAME 82 | ).result() 83 | 84 | 85 | if __name__ == "__main__": 86 | main() 87 | -------------------------------------------------------------------------------- /samples/automation/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-automation==1.0.0 3 | azure-mgmt-resource==20.1.0 4 | -------------------------------------------------------------------------------- /samples/batch/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-batch==16.0.0 3 | azure-mgmt-network==16.0.0 4 | azure-mgmt-resource==15.0.0 5 | azure-mgmt-storage==16.0.0 6 | requests 7 | -------------------------------------------------------------------------------- /samples/cdn/manage_cdn.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | import time 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.cdn import CdnManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | # - other dependence - 14 | # - end - 15 | 16 | 17 | def main(): 18 | 19 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 20 | TIME = str(time.time()).replace('.','') 21 | GROUP_NAME = "testcdn" + TIME 22 | CDN = "cdn" + TIME 23 | LOCATION='WestUs' 24 | 25 | # Create client 26 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 27 | resource_client = ResourceManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | cdn_client = CdnManagementClient( 32 | credential=DefaultAzureCredential(), 33 | subscription_id=SUBSCRIPTION_ID 34 | ) 35 | # - init depended client - 36 | # - end - 37 | 38 | # Create resource group 39 | resource_client.resource_groups.create_or_update( 40 | GROUP_NAME, 41 | {"location": LOCATION} 42 | ) 43 | 44 | # - init depended resources - 45 | # - end - 46 | 47 | # Create cdn 48 | cdn = cdn_client.profiles.begin_create( 49 | GROUP_NAME, 50 | CDN, 51 | { 52 | "location": LOCATION, 53 | "sku": { 54 | "name": "Standard_Verizon" 55 | } 56 | } 57 | ).result() 58 | print("Create cdn:\n{}\n".format(cdn)) 59 | 60 | # Get cdn 61 | cdn = cdn_client.profiles.get( 62 | GROUP_NAME, 63 | CDN 64 | ) 65 | print("Get cdn:\n{}\n".format(cdn)) 66 | 67 | # Update cdn 68 | cdn = cdn_client.profiles.begin_update( 69 | GROUP_NAME, 70 | CDN, 71 | { 72 | "tags": { 73 | "additional_properties": "Tag1" 74 | } 75 | } 76 | ).result() 77 | print("Update cdn:\n{}\n".format(cdn)) 78 | 79 | # Delete cdn 80 | cdn = cdn_client.profiles.begin_delete( 81 | GROUP_NAME, 82 | CDN 83 | ).result() 84 | print("Delete cdn.\n") 85 | 86 | # Delete Group 87 | resource_client.resource_groups.begin_delete( 88 | GROUP_NAME 89 | ).result() 90 | 91 | 92 | if __name__ == "__main__": 93 | main() 94 | -------------------------------------------------------------------------------- /samples/cdn/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-cdn==10.0.0b1 4 | -------------------------------------------------------------------------------- /samples/cognitiveservices/manage_account.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.cognitiveservices import CognitiveServicesManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | ACCOUNT = "accountxxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | cognitiveservices_client = CognitiveServicesManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create account 38 | account = cognitiveservices_client.accounts.create( 39 | GROUP_NAME, 40 | ACCOUNT, 41 | { 42 | "location": "West US", 43 | "kind": "CognitiveServices", 44 | "sku": { 45 | "name": "S0" 46 | }, 47 | "identity": { 48 | "type": "SystemAssigned" 49 | } 50 | } 51 | ) 52 | print("Create account:\n{}".format(account)) 53 | 54 | # Get account 55 | account = cognitiveservices_client.accounts.get_properties( 56 | GROUP_NAME, 57 | ACCOUNT 58 | ) 59 | print("Get account:\n{}".format(account)) 60 | 61 | # Update account 62 | account = cognitiveservices_client.accounts.update( 63 | GROUP_NAME, 64 | ACCOUNT, 65 | { 66 | "location": "West US", 67 | "kind": "CognitiveServices", 68 | "sku": { 69 | "name": "S0" 70 | }, 71 | "identity": { 72 | "type": "SystemAssigned" 73 | } 74 | } 75 | ) 76 | print("Update account:\n{}".format(account)) 77 | 78 | # Delete account 79 | account = cognitiveservices_client.accounts.delete( 80 | GROUP_NAME, 81 | ACCOUNT 82 | ) 83 | print("Delete account.\n") 84 | 85 | # Delete Group 86 | resource_client.resource_groups.begin_delete( 87 | GROUP_NAME 88 | ).result() 89 | 90 | 91 | if __name__ == "__main__": 92 | main() 93 | -------------------------------------------------------------------------------- /samples/cognitiveservices/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-cognitiveservices==11.0.0b1 3 | azure-mgmt-resource==15.0.0 4 | -------------------------------------------------------------------------------- /samples/commerce/commerce_demo.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | import datetime as dt 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.commerce import UsageManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | 17 | # Create client 18 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 19 | usage_client = UsageManagementClient( 20 | credential=DefaultAzureCredential(), 21 | subscription_id=SUBSCRIPTION_ID 22 | ) 23 | 24 | # List usage aggregates 25 | output = usage_client.usage_aggregates.list( 26 | str(dt.date.today() - dt.timedelta(days=1))+'T00:00:00Z', 27 | str(dt.date.today())+'T00:00:00Z' 28 | ) 29 | print("List usage aggregate:\n{}".format(output)) 30 | 31 | # Get rate card 32 | rate = usage_client.rate_card.get( 33 | "OfferDurableId eq 'MS-AZR-0062P' and Currency eq 'USD' and Locale eq 'en-US' and RegionInfo eq 'US'" 34 | ) 35 | print("Get rate card:\n{}".format(rate)) 36 | 37 | 38 | if __name__ == "__main__": 39 | main() 40 | -------------------------------------------------------------------------------- /samples/commerce/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-commerce==6.0.0b1 3 | -------------------------------------------------------------------------------- /samples/communication/aio/requirements.txt: -------------------------------------------------------------------------------- 1 | aiohttp==3.9.4 -------------------------------------------------------------------------------- /samples/communication/manage_communication.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.resource import ResourceManagementClient 11 | from azure.mgmt.communication import CommunicationServiceManagementClient 12 | from azure.mgmt.communication.models import CommunicationServiceResource 13 | 14 | def main(): 15 | 16 | credential = DefaultAzureCredential() 17 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 18 | GROUP_NAME = "testgroupxx" 19 | COMMUNICATION_NAME = 'test-communicationxxx' 20 | 21 | # Create client 22 | resource_client = ResourceManagementClient( 23 | credential=credential, 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | communication_client = CommunicationServiceManagementClient( 27 | credential=credential, 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_group = resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | print("Create a resource group:\n{}".format(resource_group)) 37 | 38 | # Create Communication 39 | communication = communication_client.communication_service.begin_create_or_update( 40 | resource_group_name=GROUP_NAME, 41 | communication_service_name=COMMUNICATION_NAME, 42 | parameters=CommunicationServiceResource(location="global", data_location="United States") 43 | ).result() 44 | print('Create a communication service:\n{}'.format(communication)) 45 | 46 | # Get Communication 47 | communication_res = communication_client.communication_service.get( 48 | resource_group_name=GROUP_NAME, 49 | communication_service_name=COMMUNICATION_NAME 50 | ) 51 | print('Get a communication service:\n{}'.format(communication_res)) 52 | 53 | # Delete Communication 54 | communication_client.communication_service.begin_delete( 55 | resource_group_name=GROUP_NAME, 56 | communication_service_name=COMMUNICATION_NAME 57 | ).result() 58 | print('Delete a communication service.') 59 | 60 | # Delete Group 61 | resource_client.resource_groups.begin_delete( 62 | GROUP_NAME 63 | ).result() 64 | print('Delete a resource group.') 65 | 66 | 67 | if __name__ == '__main__': 68 | main() 69 | -------------------------------------------------------------------------------- /samples/communication/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity==1.4.0 2 | azure-core==1.8.1 3 | azure-mgmt-core==1.2.0 4 | azure-mgmt-resource==20.1.0 5 | azure-mgmt-communication==1.0.0 6 | -------------------------------------------------------------------------------- /samples/compute/manage_availability_set.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.compute import ComputeManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | AVAILABILITY_SET_NAME = "availabilityset" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | compute_client = ComputeManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create availability set 37 | availability_set = compute_client.availability_sets.create_or_update( 38 | GROUP_NAME, 39 | AVAILABILITY_SET_NAME, 40 | { 41 | "location": "eastus", 42 | "platform_fault_domain_count": "2", 43 | "platform_update_domain_count": "20" 44 | } 45 | ) 46 | print("Create availability set:\n{}".format(availability_set)) 47 | 48 | # Get availability set 49 | availability_set = compute_client.availability_sets.get( 50 | GROUP_NAME, 51 | AVAILABILITY_SET_NAME 52 | ) 53 | print("Get availability set:\n{}".format(availability_set)) 54 | 55 | # Update availability set 56 | availability_set = compute_client.availability_sets.update( 57 | GROUP_NAME, 58 | AVAILABILITY_SET_NAME, 59 | { 60 | "platform_fault_domain_count": "2", 61 | "platform_update_domain_count": "20" 62 | } 63 | ) 64 | print("Update availability set:\n{}".format(availability_set)) 65 | 66 | # Delete availability set 67 | compute_client.availability_sets.delete( 68 | GROUP_NAME, 69 | AVAILABILITY_SET_NAME 70 | ) 71 | print("Delete availability set.\n") 72 | 73 | # Delete Group 74 | resource_client.resource_groups.begin_delete( 75 | GROUP_NAME 76 | ).result() 77 | 78 | 79 | if __name__ == "__main__": 80 | main() 81 | -------------------------------------------------------------------------------- /samples/compute/manage_disk.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.compute import ComputeManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | DISK = "diskxxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | compute_client = ComputeManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create disk 38 | disk = compute_client.disks.begin_create_or_update( 39 | GROUP_NAME, 40 | DISK, 41 | { 42 | "location": "eastus", 43 | "creation_data": { 44 | "create_option": "Empty" 45 | }, 46 | "disk_size_gb": "200" 47 | } 48 | ).result() 49 | print("Create disk:\n{}".format(disk)) 50 | 51 | # Get disk 52 | disk = compute_client.disks.get( 53 | GROUP_NAME, 54 | DISK 55 | ) 56 | print("Get disk:\n{}".format(disk)) 57 | 58 | # Update disk 59 | disk = compute_client.disks.begin_update( 60 | GROUP_NAME, 61 | DISK, 62 | { 63 | "disk_size_gb": "200" 64 | } 65 | ).result() 66 | print("Update disk:\n{}".format(disk)) 67 | 68 | # Delete disk 69 | disk = compute_client.disks.begin_delete( 70 | GROUP_NAME, 71 | DISK 72 | ).result() 73 | print("Delete disk.\n") 74 | 75 | # Delete Group 76 | resource_client.resource_groups.begin_delete( 77 | GROUP_NAME 78 | ).result() 79 | 80 | 81 | if __name__ == "__main__": 82 | main() 83 | -------------------------------------------------------------------------------- /samples/compute/manage_proximity_placement_group.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.compute import ComputeManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | PROXIMITY_PLACEMENT_GROUP_NAME = "proximityplacementgroup" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | compute_client = ComputeManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create proximity placement group 37 | proximity_placement_group = compute_client.proximity_placement_groups.create_or_update( 38 | GROUP_NAME, 39 | PROXIMITY_PLACEMENT_GROUP_NAME, 40 | { 41 | "location": "eastus", 42 | "proximity_placement_group_type": "Standard" 43 | } 44 | ) 45 | print("Create proximity placement group:\n{}".format(proximity_placement_group)) 46 | 47 | # Get proximity placement group 48 | proximity_placement_group = compute_client.proximity_placement_groups.get( 49 | GROUP_NAME, 50 | PROXIMITY_PLACEMENT_GROUP_NAME 51 | ) 52 | print("Get proximity placement group:\n{}".format(proximity_placement_group)) 53 | 54 | # Update proximity placement group 55 | proximity_placement_group = compute_client.proximity_placement_groups.update( 56 | GROUP_NAME, 57 | PROXIMITY_PLACEMENT_GROUP_NAME, 58 | { 59 | "location": "eastus", 60 | "proximity_placement_group_type": "Standard" 61 | } 62 | ) 63 | print("Update proximity placement group:\n{}".format(proximity_placement_group)) 64 | 65 | # Delete proximity placement group 66 | compute_client.proximity_placement_groups.delete( 67 | GROUP_NAME, 68 | PROXIMITY_PLACEMENT_GROUP_NAME 69 | ) 70 | print("Delete proximity placement group.\n") 71 | 72 | # Delete Group 73 | resource_client.resource_groups.begin_delete( 74 | GROUP_NAME 75 | ).result() 76 | 77 | 78 | if __name__ == "__main__": 79 | main() 80 | -------------------------------------------------------------------------------- /samples/compute/manage_virtual_machine_create_run_commands.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | from azure.identity import DefaultAzureCredential 8 | from azure.mgmt.compute import ComputeManagementClient 9 | 10 | 11 | # reference with https://learn.microsoft.com/en-us/azure/virtual-machines/linux/run-command-managed#execute-a-script-with-the-vm 12 | def main(): 13 | SUBSCRIPTION_ID = os.environ.get("AZURE_SUBSCRIPTION_ID", None) 14 | GROUP_NAME = "vm-run-command" # you need to create it before run the file 15 | VIRTUAL_MACHINE_NAME = "vm-run-command" # you need to create it before run the file 16 | LOCATION = 'eastus' 17 | 18 | compute_client = ComputeManagementClient(DefaultAzureCredential(), SUBSCRIPTION_ID) 19 | compute_client.virtual_machine_run_commands.begin_create_or_update( 20 | resource_group_name=GROUP_NAME, 21 | vm_name=VIRTUAL_MACHINE_NAME, 22 | run_command_name='mkdir', 23 | run_command={ 24 | "location": LOCATION, 25 | "properties": { 26 | "source": { 27 | 'script': 'cd /home;mkdir test-folder' 28 | }, 29 | "timeoutInSeconds": 10000, 30 | } 31 | } 32 | ).result() 33 | result = list(compute_client.virtual_machine_run_commands.list_by_virtual_machine( 34 | resource_group_name=GROUP_NAME, 35 | vm_name=VIRTUAL_MACHINE_NAME 36 | )) 37 | for item in result: 38 | print(item) 39 | 40 | 41 | if __name__ == "__main__": 42 | main() 43 | -------------------------------------------------------------------------------- /samples/compute/manage_virtual_machine_cross_tenant.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | from azure.identity import ClientSecretCredential 7 | from azure.mgmt.core.policies import AuxiliaryAuthenticationPolicy 8 | from azure.mgmt.compute import ComputeManagementClient 9 | 10 | 11 | # this docs show how to use Python SDK to authenticate across tenants. For more info, please refer to 12 | # https://learn.microsoft.com/en-us/azure/azure-resource-manager/management/authenticate-multi-tenant 13 | def main(): 14 | cred1 = ClientSecretCredential(tenant_id="your_teanantId1", client_id="your_clientId1", 15 | client_secret="your_clientSecret1") 16 | cred2 = ClientSecretCredential(tenant_id="your_teanantId2", client_id="your_clientId2", 17 | client_secret="your_clientSecret2") 18 | auth_policy = AuxiliaryAuthenticationPolicy(auxiliary_credentials=[cred1, cred2], 19 | scopes=['https://management.azure.com/.default']) 20 | compute_client = ComputeManagementClient( 21 | credential=cred1, 22 | subscription_id="your_subId", 23 | authentication_policy=auth_policy 24 | ) 25 | 26 | # Create virtual machine 27 | vm = compute_client.virtual_machines.begin_create_or_update(...).result() 28 | print("Create virtual machine:\n{}".format(vm.serialize())) 29 | 30 | 31 | if __name__ == "__main__": 32 | main() 33 | -------------------------------------------------------------------------------- /samples/compute/manage_virtual_machine_run_command.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | from azure.identity import DefaultAzureCredential 8 | from azure.mgmt.compute import ComputeManagementClient 9 | 10 | # reference with https://learn.microsoft.com/en-us/azure/virtual-machines/linux/run-command#azure-cli 11 | def main(): 12 | SUBSCRIPTION_ID = os.environ.get("AZURE_SUBSCRIPTION_ID", None) 13 | GROUP_NAME = "vm-run-command" # you need to create it before run the file 14 | VIRTUAL_MACHINE_NAME = "vm-run-command" # you need to create it before run the file 15 | 16 | compute_client = ComputeManagementClient(DefaultAzureCredential(), SUBSCRIPTION_ID) 17 | result = compute_client.virtual_machines.begin_run_command( 18 | resource_group_name=GROUP_NAME, 19 | vm_name=VIRTUAL_MACHINE_NAME, 20 | parameters={ 21 | 'commandId': 'RunShellScript', 22 | 'script': [ 23 | 'cd /home', 24 | 'mkdir for-test' 25 | ] 26 | } 27 | ).result() 28 | for item in result.value: 29 | print(item.message) 30 | 31 | if __name__ == "__main__": 32 | main() 33 | -------------------------------------------------------------------------------- /samples/compute/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-keyvault-keys 3 | azure-mgmt-compute>=17.0.0 4 | azure-mgmt-keyvault>=7.0.0 5 | azure-mgmt-network>=16.0.0 6 | azure-mgmt-resource>=15.0.0 7 | azure-mgmt-core>=1.4.0 8 | -------------------------------------------------------------------------------- /samples/consumption/manage_consumption.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | import time 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.consumption import ConsumptionManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | # - other dependence - 14 | # - end - 15 | 16 | 17 | def main(): 18 | 19 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 20 | TIME = str(time.time()).replace('.','') 21 | GROUP_NAME = "testconsumption" + TIME 22 | CONSUMPTION = "consumption" + TIME 23 | 24 | # Create client 25 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 26 | resource_client = ResourceManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | consumption_client = ConsumptionManagementClient( 31 | credential=DefaultAzureCredential(), 32 | subscription_id=SUBSCRIPTION_ID 33 | ) 34 | # - init depended client - 35 | # - end - 36 | 37 | # Create resource group 38 | resource_client.resource_groups.create_or_update( 39 | GROUP_NAME, 40 | {"location": "eastus"} 41 | ) 42 | 43 | # - init depended resources - 44 | # - end - 45 | 46 | # Create consumption 47 | SCOPE = '/subscriptions/{}/resourceGroups/{}'.format(SUBSCRIPTION_ID, GROUP_NAME) 48 | consumption = consumption_client.budgets.create_or_update( 49 | SCOPE, 50 | CONSUMPTION, 51 | { 52 | "category": "Cost", 53 | "amount": '100', 54 | "timeGrain": "Monthly", 55 | "timePeriod": { 56 | "startDate": "2020-10-01T00:00:00Z", 57 | "endDate": "2021-10-31T00:00:00Z" 58 | } 59 | } 60 | ) 61 | print("Create consumption:\n{}\n".format(consumption)) 62 | 63 | # Get consumption 64 | consumption = consumption_client.budgets.get( 65 | SCOPE, 66 | CONSUMPTION 67 | ) 68 | print("Get consumption:\n{}\n".format(consumption)) 69 | 70 | # Delete consumption 71 | consumption_client.budgets.delete( 72 | SCOPE, 73 | CONSUMPTION 74 | ) 75 | print("Delete consumption.\n") 76 | 77 | # Delete Group 78 | resource_client.resource_groups.begin_delete( 79 | GROUP_NAME 80 | ).result() 81 | 82 | 83 | if __name__ == "__main__": 84 | main() 85 | -------------------------------------------------------------------------------- /samples/consumption/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-consumption==8.0.0b1 -------------------------------------------------------------------------------- /samples/containerinstance/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-containerinstance==7.0.0b1 3 | azure-mgmt-resource==15.0.0 4 | -------------------------------------------------------------------------------- /samples/containerregistry/manage_registry.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.containerregistry import ContainerRegistryManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | REGISTRIES = "registriesxxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | registry_client = ContainerRegistryManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create registries 38 | registries = registry_client.registries.begin_create( 39 | GROUP_NAME, 40 | REGISTRIES, 41 | { 42 | "location": "eastus", 43 | "tags": { 44 | "key": "value" 45 | }, 46 | "sku": { 47 | "name": "Standard" 48 | }, 49 | "admin_user_enabled": True 50 | } 51 | ).result() 52 | print("Create registries:\n{}".format(registries)) 53 | 54 | # Get registries 55 | registries = registry_client.registries.get( 56 | GROUP_NAME, 57 | REGISTRIES 58 | ) 59 | print("Get registries:\n{}".format(registries)) 60 | 61 | # Update registries 62 | registries = registry_client.registries.begin_update( 63 | GROUP_NAME, 64 | REGISTRIES, 65 | { 66 | "tags": { 67 | "key": "value" 68 | }, 69 | "sku": { 70 | "name": "Standard" 71 | }, 72 | "admin_user_enabled": True 73 | } 74 | ).result() 75 | print("Update registries:\n{}".format(registries)) 76 | 77 | # Delete registries 78 | registries = registry_client.registries.begin_delete( 79 | GROUP_NAME, 80 | REGISTRIES 81 | ).result() 82 | print("Delete registries.\n") 83 | 84 | # Delete Group 85 | resource_client.resource_groups.begin_delete( 86 | GROUP_NAME 87 | ).result() 88 | 89 | 90 | if __name__ == "__main__": 91 | main() 92 | -------------------------------------------------------------------------------- /samples/containerregistry/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-containerregistry==8.0.0b1 4 | -------------------------------------------------------------------------------- /samples/containerservice/manage_get_versions.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.containerservice import ContainerServiceClient 11 | from dotenv import load_dotenv 12 | 13 | load_dotenv() 14 | 15 | def main(): 16 | # Create client 17 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 18 | client = ContainerServiceClient( 19 | credential=DefaultAzureCredential(), 20 | subscription_id=os.getenv("AZURE_SUBSCRIPTION_ID") 21 | ) 22 | 23 | # Get versions 24 | result = client.container_services.list_orchestrators(location="eastus", resource_type="managedClusters") 25 | print(result.serialize()) 26 | 27 | 28 | if __name__ == "__main__": 29 | main() 30 | -------------------------------------------------------------------------------- /samples/containerservice/requirements.txt: -------------------------------------------------------------------------------- 1 | python-dotenv 2 | azure-identity 3 | azure-mgmt-resource 4 | azure-mgmt-containerservice -------------------------------------------------------------------------------- /samples/cosmosdb/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-cosmosdb==6.4.0 4 | azure-cosmos==4.2.0 5 | -------------------------------------------------------------------------------- /samples/costmanagement/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==20.0.0 3 | azure-mgmt-costmanagement==3.0.0 4 | azure-mgmt-storage==20.0.0 5 | -------------------------------------------------------------------------------- /samples/datalakestore/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-datalake-store==1.0.0b1 -------------------------------------------------------------------------------- /samples/devtestlabs/manage_devtestlabs.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | import time 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.devtestlabs import DevTestLabsClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | # - other dependence - 14 | # - end - 15 | 16 | 17 | def main(): 18 | 19 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 20 | TIME = str(time.time()).replace('.','') 21 | GROUP_NAME = "testdevtestlabs" + TIME 22 | DEVTESTLABS = "devtestlabs" + TIME 23 | LOCATION = 'eastus' 24 | 25 | # Create client 26 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 27 | resource_client = ResourceManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | devtestlabs_client = DevTestLabsClient( 32 | credential=DefaultAzureCredential(), 33 | subscription_id=SUBSCRIPTION_ID 34 | ) 35 | # - init depended client - 36 | # - end - 37 | 38 | # Create resource group 39 | resource_client.resource_groups.create_or_update( 40 | GROUP_NAME, 41 | {"location": LOCATION} 42 | ) 43 | 44 | # - init depended resources - 45 | # - end - 46 | 47 | # Create devtestlabs 48 | devtestlabs = devtestlabs_client.labs.begin_create_or_update( 49 | GROUP_NAME, 50 | DEVTESTLABS, 51 | {'location': LOCATION} 52 | ).result() 53 | print("Create devtestlabs:\n{}".format(devtestlabs)) 54 | 55 | # Get devtestlabs 56 | devtestlabs = devtestlabs_client.labs.get( 57 | GROUP_NAME, 58 | DEVTESTLABS 59 | ) 60 | print("Get devtestlabs:\n{}".format(devtestlabs)) 61 | 62 | # Update devtestlabs 63 | BODY = { 64 | "properties": { 65 | "labStorageType": "Premium" 66 | } 67 | } 68 | devtestlabs = devtestlabs_client.labs.update( 69 | GROUP_NAME, 70 | DEVTESTLABS, 71 | BODY 72 | ) 73 | print("Update devtestlabs:\n{}".format(devtestlabs)) 74 | 75 | # Delete devtestlabs 76 | devtestlabs = devtestlabs_client.labs.begin_delete( 77 | GROUP_NAME, 78 | DEVTESTLABS 79 | ).result() 80 | print("Delete devtestlabs.\n") 81 | 82 | # Delete Group 83 | resource_client.resource_groups.begin_delete( 84 | GROUP_NAME 85 | ).result() 86 | 87 | 88 | if __name__ == "__main__": 89 | main() 90 | -------------------------------------------------------------------------------- /samples/devtestlabs/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-devtestlabs==9.0.0b1 -------------------------------------------------------------------------------- /samples/eventgrid/manage_servicename.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | import time 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.eventgrid import EventGridManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | # - other dependence - 14 | # - end - 15 | 16 | 17 | def main(): 18 | 19 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 20 | TIME = str(time.time()).replace('.','') 21 | GROUP_NAME = "testeventgrid" + TIME 22 | EVENTGRID = "eventgrid" + TIME 23 | LOCATION='eastus' 24 | 25 | # Create client 26 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 27 | resource_client = ResourceManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | eventgrid_client = EventGridManagementClient( 32 | credential=DefaultAzureCredential(), 33 | subscription_id=SUBSCRIPTION_ID 34 | ) 35 | # - init depended client - 36 | # - end - 37 | 38 | # Create resource group 39 | resource_client.resource_groups.create_or_update( 40 | GROUP_NAME, 41 | {"location": LOCATION} 42 | ) 43 | 44 | # - init depended resources - 45 | # - end - 46 | 47 | # Create eventgrid 48 | eventgrid = eventgrid_client.domains.begin_create_or_update( 49 | GROUP_NAME, 50 | EVENTGRID, 51 | { 52 | "location":LOCATION 53 | } 54 | ).result() 55 | print("Create eventgrid:\n{}".format(eventgrid)) 56 | 57 | # Get eventgrid 58 | eventgrid = eventgrid_client.domains.get( 59 | GROUP_NAME, 60 | EVENTGRID 61 | ) 62 | print("Get eventgrid:\n{}".format(eventgrid)) 63 | 64 | # Update eventgrid 65 | eventgrid = eventgrid_client.domains.begin_update( 66 | GROUP_NAME, 67 | EVENTGRID, 68 | { 69 | "tags": { 70 | "tag1": "value1", 71 | "tag2": "value2" 72 | } 73 | } 74 | ).result() 75 | print("Update eventgrid:\n{}".format(eventgrid)) 76 | 77 | # Delete eventgrid 78 | eventgrid_client.domains.begin_delete( 79 | GROUP_NAME, 80 | EVENTGRID 81 | ).result() 82 | print("Delete eventgrid.\n") 83 | 84 | # Delete Group 85 | resource_client.resource_groups.begin_delete( 86 | GROUP_NAME 87 | ).result() 88 | 89 | 90 | if __name__ == "__main__": 91 | main() 92 | -------------------------------------------------------------------------------- /samples/eventgrid/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-eventgrid==8.0.0b1 -------------------------------------------------------------------------------- /samples/eventhub/manage_namespace.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.eventhub import EventHubManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | NAMESPACE_NAME = "namespacex" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | 26 | eventhub_client = EventHubManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create Namespace 38 | namesapce = eventhub_client.namespaces.begin_create_or_update( 39 | GROUP_NAME, 40 | NAMESPACE_NAME, 41 | { 42 | "sku": { 43 | "name": "Standard", 44 | "tier": "Standard" 45 | }, 46 | "location": "eastus", 47 | "tags": { 48 | "tag1": "value1", 49 | "tag2": "value2" 50 | } 51 | } 52 | ).result() 53 | print("Create Namespace: {}".format(namesapce)) 54 | 55 | # Get Namesapce 56 | namespace = eventhub_client.namespaces.get( 57 | GROUP_NAME, 58 | NAMESPACE_NAME 59 | ) 60 | print("Get Namespace: {}".format(namespace)) 61 | 62 | # Update Namespace 63 | namespace = eventhub_client.namespaces.update( 64 | GROUP_NAME, 65 | NAMESPACE_NAME, 66 | { 67 | "location": "eastus", 68 | "tags": { 69 | "tag3": "value3", 70 | "tag4": "value4" 71 | } 72 | } 73 | ) 74 | print("Update Namespace: {}".format(namesapce)) 75 | 76 | # Delete Namespace 77 | eventhub_client.namespaces.begin_delete( 78 | GROUP_NAME, 79 | NAMESPACE_NAME 80 | ).result() 81 | print("Delete Namespace.") 82 | 83 | # Delete resource group 84 | resource_client.resource_groups.begin_delete( 85 | GROUP_NAME 86 | ).result() 87 | 88 | 89 | if __name__ == "__main__": 90 | main() 91 | -------------------------------------------------------------------------------- /samples/eventhub/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-eventhub==8.0.0 3 | azure-mgmt-resource==15.0.0 4 | azure-mgmt-storage==16.0.0 5 | -------------------------------------------------------------------------------- /samples/hdinsight/manage_hdinsignt.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | import time 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.hdinsight import HDInsightManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | # - other dependence - 15 | # - end - 16 | 17 | 18 | def main(): 19 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 20 | TIME = str(time.time()).replace('.', '') 21 | GROUP_NAME = "testhdinsight" + TIME 22 | 23 | # Create client 24 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 25 | resource_client = ResourceManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | hdinsight_client = HDInsightManagementClient( 31 | credential=DefaultAzureCredential(), 32 | subscription_id=SUBSCRIPTION_ID 33 | ) 34 | # - init depended client - 35 | # - end - 36 | 37 | # Create resource group 38 | resource_client.resource_groups.create_or_update( 39 | GROUP_NAME, 40 | {"location": "eastus"} 41 | ) 42 | 43 | # - init depended resources - 44 | # - end - 45 | 46 | # Create hdinsight 47 | hdinsight_client.operations.list() 48 | print("operations:\n") 49 | 50 | # Delete Group 51 | resource_client.resource_groups.begin_delete( 52 | GROUP_NAME 53 | ).result() 54 | 55 | 56 | if __name__ == "__main__": 57 | main() 58 | -------------------------------------------------------------------------------- /samples/hdinsight/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-hdinsight==7.0.0b1 4 | -------------------------------------------------------------------------------- /samples/iothub/manage_resource.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.iothub import IotHubClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | IOT_HUB_RESOURCE = "iothubresourcexxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | iothub_client = IotHubClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create iot hub resource 38 | iot_hub_resource = iothub_client.iot_hub_resource.begin_create_or_update( 39 | GROUP_NAME, 40 | IOT_HUB_RESOURCE, 41 | { 42 | 'location': "eastus", 43 | 'subscriptionid': SUBSCRIPTION_ID, 44 | 'resourcegroup': GROUP_NAME, 45 | 'sku': { 46 | 'name': 'S1', 47 | 'capacity': 2 48 | }, 49 | 'properties': { 50 | 'enable_file_upload_notifications': False, 51 | 'operations_monitoring_properties': { 52 | 'events': { 53 | "C2DCommands": "Error", 54 | "DeviceTelemetry": "Error", 55 | "DeviceIdentityOperations": "Error", 56 | "Connections": "Information" 57 | } 58 | }, 59 | "features": "None", 60 | } 61 | } 62 | ).result() 63 | print("Create iot hub resource:\n{}".format(iot_hub_resource)) 64 | 65 | # Get iot hub resource 66 | iot_hub_resource = iothub_client.iot_hub_resource.get( 67 | GROUP_NAME, 68 | IOT_HUB_RESOURCE 69 | ) 70 | print("Get iot hub resource:\n{}".format(iot_hub_resource)) 71 | 72 | # Delete iot hub resource 73 | iot_hub_resource = iothub_client.iot_hub_resource.begin_delete( 74 | GROUP_NAME, 75 | IOT_HUB_RESOURCE 76 | ).result() 77 | print("Delete iot hub resource.\n") 78 | 79 | # Delete Group 80 | resource_client.resource_groups.begin_delete( 81 | GROUP_NAME 82 | ).result() 83 | 84 | 85 | if __name__ == "__main__": 86 | main() 87 | -------------------------------------------------------------------------------- /samples/iothub/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-iothub==1.0.0b1 3 | azure-mgmt-resource>=15.0.0 4 | -------------------------------------------------------------------------------- /samples/iothubprovisioningservices/manage_resource.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.iothubprovisioningservices import IotDpsClient, models 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | IOT_DPS_RESOURCE = "iotdpsresourcexxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | iotdps_client = IotDpsClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Get iot dps resource 38 | iot_dps_resource = iotdps_client.iot_dps_resource.begin_create_or_update( 39 | GROUP_NAME, 40 | IOT_DPS_RESOURCE, 41 | { 42 | "location": "eastus", 43 | "subscriptionid": SUBSCRIPTION_ID, 44 | "resourcegroup": GROUP_NAME, 45 | "type": "Microsoft.Devices/ProvisioningServices", 46 | "sku": { 47 | "name": "S1", 48 | "tier": "Standard", 49 | "capacity": "1" 50 | }, 51 | "properties": {} 52 | } 53 | ).result() 54 | print("Create iot dps resource:\n{}".format(iot_dps_resource)) 55 | 56 | # Get iot dps resource 57 | iot_dps_resource = iotdps_client.iot_dps_resource.get( 58 | IOT_DPS_RESOURCE, 59 | GROUP_NAME 60 | ) 61 | print("Get iot hub resource:\n{}".format(iot_dps_resource)) 62 | 63 | # Delete iot dps resource 64 | iot_dps_resource = iotdps_client.iot_dps_resource.begin_delete( 65 | IOT_DPS_RESOURCE, 66 | GROUP_NAME 67 | ).result() 68 | print("Delete iot dps resource.\n") 69 | 70 | # Delete Group 71 | resource_client.resource_groups.begin_delete( 72 | GROUP_NAME 73 | ).result() 74 | 75 | 76 | if __name__ == "__main__": 77 | main() 78 | -------------------------------------------------------------------------------- /samples/iothubprovisioningservices/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-iothubprovisioningservices==1.0.0b1 3 | azure-mgmt-resource>=15.0.0 4 | -------------------------------------------------------------------------------- /samples/keyvault/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-keyvault==7.0.0 4 | -------------------------------------------------------------------------------- /samples/labservices/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-mgmt-resource==21.1.0 2 | azure-identity==1.10.0 3 | azure-mgmt-labservices==2.0.0b1 -------------------------------------------------------------------------------- /samples/loadtesting/requirements.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Azure-Samples/azure-samples-python-management/d2909ba8c3cd7881f1e7dd05c15e1b8378b5c969/samples/loadtesting/requirements.txt -------------------------------------------------------------------------------- /samples/loganalytics/manage_tables_list_by_workspace.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | from azure.identity import DefaultAzureCredential 4 | from azure.mgmt.resource import ResourceManagementClient 5 | from azure.mgmt.loganalytics import LogAnalyticsManagementClient 6 | 7 | 8 | def main(): 9 | subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"] 10 | credentials = DefaultAzureCredential() 11 | GROUP_NAME = "test" 12 | workspace_name = "testWorkspace" 13 | 14 | resource_client = ResourceManagementClient( 15 | credential=DefaultAzureCredential(), 16 | subscription_id=subscription_id 17 | ) 18 | 19 | loganalytics_client = LogAnalyticsManagementClient(credentials, subscription_id) 20 | 21 | resource_client.resource_groups.create_or_update( 22 | GROUP_NAME, 23 | {"location": "eastus"} 24 | ) 25 | 26 | log_analytics_client.workspaces.begin_create_or_update( 27 | resource_group_name=GROUP_NAME, 28 | workspace_name=workspace_name, 29 | parameters={ 30 | "location": "australiasoutheast", 31 | "properties": {"retentionInDays": 30, "sku": {"name": "PerGB2018"}}, 32 | "tags": {"tag1": "val1"}, 33 | }, 34 | ).result() 35 | 36 | response = log_analytics_client.tables.list_by_workspace( 37 | resource_group_name=GROUP_NAME, 38 | workspace_name=workspace_name 39 | ) 40 | for item in response: 41 | print(json.dumps(item.serialize())) 42 | 43 | loganalytics_client.workspaces.begin_delete( 44 | GROUP_NAME, 45 | workspace_name 46 | ).result() 47 | 48 | resource_client.resource_groups.begin_delete( 49 | GROUP_NAME 50 | ).result() 51 | 52 | 53 | if __name__ == '__main__': 54 | main() 55 | -------------------------------------------------------------------------------- /samples/loganalytics/manage_workspace.py: -------------------------------------------------------------------------------- 1 | import os 2 | from azure.identity import DefaultAzureCredential 3 | from azure.mgmt.resource import ResourceManagementClient 4 | from azure.mgmt.loganalytics import LogAnalyticsManagementClient 5 | 6 | 7 | def main(): 8 | subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"] 9 | credentials = DefaultAzureCredential() 10 | GROUP_NAME = "test" 11 | workspace_name="testWorkspace" 12 | resource_client = ResourceManagementClient( 13 | credential=DefaultAzureCredential(), 14 | subscription_id=subscription_id 15 | ) 16 | # 17 | loganalytics_client = LogAnalyticsManagementClient(credentials, subscription_id,) 18 | resource_client.resource_groups.create_or_update( 19 | GROUP_NAME, 20 | {"location": "eastus"} 21 | 22 | ) 23 | 24 | loganalytics=loganalytics_client.workspaces.begin_create_or_update( 25 | GROUP_NAME, 26 | workspace_name, 27 | {"location": "eastus"} 28 | ).result() 29 | print("Create consumption:\n{}\n".format(loganalytics)) 30 | 31 | loganalytics=loganalytics_client.workspaces.list() 32 | print("List consumption:") 33 | for loganalytics_list in loganalytics: 34 | print(loganalytics_list) 35 | 36 | loganalytics=loganalytics_client.workspaces.get( 37 | GROUP_NAME, 38 | workspace_name 39 | ) 40 | print("\nGet consumption:\n{}\n".format(loganalytics)) 41 | 42 | 43 | loganalytics=loganalytics_client.workspaces.begin_delete( 44 | GROUP_NAME, 45 | workspace_name 46 | ).result() 47 | print("Delete consumption:\n{}\n".format(loganalytics)) 48 | 49 | resource_client.resource_groups.begin_delete( 50 | GROUP_NAME 51 | ).result() 52 | 53 | 54 | if __name__ == "__main__": 55 | main() 56 | -------------------------------------------------------------------------------- /samples/loganalytics/manage_workspace_with_gov_cloud.py: -------------------------------------------------------------------------------- 1 | import os 2 | from msrestazure.azure_cloud import AZURE_US_GOV_CLOUD 3 | from azure.identity import DefaultAzureCredential 4 | from azure.mgmt.resource import ResourceManagementClient 5 | from azure.mgmt.loganalytics import LogAnalyticsManagementClient 6 | 7 | 8 | def main(): 9 | subscription_id = os.environ["AZURE_SUBSCRIPTION_ID"] 10 | credentials = DefaultAzureCredential() 11 | GROUP_NAME = "test" 12 | workspace_name="testWorkspace" 13 | resource_client = ResourceManagementClient( 14 | credential=DefaultAzureCredential(), 15 | subscription_id=subscription_id 16 | ) 17 | # 18 | loganalytics_client_gov = LogAnalyticsManagementClient(credentials, subscription_id, 19 | base_url=AZURE_US_GOV_CLOUD.endpoints.resource_manager, 20 | credential_scopes=[ 21 | AZURE_US_GOV_CLOUD.endpoints.resource_manager + ".default"]) 22 | resource_client.resource_groups.create_or_update( 23 | GROUP_NAME, 24 | {"location": "eastus"} 25 | ) 26 | 27 | loganalytics = loganalytics_client_gov.workspaces.begin_create_or_update( 28 | GROUP_NAME, 29 | workspace_name, 30 | {"location": "eastus"} 31 | ).result() 32 | print("Create consumption:\n{}\n".format(loganalytics)) 33 | 34 | loganalytics = loganalytics_client_gov.workspaces.list() 35 | print("List consumption:") 36 | for loganalytics_list in loganalytics: 37 | print(loganalytics_list) 38 | 39 | loganalytics = loganalytics_client_gov.workspaces.get( 40 | GROUP_NAME, 41 | workspace_name 42 | ) 43 | print("\nGet consumption:\n{}\n".format(loganalytics)) 44 | 45 | loganalytics = loganalytics_client_gov.workspaces.begin_delete( 46 | GROUP_NAME, 47 | workspace_name 48 | ).result() 49 | print("Delete consumption:\n{}\n".format(loganalytics)) 50 | 51 | 52 | if __name__ == "__main__": 53 | main() 54 | -------------------------------------------------------------------------------- /samples/loganalytics/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==20.0.0 3 | azure-mgmt-loganalytics==12.0.0 4 | msrestazure==0.6.4 -------------------------------------------------------------------------------- /samples/logic/manage_logic.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.logic import LogicManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | from azure.mgmt.logic.models import Workflow 13 | 14 | # - other dependence - 15 | # - end - 16 | 17 | 18 | def main(): 19 | 20 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 21 | GROUP_NAME = "logictest" 22 | WORKFLOW_NAME = '12HourHeartBeat' 23 | location="West US" 24 | 25 | # Create client 26 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 27 | resource_client = ResourceManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | logic_client = LogicManagementClient( 32 | credential=DefaultAzureCredential(), 33 | subscription_id=SUBSCRIPTION_ID 34 | ) 35 | # - init depended client - 36 | # - end - 37 | 38 | # Create resource group 39 | resource_client.resource_groups.create_or_update( 40 | GROUP_NAME, 41 | {"location": location} 42 | ) 43 | 44 | # - init depended resources - 45 | # - end - 46 | 47 | # Create logic 48 | workflow = Workflow( 49 | location=location, 50 | definition={ 51 | "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#", 52 | "contentVersion": "1.0.0.0", 53 | "parameters": {}, 54 | "triggers": {}, 55 | "actions": {}, 56 | "outputs": {} 57 | } 58 | ) 59 | logic_client.workflows.create_or_update( 60 | GROUP_NAME, 61 | WORKFLOW_NAME, 62 | workflow 63 | ) 64 | print("Create logic:\n") 65 | 66 | # Get logic 67 | logic_client.workflows.get( 68 | GROUP_NAME, 69 | WORKFLOW_NAME 70 | ) 71 | print("Get logic:\n") 72 | 73 | # Delete logic 74 | logic_client.workflows.delete( 75 | GROUP_NAME, 76 | WORKFLOW_NAME 77 | ) 78 | print("Delete logic.\n") 79 | 80 | # Delete Group 81 | resource_client.resource_groups.begin_delete( 82 | GROUP_NAME 83 | ).result() 84 | 85 | 86 | if __name__ == "__main__": 87 | main() 88 | -------------------------------------------------------------------------------- /samples/logic/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-logic==9.0.0b1 -------------------------------------------------------------------------------- /samples/machinelearningservices/manage_machinelearningservices.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.machinelearningservices import AzureMachineLearningWorkspaces 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | # - other dependence - 14 | # - end - 15 | 16 | 17 | def main(): 18 | 19 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 20 | GROUP_NAME = "testgroupx" 21 | MACHINELEARNINGSERVICES = "machinelearningservicesxxyyzz" 22 | 23 | # Create client 24 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 25 | resource_client = ResourceManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | machinelearningservices_client = AzureMachineLearningWorkspaces( 30 | credential=DefaultAzureCredential(), 31 | subscription_id=SUBSCRIPTION_ID 32 | ) 33 | # - init depended client - 34 | # - end - 35 | 36 | # Create resource group 37 | resource_client.resource_groups.create_or_update( 38 | GROUP_NAME, 39 | {"location": "eastus"} 40 | ) 41 | 42 | # - init depended resources - 43 | # - end - 44 | 45 | # Create machinelearningservices 46 | machinelearningservices_client.operations.list() 47 | print("list:\n") 48 | 49 | # Delete Group 50 | resource_client.resource_groups.begin_delete( 51 | GROUP_NAME 52 | ).result() 53 | 54 | 55 | if __name__ == "__main__": 56 | main() 57 | -------------------------------------------------------------------------------- /samples/machinelearningservices/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-machinelearningservices==1.0.0b1 -------------------------------------------------------------------------------- /samples/marketplaceordering/manage_marketplace_agreement.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.marketplaceordering import MarketplaceOrderingAgreements 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | 17 | # Create client 18 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 19 | marketplaceordering_client = MarketplaceOrderingAgreements( 20 | credential=DefaultAzureCredential(), 21 | subscription_id=SUBSCRIPTION_ID 22 | ) 23 | 24 | # Get marketplace agreement 25 | marketplace_agreement = marketplaceordering_client.marketplace_agreements.get( 26 | offer_type="virtualmachine", 27 | publisher_id="intel-bigdl", 28 | offer_id="bigdl_vm", 29 | plan_id="bigdl_vm_0p4" 30 | ) 31 | print("Get marketplace agreement:\n{}".format(marketplace_agreement)) 32 | 33 | 34 | if __name__ == "__main__": 35 | main() 36 | -------------------------------------------------------------------------------- /samples/marketplaceordering/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-marketplaceordering==1.0.0b1 3 | -------------------------------------------------------------------------------- /samples/monitor/manage_metric_list.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.monitor import MonitorManagementClient 10 | 11 | 12 | def main(): 13 | credentials = DefaultAzureCredential() 14 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 15 | 16 | monitor_client = MonitorManagementClient(credentials, SUBSCRIPTION_ID) 17 | 18 | result = monitor_client.metrics.list( 19 | resource_uri="resourceUri", 20 | # timespan="2022-12-14T05:38:44Z/2022-12-14T06:38:44Z", 21 | timespan="timeSpan", 22 | # metricnamespace="Microsoft.Storage/storageAccounts", 23 | metricnamespace="metricNamespace", 24 | # filter="dim eq 'AccountResourceId'", 25 | filter="dim eq 'type'", 26 | top=3, 27 | orderby="Average asc", 28 | aggregation="Average,count", 29 | interval="PT1H" 30 | ) 31 | print(result) 32 | 33 | 34 | if __name__ == '__main__': 35 | main() 36 | -------------------------------------------------------------------------------- /samples/monitor/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-compute==17.0.0 3 | azure-mgmt-monitor==1.0.0 4 | azure-mgmt-network==16.0.0 5 | azure-mgmt-resource==15.0.0 6 | azure-mgmt-storage==16.0.0 7 | -------------------------------------------------------------------------------- /samples/network/ddos/manage_ddos_protection_plan.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | DDOS_PROTECTION_PLAN = "ddos_protection_planxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create ddos protection plan 37 | ddos_protection_plan = network_client.ddos_protection_plans.begin_create_or_update( 38 | GROUP_NAME, 39 | DDOS_PROTECTION_PLAN, 40 | { 41 | "location": "westus" 42 | } 43 | ).result() 44 | print("Create ddos protection plan:\n{}".format(ddos_protection_plan)) 45 | 46 | # Get ddos protection plan 47 | ddos_protection_plan = network_client.ddos_protection_plans.get( 48 | GROUP_NAME, 49 | DDOS_PROTECTION_PLAN 50 | ) 51 | print("Get ddos protection plan:\n{}".format(ddos_protection_plan)) 52 | 53 | # Update ddos protection plan 54 | ddos_protection_plan = network_client.ddos_protection_plans.update_tags( 55 | GROUP_NAME, 56 | DDOS_PROTECTION_PLAN, 57 | { 58 | "tags": { 59 | "tag1": "value1", 60 | "tag2": "value2" 61 | } 62 | } 63 | ) 64 | print("Update ddos protection plan:\n{}".format(ddos_protection_plan)) 65 | 66 | # Delete ddos protection plan 67 | ddos_protection_plan = network_client.ddos_protection_plans.begin_delete( 68 | GROUP_NAME, 69 | DDOS_PROTECTION_PLAN 70 | ).result() 71 | print("Delete ddos protection plan.\n") 72 | 73 | # Delete Group 74 | resource_client.resource_groups.begin_delete( 75 | GROUP_NAME 76 | ).result() 77 | 78 | 79 | if __name__ == "__main__": 80 | main() 81 | 82 | -------------------------------------------------------------------------------- /samples/network/endpoint/manage_service_endpoint_policy.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | SERVICE_ENDPOINT_POLICY = "service_endpoint_policyxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create service endpoint policy 37 | service_endpoint_policy = network_client.service_endpoint_policies.begin_create_or_update( 38 | GROUP_NAME, 39 | SERVICE_ENDPOINT_POLICY, 40 | { 41 | "location": "eastus" 42 | } 43 | ).result() 44 | print("Create service endpoint policy:\n{}".format(service_endpoint_policy)) 45 | 46 | # Get service endpoint policy 47 | service_endpoint_policy = network_client.service_endpoint_policies.get( 48 | GROUP_NAME, 49 | SERVICE_ENDPOINT_POLICY 50 | ) 51 | print("Get service endpoint policy:\n{}".format(service_endpoint_policy)) 52 | 53 | # Update service endpoint policy 54 | service_endpoint_policy = network_client.service_endpoint_policies.update_tags( 55 | GROUP_NAME, 56 | SERVICE_ENDPOINT_POLICY, 57 | { 58 | "tags": { 59 | "tag1": "value1", 60 | "tag2": "value2" 61 | } 62 | } 63 | ) 64 | print("Update service endpoint policy:\n{}".format(service_endpoint_policy)) 65 | 66 | # Delete service endpoint policy 67 | service_endpoint_policy = network_client.service_endpoint_policies.begin_delete( 68 | GROUP_NAME, 69 | SERVICE_ENDPOINT_POLICY 70 | ).result() 71 | print("Delete service endpoint policy.\n") 72 | 73 | # Delete Group 74 | resource_client.resource_groups.begin_delete( 75 | GROUP_NAME 76 | ).result() 77 | 78 | 79 | if __name__ == "__main__": 80 | main() 81 | -------------------------------------------------------------------------------- /samples/network/firewall/manage_firewall_policy.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | FIREWALL_POLICY = "firewall_policyxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create firewall policy 37 | firewall_policy = network_client.firewall_policies.begin_create_or_update( 38 | GROUP_NAME, 39 | FIREWALL_POLICY, 40 | { 41 | "tags": { 42 | "key1": "value1" 43 | }, 44 | "location": "West US", 45 | "threat_intel_mode": "Alert" 46 | } 47 | ).result() 48 | print("Create firewall policy:\n{}".format(firewall_policy)) 49 | 50 | # Get firewall policy 51 | firewall_policy = network_client.firewall_policies.get( 52 | GROUP_NAME, 53 | FIREWALL_POLICY 54 | ) 55 | print("Get firewall policy:\n{}".format(firewall_policy)) 56 | 57 | # Delete firewall policy 58 | firewall_policy = network_client.firewall_policies.begin_delete( 59 | GROUP_NAME, 60 | FIREWALL_POLICY 61 | ).result() 62 | print("Delete firewall policy.\n") 63 | 64 | # Delete Group 65 | resource_client.resource_groups.begin_delete( 66 | GROUP_NAME 67 | ).result() 68 | 69 | 70 | if __name__ == "__main__": 71 | main() 72 | -------------------------------------------------------------------------------- /samples/network/firewall/manage_web_application_firewall_policy.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | WEB_APPLICATION_FIREWALL_POLICY = "web_application_firewall_policyxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create web application firewall policy 37 | web_application_firewall_policy = network_client.web_application_firewall_policies.create_or_update( 38 | GROUP_NAME, 39 | WEB_APPLICATION_FIREWALL_POLICY, 40 | { 41 | "location": "WestUs", 42 | "managed_rules": { 43 | "managed_rule_sets": [ 44 | { 45 | "rule_set_type": "OWASP", 46 | "rule_set_version": "3.0" 47 | } 48 | ] 49 | }, 50 | "custom_rules": [] 51 | } 52 | ) 53 | print("Create web application firewall policy:\n{}".format(web_application_firewall_policy)) 54 | 55 | # Get web application firewall policy 56 | web_application_firewall_policy = network_client.web_application_firewall_policies.get( 57 | GROUP_NAME, 58 | WEB_APPLICATION_FIREWALL_POLICY 59 | ) 60 | print("Get web application firewall policy:\n{}".format(web_application_firewall_policy)) 61 | 62 | # Delete web application firewall policy 63 | web_application_firewall_policy = network_client.web_application_firewall_policies.begin_delete( 64 | GROUP_NAME, 65 | WEB_APPLICATION_FIREWALL_POLICY 66 | ).result() 67 | print("Delete web application firewall policy.\n") 68 | 69 | # Delete Group 70 | resource_client.resource_groups.begin_delete( 71 | GROUP_NAME 72 | ).result() 73 | 74 | 75 | if __name__ == "__main__": 76 | main() 77 | -------------------------------------------------------------------------------- /samples/network/ip/manage_ip_group.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | IP_GROUP = "ip_groupxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create ip group 37 | ip_group = network_client.ip_groups.begin_create_or_update( 38 | GROUP_NAME, 39 | IP_GROUP, 40 | { 41 | "tags": { 42 | "key1": "value1" 43 | }, 44 | "location": "West US", 45 | "ip_addresses": [ 46 | "13.64.39.16/32", 47 | "40.74.146.80/31", 48 | "40.74.147.32/28" 49 | ] 50 | } 51 | ).result() 52 | print("Create ip group:\n{}".format(ip_group)) 53 | 54 | # Get ip group 55 | ip_group = network_client.ip_groups.get( 56 | GROUP_NAME, 57 | IP_GROUP 58 | ) 59 | print("Get ip group:\n{}".format(ip_group)) 60 | 61 | # Delete ip group 62 | ip_group = network_client.ip_groups.begin_delete( 63 | GROUP_NAME, 64 | IP_GROUP 65 | ).result() 66 | print("Delete ip group.\n") 67 | 68 | # Delete Group 69 | resource_client.resource_groups.begin_delete( 70 | GROUP_NAME 71 | ).result() 72 | 73 | 74 | if __name__ == "__main__": 75 | main() 76 | -------------------------------------------------------------------------------- /samples/network/ip/manage_ip_prefix.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | PUBLIC_IP_PREFIX = "public_ip_prefixxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create public ip prefix 37 | public_ip_prefix = network_client.public_ip_prefixes.begin_create_or_update( 38 | GROUP_NAME, 39 | PUBLIC_IP_PREFIX, 40 | { 41 | "location": "westus", 42 | "prefix_length": "30", 43 | "sku": { 44 | "name": "Standard" 45 | } 46 | } 47 | ).result() 48 | print("Create public ip prefix:\n{}".format(public_ip_prefix)) 49 | 50 | # Get public ip prefix 51 | public_ip_prefix = network_client.public_ip_prefixes.get( 52 | GROUP_NAME, 53 | PUBLIC_IP_PREFIX 54 | ) 55 | print("Get public ip prefix:\n{}".format(public_ip_prefix)) 56 | 57 | # Update public ip prefix 58 | public_ip_prefix = network_client.public_ip_prefixes.update_tags( 59 | GROUP_NAME, 60 | PUBLIC_IP_PREFIX, 61 | { 62 | "tags": { 63 | "tag1": "value1", 64 | "tag2": "value2" 65 | } 66 | } 67 | ) 68 | print("Update public ip prefix:\n{}".format(public_ip_prefix)) 69 | 70 | # Delete public ip prefix 71 | public_ip_prefix = network_client.public_ip_prefixes.begin_delete( 72 | GROUP_NAME, 73 | PUBLIC_IP_PREFIX 74 | ).result() 75 | print("Delete public ip prefix.\n") 76 | 77 | # Delete Group 78 | resource_client.resource_groups.begin_delete( 79 | GROUP_NAME 80 | ).result() 81 | 82 | 83 | if __name__ == "__main__": 84 | main() 85 | -------------------------------------------------------------------------------- /samples/network/ip/manage_public_ip_address.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | PUBLIC_IP_ADDRESS = "public_ip_addressxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create public ip address 37 | public_ip_address = network_client.public_ip_addresses.begin_create_or_update( 38 | GROUP_NAME, 39 | PUBLIC_IP_ADDRESS, 40 | { 41 | "location": "eastus" 42 | } 43 | ).result() 44 | print("Create public ip address:\n{}".format(public_ip_address)) 45 | 46 | # Get public ip address 47 | public_ip_address = network_client.public_ip_addresses.get( 48 | GROUP_NAME, 49 | PUBLIC_IP_ADDRESS 50 | ) 51 | print("Get public ip address:\n{}".format(public_ip_address)) 52 | 53 | # Update public ip address 54 | public_ip_address = network_client.public_ip_addresses.update_tags( 55 | GROUP_NAME, 56 | PUBLIC_IP_ADDRESS, 57 | { 58 | "tags": { 59 | "tag1": "value1", 60 | "tag2": "value2" 61 | } 62 | } 63 | ) 64 | print("Update public ip address:\n{}".format(public_ip_address)) 65 | 66 | # Delete public ip address 67 | public_ip_address = network_client.public_ip_addresses.begin_delete( 68 | GROUP_NAME, 69 | PUBLIC_IP_ADDRESS 70 | ).result() 71 | print("Delete public ip address.\n") 72 | 73 | # Delete Group 74 | resource_client.resource_groups.begin_delete( 75 | GROUP_NAME 76 | ).result() 77 | 78 | 79 | if __name__ == "__main__": 80 | main() 81 | 82 | -------------------------------------------------------------------------------- /samples/network/raw_request_hook.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | from azure.identity import DefaultAzureCredential 5 | from azure.mgmt.network import NetworkManagementClient 6 | from azure.mgmt.network.models import VirtualNetworkGateway 7 | 8 | 9 | # This sample is just to show how to customize request if needed 10 | def main(): 11 | credentials = DefaultAzureCredential() 12 | subscription = os.getenv('SUBSCRIPTION_ID') 13 | 14 | def callback(request): 15 | origin_req = json.loads(request.http_request.body) 16 | with open('result.json', 'w') as file: 17 | file.write(json.dumps(origin_req, indent=4)) 18 | 19 | client = NetworkManagementClient(credentials, subscription) 20 | 21 | virtual_network_gateway = client.virtual_network_gateways.begin_create_or_update( 22 | resource_group_name='GROUP_NAME', 23 | vm_name='NEW_VIRTUAL_NETWORK_GATEWAY', 24 | parameters='vn_para', 25 | raw_request_hook=callback 26 | ).result() 27 | 28 | 29 | if __name__ == '__main__': 30 | main() 31 | -------------------------------------------------------------------------------- /samples/network/raw_response_hook.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | 4 | from azure.identity import DefaultAzureCredential 5 | from azure.mgmt.network import NetworkManagementClient 6 | 7 | 8 | # This sample is just to show how to customize response if needed 9 | def main(): 10 | 11 | credentials = DefaultAzureCredential() 12 | subscription = os.getenv('SUBSCRIPTION_ID') 13 | 14 | def callback(response): 15 | origin_req = json.loads(response.http_response.internal_response.text) 16 | with open('result.json', 'w') as file: 17 | file.write(json.dumps(origin_req, indent=4)) 18 | 19 | client = NetworkManagementClient(credentials, subscription) 20 | 21 | virtual_network_gateway = client.network_managers.get( 22 | resource_group_name='resource_group_name', 23 | network_manager_name='network_manager_name', 24 | raw_response_hook=callback 25 | ) 26 | 27 | 28 | if __name__ == '__main__': 29 | main() 30 | -------------------------------------------------------------------------------- /samples/network/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-compute==17.0.0 3 | azure-mgmt-network==16.0.0 4 | azure-mgmt-resource==15.0.0 5 | azure-mgmt-storage==16.0.0 6 | -------------------------------------------------------------------------------- /samples/network/route/manage_route.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | ROUTE = "routexxyyzz" 18 | ROUTE_TABLE = "route" 19 | 20 | # Create client 21 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | network_client = NetworkManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # - init depended resources - 38 | # Create route table 39 | network_client.route_tables.begin_create_or_update( 40 | GROUP_NAME, 41 | ROUTE_TABLE, 42 | { 43 | "location": "westus" 44 | } 45 | ).result() 46 | # - end - 47 | 48 | # Create route 49 | route = network_client.routes.begin_create_or_update( 50 | GROUP_NAME, 51 | ROUTE_TABLE, 52 | ROUTE, 53 | { 54 | "address_prefix": "10.0.3.0/24", 55 | "next_hop_type": "VirtualNetworkGateway" 56 | } 57 | ).result() 58 | print("Create route:\n{}".format(route)) 59 | 60 | # Get route 61 | route = network_client.routes.get( 62 | GROUP_NAME, 63 | ROUTE_TABLE, 64 | ROUTE 65 | ) 66 | print("Get route:\n{}".format(route)) 67 | 68 | # Delete route 69 | route = network_client.routes.begin_delete( 70 | GROUP_NAME, 71 | ROUTE_TABLE, 72 | ROUTE 73 | ).result() 74 | print("Delete route.\n") 75 | 76 | # Delete Group 77 | resource_client.resource_groups.begin_delete( 78 | GROUP_NAME 79 | ).result() 80 | 81 | 82 | if __name__ == "__main__": 83 | main() 84 | -------------------------------------------------------------------------------- /samples/network/route/manage_route_table.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | ROUTE_TABLE = "route_tablexxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create route table 37 | route_table = network_client.route_tables.begin_create_or_update( 38 | GROUP_NAME, 39 | ROUTE_TABLE, 40 | { 41 | "location": "westus" 42 | } 43 | ).result() 44 | print("Create route table:\n{}".format(route_table)) 45 | 46 | # Get route table 47 | route_table = network_client.route_tables.get( 48 | GROUP_NAME, 49 | ROUTE_TABLE 50 | ) 51 | print("Get route table:\n{}".format(route_table)) 52 | 53 | # Update route table 54 | route_table = network_client.route_tables.update_tags( 55 | GROUP_NAME, 56 | ROUTE_TABLE, 57 | { 58 | "tags": { 59 | "tag1": "value1", 60 | "tag2": "value2" 61 | } 62 | } 63 | ) 64 | print("Update route table:\n{}".format(route_table)) 65 | 66 | # Delete route table 67 | route_table = network_client.route_tables.begin_delete( 68 | GROUP_NAME, 69 | ROUTE_TABLE 70 | ).result() 71 | print("Delete route table.\n") 72 | 73 | # Delete Group 74 | resource_client.resource_groups.begin_delete( 75 | GROUP_NAME 76 | ).result() 77 | 78 | 79 | if __name__ == "__main__": 80 | main() 81 | -------------------------------------------------------------------------------- /samples/network/route_filter/manage_route_filter.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | ROUTE_FILTER = "route_filterxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create route filter 37 | route_filter = network_client.route_filters.begin_create_or_update( 38 | GROUP_NAME, 39 | ROUTE_FILTER, 40 | { 41 | "location": "eastus", 42 | "tags": { 43 | "key1": "value1" 44 | }, 45 | "rules": [] 46 | } 47 | ).result() 48 | print("Create route filter:\n{}".format(route_filter)) 49 | 50 | # Get route filter 51 | route_filter = network_client.route_filters.get( 52 | GROUP_NAME, 53 | ROUTE_FILTER 54 | ) 55 | print("Get route filter:\n{}".format(route_filter)) 56 | 57 | # Update route filter 58 | route_filter = network_client.route_filters.update_tags( 59 | GROUP_NAME, 60 | ROUTE_FILTER, 61 | { 62 | "tags": { 63 | "key1": "value1" 64 | } 65 | } 66 | ) 67 | print("Update route filter:\n{}".format(route_filter)) 68 | 69 | # Delete route filter 70 | route_filter = network_client.route_filters.begin_delete( 71 | GROUP_NAME, 72 | ROUTE_FILTER 73 | ).result() 74 | print("Delete route filter.\n") 75 | 76 | # Delete Group 77 | resource_client.resource_groups.begin_delete( 78 | GROUP_NAME 79 | ).result() 80 | 81 | 82 | if __name__ == "__main__": 83 | main() 84 | -------------------------------------------------------------------------------- /samples/network/route_filter/manage_route_filter_rule.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | ROUTE_FILTER_RULE = "route_filter_rulexxyyzz" 18 | ROUTE_FILTER = "route_filterxxyyzz" 19 | 20 | # Create client 21 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | network_client = NetworkManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # - init depended resources - 38 | # Create route filter 39 | network_client.route_filters.begin_create_or_update( 40 | GROUP_NAME, 41 | ROUTE_FILTER, 42 | { 43 | "location": "eastus", 44 | "tags": { 45 | "key1": "value1" 46 | }, 47 | "rules": [] 48 | } 49 | ).result() 50 | # - end - 51 | 52 | # Create route filter rule 53 | route_filter_rule = network_client.route_filter_rules.begin_create_or_update( 54 | GROUP_NAME, 55 | ROUTE_FILTER, 56 | ROUTE_FILTER_RULE, 57 | { 58 | "access": "Allow", 59 | "route_filter_rule_type": "Community", 60 | "communities": [ 61 | "12076:51004" 62 | ] 63 | } 64 | ).result() 65 | print("Create route filter rule:\n{}".format(route_filter_rule)) 66 | 67 | # Get route filter rule 68 | route_filter_rule = network_client.route_filter_rules.get( 69 | GROUP_NAME, 70 | ROUTE_FILTER, 71 | ROUTE_FILTER_RULE 72 | ) 73 | print("Get route filter rule:\n{}".format(route_filter_rule)) 74 | 75 | # Delete route filter rule 76 | route_filter_rule = network_client.route_filter_rules.begin_delete( 77 | GROUP_NAME, 78 | ROUTE_FILTER, 79 | ROUTE_FILTER_RULE 80 | ).result() 81 | print("Delete route filter rule.\n") 82 | 83 | # Delete Group 84 | resource_client.resource_groups.begin_delete( 85 | GROUP_NAME 86 | ).result() 87 | 88 | 89 | if __name__ == "__main__": 90 | main() 91 | -------------------------------------------------------------------------------- /samples/network/virtual_network/manage_subnet.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | SUBNET = "subnetxxyyzz" 18 | VIRTUAL_NETWORK_NAME = "virtualnetworkxxxyyzz" 19 | 20 | # Create client 21 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | network_client = NetworkManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create virtual network 38 | network_client.virtual_networks.begin_create_or_update( 39 | GROUP_NAME, 40 | VIRTUAL_NETWORK_NAME, 41 | { 42 | "address_space": { 43 | "address_prefixes": [ 44 | "10.0.0.0/16" 45 | ] 46 | }, 47 | "location": "eastus" 48 | } 49 | ).result() 50 | 51 | # Create subnet 52 | subnet = network_client.subnets.begin_create_or_update( 53 | GROUP_NAME, 54 | VIRTUAL_NETWORK_NAME, 55 | SUBNET, 56 | { 57 | "address_prefix": "10.0.0.0/24" 58 | } 59 | ).result() 60 | print("Create subnet:\n{}".format(subnet)) 61 | 62 | # Get subnet 63 | subnet = network_client.subnets.get( 64 | GROUP_NAME, 65 | VIRTUAL_NETWORK_NAME, 66 | SUBNET 67 | ) 68 | print("Get subnet:\n{}".format(subnet)) 69 | 70 | # Delete subnet 71 | subnet = network_client.subnets.begin_delete( 72 | GROUP_NAME, 73 | VIRTUAL_NETWORK_NAME, 74 | SUBNET 75 | ).result() 76 | print("Delete subnet.\n") 77 | 78 | # Delete Group 79 | resource_client.resource_groups.begin_delete( 80 | GROUP_NAME 81 | ).result() 82 | 83 | 84 | if __name__ == "__main__": 85 | main() 86 | -------------------------------------------------------------------------------- /samples/network/virtual_network/manage_virtual_network.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | VIRTUAL_NETWORK_NAME = "virtualnetwork" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create virtual network 37 | network = network_client.virtual_networks.begin_create_or_update( 38 | GROUP_NAME, 39 | VIRTUAL_NETWORK_NAME, 40 | { 41 | "address_space": { 42 | "address_prefixes": [ 43 | "10.0.0.0/16" 44 | ] 45 | }, 46 | "location": "eastus" 47 | } 48 | ).result() 49 | print("Create virtual network:\n{}".format(network)) 50 | 51 | # Get virtual network 52 | network = network_client.virtual_networks.get( 53 | GROUP_NAME, 54 | VIRTUAL_NETWORK_NAME 55 | ) 56 | print("Get virtual network:\n{}".format(network)) 57 | 58 | # Update virtual network tags 59 | network = network_client.virtual_networks.update_tags( 60 | GROUP_NAME, 61 | VIRTUAL_NETWORK_NAME, 62 | { 63 | "tags": { 64 | "tag1": "value1", 65 | "tag2": "value2" 66 | } 67 | } 68 | ) 69 | print("Update virtual network tags:\n{}".format(network)) 70 | 71 | # Delete virtual network 72 | network_client.virtual_networks.begin_delete( 73 | GROUP_NAME, 74 | VIRTUAL_NETWORK_NAME 75 | ).result() 76 | print("Delete virtual network.\n") 77 | 78 | # Delete Group 79 | resource_client.resource_groups.begin_delete( 80 | GROUP_NAME 81 | ).result() 82 | 83 | 84 | if __name__ == "__main__": 85 | main() 86 | -------------------------------------------------------------------------------- /samples/network/virtual_wan/manage_virtual_wan.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | VIRTUAL_WAN = "virtual_wanxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create virtual wan 37 | virtual_wan = network_client.virtual_wans.begin_create_or_update( 38 | GROUP_NAME, 39 | VIRTUAL_WAN, 40 | { 41 | "location": "West US", 42 | "tags": { 43 | "key1": "value1" 44 | }, 45 | "disable_vpn_encryption": False, 46 | "type": "Basic" 47 | } 48 | ).result() 49 | print("Create virtual wan:\n{}".format(virtual_wan)) 50 | 51 | # Get virtual wan 52 | virtual_wan = network_client.virtual_wans.get( 53 | GROUP_NAME, 54 | VIRTUAL_WAN 55 | ) 56 | print("Get virtual wan:\n{}".format(virtual_wan)) 57 | 58 | # Update virtual wan 59 | virtual_wan = network_client.virtual_wans.update_tags( 60 | GROUP_NAME, 61 | VIRTUAL_WAN, 62 | { 63 | "tags": { 64 | "tag1": "value1", 65 | "tag2": "value2" 66 | } 67 | } 68 | ) 69 | print("Update virtual wan:\n{}".format(virtual_wan)) 70 | 71 | # Delete virtual wan 72 | virtual_wan = network_client.virtual_wans.begin_delete( 73 | GROUP_NAME, 74 | VIRTUAL_WAN 75 | ).result() 76 | print("Delete virtual wan.\n") 77 | 78 | # Delete Group 79 | resource_client.resource_groups.begin_delete( 80 | GROUP_NAME 81 | ).result() 82 | 83 | 84 | if __name__ == "__main__": 85 | main() 86 | -------------------------------------------------------------------------------- /samples/network/watcher/manage_network_security_group.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | NETWORK_SECURITY_GROUP = "network_security_groupxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create network security group 37 | network_security_group = network_client.network_security_groups.begin_create_or_update( 38 | GROUP_NAME, 39 | NETWORK_SECURITY_GROUP, 40 | { 41 | "location": "eastus" 42 | } 43 | ).result() 44 | print("Create network security group:\n{}".format(network_security_group)) 45 | 46 | # Get network security group 47 | network_security_group = network_client.network_security_groups.get( 48 | GROUP_NAME, 49 | NETWORK_SECURITY_GROUP 50 | ) 51 | print("Get network security group:\n{}".format(network_security_group)) 52 | 53 | # Update network security group 54 | network_security_group = network_client.network_security_groups.update_tags( 55 | GROUP_NAME, 56 | NETWORK_SECURITY_GROUP, 57 | { 58 | "tags": { 59 | "tag1": "value1", 60 | "tag2": "value2" 61 | } 62 | } 63 | ) 64 | print("Update network security group:\n{}".format(network_security_group)) 65 | 66 | # Delete network security group 67 | network_security_group = network_client.network_security_groups.begin_delete( 68 | GROUP_NAME, 69 | NETWORK_SECURITY_GROUP 70 | ).result() 71 | print("Delete network security group.\n") 72 | 73 | # Delete Group 74 | resource_client.resource_groups.begin_delete( 75 | GROUP_NAME 76 | ).result() 77 | 78 | 79 | if __name__ == "__main__": 80 | main() 81 | -------------------------------------------------------------------------------- /samples/network/watcher/manage_network_watcher.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.network import NetworkManagementClient 10 | from azure.mgmt.resource import ResourceManagementClient 11 | 12 | 13 | def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | NETWORK_WATCHER = "network_watcherxxyyzz" 18 | 19 | # Create client 20 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 21 | resource_client = ResourceManagementClient( 22 | credential=DefaultAzureCredential(), 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | network_client = NetworkManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | 30 | # Create resource group 31 | resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | 36 | # Create network watcher 37 | network_watcher = network_client.network_watchers.create_or_update( 38 | GROUP_NAME, 39 | NETWORK_WATCHER, 40 | { 41 | "location": "eastus" 42 | } 43 | ) 44 | print("Create network watcher:\n{}".format(network_watcher)) 45 | 46 | # Get network watcher 47 | network_watcher = network_client.network_watchers.get( 48 | GROUP_NAME, 49 | NETWORK_WATCHER 50 | ) 51 | print("Get network watcher:\n{}".format(network_watcher)) 52 | 53 | # Update network watcher 54 | network_watcher = network_client.network_watchers.update_tags( 55 | GROUP_NAME, 56 | NETWORK_WATCHER, 57 | { 58 | "tags": { 59 | "tag1": "value1", 60 | "tag2": "value2" 61 | } 62 | } 63 | ) 64 | print("Update network watcher:\n{}".format(network_watcher)) 65 | 66 | # Delete network watcher 67 | network_watcher = network_client.network_watchers.begin_delete( 68 | GROUP_NAME, 69 | NETWORK_WATCHER 70 | ).result() 71 | print("Delete network watcher.\n") 72 | 73 | # Delete Group 74 | resource_client.resource_groups.begin_delete( 75 | GROUP_NAME 76 | ).result() 77 | 78 | 79 | if __name__ == "__main__": 80 | main() 81 | -------------------------------------------------------------------------------- /samples/notificationhubs/manage_namespace.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | import time 9 | 10 | from azure.identity import DefaultAzureCredential 11 | from azure.mgmt.notificationhubs import NotificationHubsManagementClient 12 | from azure.mgmt.resource import ResourceManagementClient 13 | 14 | 15 | def main(): 16 | 17 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 18 | GROUP_NAME = "testgroupx" 19 | NAMESPACE = "namespacexxyyzz" 20 | 21 | # Create client 22 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 23 | resource_client = ResourceManagementClient( 24 | credential=DefaultAzureCredential(), 25 | subscription_id=SUBSCRIPTION_ID 26 | ) 27 | notificationhubs_client = NotificationHubsManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | 32 | # Create resource group 33 | resource_client.resource_groups.create_or_update( 34 | GROUP_NAME, 35 | {"location": "eastus"} 36 | ) 37 | 38 | # Create namespace 39 | namespace = notificationhubs_client.namespaces.create_or_update( 40 | GROUP_NAME, 41 | NAMESPACE, 42 | { 43 | "location": "eastus" 44 | } 45 | ) 46 | print("Create namespace:\n{}".format(namespace)) 47 | 48 | # Get namespace 49 | namespace = notificationhubs_client.namespaces.get( 50 | GROUP_NAME, 51 | NAMESPACE 52 | ) 53 | while namespace.status == "Created": 54 | time.sleep(30) 55 | namespace = notificationhubs_client.namespaces.get( 56 | GROUP_NAME, 57 | NAMESPACE, 58 | ) 59 | print("Get namespace:\n{}".format(namespace)) 60 | 61 | # Update namespace 62 | namespace = notificationhubs_client.namespaces.patch( 63 | GROUP_NAME, 64 | NAMESPACE, 65 | { 66 | "enabled": True 67 | } 68 | ) 69 | print("Update namespace:\n{}".format(namespace)) 70 | 71 | # Delete namespace 72 | notificationhubs_client.namespaces.begin_delete( 73 | GROUP_NAME, 74 | NAMESPACE 75 | ).result() 76 | print("Delete namespace.\n") 77 | 78 | # Delete Group 79 | resource_client.resource_groups.begin_delete( 80 | GROUP_NAME 81 | ).result() 82 | 83 | 84 | if __name__ == "__main__": 85 | main() 86 | -------------------------------------------------------------------------------- /samples/notificationhubs/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-notificationhubs==7.0.0b1 3 | azure-mgmt-resource==15.0.0 4 | -------------------------------------------------------------------------------- /samples/policyinsights/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-policyinsights==1.0.0b1 3 | -------------------------------------------------------------------------------- /samples/quota/Group Quota Samples/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | page_type: sample 3 | languages: 4 | - python 5 | products: 6 | - azure 7 | description: "These code samples will show you how to manage Group Quota using Azure SDK for Python." 8 | urlFragment: quota 9 | --- 10 | 11 | # Getting started - Managing Group Quota using Azure Python SDK 12 | 13 | These code samples will show you how to manage Group Quota using Azure SDK for Python. 14 | 15 | ## Features 16 | 17 | This project framework provides examples for the following services: 18 | 19 | ### Quota 20 | - Using the Azure SDK for Python - Quota Management Library [azure-mgmt-quota 2.0.0b1](https://pypi.org/project/azure-mgmt-quota/2.0.0b1/) 21 | 22 | `pip install azure-mgmt-quota==2.0.0b1` 23 | 24 | ## Getting Started 25 | 26 | ### Prerequisites 27 | 28 | 1. Before we run the samples, we need to make sure we have setup the credentials. Follow the instructions in [register a new application using Azure portal](https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-create-service-principal-portal) to obtain `subscription id`,`client id`,`client secret`, and `application id` 29 | 30 | 2. Store your credentials an environment variables. 31 | For example, in Linux-based OS, you can do 32 | ```bash 33 | export AZURE_TENANT_ID="xxx" 34 | export AZURE_CLIENT_ID="xxx" 35 | export AZURE_CLIENT_SECRET="xxx" 36 | ``` 37 | 38 | ### Installation 39 | 40 | 1. If you don't already have it, [install Python](https://www.python.org/downloads/). 41 | 42 | This sample (and the SDK) is compatible with Python 3.7+. 43 | 44 | 2. Install the following specific SDK version, [Link to SDK 2.0.0b1](https://pypi.org/project/azure-mgmt-quota/2.0.0b1/) 45 | 46 | ### Quickstart 47 | 48 | 1. Clone the repository. 49 | 50 | ``` 51 | git clone https://github.com/Azure/azure-sdk-for-python.git 52 | ``` 53 | 54 | 2. Install the dependencies using pip. 55 | 56 | ``` 57 | pip install azure-identity 58 | pip install azure-mgmt-quota==2.0.0b1 59 | ``` 60 | 61 | ## Run 62 | 63 | To run the script, execute `python sample.py` 64 | 65 | To run each individual demo, point directly to the file. For example (i.e. not complete list): 66 | 67 | - `python sample.py` 68 | 69 | Includes creating Group Quota Functions, assigning group quota limit, setting subscription quota allocation and cleanup 70 | 71 | ## Resources 72 | 73 | Link to full list of SDK scripts 74 | 75 | - https://github.com/Azure/azure-sdk-for-python/tree/0a8dfb57ae574d38a304ca447957c27aa7224f2c/sdk/quota/azure-mgmt-quota/generated_samples -------------------------------------------------------------------------------- /samples/quota/mamge_create_or_update.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from azure.identity import DefaultAzureCredential 4 | from azure.mgmt.quota import AzureQuotaExtensionAPI 5 | from azure.mgmt.resource import ResourceManagementClient 6 | 7 | 8 | def main(): 9 | subscription = os.getenv('AZURE_SUBSCRIPTION_ID') 10 | quota_client = AzureQuotaExtensionAPI(DefaultAzureCredential(), subscription) 11 | resource_client = ResourceManagementClient(DefaultAzureCredential(), subscription) 12 | 13 | GROUP_NAME = 'zbw_test' 14 | 15 | # Create resource group 16 | resource_client.resource_groups.create_or_update( 17 | GROUP_NAME, 18 | {"location": "eastus"} 19 | ) 20 | 21 | result = quota_client.quota.begin_create_or_update( 22 | resource_name=GROUP_NAME, 23 | scope='/subscriptions/' + subscription + 'providers/Microsoft.Compute/location/eastus', 24 | create_quota_request={ 25 | "properties": { 26 | "limit": { 27 | "limit_object_type": "1000" 28 | }, 29 | "resourceType": "dedicated" 30 | } 31 | } 32 | ).result() 33 | print(result) 34 | 35 | # delete resource group 36 | resource_client.resource_groups.begin_delete(GROUP_NAME).result() 37 | 38 | 39 | if __name__ == '__main__': 40 | main() 41 | -------------------------------------------------------------------------------- /samples/quota/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity==1.11.0 2 | azure-mgmt-quota==1.0.0b2 3 | azure-mgmt-resource==21.2.0 -------------------------------------------------------------------------------- /samples/recoveryservices/manage_vault.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.recoveryservices import RecoveryServicesClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | VAULT = "vaultxxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | recoveryservices_client = RecoveryServicesClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create vault 38 | vault = recoveryservices_client.vaults.create_or_update( 39 | GROUP_NAME, 40 | VAULT, 41 | { 42 | "location": "eastus", 43 | "sku": { 44 | "name": "standard" 45 | }, 46 | "properties": {} 47 | } 48 | ) 49 | print("Create vault:\n{}".format(vault)) 50 | 51 | # Get vault 52 | vault = recoveryservices_client.vaults.get( 53 | GROUP_NAME, 54 | VAULT 55 | ) 56 | print("Get vault:\n{}".format(vault)) 57 | 58 | # Update vault 59 | vault = recoveryservices_client.vaults.update( 60 | GROUP_NAME, 61 | VAULT, 62 | { 63 | "location": "eastus", 64 | "sku": { 65 | "name": "standard" 66 | }, 67 | "properties": {} 68 | } 69 | ) 70 | print("Update vault:\n{}".format(vault)) 71 | 72 | # Delete vault 73 | vault = recoveryservices_client.vaults.delete( 74 | GROUP_NAME, 75 | VAULT 76 | ) 77 | print("Delete vault.\n") 78 | 79 | # Delete Group 80 | resource_client.resource_groups.begin_delete( 81 | GROUP_NAME 82 | ).result() 83 | 84 | 85 | if __name__ == "__main__": 86 | main() 87 | -------------------------------------------------------------------------------- /samples/recoveryservices/manage_vault_extended_info.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import base64 8 | import os 9 | import random 10 | 11 | from azure.identity import DefaultAzureCredential 12 | from azure.mgmt.recoveryservices import RecoveryServicesClient 13 | from azure.mgmt.resource import ResourceManagementClient 14 | 15 | 16 | def main(): 17 | 18 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 19 | GROUP_NAME = "testgroupx" 20 | VAULT_EXTENDED_INFO = "vault_extended_infoxxyyzz" 21 | VAULT = "vaultxxyyzz" 22 | 23 | # Create client 24 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 25 | resource_client = ResourceManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | recoveryservices_client = RecoveryServicesClient( 30 | credential=DefaultAzureCredential(), 31 | subscription_id=SUBSCRIPTION_ID 32 | ) 33 | 34 | # Create resource group 35 | resource_client.resource_groups.create_or_update( 36 | GROUP_NAME, 37 | {"location": "eastus"} 38 | ) 39 | 40 | # - init depended resources - 41 | # Create vault 42 | vault = recoveryservices_client.vaults.create_or_update( 43 | GROUP_NAME, 44 | VAULT, 45 | { 46 | "location": "eastus", 47 | "sku": { 48 | "name": "standard" 49 | }, 50 | "properties": {} 51 | } 52 | ) 53 | print("Create vault:\n{}".format(vault)) 54 | # - end - 55 | 56 | # Create vault extended info 57 | vault_extended_info = recoveryservices_client.vault_extended_info.create_or_update( 58 | GROUP_NAME, 59 | VAULT, 60 | { 61 | "algorithm": "None", 62 | "integrity_key": base64.b64encode(bytearray(random.getrandbits(8) for i in range(16))) 63 | } 64 | ) 65 | print("Create vault extended info:\n{}".format(vault_extended_info)) 66 | 67 | # Get vault extended info 68 | vault_extended_info = recoveryservices_client.vault_extended_info.get( 69 | GROUP_NAME, 70 | VAULT 71 | ) 72 | print("Get vault extended info:\n{}".format(vault_extended_info)) 73 | 74 | # Delete Group 75 | resource_client.resource_groups.begin_delete( 76 | GROUP_NAME 77 | ).result() 78 | 79 | 80 | if __name__ == "__main__": 81 | main() 82 | -------------------------------------------------------------------------------- /samples/recoveryservices/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-recoveryservices==1.0.0b1 3 | azure-mgmt-resource>=15.0.0 4 | -------------------------------------------------------------------------------- /samples/recoveryservicesbackup/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity==1.16.1 2 | azure-mgmt-resource==21.1.0 3 | azure-mgmt-recoveryservicesbackup==5.0.0 4 | azure-mgmt-recoveryservices==2.0.0 5 | azure-mgmt-compute==27.0.0 6 | azure-mgmt-network==19.3.0 -------------------------------------------------------------------------------- /samples/redis/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-network>=16.0.0 3 | azure-mgmt-redis==12.0.0b1 4 | azure-mgmt-resource>=15.0.0 5 | -------------------------------------------------------------------------------- /samples/relay/manage_hybridconnection.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.relay import RelayAPI 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | NAMESPACE = "namespacexxyzx" 19 | HYBRIDCONNECTION = "hybridconnectionxxyyzz" 20 | 21 | # Create client 22 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 23 | resource_client = ResourceManagementClient( 24 | credential=DefaultAzureCredential(), 25 | subscription_id=SUBSCRIPTION_ID 26 | ) 27 | relay_client = RelayAPI( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | 32 | # Create resource group 33 | resource_client.resource_groups.create_or_update( 34 | GROUP_NAME, 35 | {"location": "eastus"} 36 | ) 37 | 38 | # - init depended resources - 39 | # Create namespace 40 | namespace = relay_client.namespaces.begin_create_or_update( 41 | GROUP_NAME, 42 | NAMESPACE, 43 | { 44 | "location": "eastus", 45 | "tags": { 46 | "tag1": "value1", 47 | "tag2": "value2" 48 | }, 49 | "sku": { 50 | "tier": "standard" 51 | } 52 | } 53 | ).result() 54 | print("Create namespace:\n{}".format(namespace)) 55 | # - end - 56 | 57 | # Create hybridconnection 58 | hybridconnection = relay_client.hybrid_connections.create_or_update( 59 | GROUP_NAME, 60 | NAMESPACE, 61 | HYBRIDCONNECTION, 62 | { 63 | "requires_client_authorization": True, 64 | "user_metadata": "User data for HybridConnection" 65 | } 66 | ) 67 | print("Create hybridconnection:\n{}".format(hybridconnection)) 68 | 69 | # Get hybridconnection 70 | hybridconnection = relay_client.hybrid_connections.get( 71 | GROUP_NAME, 72 | NAMESPACE, 73 | HYBRIDCONNECTION 74 | ) 75 | print("Get hybridconnection:\n{}".format(hybridconnection)) 76 | 77 | # Delete hybridconnection 78 | hybridconnection = relay_client.hybrid_connections.delete( 79 | GROUP_NAME, 80 | NAMESPACE, 81 | HYBRIDCONNECTION 82 | ) 83 | print("Delete hybridconnection.\n") 84 | 85 | # Delete Group 86 | resource_client.resource_groups.begin_delete( 87 | GROUP_NAME 88 | ).result() 89 | 90 | 91 | if __name__ == "__main__": 92 | main() 93 | -------------------------------------------------------------------------------- /samples/relay/manage_namespace.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.relay import RelayAPI 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | # - other dependence - 14 | # - end - 15 | 16 | 17 | def main(): 18 | 19 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 20 | GROUP_NAME = "testgroupx" 21 | NAMESPACE = "namespacexxyyzz" 22 | 23 | # Create client 24 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 25 | resource_client = ResourceManagementClient( 26 | credential=DefaultAzureCredential(), 27 | subscription_id=SUBSCRIPTION_ID 28 | ) 29 | relay_client = RelayAPI( 30 | credential=DefaultAzureCredential(), 31 | subscription_id=SUBSCRIPTION_ID 32 | ) 33 | 34 | # Create resource group 35 | resource_client.resource_groups.create_or_update( 36 | GROUP_NAME, 37 | {"location": "eastus"} 38 | ) 39 | 40 | # Create namespace 41 | namespace = relay_client.namespaces.begin_create_or_update( 42 | GROUP_NAME, 43 | NAMESPACE, 44 | { 45 | "location": "eastus", 46 | "tags": { 47 | "tag1": "value1", 48 | "tag2": "value2" 49 | }, 50 | "sku": { 51 | "tier": "standard" 52 | } 53 | } 54 | ).result() 55 | print("Create namespace:\n{}".format(namespace)) 56 | 57 | # Get namespace 58 | namespace = relay_client.namespaces.get( 59 | GROUP_NAME, 60 | NAMESPACE 61 | ) 62 | print("Get namespace:\n{}".format(namespace)) 63 | 64 | # Update namespace 65 | namespace = relay_client.namespaces.update( 66 | GROUP_NAME, 67 | NAMESPACE, 68 | { 69 | "tags": { 70 | "tag1": "value2" 71 | } 72 | } 73 | ) 74 | print("Update namespace:\n{}".format(namespace)) 75 | 76 | # Delete namespace 77 | namespace = relay_client.namespaces.begin_delete( 78 | GROUP_NAME, 79 | NAMESPACE 80 | ).result() 81 | print("Delete namespace.\n") 82 | 83 | # Delete Group 84 | resource_client.resource_groups.begin_delete( 85 | GROUP_NAME 86 | ).result() 87 | 88 | 89 | if __name__ == "__main__": 90 | main() 91 | -------------------------------------------------------------------------------- /samples/relay/manage_wcfrelay.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.relay import RelayAPI 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | WCFRELAY = "wcfrelayxxyyzz" 19 | NAMESPACE = "namespacexxyze" 20 | 21 | # Create client 22 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 23 | resource_client = ResourceManagementClient( 24 | credential=DefaultAzureCredential(), 25 | subscription_id=SUBSCRIPTION_ID 26 | ) 27 | relay_client = RelayAPI( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | 32 | # Create resource group 33 | resource_client.resource_groups.create_or_update( 34 | GROUP_NAME, 35 | {"location": "eastus"} 36 | ) 37 | 38 | # - init depended resources - 39 | # Create namespace 40 | namespace = relay_client.namespaces.begin_create_or_update( 41 | GROUP_NAME, 42 | NAMESPACE, 43 | { 44 | "location": "eastus", 45 | "tags": { 46 | "tag1": "value1", 47 | "tag2": "value2" 48 | }, 49 | "sku": { 50 | "tier": "standard" 51 | } 52 | } 53 | ).result() 54 | print("Create namespace:\n{}".format(namespace)) 55 | # - end - 56 | 57 | # Create wcfrelay 58 | wcfrelay = relay_client.wcf_relays.create_or_update( 59 | GROUP_NAME, 60 | NAMESPACE, 61 | WCFRELAY, 62 | { 63 | "relay_type": "NetTcp", 64 | "requires_client_authorization": True, 65 | "requires_transport_security": True, 66 | "user_metadata": "User dta for WcfRelay" 67 | } 68 | ) 69 | print("Create wcfrelay:\n{}".format(wcfrelay)) 70 | 71 | # Get wcfrelay 72 | wcfrelay = relay_client.wcf_relays.get( 73 | GROUP_NAME, 74 | NAMESPACE, 75 | WCFRELAY 76 | ) 77 | print("Get wcfrelay:\n{}".format(wcfrelay)) 78 | 79 | # Delete wcfrelay 80 | wcfrelay = relay_client.wcf_relays.delete( 81 | GROUP_NAME, 82 | NAMESPACE, 83 | WCFRELAY 84 | ) 85 | print("Delete wcfrelay.\n") 86 | 87 | # Delete Group 88 | resource_client.resource_groups.begin_delete( 89 | GROUP_NAME 90 | ).result() 91 | 92 | 93 | if __name__ == "__main__": 94 | main() 95 | -------------------------------------------------------------------------------- /samples/relay/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-relay==1.0.0b1 3 | azure-mgmt-resource==15.0.0 4 | -------------------------------------------------------------------------------- /samples/reservations/manage_reservations_list.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | from azure.identity import DefaultAzureCredential 5 | from azure.mgmt.reservations import AzureReservationAPI 6 | 7 | 8 | def main(): 9 | # Create client 10 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 11 | client = AzureReservationAPI( 12 | credential=DefaultAzureCredential(), 13 | subscription_id=os.environ.get("SUBSCRIPTION_ID", None) 14 | ) 15 | 16 | result = client.operation.list() 17 | for item in result: 18 | print(json.dumps(item.serialize())) 19 | 20 | 21 | if __name__ == "__main__": 22 | main() 23 | -------------------------------------------------------------------------------- /samples/reservations/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-reservations -------------------------------------------------------------------------------- /samples/resourceconnector/manage_create.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.resource import ResourceManagementClient 10 | from azure.mgmt.resourceconnector import ResourceConnectorMgmtClient 11 | from azure.mgmt.resourceconnector.models import Appliance 12 | 13 | # If you want to see the log, please deannotate the following code: 14 | # import sys 15 | # import logging 16 | # 17 | # logging.basicConfig(level=logging.DEBUG, 18 | # format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 19 | # stream=sys.stdout) 20 | 21 | def main(): 22 | sub_id = os.environ.get("SUBSCRIPTION_ID", None) 23 | group_name = "testgroupx" 24 | resource_name = "resourceconnector" 25 | location = "eastus" 26 | 27 | # Create client 28 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 29 | resource_client = ResourceManagementClient( 30 | credential=DefaultAzureCredential(), 31 | subscription_id=sub_id 32 | ) 33 | client = ResourceConnectorMgmtClient( 34 | credential=DefaultAzureCredential(), 35 | subscription_id=sub_id 36 | ) 37 | 38 | # Create resource group 39 | resource_client.resource_groups.create_or_update( 40 | group_name, 41 | {"location": location}, 42 | ) 43 | 44 | # - init depended resources - 45 | # Create virtual network 46 | result = client.appliances.begin_create_or_update( 47 | group_name, 48 | resource_name, 49 | Appliance(location=location, identity={"type":"SystemAssigned"},infrastructure_config={"provider":"VMWare"}), 50 | headers={"x-ms-client-request-id": "4159a480-c203-11ed-b9e5-6045bdc724a6"}, 51 | ).result() 52 | print("result of begin_create_or_update: {}".format(result.serialize())) 53 | 54 | # Delete Group 55 | resource_client.resource_groups.begin_delete( 56 | group_name 57 | ).result() 58 | 59 | 60 | if __name__ == "__main__": 61 | main() 62 | -------------------------------------------------------------------------------- /samples/resourceconnector/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resourceconnector 3 | azure-mgmt-resource 4 | 5 | -------------------------------------------------------------------------------- /samples/resourcegraph/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-resourcegraph==7.0.0 -------------------------------------------------------------------------------- /samples/resourcegraph/resources_query_customed_response.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | from azure.identity import DefaultAzureCredential 8 | from azure.mgmt.resourcegraph import ResourceGraphClient 9 | from azure.mgmt.resourcegraph.models import QueryRequest 10 | 11 | 12 | def custom_res(pipeline_response, deserialized, *kwargs): 13 | resource = deserialized 14 | quota_remaining = None 15 | quota_resets_after = None 16 | try: 17 | headers = pipeline_response.http_response.internal_response.headers 18 | quota_remaining = headers._store['x-ms-user-quota-remaining'] 19 | quota_resets_after = headers._store['x-ms-user-quota-resets-after'] 20 | except AttributeError: 21 | pass 22 | setattr(resource, 'x-ms-user-quota-remaining', quota_remaining) 23 | setattr(resource, 'x-ms-user-quota-resets-after', quota_resets_after) 24 | return resource 25 | 26 | 27 | def main(): 28 | # If "SUBSCRIPTION_ID" is not set in the environment variable, you need to set it manually: export SUBSCRIPTION_ID="{SUBSCRIPTION_ID}" 29 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 30 | 31 | # Create client 32 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 33 | resourcegraph_client = ResourceGraphClient( 34 | credential=DefaultAzureCredential(), 35 | subscription_id=SUBSCRIPTION_ID 36 | ) 37 | 38 | # Basic query up to 2 pieces of data 39 | query = QueryRequest( 40 | query='project id, tags, properties | limit 2', 41 | subscriptions=[SUBSCRIPTION_ID] 42 | ) 43 | query_response = resourcegraph_client.resources(query, cls=custom_res) 44 | print("Basic query up to 2 pieces of data:\n{}".format(query_response)) 45 | 46 | 47 | if __name__ == "__main__": 48 | main() 49 | -------------------------------------------------------------------------------- /samples/resourcehealth/manage_availability_statuses_list_by_subscription_id.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | from typing import List 4 | 5 | from azure.identity import DefaultAzureCredential 6 | from msrest import serialization 7 | 8 | 9 | def send_request(client, next_link=None): 10 | headers = {"Accept": client._serialize.header("accept", "application/json", "str")} 11 | if not next_link: 12 | params = {"api-version": client._serialize.query("api_version", "2015-01-01", "str")} 13 | path_format_arguments = { 14 | 'subscriptionId': client._serialize.url( 15 | "self._config.subscription_id", client._config.subscription_id, 'str' 16 | ), 17 | } 18 | url = "/subscriptions/{subscriptionId}/providers/Microsoft.ResourceHealth/availabilityStatuses" 19 | url = client._client.format_url(url, **path_format_arguments) 20 | else: 21 | url = next_link 22 | params = {} 23 | 24 | http_request = client._client.get(url=url, params=params, headers=headers) 25 | pipeline_response = client._client._pipeline.run(request=http_request, stream=False) 26 | return client._deserialize("AvailabilityStatusListResult", pipeline_response) 27 | 28 | 29 | def print_result(result: List[serialization.Model]): 30 | print(f"there are {len(result)} items:") 31 | for item in result: 32 | print(json.dumps(item.serialize())) 33 | 34 | 35 | def list1(): 36 | sub_id = os.environ.get("SUBSCRIPTION_ID", None) 37 | from azure.mgmt.resourcehealth import MicrosoftResourceHealth 38 | client = MicrosoftResourceHealth( 39 | credential=DefaultAzureCredential(), 40 | subscription_id=sub_id 41 | ) 42 | result = list(client.availability_statuses.list_by_subscription_id()) 43 | print_result(result) 44 | 45 | 46 | def list2(): 47 | sub_id = os.environ.get("SUBSCRIPTION_ID", None) 48 | from azure.mgmt.resourcehealth.v2015_01_01 import MicrosoftResourceHealth 49 | client = MicrosoftResourceHealth( 50 | credential=DefaultAzureCredential(), 51 | subscription_id=sub_id 52 | ) 53 | response = send_request(client) 54 | result = response.value 55 | while response.next_link: 56 | response = send_request(client, response.next_link) 57 | result.extend(response.value) 58 | print_result(result) 59 | 60 | 61 | def main(): 62 | ### There are 2 ways to list the resources with SDK ### 63 | 64 | # Solution 1: call operation directly (recommended) 65 | list1() 66 | 67 | # Solution 2 DIY HttpRequest (not recommended) 68 | # Only when solution 1 fails, you can try this solution 69 | list2() 70 | 71 | 72 | if __name__ == "__main__": 73 | main() 74 | -------------------------------------------------------------------------------- /samples/resourcehealth/manage_availability_statuses_operations.py: -------------------------------------------------------------------------------- 1 | import os 2 | import json 3 | 4 | from azure.identity import DefaultAzureCredential 5 | from azure.mgmt.resourcehealth import MicrosoftResourceHealth 6 | 7 | 8 | def main(): 9 | # Create client 10 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 11 | resourcehealth_client = MicrosoftResourceHealth( 12 | credential=DefaultAzureCredential(), 13 | subscription_id=os.environ.get("SUBSCRIPTION_ID", None) 14 | ) 15 | 16 | availability_statuses_list = list(resourcehealth_client.availability_statuses.list_by_subscription_id()) 17 | print(f"There are {len(availability_statuses_list)} items") 18 | for item in availability_statuses_list: 19 | print(json.dumps(item.serialize())) 20 | 21 | 22 | if __name__ == "__main__": 23 | main() 24 | -------------------------------------------------------------------------------- /samples/resourcehealth/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resourcehealth==1.0.0b1 -------------------------------------------------------------------------------- /samples/resources/aio/manage_resource_group_async.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import asyncio 7 | import os 8 | 9 | from azure.identity.aio import DefaultAzureCredential 10 | from azure.mgmt.resource.resources.aio import ResourceManagementClient 11 | 12 | 13 | async def main(): 14 | 15 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 16 | GROUP_NAME = "testgroupx" 17 | 18 | # Create client 19 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 20 | credential = DefaultAzureCredential() 21 | resource_client = ResourceManagementClient( 22 | credential=credential, 23 | subscription_id=SUBSCRIPTION_ID 24 | ) 25 | 26 | # Check resource group existence 27 | result_check = await resource_client.resource_groups.check_existence( 28 | GROUP_NAME 29 | ) 30 | print("Whether resource group exists:\n{}".format(result_check)) 31 | 32 | # Create resource group 33 | resource_group = await resource_client.resource_groups.create_or_update( 34 | GROUP_NAME, 35 | {"location": "eastus"} 36 | ) 37 | print("Create resource group:\n{}".format(resource_group)) 38 | 39 | # Get resource group 40 | resource_group = await resource_client.resource_groups.get( 41 | GROUP_NAME 42 | ) 43 | print("Get resource group:\n{}".format(resource_group)) 44 | 45 | # List resource group 46 | resource_groups = list() 47 | async for g in resource_client.resource_groups.list(): 48 | resource_groups.append(g) 49 | print("List resource groups:\n{}".format(resource_groups)) 50 | 51 | # Update resource group 52 | resource_group = await resource_client.resource_groups.update( 53 | GROUP_NAME, 54 | { 55 | "tags":{ 56 | "tag1": "valueA", 57 | "tag2": "valueB" 58 | } 59 | } 60 | ) 61 | print("Update resource group:\n{}".format(resource_group)) 62 | 63 | # Delete Group 64 | async_poller = await resource_client.resource_groups.begin_delete( 65 | GROUP_NAME 66 | ) 67 | await async_poller.result() 68 | print("Delete resource group.\n") 69 | 70 | # [Warning] All clients and credentials need to be closed. 71 | # link: https://github.com/Azure/azure-sdk-for-python/issues/8990 72 | await resource_client.close() 73 | await credential.close() 74 | 75 | 76 | if __name__ == "__main__": 77 | event_loop = asyncio.get_event_loop() 78 | event_loop.run_until_complete( 79 | main() 80 | ) 81 | event_loop.close() 82 | -------------------------------------------------------------------------------- /samples/resources/manage_providers.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.resource import ResourceManagementClient 10 | 11 | 12 | def main(): 13 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID") 14 | client = ResourceManagementClient(credential=DefaultAzureCredential(), subscription_id=SUBSCRIPTION_ID) 15 | result = client.providers.list() 16 | for item in result: 17 | print(item) 18 | 19 | 20 | if __name__ == "__main__": 21 | main() 22 | -------------------------------------------------------------------------------- /samples/resources/manage_resource_check_exsistence.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.resource import ResourceManagementClient 10 | 11 | import sys 12 | import logging 13 | 14 | logging.basicConfig(level=logging.DEBUG, 15 | format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 16 | stream=sys.stdout) 17 | 18 | def main(): 19 | 20 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 21 | GROUP_NAME = "testgroupx" 22 | RESOURCE_NAME = "pytestresource" 23 | 24 | # Create client 25 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 26 | resource_client = ResourceManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Check resource existence 32 | result = resource_client.resources.check_existence( 33 | resource_group_name=GROUP_NAME, 34 | resource_provider_namespace="Microsoft.Web", 35 | parent_resource_path="", 36 | resource_type="sites", 37 | resource_name=RESOURCE_NAME, 38 | api_version="2021-04-01" 39 | ) 40 | print(result) 41 | 42 | 43 | if __name__ == "__main__": 44 | main() 45 | -------------------------------------------------------------------------------- /samples/resources/manage_resource_group.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.resource import ResourceManagementClient 10 | 11 | 12 | def main(): 13 | 14 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 15 | GROUP_NAME = "testgroupx" 16 | 17 | # Create client 18 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 19 | resource_client = ResourceManagementClient( 20 | credential=DefaultAzureCredential(), 21 | subscription_id=SUBSCRIPTION_ID 22 | ) 23 | 24 | # Check resource group existence 25 | result_check = resource_client.resource_groups.check_existence( 26 | GROUP_NAME 27 | ) 28 | print("Whether resource group exists:\n{}".format(result_check)) 29 | 30 | # Create resource group 31 | resource_group = resource_client.resource_groups.create_or_update( 32 | GROUP_NAME, 33 | {"location": "eastus"} 34 | ) 35 | print("Create resource group:\n{}".format(resource_group)) 36 | 37 | # Get resource group 38 | resource_group = resource_client.resource_groups.get( 39 | GROUP_NAME 40 | ) 41 | print("Get resource group:\n{}".format(resource_group)) 42 | 43 | # Update resource group 44 | resource_group = resource_client.resource_groups.update( 45 | GROUP_NAME, 46 | { 47 | "tags":{ 48 | "tag1": "valueA", 49 | "tag2": "valueB" 50 | } 51 | } 52 | ) 53 | print("Update resource group:\n{}".format(resource_group)) 54 | 55 | # Delete Group 56 | resource_client.resource_groups.begin_delete( 57 | GROUP_NAME 58 | ).result() 59 | print("Delete resource group.\n") 60 | 61 | 62 | if __name__ == "__main__": 63 | main() 64 | -------------------------------------------------------------------------------- /samples/resources/manage_resource_group_tag.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.resource import ResourceManagementClient 10 | from azure.mgmt.resource.resources.models import ResourceGroup, ResourceGroupPatchable 11 | from azure.core.serialization import NULL as AzureCoreNull 12 | 13 | import sys 14 | import logging 15 | 16 | logging.basicConfig(level=logging.DEBUG, 17 | format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', 18 | stream=sys.stdout) 19 | 20 | def main(): 21 | 22 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 23 | GROUP_NAME = "testgroupxx" 24 | 25 | # Create client 26 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 27 | resource_client = ResourceManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID, 30 | logging_enable=True 31 | ) 32 | 33 | # Create resource group 34 | resource_group = resource_client.resource_groups.create_or_update( 35 | GROUP_NAME, 36 | parameters=ResourceGroup(location="eastus") 37 | ) 38 | print("Create resource group:\n{}".format(resource_group.serialize())) 39 | 40 | # Update resource group 41 | resource_group = resource_client.resource_groups.update( 42 | GROUP_NAME, 43 | parameters=ResourceGroupPatchable(tags={"hello": "world"}) 44 | ) 45 | print("Update resource group:\n{}".format(resource_group.serialize())) 46 | 47 | resource_group = resource_client.resource_groups.update( 48 | GROUP_NAME, 49 | parameters=ResourceGroupPatchable(tags=None) 50 | ) 51 | print("Update resource group:\n{}".format(resource_group.serialize())) 52 | 53 | resource_group = resource_client.resource_groups.update( 54 | GROUP_NAME, 55 | parameters=ResourceGroupPatchable(tags=AzureCoreNull) 56 | ) 57 | print("Update resource group:\n{}".format(resource_group.serialize())) 58 | 59 | # Delete Group 60 | resource_client.resource_groups.begin_delete( 61 | GROUP_NAME 62 | ).result() 63 | print("Delete resource group.\n") 64 | 65 | 66 | if __name__ == "__main__": 67 | main() 68 | -------------------------------------------------------------------------------- /samples/resources/manage_resource_lock_at_resource_group.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.resource import ManagementLockClient, ResourceManagementClient 10 | 11 | 12 | def main(): 13 | 14 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 15 | GROUP_NAME = "testgroupx" 16 | LOCK_NAME = "locktestx" 17 | 18 | # Create client 19 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 20 | lock_client = ManagementLockClient( 21 | credential=DefaultAzureCredential(), 22 | subscription_id=SUBSCRIPTION_ID 23 | ) 24 | resource_client = ResourceManagementClient( 25 | credential=DefaultAzureCredential(), 26 | subscription_id=SUBSCRIPTION_ID 27 | ) 28 | 29 | # Create resource group 30 | resource_client.resource_groups.create_or_update( 31 | GROUP_NAME, 32 | {"location": "eastus"} 33 | ) 34 | 35 | # Create resource lock 36 | lock = lock_client.management_locks.create_or_update_at_resource_group_level( 37 | GROUP_NAME, 38 | LOCK_NAME, 39 | { 40 | "level": "CanNotDelete" 41 | } 42 | ) 43 | print("Create lock: {}".format(lock)) 44 | 45 | # Get lock 46 | lock = lock_client.management_locks.get_at_resource_group_level( 47 | GROUP_NAME, 48 | LOCK_NAME 49 | ) 50 | print("Get lock: {}".format(lock)) 51 | 52 | # Delete lock 53 | lock_client.management_locks.delete_at_resource_group_level( 54 | GROUP_NAME, 55 | LOCK_NAME 56 | ) 57 | print("Delete lock.") 58 | 59 | # Delete Group 60 | resource_client.resource_groups.begin_delete( 61 | GROUP_NAME 62 | ).result() 63 | 64 | 65 | if __name__ == "__main__": 66 | main() 67 | -------------------------------------------------------------------------------- /samples/resources/manage_resource_subscriptions.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.resource.subscriptions import SubscriptionClient 10 | 11 | 12 | def main(): 13 | # Create client 14 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 15 | subscription_client = SubscriptionClient( 16 | credential=DefaultAzureCredential() 17 | ) 18 | 19 | # List subscriptions 20 | page_result = subscription_client.subscriptions.list() 21 | result = [item for item in page_result] 22 | for item in result: 23 | print(item.subscription_id) 24 | print(item.tags) 25 | 26 | 27 | if __name__ == "__main__": 28 | main() 29 | -------------------------------------------------------------------------------- /samples/resources/manage_resource_tags.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | import os 7 | 8 | from azure.identity import DefaultAzureCredential 9 | from azure.mgmt.resource import ResourceManagementClient 10 | 11 | 12 | def main(): 13 | 14 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 15 | TAG_NAME = "tagxyz" 16 | TAG_VALUE = "value1" 17 | 18 | # Create client 19 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 20 | resource_client = ResourceManagementClient( 21 | credential=DefaultAzureCredential(), 22 | subscription_id=SUBSCRIPTION_ID 23 | ) 24 | 25 | # Create tag 26 | tag = resource_client.tags.create_or_update( 27 | TAG_NAME 28 | ) 29 | print("Create tag:\n{}".format(tag)) 30 | 31 | # Create tag value 32 | tag = resource_client.tags.create_or_update_value( 33 | TAG_NAME, 34 | TAG_VALUE 35 | ) 36 | print("Create tag value:\n{}".format(tag)) 37 | 38 | # Get at scope 39 | scope = "subscriptions/" + SUBSCRIPTION_ID 40 | tag = resource_client.tags.get_at_scope( 41 | scope 42 | ) 43 | print("Get tag:\n{}".format(tag)) 44 | 45 | # Delete tag value 46 | resource_client.tags.delete_value( 47 | TAG_NAME, 48 | TAG_VALUE 49 | ) 50 | print("Delete tag value:\n") 51 | 52 | # Delete tag 53 | tag = resource_client.tags.delete( 54 | TAG_NAME 55 | ) 56 | print("Delete tag.\n") 57 | 58 | 59 | if __name__ == "__main__": 60 | main() 61 | -------------------------------------------------------------------------------- /samples/resources/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | -------------------------------------------------------------------------------- /samples/scheduler/manage_job_collection.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.scheduler import SchedulerManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | JOB_COLLECTION = "jobcollectionxxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | scheduler_client = SchedulerManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create job collection 38 | job_collection = scheduler_client.job_collections.create_or_update( 39 | GROUP_NAME, 40 | JOB_COLLECTION, 41 | { 42 | "location": "eastus", 43 | "properties": { 44 | "sku": { 45 | "name": "Free" 46 | } 47 | } 48 | } 49 | ) 50 | print("Create job collection:\n{}".format(job_collection)) 51 | 52 | # Get job collection 53 | job_collection = scheduler_client.job_collections.get( 54 | GROUP_NAME, 55 | JOB_COLLECTION 56 | ) 57 | print("Get job collection:\n{}".format(job_collection)) 58 | 59 | # Delete job collection 60 | job_collection = scheduler_client.job_collections.begin_delete( 61 | GROUP_NAME, 62 | JOB_COLLECTION 63 | ).result() 64 | print("Delete job collection.\n") 65 | 66 | # Delete Group 67 | resource_client.resource_groups.begin_delete( 68 | GROUP_NAME 69 | ).result() 70 | 71 | 72 | if __name__ == "__main__": 73 | main() 74 | -------------------------------------------------------------------------------- /samples/scheduler/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-scheduler==7.0.0b1 3 | -------------------------------------------------------------------------------- /samples/search/manage_query_key.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.search import SearchManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | QUERY_KEY = "query_keyxxyyzz" 19 | SERVICE = "servicexxyz" 20 | 21 | # Create client 22 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 23 | resource_client = ResourceManagementClient( 24 | credential=DefaultAzureCredential(), 25 | subscription_id=SUBSCRIPTION_ID 26 | ) 27 | search_client = SearchManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | 32 | # Create resource group 33 | resource_client.resource_groups.create_or_update( 34 | GROUP_NAME, 35 | {"location": "eastus"} 36 | ) 37 | 38 | # - init depended resources - 39 | # Create service 40 | service = search_client.services.begin_create_or_update( 41 | GROUP_NAME, 42 | SERVICE, 43 | { 44 | 'location': "eastus", 45 | 'replica_count': 1, 46 | 'partition_count': 1, 47 | 'hosting_mode': 'Default', 48 | 'sku': { 49 | 'name': 'standard' 50 | } 51 | } 52 | ).result() 53 | print("Create service:\n{}".format(service)) 54 | # - end - 55 | 56 | # Create query key 57 | query_key = search_client.query_keys.create( 58 | GROUP_NAME, 59 | SERVICE, 60 | QUERY_KEY 61 | ) 62 | print("Create query key:\n{}".format(query_key)) 63 | 64 | # List query key 65 | query_keys = search_client.query_keys.list_by_search_service( 66 | GROUP_NAME, 67 | SERVICE 68 | ) 69 | print("List query key:\n{}".format(list(query_keys))) 70 | 71 | # Delete query key 72 | query_key = search_client.query_keys.delete( 73 | GROUP_NAME, 74 | SERVICE, 75 | QUERY_KEY 76 | ) 77 | print("Delete query key.\n") 78 | 79 | # Delete Group 80 | resource_client.resource_groups.begin_delete( 81 | GROUP_NAME 82 | ).result() 83 | 84 | 85 | if __name__ == "__main__": 86 | main() 87 | -------------------------------------------------------------------------------- /samples/search/manage_service.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.search import SearchManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | SERVICE = "servicexxyyzz" 19 | 20 | # Create client 21 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 22 | resource_client = ResourceManagementClient( 23 | credential=DefaultAzureCredential(), 24 | subscription_id=SUBSCRIPTION_ID 25 | ) 26 | search_client = SearchManagementClient( 27 | credential=DefaultAzureCredential(), 28 | subscription_id=SUBSCRIPTION_ID 29 | ) 30 | 31 | # Create resource group 32 | resource_client.resource_groups.create_or_update( 33 | GROUP_NAME, 34 | {"location": "eastus"} 35 | ) 36 | 37 | # Create service 38 | service = search_client.services.begin_create_or_update( 39 | GROUP_NAME, 40 | SERVICE, 41 | { 42 | 'location': "eastus", 43 | 'replica_count': 1, 44 | 'partition_count': 1, 45 | 'hosting_mode': 'Default', 46 | 'sku': { 47 | 'name': 'standard' 48 | } 49 | } 50 | ).result() 51 | print("Create service:\n{}".format(service)) 52 | 53 | # Get service 54 | service = search_client.services.get( 55 | GROUP_NAME, 56 | SERVICE 57 | ) 58 | print("Get service:\n{}".format(service)) 59 | 60 | # Delete service 61 | service = search_client.services.delete( 62 | GROUP_NAME, 63 | SERVICE 64 | ) 65 | print("Delete service.\n") 66 | 67 | # Delete Group 68 | resource_client.resource_groups.begin_delete( 69 | GROUP_NAME 70 | ).result() 71 | 72 | 73 | if __name__ == "__main__": 74 | main() 75 | -------------------------------------------------------------------------------- /samples/search/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource==15.0.0 3 | azure-mgmt-search==8.0.0b1 4 | -------------------------------------------------------------------------------- /samples/security/manage_advanced_threat_protection.py: -------------------------------------------------------------------------------- 1 | import os 2 | 3 | from azure.identity import DefaultAzureCredential 4 | from azure.mgmt.security import SecurityCenter 5 | from azure.mgmt.security.models import AdvancedThreatProtectionSetting 6 | 7 | 8 | def main(): 9 | credentials = DefaultAzureCredential() 10 | subscription = os.getenv('SUBSCRIPTION_ID') 11 | 12 | security_client = SecurityCenter(credentials, subscription) 13 | 14 | # Creates or updates the Advanced Threat Protection settings on a specified resource. 15 | security_client.advanced_threat_protection.create( 16 | resource_id='', # Specify resource id, e.g. "subscriptions/20ff7fc3-e762-44dd-bd96-b71116dcdc23/resourceGroups/SampleRG/providers/Microsoft.Storage/storageAccounts/samplestorageaccount" 17 | advanced_threat_protection_setting=AdvancedThreatProtectionSetting(is_enabled=True) 18 | ).result() 19 | 20 | # Gets the Advanced Threat Protection settings for the specified resource. 21 | security_features = security_client.advanced_threat_protection.get( 22 | resource_id='' # Specify resource id 23 | ) 24 | print(security_features.is_enabled) 25 | print(security_features.type) 26 | print(security_features.id) 27 | 28 | 29 | if __name__ == '__main__': 30 | main() 31 | -------------------------------------------------------------------------------- /samples/security/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-security=2.0.0 -------------------------------------------------------------------------------- /samples/servicebus/manage_queue.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.servicebus import ServiceBusManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupxx" 18 | NAMESPACE = "namespacexxyyzz" 19 | QUEUE = "queuexxyyzz" 20 | 21 | # Create client 22 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 23 | resource_client = ResourceManagementClient( 24 | credential=DefaultAzureCredential(), 25 | subscription_id=SUBSCRIPTION_ID 26 | ) 27 | servicebus_client = ServiceBusManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | 32 | # Create resource group 33 | resource_client.resource_groups.create_or_update( 34 | GROUP_NAME, 35 | {"location": "eastus"} 36 | ) 37 | 38 | # - init depended resources - 39 | # Create namespace 40 | namespace = servicebus_client.namespaces.begin_create_or_update( 41 | GROUP_NAME, 42 | NAMESPACE, 43 | { 44 | "sku": { 45 | "name": "Standard", 46 | "tier": "Standard" 47 | }, 48 | "location": "eastus", 49 | "tags": { 50 | "tag1": "value1", 51 | "tag2": "value2" 52 | } 53 | } 54 | ).result() 55 | # - end - 56 | 57 | # Create queue 58 | queue = servicebus_client.queues.create_or_update( 59 | GROUP_NAME, 60 | NAMESPACE, 61 | QUEUE, 62 | { 63 | "enable_partitioning": True 64 | } 65 | ) 66 | print("Create queue:\n{}".format(queue)) 67 | 68 | # Get queue 69 | queue = servicebus_client.queues.get( 70 | GROUP_NAME, 71 | NAMESPACE, 72 | QUEUE 73 | ) 74 | print("Get queue:\n{}".format(queue)) 75 | 76 | # Delete queue 77 | queue = servicebus_client.queues.delete( 78 | GROUP_NAME, 79 | NAMESPACE, 80 | QUEUE 81 | ) 82 | print("Delete queue.\n") 83 | 84 | # Delete Group 85 | resource_client.resource_groups.begin_delete( 86 | GROUP_NAME 87 | ).result() 88 | 89 | 90 | if __name__ == "__main__": 91 | main() 92 | -------------------------------------------------------------------------------- /samples/servicebus/manage_topic.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.servicebus import ServiceBusManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | GROUP_NAME = "testgroupx" 18 | NAMESPACE = "namespacexxyyzz" 19 | TOPIC = "topicxxyyzz" 20 | 21 | # Create client 22 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 23 | resource_client = ResourceManagementClient( 24 | credential=DefaultAzureCredential(), 25 | subscription_id=SUBSCRIPTION_ID 26 | ) 27 | servicebus_client = ServiceBusManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | 32 | # Create resource group 33 | resource_client.resource_groups.create_or_update( 34 | GROUP_NAME, 35 | {"location": "eastus"} 36 | ) 37 | 38 | # - init depended resources - 39 | namespace = servicebus_client.namespaces.begin_create_or_update( 40 | GROUP_NAME, 41 | NAMESPACE, 42 | { 43 | "sku": { 44 | "name": "Standard", 45 | "tier": "Standard" 46 | }, 47 | "location": "eastus", 48 | "tags": { 49 | "tag1": "value1", 50 | "tag2": "value2" 51 | } 52 | } 53 | ).result() 54 | # - end - 55 | 56 | # Create topic 57 | topic = servicebus_client.topics.create_or_update( 58 | GROUP_NAME, 59 | NAMESPACE, 60 | TOPIC, 61 | { 62 | "enable_express": True 63 | } 64 | ) 65 | print("Create topic:\n{}".format(topic)) 66 | 67 | # Get topic 68 | topic = servicebus_client.topics.get( 69 | GROUP_NAME, 70 | NAMESPACE, 71 | TOPIC 72 | ) 73 | print("Get topic:\n{}".format(topic)) 74 | 75 | # Delete topic 76 | topic = servicebus_client.topics.delete( 77 | GROUP_NAME, 78 | NAMESPACE, 79 | TOPIC 80 | ) 81 | print("Delete topic.\n") 82 | 83 | # Delete Group 84 | resource_client.resource_groups.begin_delete( 85 | GROUP_NAME 86 | ).result() 87 | 88 | 89 | if __name__ == "__main__": 90 | main() 91 | -------------------------------------------------------------------------------- /samples/servicebus/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-network>=16.0.0 3 | azure-mgmt-resource>=15.0.0 4 | azure-mgmt-servicebus==6.0.0 5 | -------------------------------------------------------------------------------- /samples/servicelinker/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity==1.9.0 2 | azure-mgmt-servicelinker==1.0.0 3 | azure-mgmt-resource==21.0.0 4 | azure-mgmt-appplatform==7.0.0 5 | azure-mgmt-sql==3.0.1 6 | azure-mgmt-web==6.1.0 7 | azure-mgmt-keyvault==9.3.0 8 | azure-mgmt-msi==6.0.0 9 | -------------------------------------------------------------------------------- /samples/sql/manage_firewall_rule.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.sql import SqlManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | PASSWORD = os.environ.get("PASSWORD", None) 18 | GROUP_NAME = "testgroupx" 19 | FIREWALL_RULE = "firewall_rulexxyyzz" 20 | SERVER = "serverxx" 21 | 22 | # Create client 23 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 24 | resource_client = ResourceManagementClient( 25 | credential=DefaultAzureCredential(), 26 | subscription_id=SUBSCRIPTION_ID 27 | ) 28 | sql_client = SqlManagementClient( 29 | credential=DefaultAzureCredential(), 30 | subscription_id=SUBSCRIPTION_ID 31 | ) 32 | 33 | # Create resource group 34 | resource_client.resource_groups.create_or_update( 35 | GROUP_NAME, 36 | {"location": "eastus"} 37 | ) 38 | 39 | # - init depended resources - 40 | # Create Server 41 | server = sql_client.servers.begin_create_or_update( 42 | GROUP_NAME, 43 | SERVER, 44 | { 45 | "location": "eastus", 46 | "administrator_login": "dummylogin", 47 | "administrator_login_password": PASSWORD 48 | } 49 | ).result() 50 | print("Create server:\n{}".format(server)) 51 | # - end - 52 | 53 | # Create firewall rule 54 | firewall_rule = sql_client.firewall_rules.create_or_update( 55 | GROUP_NAME, 56 | SERVER, 57 | FIREWALL_RULE, 58 | { 59 | "start_ip_address": "0.0.0.3", 60 | "end_ip_address": "0.0.0.3" 61 | } 62 | ) 63 | print("Create firewall rule:\n{}".format(firewall_rule)) 64 | 65 | # Get firewall rule 66 | firewall_rule = sql_client.firewall_rules.get( 67 | GROUP_NAME, 68 | SERVER, 69 | FIREWALL_RULE 70 | ) 71 | print("Get firewall rule:\n{}".format(firewall_rule)) 72 | 73 | # Delete firewall rule 74 | firewall_rule = sql_client.firewall_rules.delete( 75 | GROUP_NAME, 76 | SERVER, 77 | FIREWALL_RULE 78 | ) 79 | print("Delete firewall rule.\n") 80 | 81 | # Delete Group 82 | resource_client.resource_groups.begin_delete( 83 | GROUP_NAME 84 | ).result() 85 | 86 | 87 | if __name__ == "__main__": 88 | main() 89 | -------------------------------------------------------------------------------- /samples/sql/manage_server.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.sql import SqlManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | PASSWORD = os.environ.get("PASSWORD", None) 18 | GROUP_NAME = "testgroupx" 19 | SERVER = "serverxxyyzz" 20 | 21 | # Create client 22 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 23 | resource_client = ResourceManagementClient( 24 | credential=DefaultAzureCredential(), 25 | subscription_id=SUBSCRIPTION_ID 26 | ) 27 | sql_client = SqlManagementClient( 28 | credential=DefaultAzureCredential(), 29 | subscription_id=SUBSCRIPTION_ID 30 | ) 31 | 32 | # Create resource group 33 | resource_client.resource_groups.create_or_update( 34 | GROUP_NAME, 35 | {"location": "eastus"} 36 | ) 37 | 38 | # Create server 39 | server = sql_client.servers.begin_create_or_update( 40 | GROUP_NAME, 41 | SERVER, 42 | { 43 | "location": "eastus", 44 | "administrator_login": "dummylogin", 45 | "administrator_login_password": PASSWORD 46 | } 47 | ).result() 48 | print("Create server:\n{}".format(server)) 49 | 50 | # Get server 51 | server = sql_client.servers.get( 52 | GROUP_NAME, 53 | SERVER 54 | ) 55 | print("Get server:\n{}".format(server)) 56 | 57 | # Update server 58 | server = sql_client.servers.begin_update( 59 | GROUP_NAME, 60 | SERVER, 61 | { 62 | "administrator_login": "dummylogin", 63 | "administrator_login_password": PASSWORD 64 | } 65 | ).result() 66 | print("Update server:\n{}".format(server)) 67 | 68 | # Delete server 69 | server = sql_client.servers.begin_delete( 70 | GROUP_NAME, 71 | SERVER 72 | ).result() 73 | print("Delete server.\n") 74 | 75 | # Delete Group 76 | resource_client.resource_groups.begin_delete( 77 | GROUP_NAME 78 | ).result() 79 | 80 | 81 | if __name__ == "__main__": 82 | main() 83 | -------------------------------------------------------------------------------- /samples/sql/manage_server_dns_alias.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | 9 | from azure.identity import DefaultAzureCredential 10 | from azure.mgmt.sql import SqlManagementClient 11 | from azure.mgmt.resource import ResourceManagementClient 12 | 13 | 14 | def main(): 15 | 16 | SUBSCRIPTION_ID = os.environ.get("SUBSCRIPTION_ID", None) 17 | PASSWORD = os.environ.get("PASSWORD", None) 18 | GROUP_NAME = "testgroupx" 19 | SERVER_DNS_ALIAS = "serverdnsaliasxxyyzz" 20 | SERVER = "serverxxy" 21 | 22 | # Create client 23 | # # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 24 | resource_client = ResourceManagementClient( 25 | credential=DefaultAzureCredential(), 26 | subscription_id=SUBSCRIPTION_ID 27 | ) 28 | sql_client = SqlManagementClient( 29 | credential=DefaultAzureCredential(), 30 | subscription_id=SUBSCRIPTION_ID 31 | ) 32 | 33 | # Create resource group 34 | resource_client.resource_groups.create_or_update( 35 | GROUP_NAME, 36 | {"location": "eastus"} 37 | ) 38 | 39 | # - init depended resources - 40 | # Create Server 41 | server = sql_client.servers.begin_create_or_update( 42 | GROUP_NAME, 43 | SERVER, 44 | { 45 | "location": "eastus", 46 | "administrator_login": "dummylogin", 47 | "administrator_login_password": PASSWORD 48 | } 49 | ).result() 50 | print("Create server:\n{}".format(server)) 51 | # - end - 52 | 53 | # Create server dns alias 54 | server_dns_alias = sql_client.server_dns_aliases.begin_create_or_update( 55 | GROUP_NAME, 56 | SERVER, 57 | SERVER_DNS_ALIAS 58 | ).result() 59 | print("Create server dns alias:\n{}".format(server_dns_alias)) 60 | 61 | # Get server dns alias 62 | server_dns_alias = sql_client.server_dns_aliases.get( 63 | GROUP_NAME, 64 | SERVER, 65 | SERVER_DNS_ALIAS 66 | ) 67 | print("Get server dns alias:\n{}".format(server_dns_alias)) 68 | 69 | # Delete server dns alias 70 | server_dns_alias = sql_client.server_dns_aliases.begin_delete( 71 | GROUP_NAME, 72 | SERVER, 73 | SERVER_DNS_ALIAS 74 | ).result() 75 | print("Delete server dns alias.\n") 76 | 77 | # Delete Group 78 | resource_client.resource_groups.begin_delete( 79 | GROUP_NAME 80 | ).result() 81 | 82 | 83 | if __name__ == "__main__": 84 | main() 85 | -------------------------------------------------------------------------------- /samples/sql/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-keyvault-keys==4.3.0 3 | azure-mgmt-keyvault==8.0.0 4 | azure-mgmt-network==16.0.0 5 | azure-mgmt-resource==15.0.0 6 | azure-mgmt-sql 7 | azure-mgmt-storage==16.0.0 8 | -------------------------------------------------------------------------------- /samples/storage/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-mgmt-resource 3 | azure-mgmt-storage 4 | -------------------------------------------------------------------------------- /samples/testbase/manage_testbase_account.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import os 8 | import json 9 | 10 | # Use `from azure.identity import AzureCliCredential` if authenticating via Azure CLI for test 11 | from azure.identity import DefaultAzureCredential 12 | 13 | from azure.mgmt.testbase import TestBase 14 | from azure.mgmt.testbase.models import TestBaseAccountResource 15 | from azure.mgmt.testbase.models import TestBaseAccountSKU 16 | 17 | def _format_json(content): 18 | return json.dumps(content.serialize(keep_readonly=True), indent=4, separators=(',', ': ')) 19 | 20 | def main(): 21 | # Requesting token from Azure 22 | print("Requesting token from Azure...") 23 | # For other authentication approaches, please see: https://pypi.org/project/azure-identity/ 24 | # Use `credential = AzureCliCredential()` if authenticating via Azure CLI for test 25 | credential = DefaultAzureCredential() 26 | 27 | # Run `export SUBSCRIPTION_ID=""` on Linux-based OS 28 | # Run `set SUBSCRIPTION_ID=` on Windows 29 | subscription_id = os.environ.get("SUBSCRIPTION_ID", None) 30 | 31 | # Set variables 32 | resource_group = "" # replace with real resource group name 33 | testBaseAccount_name = "contoso-testbaseAccount" 34 | testBaseAccount_location = "global" 35 | sku_name = "S0" 36 | sku_tier = "Standard" 37 | sku_locations = {"global"} 38 | 39 | # Create client 40 | testbase_client = TestBase(credential, subscription_id) 41 | 42 | # Create sku for TestBaseAccount 43 | sku = TestBaseAccountSKU(name=sku_name, tier=sku_tier, locations=sku_locations) 44 | 45 | # Create TestBaseAccount 46 | print("Creating TestBaseAccount...") 47 | parameters = TestBaseAccountResource(location=testBaseAccount_location, sku=sku) 48 | testBaseAccount = testbase_client.test_base_accounts.begin_create(resource_group, testBaseAccount_name, parameters).result() 49 | 50 | # Get TestBaseAccount 51 | print("Getting TestBaseAccount...") 52 | result = testbase_client.test_base_accounts.get(resource_group, testBaseAccount_name) 53 | print(_format_json(result)) 54 | 55 | if __name__ == "__main__": 56 | main() 57 | -------------------------------------------------------------------------------- /samples/testbase/requirements.txt: -------------------------------------------------------------------------------- 1 | azure-identity 2 | azure-storage-blob 3 | azure-mgmt-testbase==1.0.0b1 -------------------------------------------------------------------------------- /samples/testbase/testbase_util.py: -------------------------------------------------------------------------------- 1 | # -------------------------------------------------------------------------- 2 | # Copyright (c) Microsoft Corporation. All rights reserved. 3 | # Licensed under the MIT License. See License.txt in the project root for 4 | # license information. 5 | # -------------------------------------------------------------------------- 6 | 7 | import json 8 | 9 | def format_json(content): 10 | return json.dumps(content.serialize(keep_readonly=True), indent=4, separators=(',', ': ')) 11 | --------------------------------------------------------------------------------