【问题标题】:Add endpoints in Traffic Manager using python Azure SDK使用 python Azure SDK 在流量管理器中添加端点
【发布时间】:2020-10-21 10:33:48
【问题描述】:

我在 azure 中有一个流量管理器配置文件,我想使用我的 python 脚本将端点添加到我的流量管理器。我参考了 python sdk for azure 来添加端点。

我们可以使用这个函数添加或更新端点

tm_client.endpoints.create_or_update()

但我似乎不明白需要在这个函数中传递的参数。如果有人可以发布示例代码或帮助我。

【问题讨论】:

    标签: azure azure-traffic-manager azure-sdk-python


    【解决方案1】:

    如果要向 Azure 流量管理器添加端点,则需要定义 Endpoint 对象,profileNamegroupNameendpointType。此外,请注意,我们必须根据端点类型和流量路由方式定义不同的Endpoint 对象。更多详情请参考here

    例如。我的流量路由方式是Priority,端点类型是AzureEndpoints

    例如

    1. 创建服务主体并将 Contributor 角色分配给 sp
    az login
    az ad sp create-for-rbac -n "MyApp" --role contributor \
        --scopes /subscriptions/{SubID} --sdk-auth true
    
    1. 代码
    from azure.common.credentials import ServicePrincipalCredentials
    from azure.mgmt.trafficmanager import TrafficManagerManagementClient
    from azure.mgmt.trafficmanager.models import EndpointStatus, Endpoint
    
    client_id = "<sp appId>"
    secret = "<sp password>"
    tenant = "<sp tenant>"
    subscription_ID = "<>"
    
    tm_client = TrafficManagerManagementClient(creds, subscription_ID)
    # define endpoint
    param = Endpoint(
        # my target resource is app service
        target_resource_id='/subscriptions/<>/resourceGroups/<>/providers/Microsoft.Web/sites/<>',
        endpoint_status=EndpointStatus.enabled,
        priority=1
    )
    result = tm_client.endpoints.create_or_update(
        resource_group_name='testsignlar',
        profile_name='test05',
        endpoint_type='AzureEndpoints',
        endpoint_name='mypoint',
        parameters=param)
    
    print(result.id)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多