简体   繁体   English

如何使用 python SDK 获取 Azure FunctionApp 列表

[英]How to get Azure FunctionApp list using python SDK

I am trying to get details of function apps using python SDK and finding suitable client and methods.我正在尝试使用 python SDK 获取功能应用程序的详细信息并寻找合适的客户端和方法。 I can use ResourceManagementClient and get basic info on them but does not get runtime and other details.我可以使用 ResourceManagementClient 并获取有关它们的基本信息,但无法获取运行时和其他详细信息。 I can run CLI az functionapp list and get all the details.我可以运行 CLI az functionapp list并获取所有详细信息。 I am looking to do something equivalent using python SDK我希望使用 python SDK 做一些等效的事情

Below code will give us the list of function apps with all the details:下面的代码将为我们提供包含所有详细信息的功能应用程序列表:

Enter your subscription id and resource group to their respective variables.将您的订阅 ID 和资源组输入到它们各自的变量中。

# Import the needed credential and management objects from the libraries.
from types import FunctionType
from azure.identity import AzureCliCredential
from azure.mgmt.resource import ResourceManagementClient
import os

credential = AzureCliCredential()
subscription_id = "SUBSCRIPTION_ID" #Add your subscription ID
resource_group = "RESOURCE_GROUP_ID" #Add your resource group
resource_client = ResourceManagementClient(credential, subscription_id)
resource_list = resource_client.resources.list()

print(resource_list)
column_width =36
print("Resource".ljust(column_width) + "Type".ljust(column_width)+ "Id".ljust(column_width))
print("-" * (column_width * 2))
for resource in list (resource_list) :
    if (resource.type == "Microsoft.Web/sites" ) and ((resource.kind == "functionapp" ) or (resource.kind == "functionapp,linux" )) :
        print(f"{resource.name:<{column_width}}{resource.type:<{column_width}}{resource.id:<{column_width}}")

Check the documentation for adding extra parameters.查看文档以添加额外参数。

Output information from my testing:我测试的输出信息:

输出图片

You can use the WebSiteManagementClient class to query more details of your function app.您可以使用WebSiteManagementClient类查询函数应用的更多详细信息。

A WebSiteManagementClient instance can instantiate the WebAppsOperations class which will allow you to perform many actions on your function app. WebSiteManagementClient 实例可以实例化WebAppsOperations类,这将允许您在函数应用程序上执行许多操作。

See sample code below that worked for me:请参阅下面对我有用的示例代码:

from azure.identity import AzureCliCredential
from azure.mgmt.web import WebSiteManagementClient

credential = AzureCliCredential()
subscription_id = "SUBSCRIPTION_ID" #Add your subscription ID
resource_group = "RESOURCE_GROUP_ID" #Add your resource group
function_app_name = "FUNCTION_APP_NAME" #Add your function app name

# Create the web management client
web_mgmt_client = WebSiteManagementClient(credential, subscription_id)

# Get function app details
function_app_details = app_service_client.web_apps.get(resource_group, function_app_name)
print(function_app_details)

# Get function app configuration details
function_app_config = app_service_client.web_apps.get_configuration(resource_group, function_app_name)
print(function_app_config)

# List function app application settings
function_app_settings = app_service_client.web_apps.list_application_settings(resource_group, function_app_name)
print(function_app_settings)

See WebAppsOperations methods for any other details you need to access.有关您需要访问的任何其他详细信息,请参阅WebAppsOperations 方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM