You can use SDK for Java provided by Enterprise Distributed Application Service (EDAS) to call the EDAS API.

Obtain EDAS SDK for Python

Python 2.7.x or later is required.

  • Use pip to install SDK for Python (recommended if Internet connection is available)
    root# pip install -U aliyun-python-sdk-core
    root# pip install -U aliyun-python-sdk-edas
    Note root# indicates that you must run the preceding commands as the root user in Linux. In macOS, add sudo before the commands and then run them. We recommend that you run the preceding commands every two to three months to update the versions of the two SDK packages.
  • Install SDK for Python offline (recommended if Internet connection is unavailable)
    1. On a machine where Internet connection is available, visit Alibaba Cloud Open Platform. Then, download the SDK for Python core library as prompted.
    2. On the machine where you want to use EDAS SDK for Python to call the API, upload the downloaded package and decompress it. In the aliyun-python-sdk-core directory, run the following command to install the aliyun-python-sdk-core SDK. In the aliyun-python-sdk-edas directory, run the following command to install the aliyun-python-sdk-edas SDK.
      root# python setup.py install

Use EDAS SDK for Python to call the EDAS API

Replace the values of the aliyun_user_ak, aliyun_user_sk, and region_id common parameters in the following sample code with your actual values, and replace the values of other necessary parameters with your actual values. For more information about the common parameters, see Common parameters for API calls.

#!/usr/bin/env python
# -*- coding=UTF-8 -*-

import sys, json
from aliyunsdkcore.client import AcsClient
from aliyunsdkcore.profile import region_provider
from aliyunsdkedas.request.v20170801.ListApplicationRequest import ListApplicationRequest
from aliyunsdkedas.request.v20170801.ListDeployGroupRequest import ListDeployGroupRequest


if __name__ == '__main__':
    #The AccessKey ID of your Alibaba Cloud account or Resource Access Management (RAM) user.
    aliyun_user_ak = 'LTAIPQxxxxxxxxxx'
    #The AccessKey secret of your Alibaba Cloud account or RAM user.
    aliyun_user_sk = 'W75qdr9ORkxxxxxxxxxxxxxx'
    #The ID of the region that corresponds to your application and resources on which you want to make API requests. The resources include Elastic Compute Service (ECS) instances, Server Load Balancer (SLB) instances, and virtual private clouds (VPCs). 
    region_id = 'cn-shanghai'


    client = AcsClient(ak=aliyun_user_ak, secret=aliyun_user_sk, region_id=region_id, timeout=300)
    applist_req = ListApplicationRequest()
    applist_resp = json.loads(client.do_action_with_exception(applist_req))
    if applist_resp['Code'] == 200:
        applist = applist_resp['ApplicationList']['Application']
        for app in applist:
            app_name = app['Name']
            app_id = app['AppId']
            print u'Application name:'+ app_name + u',Application ID:' + app_id
            dglist_req = ListDeployGroupRequest()
            dglist_req.set_AppId(app_id)
            dglist_resp = json.loads(client.do_action_with_exception(dglist_req))
            if dglist_resp['Code'] == 200:
                dglist = dglist_resp['DeployGroupList']['DeployGroup']
                for dg in dglist:
                    dg_name = dg['GroupName']
                    if dg_name == '_DEFAULT_GROUP':
                        dg_name=u'Default group'
                    dg_id = dg['GroupId']
                    print u'\tGroup name: '+ dg_name + u',Group ID: ' + dg_id
            else:
                Print u'Failed to obtain ' + app_name + u 'instance groups.'
    else:
        Print u'Failed to obtain applications.'
            
Note
  • In aliyun-python-sdk-core 2.13.9 and later and aliyun-python-sdk-edas 2.52.1 and later, you do not need to set product_name (Edas) or region_domain (for example, edas.cn-shanghai.aliyuncs.com) when you use EDAS SDK for Python to call the EDAS API. The aliyun-python-sdk-core SDK can automatically resolve the corresponding endpoint based on the value of region_id. To use this feature, update aliyun-python-sdk-core and aliyun-python-sdk-edas to their latest versions.
    root# pip install -U aliyun-python-sdk-core
    root# pip install -U aliyun-python-sdk-edas
    root# pip list 2>/dev/null | grep -E "aliyun-python-sdk-core|aliyun-python-sdk-edas"
    aliyun-python-sdk-core        2.13.9
    aliyun-python-sdk-edas        2.52.1          
  • The preceding sample code has been tested in Python 2.7.x and is effective in this version. When you use Python 3.x, make sure that Python 3.x is compatible.

References