OpenAPI文档
  • 基础、平台产品
  • CDN
  • Kafka
  • Memcached
  • MongoDB
  • MySQL
  • Redis
  • 对象存储
  • 对象存储(v1.1)
  • 负载均衡
    • 新版MongoDB
    • Vira
    • Vira2
    • OpenAPI
    • 负载均衡

    负载均衡

    # 负载均衡 公开API目录

    • 认证方式
      • 1.公共请求参数
      • 2.签名机制
        • 步骤一:构造规范化请求字符串
        • 步骤二:构造签名字符串
      • 3.获取签名代码
    • 错误码
    • 访问地址
    • API概览
      • 1.DescribeZones
      • 2.DescribeLoadBalancersSpec
      • 3.CreateLoadBalancer
      • 4.DescribeLoadBalancers
      • 5.DescribeLoadBalancersModifySpec
      • 6.ModifyLoadBalancerInstanceSpec
      • 7.DeleteloadBalancer
      • 8.DescribeCACertificates
      • 9.DescribeCACertificate
      • 10.DeleteCACertificate
      • 11.UploadCACertificate
      • 12.DescribeLoadBalancerStrategys
      • 13.ModifyLoadBalancerStrategys
      • 14.AddLoadBalancerStrategys
      • 15.DescribeHaproxyCustomConfig
      • 16.ModifyHaproxyCustomConfig
      • 17.DescribeLBInstancePerformance
      • 18.ModifyLoadBalancerName

    # API概览

    负载均衡HaProxy(以下简称Ha)产品提供以下相关API接口

    API 描述
    1. DescribeZones 获取负载均衡Ha支持的区域。
    2. DescribeLoadBalancersSpec 获取某个站点支持的Haproxy产品类型以及规格。
    3. CreateLoadBalancer 创建Ha实例。
    4. DescribeLoadBalancers 获取Ha实例列表。
    5. DescribeLoadBalancersModifySpec 获取实例Ha的配置变更所支持的规格。
    6. ModifyLoadBalancerInstanceSpec 修改实例规格。
    7. DeleteLoadBalancer 删除Ha实例。
    8. DescribeCACertificates 获取用户的证书列表。
    9. DescribeCACertificate 获取用户的证书详情。
    10. DeleteCACertificate 删除证书。
    11. UploadCACertificate 添加证书。
    12. DescribeLoadBalancerStrategys 获取Ha实例的当前监听的策略配置列表。
    13. ModifyLoadBalancerStrategys 修改(删除、修改、添加)Ha实例的当前监听的策略配置列表。
    14. AddLoadBalancerStrategys 增加(不覆盖)Ha实例的当前监听的策略配置列表。
    15. DescribeHaproxyCustomConfig 获取Ha自定义配置策略的配置文件。
    16. ModifyHaproxyCustomConfig 修改Ha自定义配置策略的配置文件。
    17. DescribeLBInstancePerformance 获取Ha实例的监控值。
    18. ModifyLoadBalancerName 修改Ha实例的名称。

    # 错误码

    HttpCode 错误码 描述
    400 ArgMissing 缺少参数错误
    400 InvalidParameter 参数错误
    400 BadArgs 参数错误
    400 UnsupportedOperation 操作不支持
    404 ResourceNotFound 资源不存在
    409 ResourceInUse 资源正在被其他任务占用,操作冲突
    500 InternalError 内部错误
    500 CreateOrderExcept 创建订单异常

    # 访问地址

    地区 访问地址
    中国大陆 cdsapi.capitalonline.net
    亚太地区 cdsapi-asia.capitalonline.net
    欧美地区 cdsapi-us.capitalonline.net

    # 1.DescribeZones

    Action: DescribeZones

    描述: 获取负载均衡Ha支持的区域

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: GET

    请求参数: 无

    请求示例

    def get_haproxy_zones():
        """
        获取haproxy支持的站点区域
        """
        action = "DescribeZones"
        method = "GET"
        param = {
        }
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param)
        res = requests.get(url)
        result = json.loads(res.content)
        result = json.dumps(result)  # json格式化
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12

    返回示例

    {
        "Code": "Success",
        "Data": [{
            "CityId": "3082f45e-306e-11e7-9796-0050569b4d9c",
            "CityName": "洛杉矶",
            "IsSaling": 1,
            "RegionId": "US_LosAngeles_A",
            "RegionName": "北美地区",
            "SiteName": "洛杉矶1"
        }, {
            "CityId": "7b98a5d1-306e-11e7-9796-0050569b4d9c",
            "CityName": "法兰克福",
            "IsSaling": 1,
            "RegionId": "EUR_Germany_A",
            "RegionName": "欧洲地区",
            "SiteName": "德国1"
        }, {
            "CityId": "8737606f-306d-11e7-9796-0050569b4d9c",
            "CityName": "东京",
            "IsSaling": 1,
            "RegionId": "APAC_Tokyo_A",
            "RegionName": "亚太地区",
            "SiteName": "东京1"
        }, {
            "CityId": "27b57297-306d-11e7-9796-0050569b4d9c",
            "CityName": "香港",
            "IsSaling": 1,
            "RegionId": "CN_Hongkong_A",
            "RegionName": "亚太地区",
            "SiteName": "香港1"
        }, {
            "CityId": "a8937b00-306d-11e7-9796-0050569b4d9c",
            "CityName": "新加坡",
            "IsSaling": 1,
            "RegionId": "APAC_Singapore_A",
            "RegionName": "亚太地区",
            "SiteName": "新加坡1"
        }, {
            "CityId": "5c432e0e-306e-11e7-9796-0050569b4d9c",
            "CityName": "阿姆斯特丹",
            "IsSaling": 1,
            "RegionId": "EUR_Netherlands_A",
            "RegionName": "欧洲地区",
            "SiteName": "荷兰1"
        }, {
            "CityId": "154ed19e-306e-11e7-9796-0050569b4d9c",
            "CityName": "纽约",
            "IsSaling": 1,
            "RegionId": "US_NewYork_A",
            "RegionName": "北美地区",
            "SiteName": "纽约1"
        }, {
            "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c",
            "CityName": "北京",
            "IsSaling": 1,
            "RegionId": "CN_Beijing_B",
            "RegionName": "中国大陆",
            "SiteName": "北京2"
        }, {
            "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c",
            "CityName": "北京",
            "IsSaling": 1,
            "RegionId": "CN_Beijing_E",
            "RegionName": "中国大陆",
            "SiteName": "北京5"
        }, {
            "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c",
            "CityName": "北京",
            "IsSaling": 1,
            "RegionId": "CN_Beijing_A",
            "RegionName": "中国大陆",
            "SiteName": "北京1"
        }, {
            "CityId": "e48e2312-306d-11e7-9796-0050569b4d9c",
            "CityName": "达拉斯",
            "IsSaling": 1,
            "RegionId": "US_Dallas_A",
            "RegionName": "北美地区",
            "SiteName": "达拉斯1"
        }, {
            "CityId": "713d3745-306d-11e7-9796-0050569b4d9c",
            "CityName": "台北",
            "IsSaling": 1,
            "RegionId": "CN_Taipei_A",
            "RegionName": "亚太地区",
            "SiteName": "台北1"
        }, {
            "CityId": "123d0d01-306d-11e7-9796-0050569b4d9c",
            "CityName": "无锡",
            "IsSaling": 1,
            "RegionId": "CN_Wuxi_A",
            "RegionName": "中国大陆",
            "SiteName": "无锡1"
        }, {
            "CityId": "87fcbbd6-be0a-11e7-9d6b-0242ac110004",
            "CityName": "首尔",
            "IsSaling": 1,
            "RegionId": "APAC_Seoul_A",
            "RegionName": "亚太地区",
            "SiteName": "首尔1"
        }, {
            "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c",
            "CityName": "北京",
            "IsSaling": 1,
            "RegionId": "CN_Beijing_C",
            "RegionName": "中国大陆",
            "SiteName": "北京3"
        }, {
            "CityId": "c11a5abe-3f7e-11e7-86b1-0242ac11000e",
            "CityName": "广州",
            "IsSaling": 1,
            "RegionId": "CN_Guangzhou_A",
            "RegionName": "中国大陆",
            "SiteName": "广州1"
        }, {
            "CityId": "b44355d0-65e7-11e7-8ea9-0050569b651c",
            "CityName": "上海",
            "IsSaling": 1,
            "RegionId": "CN_Shanghai_A",
            "RegionName": "中国大陆",
            "SiteName": "上海1"
        }, {
            "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c",
            "CityName": "北京",
            "IsSaling": 1,
            "RegionId": "CN_Beijing_H",
            "RegionName": "中国大陆",
            "SiteName": "北京8"
        }],
        "Message": "Success."
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131

    返回参数说明

    参数名 类型 说明
    Message string 信息描述
    Code string 状态码
    Data string 数据
    RegionId string 站点编号
    RegionName string 区域名称
    CityId string 城市编号
    CityName string 城市名称
    SiteName string 站点名称
    IsSaling Int 站点是否能购买服务,1:支持购买;0:已下线

    # 2.DescribeLoadBalancersSpec

    Action: DescribeLoadBalancersSpec

    描述: 获取某个站点支持的Haproxy产品类型以及规格

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: GET

    请求参数:

    参数名 必选 类型 说明
    RegionId 是 string 站点编号

    请求示例

    def get_haproxy_specInfo():
        """
        获取某个站点支持的haproxy产品类型以及规格
        """
        action = "DescribeLoadBalancersSpec"
        method = "GET"
        param = {
            "RegionId": "CN_Hongkong_A"
        }
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param)
        res = requests.get(url)
        result = json.loads(res.content)
        result = json.dumps(result)  # json格式化
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13

    返回参数说明

    参数名 类型 说明
    Code string 状态码
    Data DataObj 可购买的HaProxy产品类型以及规格数据对象
    Message string 返回调用接口状态信息和code相对应,比如:Success, Error
    TaskId string 任务Id, 暂时不支持根据任务查询任务状态

    # DataObj

    参数名 类型 说明
    ProductName string 产品名称,比如haproxy
    Products list of ProductObj 该类产品支持的产品列表
    RegionId string 站点编号

    # ProductObj

    参数名 类型 说明
    Architectures list of ArchitectureObj 产品支持的架构列表
    Version string 产品支持的版本

    # ArchitectureObj

    参数名 类型 说明
    ArchitectureName string 架构名称
    ArchitectureType int 架构类型:
    1-主从版
    ComputeRoles list of ComputeRoleObj 支持的计算类型,不同的计算类型支持不同规格,并支持添加不同类型的硬盘
    EnginesType string 引擎类型
    SubProductName string 子产品名称,比如:haproxy 主从版

    # ComputeRoleObj

    参数名 类型 说明
    ComputeName string 计算类型名称, 比如:通用型
    ComputeType int 支持的计算类型(目前仅支持通用型计算类型):
    0-通用型
    Standards StandardObj 该类型支持的规格

    # StandardObj

    参数名 类型 说明
    AttachDisk list of AttachDiskObj 该类型规格能够添加的磁盘类型列表
    CpuRam list of CpuRamObj 支持的规格列表

    # AttachDiskObj

    参数名 类型 说明
    BasicIops string 基础的磁盘的iops
    DiskMax int 单次支持扩容到最大磁盘容量为2000
    DiskMaxExpand string 磁盘最大可扩容大小
    DiskMin string 磁盘容量支持的最小值,起步为100
    DiskName string 磁盘类型名称,包含SSD和性能型
    SSD:SSD磁盘,磁盘IOPS默认为5000,可购买IOPS性能包
    性能型:普通SSD盘,磁盘IOPS限定在3000
    DiskStep string 磁盘扩容步长,步长大小=100
    DiskUnit string 磁盘容量单位:GB
    DiskValue string 磁盘类型,用于创建服务实例指定磁盘类型 (创建服务时候使用)

    # CpuRamObj

    参数名 类型 说明
    CPU int 核心数量,单位:个
    Name string 规格名称
    PaasGoodsId int 具体的产品编号,根据产品编号确定购买哪一种规格
    RAM int 内存大小,单位:GB

    返回示例

    {
        "Code": "Success",
        "Data": {
            "ProductName": "haproxy",
            "Products": [{
                "Architectures": [{
                    "ArchitectureName": "主从",
                    "ComputeRoles": [{
                        "ComputeName": "通用型",
                        "Standards": {
                            "AttachDisk": [{
                                "BasicIops": "",
                                "DiskMax": 2000,
                                "DiskMaxExpand": 2000,
                                "DiskMin": 100,
                                "DiskName": "SSD",
                                "DiskStep": 100,
                                "DiskUnit": "G",
                                "DiskValue": "ssd_disk"
                            }],
                            "CpuRam": [{
                                "CPU": 1,
                                "Name": "1C2G",
                                "PaasGoodsId": 13565,
                                "RAM": 2
                            }]
                        }
                    }],
                    "EnginesType": [],
                    "NetworkLinks": null,
                    "SubProductName": "haproxy 主从版"
                }],
                "Version": "2.4"
            }],
            "RegionId": "*******"
        },
        "Message": "success",
        "TaskId": ""
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39

    # 3.CreateLoadBalancer

    Action: CreateLoadBalancer

    描述: 创建Ha实例

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: POST

    请求参数:

    参数名 必选 类型 说明
    RegionId 是 string 站点编号
    VdcId 是 string 数据中心的编号
    BasePipeId 是 string 数据中心的私网编号,创建服务将按这个私网分配id
    InstanceName 是 string 实例名称
    PaasGoodsId 是 int 产品的规格编号
    Ips 是 list ha使用的网络,根据所传不通网络,创建不同网络机器
    IsVip 否 int 是否开启内网,此参数只适用于公网SLB,内网SLB无需配置,默认值 : 1
    1: 表示开启内网Vip
    0:表示不开启内网VIp
    PipeType 是 list ha使用的网络 ["pipe_type","public"]
    PipeId 是 string 内网网络id,或者公网的网络id
    SegmentId 是 string 占用的公网网段的编号,会占用3个公网
    Amount 否 int 购买的数量一次最多购买三个

    请求示例**

    def create_haproxy():
        """
        创建haproxy实例
        """
        action = "CreateLoadBalancer"
        method = "POST"
        param = {}
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param=param)
        body = {
            "RegionId": "******",
            "VdcId": "******",
            "BasePipeId": "******",
            "InstanceName": "test-haproxy",
            "PaasGoodsId": "5072",
            "Ips": [
                {
                    "PipeType": "private",
                    "PipeId": "******",
                    "IsVip": 1},
                {
                    "PipeType": "public",  # 如创建公网,则需要
                    "PipeId": "******",
                    "SegmentId": "******"
                }
            ],
            "Amount": 1
        }
    
        res = requests.post(url, json=body)
        result = json.loads(res.content)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30

    返回示例

    {
        "Message": "Success.",
        "Code": "Success",
        "Data": {
            "InstancesUuid":["5d74bb81-0473-464d-b15b-0ae418619248",]
        },
        "TaskId": "********"
    }
    
    1
    2
    3
    4
    5
    6
    7
    8

    返回参数说明

    参数名 类型 说明
    Message string 信息描述
    Code string 状态码
    Data dict 包含任务编码和实例编码列表
    InstancesUuid list 实例编码
    TaskId string 任务id

    # 4.DescribeLoadBalancers

    Action: DescribeLoadBalancers

    描述: 获取Ha实例列表(支持常见字段过滤、instance_uuid/instance_name/ip)

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: GET

    请求参数:

    参数名 必选 类型 说明
    IP 否 string 要过滤的服务IP
    InstanceUuid 否 string 要过滤的实例编号
    InstanceName 否 string 要过滤的实例名称
    StartTime 否 string 选取创建时间大于该时间的实例,时间格式为2021-03-10 14:00:00
    EndTime 否 string 选取创建时间小于该时间的实例,时间格式为2021-03-10 15:00:00

    请求示例

    def get_haproxyInstances_list():
        """
        获取haproxy实例列表(支持常见字段过滤、instance_uuid/instance_name/ip)
        """
        action = "DescribeLoadBalancers"
        method = "GET"
        param = {
            "IP": "66.66",  # 可选字段
            "InstanceName": "haproxy"  # 可选字段
        }
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param)
        res = requests.get(url)
        result = json.loads(res.content)
        print(result)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14

    返回示例

    {
        "Code": "Success",
        "Data": [{
            "CloneServices": null,
            "Cpu": 1,
            "CreatedTime": "2020-05-05 00:13:53",
            "DisplayName": "亚太地区-香港-可用区A",
            "IP": "66.66.0.52",
            "InstanceName": "*******",
            "InstanceUuid": "*************",
            "IsCustomConf":0,
            "LinkType": "",
            "LinkTypeStr": "",
            "MasterInfo": "",
            "Port": 0,
            "ProjectName": "默认项目"
            "Ram": 2048,
            "RegionId": "CN_Hongkong_A",
            "RelationService": null,
            "ResourceId": "71bf731e-7cc8-4307-8408-4952e4dcd470",
            "RoGroups": null,
            "Status": "RUNNING",
            "StatusStr": "运行中",
            "SubProductName": "haproxy 主从版",
            "VdcId": "********",
            "VdcName": "香港PaaS1",
            "Version": "1.8.3"
            "Vips": [{
               "IP": "xx.xx.xx.xx",
               "Type": "private"
            },{
               "IP": "xx.xx.xx.xx",
               "Type": "public"
            }]
        }],
        "Message": "Success."
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37

    返回参数说明

    参数名 类型 说明
    Message string 信息描述
    Code string 状态码
    Data dict 数据
    RelationService dict 相关联的服务实例 (该服务这里为空)
    CloneServices list 克隆的临时实例列表(该服务这里为空)
    DisplayName string 站点名称
    IP string 负载均衡实例的连接的IP,当有公网vip时,返回公网vip,没有公网vip时,返回内网vip
    Port int 连接的端口
    ProjectName string 项目名称
    Cpu int cpu大小
    Ram int 内存 单位M
    RegionId string 站点编号
    VdcId string 数据中心的编号
    VdcName string 数据中心名称
    MasterInfo dict 从属集群,只读服务会有值
    LinkTypeStr string 链路类型名称
    ro_groups list 只读实例列表(该服务这里为空)
    SubProductName string 子产品的名字
    Version string 服务版本
    LinkType string 单次支持最大规格的磁盘
    Status stringstring 实例状态
    StatusStr string 状态对应的中文
    InstanceUuid string 实例编号
    InstanceName string 实例名称
    CreatedTime string 实例创建时间
    vips list 负载均衡多个vip地址信息
    ip string 其中一个vip地址
    type string 网络类型 内网/公网
    ResourceId string 账单ID,查询账单时的唯一标识
    IsCustomConf int 是否启用策略高级配置,此参数通过调用不同的策略配置接口更改,默认值:0。
    0:表示当前启用基础配置
    1:表示当前启用高级配置

    # 5.DescribeLoadBalancersModifySpec

    Action: DescribeLoadBalancersModifySpec

    描述: 获取实例Ha的配置变更所支持的规格

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: GET

    请求参数:

    参数名 必选 类型 说明
    InstanceUuid 是 string 实例编号

    请求示例

    def get_haproxy_modify_spec(instance_uuid):
        """
        获取实例Ha的配置变更所支持的规格
        :param instance_uuid: 实例编号
        :return:
        """
        action = "DescribeLoadBalancersModifySpec"
        method = "GET"
        param = {
            "InstanceUuid": instance_uuid
        }
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param)
        res = requests.get(url)
        result = json.loads(res.content)
        print(result)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15

    返回示例

    {
        "Code": "Success",
        "Data": {
            "AttachDisk": [{
                "BasicIops": "3000",
                "DiskMax": 2000,
                "DiskMaxExpand": 2000,
                "DiskMin": 100,
                "DiskName": "性能型",
                "DiskStep": 100,
                "DiskUnit": "G",
                "DiskValue": "high_disk"
            }],
            "CpuRam": [{
                "CPU": 1,
                "N": "1C2G",
                "PaasGoodsId": 5072,
                "RAM": 2
            }, {
                "CPU": 2,
                "Name": "2C4G",
                "PaasGoodsId": 5075,
                "RAM": 4
            }, {
                "CPU": 4,
                "Name": "4C8G",
                "PaasGoodsId": 5078,
                "RAM": 8
            }, {
                "CPU": 8,
                "Name": "8C16G",
                "PaasGoodsId": 5081,
                "RAM": 16
            }],
            "ProductName": "haproxy 主从版",
            "RegionId": "CN_Hongkong_A"
        },
        "Message": "Success.",
        "TaskId": ""
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40

    返回参数说明

    参数名 类型 说明
    Message string 信息描述
    Code string 状态码
    TaskId string 任务编号
    Data dict 数据
    ProductName string 产品名称
    RegionId string 站点编号
    CpuRam list 支持的规格列表
    CPU int 购买产吕CPU数量
    Name string 购买产品名称
    PaasGoodsId int 可购买的产品规格编号
    RAM int 购买产品内存大小
    AttachDisk list 该类型规格能够添加的磁盘类型
    BasicIops string 基础IOPS大小
    DiskMax int 最大磁盘大小
    DiskMaxExpand int 最大可扩展磁盘大小
    DiskMin int 最小磁盘大小
    DiskName string 磁盘类型
    DiskStep int 磁盘增大步长
    DiskUnit string 磁盘单位
    DiskValue string 磁盘类型key

    # 6.ModifyLoadBalancerInstanceSpec

    Action: ModifyLoadBalancerInstanceSpec

    描述: 修改实例规格

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: POST

    请求参数:

    参数名 必选 类型 说明
    InstanceUuid 是 string 要修改的实例id
    PaasGoodsId 是 int 要修改成为的规格产品编号

    请求示例

    def modify_haproxy_spec(instance_uuid):
        """
        修改haproxy实例规格
        :param instance_uuid: 实例编号
        """
        action = "ModifyLoadBalancerInstanceSpec"
        method = "POST"
        param = {}
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param=param)
        body = {
            "InstanceUuid": instance_uuid,
            "PaasGoodsId": 5078,  # 此处必须传int类型且goodsid存在,否则报错
        }
    
        res = requests.post(url, json=body)
        result = json.loads(res.content)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16

    返回示例

    {
        "Code": "Success",
        "Data": {},
        "Message": "Success.",
        "TaskId": "******"
    }
    
    1
    2
    3
    4
    5
    6

    返回参数说明

    参数名 类型 说明
    Message string 信息描述
    Code string 状态码
    TaskId string 任务状态
    Data string 数据

    # 7.DeleteLoadBalancer

    Action: DeleteLoadBalancer

    描述: 删除Ha实例

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: POST

    请求参数:

    参数名 必选 类型 说明
    InstanceUuid 否 string 实例编号

    请求示例

    def delete_haproxy(instance_uuid, ):
        """
        删除haproxy实例
        :param instance_uuid: 实例编号
        """
        action = "DeleteLoadBalancer"
        method = "POST"
        param = {}
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param=param)
        body = {
            "InstanceUuid": instance_uuid,
        }
    
        res = requests.post(url, json=body)
        result = json.loads(res.content)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15

    返回示例**

    {
        "Code": "Success",
        "Data": {},
        "Message": "Success.",
        "TaskId": "******"
    }
    
    1
    2
    3
    4
    5
    6

    返回参数说明

    参数名 类型 说明
    Code string 状态码
    Data dict 数据
    Message string 信息描述
    TaskId string 任务编号

    # 8.DescribeCACertificates

    Action: DescribeCACertificates

    描述: 获取用户的证书列表

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: GET

    请求参数: 无

    请求示例

    def get_user_ca_lists():
        """
        获取用户的证书列表
        """
        action = "DescribeCACertificates"
        method = "GET"
        param = {
        }
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param)
        res = requests.get(url)
        result = json.loads(res.content)
        result = json.dumps(result)  # json格式化
        print(result)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13

    返回示例**

    {
        "Code": "Success",
        "Data": [{
            "Brand": "Encryption Everywhere DV TLS CA - G1",
            "CertificateId": "******",
            "CertificateName": "******",
            "CertificateType": "DV",
            "Domain": "******",
            "EndTime": "2021-02-25 12:00:00",
            "Organization": "DigiCert Inc",
            "StartTime": "2020-02-26 00:00:00",
            "Valid": 1
        }],
        "Message": "Success."
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15

    返回参数说明

    参数名 类型 说明
    Message string 信息描述
    Code string 状态码
    Data dict 数据
    Domain string 域名
    CertificateName string 证书名称,用户自定义名称
    CertificateType string 证书类型
    Brand string 证书品牌
    CertificateId string 证书编号
    Organization string 颁发机构
    StartTime string 证书有效开始时间
    EndTime string 证书有效结束时间
    Valid int 证书是否有效,0过期的,1有效的 ,2即将过期的(30天内)

    # 9.DescribeCACertificate

    Action: DescribeCACertificate

    描述: 获取用户的证书详情

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: GET

    请求参数:

    参数名 必选 类型 说明
    CertificateId 是 string 证书编号

    请求示例

    def get_user_caId(caId):
        """
        获取单个证书详情
        """
        action = "DescribeCACertificate"
        method = "GET"
        param = {
            "CertificateId": caId
        }
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param)
        res = requests.get(url)
        result = json.loads(res.content)
        result = json.dumps(result)  # json格式化
        print(result)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14

    返回示例

    {
        "Code": "Success",
        "Data": {
            "Brand": "Encryption Everywhere DV TLS CA - G1",
            "Certificate": "-----BEGIN CERTIFICATE-----\n******\n-----END CERTIFICATE-----\n-----BEGIN CERTIFICATE-----\n******\n-----END CERTIFICATE-----\n", 
            "CertificateId": "******",
            "CertificateName": "******",
            "CertificateType": "DV",
            "Domain": "******",
            "EndTime": "2021-02-25 12:00:00",
            "Organization": "DigiCert Inc",
            "PirvateKey": "-----BEGIN RSA PRIVATE KEY-----\n******=\n-----END RSA PRIVATE KEY-----\n",
            "PublicKey": "-----BEGIN PUBLIC KEY-----\n******\n-----END PUBLIC KEY-----\n",
            "StartTime": "2020-02-26 00:00:00",
            "Valid": 1
        },
        "Message": "Success.",
        "TaskId": ""
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19

    返回参数说明

    参数名 类型 说明
    Message string 信息描述
    Code string 状态码
    TaskId string 任务编号
    Data dict 数据
    Certificate string 证书信息
    PublicKey string 公钥
    PirvateKey string 私钥
    Domain string 域名
    CertificateName string 证书名称,用户自定义名称
    CertificateType string 证书类型
    Brand string 证书品牌
    CertificateId string 证书编号
    Organization string 颁发机构
    StartTime string 证书有效开始时间
    EndTime string 证书有效结束时间
    Valid int 是否有效,0:过期的 1:有效的 2:即将过期的(30天内)

    # 10.DeleteCACertificate

    Action: DeleteCACertificate

    描述: 删除证书

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: POST

    请求参数:

    参数名 必选 类型 说明
    CertificateId 是 string 证书编号

    请求示例

    def delete_ca(caId):
        """
        删除证书
        :param caId:
        """
        action = "DeleteCACertificate"
        method = "POST"
        param = {}
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param=param)
        body = {
            "CertificateId": caId,
        }
    
        res = requests.post(url, json=body)
        result = json.loads(res.content)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15

    返回示例

    {
        "Code": "Success",
        "Data": {},
        "Message": "Success.",
        "TaskId": ""
    }
    
    1
    2
    3
    4
    5
    6

    返回参数说明

    参数名 类型 说明
    Code string 状态码
    Data dict 数据
    Message string 信息描述
    TaskId string 任务编号

    # 11.UploadCACertificate

    Action: UploadCACertificate

    描述: 添加证书

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: POST

    请求参数:

    参数名 必选 类型 说明
    Certificate 是 string 证书 (-----BEGIN CERTIFICATE-----\n -----END CERTIFICATE-----\n必须有标准的换行"\n")
    PrivateKey 是 string 私钥
    CertificateName 是 string 自定义证书名称

    请求示例

    def add_ca():
        """
        添加证书
        """
        action = "UploadCACertificate"
        method = "POST"
        param = {}
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param=param)
        body = {
            "Certificate": "-----BEGIN CERTIFICATE-----\n******\n-----END CERTIFICATE-----\n-----	BEGIN CERTIFICATE-----\n******\n-----END CERTIFICATE-----\n",
            "PrivateKey": "-----BEGIN RSA PRIVATE KEY-----\n******\n-----END RSA PRIVATE KEY-----\n", #此处证书必须符合规范,且有相应的换行符\n
            "CertificateName": "******"
        }
    
        res = requests.post(url, json=body)
        result = json.loads(res.content)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16

    返回示例

    {
        "Code": "Success",
        "Data": {},
        "Message": "Success.",
        "TaskId": ""
    }
    
    1
    2
    3
    4
    5
    6

    返回参数说明

    参数名 类型 说明
    Code string 状态码
    Data dict 数据
    Message string 信息描述
    TaskId string 任务编号

    # 12.DescribeLoadBalancerStrategys

    Action: DescribeLoadBalancerStrategys

    描述: 获取Ha实例的当前监听的策略配置列表

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: GET

    请求参数:

    参数名 必选 类型 说明
    InstanceUuid 是 string 实例编号

    请求示例

    def get_strategy_list(instance_uuid):
        """
        获取单个实例所有的策略配置
        """
        action = "DescribeLoadBalancerStrategys"
        method = "GET"
        param = {
            "InstanceUuid": "***************"
        }
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param)
        res = requests.get(url)
        result = json.loads(res.content)
        result = json.dumps(result)  # json格式化
    
        print(result)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15

    返回示例

    {
        "Code": "Success",
        "Data": {
            "HttpListeners": [{
                "AclWhiteList": ["192.168.1.2"],
                "BackendServer": [{
                    "IP": "88.88.0.9",
                    "MaxConn": 2222,
                    "Port": 22221,
                    "Weight": "29"
                }],
                "CertificateIds": [{
                    "CertificateId": "*****************",
                    "CertificateName": "证书oXDYdSgK"
                }],
                "ClientTimeout": "1000",
                "ClientTimeoutUnit": "ms",
                "ConnectTimeout": "1000",
                "ConnectTimeoutUnit": "ms",
                "ListenerMode": "http",
                "ListenerName": "http34",
                "ListenerPort": 23425,
                "MaxConn": 100000,
                "Option": {
                    "Httpchk": {
                        "Method": "GET",
                        "Uri": "/index.htm"
                    }
                },
                "Scheduler": "roundrobin",
                "ServerTimeout": "1002",
                "ServerTimeoutUnit": "ms",
                "SessionPersistence": {
                    "Key": "test123",
                    "Mode": 2,
                    "Timer": {
                        "MaxIdle": 3333,
                        "MaxLife": 3444
                    }
                },
                "StickySession": "on"
            }],
            "TcpListeners": [{
                "AclWhiteList": [],
                "BackendServer": [{
                    "IP": "88.88.0.9",
                    "MaxConn": 2000,
                    "Port": 2341,
                    "Weight": "256"
                }],
                "ClientTimeout": "1010",
                "ClientTimeoutUnit": "ms",
                "ConnectTimeout": "22",
                "ConnectTimeoutUnit": "s",
                "EnableRepeaterMode": "on",
                "EnableSourceIp": "on",
                "ListenerMode": "tcp",
                "ListenerName": "http343",
                "ListenerPort": 2343,
                "MaxConn": 2323,
                "Scheduler": "leastconn",
                "ServerTimeout": "10000",
                "ServerTimeoutUnit": "ms"
            }]
        },
        "Message": "success",
        "TaskId": ""
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68

    返回参数:

    参数名 类型 说明
    Code string 状态码
    Data dict of Data 数据
    Message string 信息描述

    # 查询策略DataObj

    参数名 类型 说明
    HttpListeners list of HttpListeners http 监听策略配置列表
    TcpListeners list of TcpListeners tcp 的监听策略列表

    # 查询策略HttpListenersObj

    参数名 类型 说明
    AclWhiteList list 设置白名单,例如【"129.12.12.1","192.168.1.1/20"】
    BackendServer list of BackendServer 后端服务器配置
    CertificateIds list of CertificateIds http 监听可以绑定证书,不绑定传空列表
    ClientTimeout string 设置客户端连接超时的时间
    ClientTimeoutUnit string 设置客户端连接超时的时间单位【"ms","s"】
    ConnectTimeout string 设置请求连接超时时间
    ConnectTimeoutUnit string 设置请求连接超时时间的时间单位
    ListenerMode string 监听模式
    ListenerName string 监听策略的名称,用于生成配置文件,名称不能相同
    ListenerPort int 策略监听端口
    MaxConn int 代理端的最大连接数
    Option object of OptionObj 高级配置
    Scheduler string 调度算法【"roundrobin", "leastconn", "static-rr", "source"】
    ServerTimeout string 设置服务端超时时间
    ServerTimeoutUnit string 设置服务端超时时间单位 【"ms","s"】
    SessionPersistence object of SessionPersistence 设置会话保持功能
    StickySession string 是否开启长连接(Keep Alive) 【"on","off"】

    # 查询策略TcpListenersObj

    参数名 类型 说明
    AclWhiteList list 设置白名单,例如【"129.12.12.1","192.168.1.1/20"】
    BackendServer list of BackendServer 后端服务器配置
    ClientTimeout string 设置客户端连接超时的时间
    ClientTimeoutUnit string 设置客户端连接超时的时间单位【"ms","s"】
    ConnectTimeout string 设置请求连接超时时间
    ConnectTimeoutUnit string 设置请求连接超时时间的时间单位
    EnableSourceIp string 是否开启获取源IP 【"on","off"】
    EnableRepeaterMode string 是否当前Haproxy为中继默认且支持源IP透传 【"on","off"】
    ListenerMode string 监听模式
    ListenerName string 监听策略的名称,用于生成配置文件,名称不能相同
    ListenerPort int 策略监听端口
    MaxConn int 代理端的最大连接数
    Scheduler string 调度算法【"roundrobin", "leastconn", "static-rr", "source"】
    ServerTimeout string 设置服务端超时时间
    ServerTimeoutUnit string 设置服务端超时时间单位 【"ms","s"】

    # 查询策略BackendServerObj

    参数名 类型 说明
    IP string 后端服务器Ip地址
    MaxConn int 后端服务器最大连接数
    Port int 后端服务器端口
    Weight string 后端服务器权重

    # 查询策略CertificateIdsObj

    参数名 类型 说明
    CertificateId string 证书编号
    CertificateName string 证书名称

    # 查询策略OptionObj

    参数名 类型 说明
    Httpchk object of Httpchk HTTP开启健康检查

    # 查询策略HttpchkObj

    参数名 类型 说明
    Method string 默认值为:"GET"
    参数范围:["GET","HEAD","OPTIONS"]
    Uri string 健康检查uri

    # 查询策略SessionPersistenceObj

    参数名 必选 类型 说明
    Key 是 string 在http的reponse设置Cookie的Key的值。字符长度为2~15,以字母开头,以字母或数字结尾,由小写字母、数字或下划线组成, key要求唯一。
    Mode 否 int 默认值为1。
    0. 表示在缓存中 ( 例如:CDN ) 保留Cookie的内容
    1. 表示不在缓存中 ( 例如:CDN ) 保留Cookie的内容, 负载均衡设置的cookie在后端服务可见。
    2. 表示不在缓存中 ( 例如:CDN ) 保留Cookie的内容, 负载均衡设置的cookie在后端服务是不可见,即透明模式只能看到客户自己设置的Cookie。
    Timer 否 object of Timer 设置会话保持的时间参数,单位: 秒。

    # 查询策略TimerObj

    参数名 必选 类型 说明
    MaxIdle 是 int 默认值为0, 表示不设置,即空闲也会会话保持。
    单位: 秒。支持范围:0-7200。
    设置会话保持的最大空闲时长,当连接在该时长内无新的请求,则会话保持结束。
    MaxLife 是 int 默认值为0,表示不设置,即会话会一直保持。
    单位: 秒。支持范围:0-7200。
    设置会话保持的最大时长,超过该时长则会话保持结束, 且要求maxlife 大于maxidle。

    # 13.ModifyLoadBalancerStrategys

    Action: ModifyLoadBalancerStrategys

    描述: 修改(删除、修改、添加)Ha实例的当前监听的策略配置列表

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: POST

    请求参数:

    参数名 必选 类型 说明
    InstanceUuid 是 string 要修改的实例编号
    HttpListeners 是 list of HttpListeners http 监听策略配置列表
    TcpListeners 否 list of TcpListeners tcp 的监听策略列表

    # 修改策略HttpListenersObj

    参数名 必选 类型 说明
    ServerTimeoutUnit 是 string 设置服务端超时时间单位 【"ms","s"】
    ServerTimeout 是 string 设置服务端超时时间
    StickySession 是 string 是否开启长连接(Keep Alive) 【"on","off"】
    AclWhiteList 否 list 设置白名单 例如【"129.12.12.1","192.168.1.1/20"】
    CertificateIds 否 list of CertificateIdsObj http 监听可以绑定证书,不绑定传空列表
    ListenerMode 是 string 监听模式
    MaxConn 是 int 代理端的最大连接数
    ConnectTimeoutUnit 是 string 设置请求连接超时的时间单位【"ms","s"】
    Scheduler 是 string 调度算法【"roundrobin", "leastconn", "static-rr", "source"】
    SessionPersistence 否 object of SessionPersistence 设置会话保持功能
    BackendServer 是 list of BackendServer 后端服务器配置
    ConnectTimeout 是 string 设置请求连接超时时间
    ClientTimeout 是 string 设置客户端连接超时的时间
    ListenerName 是 string 监听策略的名称。
    字符长度为1~50,以字母开头,以字母或数字结尾,由小写字母、数字或下划线组成, 名字要求唯一。
    ClientTimeoutUnit 是 string 设置客户端连接超时的时间单位【"ms","s"】
    ListenerPort 是 int 策略监听端口。
    取值范围1-65535,其中22、1080、9100、9101端口不在取值范围已被禁用。
    Option 否 object of OptionObj 高级配置

    # 修改策略TcpListenersObj

    参数名 必选 类型 说明
    ServerTimeoutUnit 是 string 设置服务端超时时间单位 【"ms","s"】
    AclWhiteList 否 list 设置白名单 例如【"129.12.12.1","192.168.1.1/20"】
    ListenerMode 是 string 监听模式
    ListenerName 是 string 监听策略的名称。
    字符长度为1~50,以字母开头,以字母或数字结尾,由小写字母、数字或下划线组成, 名字要求唯一。
    Scheduler 是 string 调度算法【"roundrobin", "leastconn", "static-rr", "source"】
    MaxConn 是 int 代理端的最大连接数
    ClientTimeoutUnit 是 string 设置客户端连接超时的时间单位【"ms","s"】
    ListenerPort 是 int 策略监听端口。
    取值范围1-65535,其中22、1080、9100、9101端口不在取值范围已被禁用。
    ServerTimeout 是 string 设置服务端超时时间
    ConnectTimeoutUnit 是 string 设置请求连接超时的时间单位【"ms","s"】
    BackendServer 是 list of BackendServer 后端服务器配置
    ConnectTimeout 是 string 设置请求连接超时时间
    ClientTimeout 是 string 设置客户端连接超时的时间
    EnableSourceIp 否 string 设置获取源IP。取值范围【"on","off"】,默认为off
    EnableRepeaterMode 否 string 设置当前Haproxy为中继默认且支持源IP透传。取值范围 【"on","off"】,默认为off,注意:如果设置了EnableRepeaterMode为on,则EnableSourceIp参数也必须为on

    # 修改策略CertificateIdsObj

    参数名 必选 类型 说明
    CertificateId 否 string 证书编号
    CertificateName 否 string 证书名称

    # 修改策略SessionPersistenceObj

    参数名 必选 类型 说明
    Key 是 string 在http的reponse设置Cookie的Key的值。字符长度为2~15,以字母开头,以字母或数字结尾,由小写字母、数字或下划线组成, key要求唯一。
    Mode 否 int 默认值为1。
    0. 表示在缓存中 ( 例如:CDN ) 保留Cookie的内容
    1. 表示不在缓存中 ( 例如:CDN ) 保留Cookie的内容, 负载均衡设置的cookie在后端服务可见。
    2. 表示不在缓存中 ( 例如:CDN ) 保留Cookie的内容, 负载均衡设置的cookie在后端服务是不可见,即透明模式只能看到客户自己设置的Cookie。
    Timer 否 object of Timer 设置会话保持的时间参数,单位: 秒。

    # 修改策略TimerObj

    参数名 必选 类型 说明
    MaxIdle 是 int 默认值为0, 表示不设置,即空闲也会会话保持。
    单位: 秒。支持范围:0-7200。
    设置会话保持的最大空闲时长,当连接在该时长内无新的请求,则会话保持结束。
    MaxLife 是 int 默认值为0,表示不设置,即会话会一直保持。
    单位: 秒。支持范围:0-7200。
    设置会话保持的最大时长,超过该时长则会话保持结束, 且要求maxlife 大于maxidle。

    # 修改策略BackendServerObj

    参数名 必选 类型 说明
    IP 是 string 后端服务器Ip地址(公网下支持域名)
    Port 是 int 后端服务器端口
    Weight 是 string 后端服务器权重,权重范围为1-256
    MaxConn 是 int 后端服务器最大连接数

    # 修改策略OptionObj

    参数名 必选 类型 说明
    Httpchk 否 object of Httpchk HTTP开启健康检查

    # 修改策略HttpchkObj

    参数名 必选 类型 说明
    Method 是 string 默认值为:"GET"
    参数范围:["GET","HEAD","OPTIONS"]
    Uri 是 string 健康检查uri

    请求示例

    def modify_strategy(instance_uuid):
        """
        修改(删除、修改、添加)Ha实例的当前监听的策略配置列表
        :param instance_uuid: 实例id
        """
        action = "ModifyLoadBalancerStrategys"
        method = "POST"
        param = {}
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param=param)
        body = {
                "InstanceUuid": instance_uuid,
                # "HttpListeners": [],
                "HttpListeners": [
                    {
                        "ServerTimeoutUnit": "ms",
                        "ServerTimeout": "1000",
                        "StickySession": "on",
                        "AclWhiteList": [
                            "192.168.1.2"
                        ],
                        "Option": {
                            "Httpchk": {
                                "Method": "GET",
                                "Uri": "/index.htm"
                            }
                        },
                        "SessionPersistence": {
                            "Key": "test123",
                            "Mode": 2,
                            "Timer": {
                                "MaxIdle": 3333,
                                "MaxLife": 3444
                            }
                        },
                        "CertificateIds": [
                            {
                                "CertificateId": "******",
                                "CertificateName": "******"
                            }
                        ],
                        "ListenerMode": "http",
                        "MaxConn": 100000,
                        "ConnectTimeoutUnit": "ms",
                        "Scheduler": "roundrobin",
                        "BackendServer": [
                            {
                                "IP": "66.66.0.8",
                                "Port": 22222,
                                "Weight": "1",
                                "MaxConn": 2222
                            }
                        ],
                        "ConnectTimeout": "1000",
                        "ClientTimeout": "1000",
                        "ListenerName": "http-test",
                        "ClientTimeoutUnit": "ms",
                        "ListenerPort": 23425
                    }
                ],
                 "TcpListeners": [
                   {
                        "EnableSourceIp":"on",
                        "EnableRepeaterMode":"on",
                        "ServerTimeoutUnit": "ms",
                        "AclWhiteList": [],
                        "ListenerMode": "tcp",
                        "ListenerName": "tcp-test",
                        "Scheduler": "leastconn",
                        "MaxConn": 2323,
                        "ClientTimeoutUnit": "ms",
                        "ListenerPort": 2342,
                        "ServerTimeout": "10000",
                        "ConnectTimeoutUnit": "s",
                        "BackendServer": [
                             {
                                 "IP": "66.66.0.8",
                                 "MaxConn": 2000,
                                 "Port": 2342,
                                 "Weight": "1"
                             }
                         ],
                         "ConnectTimeout": "22",
                         "ClientTimeout": "10000",
                    }
                 ]
        }
        res = requests.post(url, json=body)
        result = json.loads(res.content)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88

    返回示例

    {
        "Code": "Success",
        "Data": {},
        "Message": "Success.",
        "TaskId": "******"
    }
    
    1
    2
    3
    4
    5
    6

    返回参数说明

    参数名 必选 类型 说明
    Message 是 string 信息描述
    Code 是 string 状态码
    Data 是 dict 数据
    TaskId 是 string 任务

    # 14.AddLoadBalancerStrategys

    Action: AddLoadBalancerStrategys

    描述: 增加(不覆盖)Ha实例的当前监听的策略配置列表。

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: POST

    请求参数:

    参数名 必选 类型 说明
    InstanceUuid 是 string 要修改的实例编号
    HttpListeners 是 list of HttpListeners http 监听策略配置列表
    TcpListeners 否 list of TcpListeners tcp 的监听策略列表

    # 新增策略HttpListenersObj

    参数名 必选 类型 说明
    ServerTimeoutUnit 是 string 设置服务端超时时间单位 【"ms","s"】
    ServerTimeout 是 string 设置服务端超时时间
    StickySession 是 string 是否开启长连接(Keep Alive) 【"on","off"】
    AclWhiteList 否 list 设置白名单 例如【"129.12.12.1","192.168.1.1/20"】
    CertificateIds 否 list of CertificateIdsObj http 监听可以绑定证书,不绑定传空列表
    ListenerMode 是 string 监听模式
    MaxConn 是 int 代理端的最大连接数
    ConnectTimeoutUnit 是 string 设置请求连接超时的时间单位【"ms","s"】
    Scheduler 是 string 调度算法【"roundrobin", "leastconn", "static-rr", "source"】
    SessionPersistence 否 object of SessionPersistence 设置会话保持功能
    BackendServer 是 list of BackendServer 后端服务器配置
    ConnectTimeout 是 string 设置请求连接超时时间
    ClientTimeout 是 string 设置客户端连接超时的时间
    ListenerName 是 string 监听策略的名称。
    字符长度为1~50,以字母开头,以字母或数字结尾,由小写字母、数字或下划线组成, 名字要求唯一。
    ClientTimeoutUnit 是 string 设置客户端连接超时的时间单位【"ms","s"】
    ListenerPort 是 int 策略监听端口。
    取值范围1-65535,其中22、1080、9100、9101端口不在取值范围已被禁用。
    Option 否 object of OptionObj 高级配置

    # 新增策略TcpListenersObj

    参数名 必选 类型 说明
    ServerTimeoutUnit 是 string 设置服务端超时时间单位 【"ms","s"】
    AclWhiteList 否 list 设置白名单 例如【"129.12.12.1","192.168.1.1/20"】
    ListenerMode 是 string 监听模式
    ListenerName 是 string 监听策略的名称。
    字符长度为1~50,以字母开头,以字母或数字结尾,由小写字母、数字或下划线组成, 名字要求唯一。
    Scheduler 是 string 调度算法【"roundrobin", "leastconn", "static-rr", "source"】
    MaxConn 是 int 代理端的最大连接数
    ClientTimeoutUnit 是 string 设置客户端连接超时的时间单位【"ms","s"】
    ListenerPort 是 int 策略监听端口。
    取值范围1-65535,其中22、1080、9100、9101端口不在取值范围已被禁用。
    ServerTimeout 是 string 设置服务端超时时间
    ConnectTimeoutUnit 是 string 设置请求连接超时的时间单位【"ms","s"】
    BackendServer 是 list of BackendServer 后端服务器配置
    ConnectTimeout 是 string 设置请求连接超时时间
    ClientTimeout 是 string 设置客户端连接超时的时间
    EnableSourceIp 否 string 设置获取源IP。取值范围【"on","off"】,默认为off
    EnableRepeaterMode 否 string 设置当前Haproxy为中继默认且支持源IP透传。取值范围 【"on","off"】,默认为off,注意:如果设置了EnableRepeaterMode为on,则EnableSourceIp参数也必须为on

    # 新增策略CertificateIdsObj

    参数名 必选 类型 说明
    CertificateId 否 string 证书编号
    CertificateName 否 string 证书名称

    # 新增策略SessionPersistenceObj

    参数名 必选 类型 说明
    Key 是 string 在http的reponse设置Cookie的Key的值。字符长度为2~15,以字母开头,以字母或数字结尾,由小写字母、数字或下划线组成, key要求唯一。
    Mode 否 int 默认值为1。
    0. 表示在缓存中 ( 例如:CDN ) 保留Cookie的内容
    1. 表示不在缓存中 ( 例如:CDN ) 保留Cookie的内容, 负载均衡设置的cookie在后端服务可见。
    2. 表示不在缓存中 ( 例如:CDN ) 保留Cookie的内容, 负载均衡设置的cookie在后端服务是不可见,即透明模式只能看到客户自己设置的Cookie。
    Timer 否 object of Timer 设置会话保持的时间参数,单位: 秒。

    # 新增策略TimerObj

    参数名 必选 类型 说明
    MaxIdle 是 int 默认值为0, 表示不设置,即空闲也会会话保持。
    单位: 秒。支持范围:0-7200。
    设置会话保持的最大空闲时长,当连接在该时长内无新的请求,则会话保持结束。
    MaxLife 是 int 默认值为0,表示不设置,即会话会一直保持。
    单位: 秒。支持范围:0-7200。
    设置会话保持的最大时长,超过该时长则会话保持结束, 且要求maxlife 大于maxidle。

    # 新增策略BackendServerObj

    参数名 必选 类型 说明
    IP 是 string 后端服务器Ip地址(公网下支持域名)
    Port 是 int 后端服务器端口
    Weight 是 string 后端服务器权重,权重范围为1-256
    MaxConn 是 int 后端服务器最大连接数

    # 新增策略OptionObj

    参数名 必选 类型 说明
    Httpchk 否 object of Httpchk HTTP开启健康检查

    # 新增策略HttpchkObj

    参数名 必选 类型 说明
    Method 是 string 默认值为:"GET"
    参数范围:["GET","HEAD","OPTIONS"]
    Uri 是 string 健康检查uri

    请求示例

    def add_modify_strategy(instance_uuid):
        """
        增量添加策略
        @param instance_uuid:
        @return:
        """
        action = "AddLoadBalancerStrategys"
        method = "POST"
        param = {}
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param=param)
        body = {
            "InstanceUuid": instance_uuid,
            "HttpListeners": [
                {
                    "ServerTimeoutUnit": "ms",
                    "ServerTimeout": "1002",
                    "StickySession": "on",
                    "AclWhiteList": [
                        "192.168.1.2"
                    ],
                    "Option": {
                        "Httpchk": {
                            'Method': "GET",
                            "Uri": '/index.htm'
                        }
                    },
                    "SessionPersistence": {
                        "Key": "test123",
                        "Mode": 2,
                        "Timer": {
                            "MaxIdle": 3333,
                            "MaxLife": 3444
                        }
                    },
                    "CertificateIds": [
                        {
                            "CertificateId": "e414686d-4cb2-4bfd-8bae-061703c56781",
                            "CertificateName": "证书测试aa0427"
                        }
                    ],
                    "ListenerMode": "http",
                    "MaxConn": 100000,
                    "ConnectTimeoutUnit": "ms",
                    "Scheduler": "roundrobin",
                    "BackendServer": [
                        {
                            "IP": "88.88.0.9",
                            "Port": 22221,
                            "Weight": "29",
                            "MaxConn": 2222
                        }
    
                    ],
                    "ConnectTimeout": "1000",
                    "ClientTimeout": "1000",
                    "ListenerName": "http343",
                    "ClientTimeoutUnit": "ms",
                    "ListenerPort": 2345
                }
            ],
        }
        res = requests.post(url, json=body)
        result = json.loads(res.content)
        result = json.dumps(result)
        print(result)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65

    返回示例

    {
        "Code": "Success",
        "Data": {},
        "Message": "The Base configuration will be enabled.The policy modification task is successfully delivered. Wait until the task is executed.",
        "TaskId": "******"
    }
    
    1
    2
    3
    4
    5
    6

    返回参数说明

    参数名 必选 类型 说明
    Message 是 string 信息描述
    Code 是 string 状态码
    Data 是 dict 数据
    TaskId 是 string 任务

    # 15.DescribeHaproxyCustomConfig

    Action: DescribeHaproxyCustomConfig

    描述: 获取负载均衡自定义配置策略的配置文件

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: GET

    请求参数:

    参数名 必选 类型 说明
    InstanceUuid 是 string 实例编号

    请求示例

    def get_custom_config(instance_uuid):
        action = "DescribeHaproxyCustomConfig"
        method = "GET"
        param = {
            "InstanceUuid": instance_uuid
        }
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param)
        res = requests.get(url)
        result = json.loads(res.content)
        result = json.dumps(result)  # json格式化
        print(result)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    返回示例

    {
        "Code": "Success",
        "Data": {
            "Configs": "global\n        log 127.0.0.1   local0\n        chroot /var/lib/haproxy\n        stats socket /run/haproxy/admin.sock mode 660 level admin  expose-fd listeners\n        stats timeout 30s\n        user haproxy\n        group haproxy\n        #maxconn 200000\n        maxconn 150000\n        nbproc 1\n        nbthread 2\n        tune.ssl.default-dh-param 2048\n        daemon\n        hard-stop-after 5s\n        ssl-default-bind-options ssl-min-ver TLSv1.0\n\ndefaults\n        log     global\n        log-format %ci:%cp\\ [%t]\\ %ft\\ %b/%s\\ %Tq/%Tw/%Tc/%Tr/%Tt\\ %ST\\ %B\\ %CC\\ %CS\\ %tsc\\ %ac/%fc/%bc/%sc/%rc\\ %sq/%bq\\ %hr\\ %hs\\ %{+Q}r\n        mode    http\n        option  httplog\n        option tcplog\n        option abortonclose\n        option httpclose\n        option forwardfor\n        maxconn 5000\n        #websocket\n        timeout tunnel 1h\n        timeout client-fin 30s\n\nlisten status\n     bind 127.0.0.1:1081\n     mode http\n     log global\n     stats refresh 30s\n     stats uri /admin?stats\n     stats realm Private lands\n     stats auth admin:h0jMl0ka0df71WGI1\n     stats hide-version\n     timeout connect 5000ms\n     timeout client  5000ms\n     timeout server  5000ms\n     option accept-invalid-http-response\n\n\n\nfrontend ng80\n    default_backend ng80-abk\n    compression algo gzip\n    bind 0.0.0.0:80\n    http-response add-header Connection keep-alive\n    http-request set-header http_x_forwarded_proto http\n    http-request set-header X-Forwarded-Proto http\n    http-request set-header X-Forwarded-Port %[dst_port]\n    http-request set-header X-Forwarded-Client-srcport %[src_port]\n    mode http\n    timeout client 12333ms\n    maxconn 150\n    option accept-invalid-http-request\n    \n\nbackend ng80-abk\n    balance roundrobin\n    fullconn 2000\n    timeout connect 12333ms\n    timeout server 12333ms\n    server s10.240.104.24:80 10.240.104.24:80 maxconn 2220 weight 1 check\n\n\nfrontend ng801\n    default_backend ng801-abk\n    compression algo gzip\n    bind 0.0.0.0:88\n    http-response add-header Connection keep-alive\n    http-request set-header http_x_forwarded_proto http\n    http-request set-header X-Forwarded-Proto http\n    http-request set-header X-Forwarded-Port %[dst_port]\n    http-request set-header X-Forwarded-Client-srcport %[src_port]\n    mode http\n    timeout client 12333ms\n    maxconn 150\n    option accept-invalid-http-request\n    \n\nbackend ng801-abk\n    balance roundrobin\n    fullconn 2000\n    timeout connect 12333ms\n    timeout server 12333ms\n    server s10.240.104.24:80 10.240.104.24:80 maxconn 2220 weight 1 check\n\n\n\n\n\n"
        },
        "Message": "success"
    }
    
    1
    2
    3
    4
    5
    6
    7

    返回参数:

    参数名 类型 说明
    Code string 状态码
    Data dict of Data 数据
    Message string 信息描述

    # 查询自定义策略DataObj

    参数名 类型 说明
    Configs string 实例配置文件

    # 16.ModifyHaproxyCustomConfig

    Action: ModifyHaproxyCustomConfig

    描述: 修改负载均衡自定义配置策略的配置文件

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: POST

    请求参数:

    参数名 必选 类型 说明
    InstanceUuid 是 string 实例编号
    Configs 是 string 实例配置文件

    请求示例

    def custom_modify_strategy(instance_uuid):
        """
        修改Ha实例的自定义监听策略配置
        :param instance_uuid: 实例id
        """
        action = "ModifyHaproxyCustomConfig"
        method = "POST"
        param = {}
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param=param)
        body = {
            "InstanceUuid": instance_uuid,
            "Configs": "global\n        log 127.0.0.1   local0\n        chroot /var/lib/haproxy\n        stats socket /run/haproxy/admin.sock mode 660 level admin  expose-fd listeners\n        stats timeout 30s\n        user haproxy\n        group haproxy\n        #maxconn 200000\n        maxconn 150000\n        nbproc 1\n        nbthread 2\n        tune.ssl.default-dh-param 2048\n        daemon\n        hard-stop-after 5s\n        ssl-default-bind-options ssl-min-ver TLSv1.0\n\ndefaults\n        log     global\n        log-format %ci:%cp\\ [%t]\\ %ft\\ %b/%s\\ %Tq/%Tw/%Tc/%Tr/%Tt\\ %ST\\ %B\\ %CC\\ %CS\\ %tsc\\ %ac/%fc/%bc/%sc/%rc\\ %sq/%bq\\ %hr\\ %hs\\ %{+Q}r\n        mode    http\n        option  httplog\n        option tcplog\n        option abortonclose\n        option httpclose\n        option forwardfor\n        maxconn 5000\n        #websocket\n        timeout tunnel 1h\n        timeout client-fin 30s\n\nlisten status\n     bind 127.0.0.1:1081\n     mode http\n     log global\n     stats refresh 30s\n     stats uri /admin?stats\n     stats realm Private lands\n     stats auth admin:h0jMl0ka0df71WGI1\n     stats hide-version\n     timeout connect 5000ms\n     timeout client  5000ms\n     timeout server  5000ms\n     option accept-invalid-http-response\n\n\n\nfrontend ng80\n    default_backend ng80-abk\n    compression algo gzip\n    bind 0.0.0.0:80\n    http-response add-header Connection keep-alive\n    http-request set-header http_x_forwarded_proto http\n    http-request set-header X-Forwarded-Proto http\n    http-request set-header X-Forwarded-Port %[dst_port]\n    http-request set-header X-Forwarded-Client-srcport %[src_port]\n    mode http\n    timeout client 12333ms\n    maxconn 150\n    option accept-invalid-http-request\n    \n\nbackend ng80-abk\n    balance roundrobin\n    fullconn 2000\n    timeout connect 12333ms\n    timeout server 12333ms\n    server s10.240.104.24:80 10.240.104.24:80 maxconn 2220 weight 1 check\n\n\nfrontend ng801\n    default_backend ng801-abk\n    compression algo gzip\n    bind 0.0.0.0:88\n    http-response add-header Connection keep-alive\n    http-request set-header http_x_forwarded_proto http\n    http-request set-header X-Forwarded-Proto http\n    http-request set-header X-Forwarded-Port %[dst_port]\n    http-request set-header X-Forwarded-Client-srcport %[src_port]\n    mode http\n    timeout client 12333ms\n    maxconn 150\n    option accept-invalid-http-request\n    \n\nbackend ng801-abk\n    balance roundrobin\n    fullconn 2000\n    timeout connect 12333ms\n    timeout server 12333ms\n    server s10.240.104.24:80 10.240.104.24:80 maxconn 2220 weight 1 check\n\n\n\n\n"
        }
        res = requests.post(url, json=body)
        result = json.loads(res.content)
        print(result)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16

    返回示例

    {
        "Code": "Success",
        "Data": {},
        "Message": "The policy modification task is successfully delivered. Wait until the task is executed.",
        "TaskId":"******************"
    }
    
    1
    2
    3
    4
    5
    6

    返回参数:

    参数名 类型 说明
    Code string 状态码
    Data dict 数据
    Message string 信息描述
    TaskId string 任务

    # 17.DescribeLBInstancePerformance

    Action: DescribeLBInstancePerformance

    描述: 获取负载均衡指标的监控数据

    请求地址: http://cdsapi.capitalonline.net/paas/monitor

    请求方法: POST

    请求参数:

    参数名 必选 类型 说明
    InstanceUuid 是 string 实例编号
    MetricKey 是 string 可选指标参数(见下表)
    StartTime 是 string 开始时间
    EndTime 是 string 结束时间

    性能参数表:

    API参数名 类别 类型 单位 含义
    ha_cpu_usage resources gauge 百分比 cpu使用率
    ha_mem_usage resources gauge 百分比 内存使用率
    ha_outpackage resources gauge 个/s 负载均衡实例每秒出包量
    ha_inpackage resources gauge 个/s 负载均衡实例每秒入包量
    ha_outflow resources gauge MB/s 负载均衡实例每秒出流量
    ha_inflow resources gauge MB/s 负载均衡实例每秒入流量

    时间粒度:

    监控粒度自适应方法如下:

    时间跨度 监控粒度 自适应说明 保留时长
    (0h, 4h] 30s 时间跨度在4小时内,监控粒度为5秒 1天
    (4h, 2d] 1min 时间跨度超过4小时,但在2天内,监控粒度调整为1分钟 15天
    (2d, 10d] 5min 时间跨度超过2天,但在10天内,监控粒度调整为5分钟 31天
    (10d, 30d] 1h 时间跨度超过10天,但在30天内,监控粒度调整为1小时 62天

    请求示例:

    def get_haproxy_monitor(instance_uuid):
        """
        获取haproxy监控
        """
        action = "DescribeLBInstancePerformance"
        method = "POST"
        url = get_signature(action, AK, AccessKeySecret, method, MONITOR_URL)
        body = {
            "InstanceUuid": instance_uuid,
            "MetricKey": "ha_mem_usage",
            "StartTime": "2021-10-21 13:25:00",
            "EndTime": "2021-10-21 13:28:00"
        }
        res = requests.post(url, json=body)
        result = json.loads(res.content)
        result = json.dumps(result)
        print(result)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17

    返回参数:

    参数名 类型 说明
    Code string 状态码
    Data MonitorDataObj 负载均衡监控数据集合以及监控参数
    Message string 返回调用接口状态信息和code相对应,比如:Success, Error
    TaskId string 任务Id

    # MonitorDataObj

    参数名 类型 说明
    DataPoints list of DataPointObj 监控数据集合
    EndTime string 结束时间
    InstanceUuid str 实例编号
    MetricKey string 性能指标参数
    Period int 监控粒度(根据时间跨度自适应监控粒度,单位为秒)
    ProductType str 产品类型
    StartTime string 开始时间

    # DataPointObj

    参数名 类型 说明
    MetricName string 性能指标名称
    MetricType string 指标类型(gauge,counter)
    MonitorType list 监控类型(resources,engine, engine_extension, deploy)
    Unit string 单位
    Values list of ValueObj 监控数据列表

    # ValueObj

    参数名 类型 说明
    DateTime string 监控时间点
    Value float 监控数值

    返回示例:

    {
        "Code": "Success",
        "Data": {
            "DataPoints": [{
                "MetricName": "lb_current_memory",
                "MetricType": "gauge",
                "MonitorType": "mem_usage",
                "Unit": "%",
                "Values": [{
                    "DateTime": "2021-10-21 13:25:08",
                    "Value": 9.29
                }, {
                    "DateTime": "2021-10-21 13:25:38",
                    "Value": 9.29
                }, {
                    "DateTime": "2021-10-21 13:26:08",
                    "Value": 9.29
                }, {
                    "DateTime": "2021-10-21 13:26:38",
                    "Value": 9.29
                }, {
                    "DateTime": "2021-10-21 13:27:08",
                    "Value": 9.3
                }, {
                    "DateTime": "2021-10-21 13:27:38",
                    "Value": 9.32
                }]
            }],
            "EndTime": "2021-10-21 13:28:00",
            "InstanceUuid": "********************",
            "MetricKey": "ha_mem_usage",
            "Period": 30,
            "ProductType": "haproxy",
            "StartTime": "2021-10-21 13:25:00"
        },
        "Message": "success",
        "TaskId": ""
    }
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38

    # 18.ModifyLoadBalancerName

    Action: ModifyLoadBalancerName

    描述: 修改负载均衡实例名称

    请求地址: cdsapi.capitalonline.net/lb

    请求方法: POST

    请求参数:

    参数名 必选 类型 说明
    InstanceUuid 是 string 实例ID
    InstanceName 是 string 修改后实例名称

    请求示例

    def modify_haproxy_name(instance_uuid):
        """
        修改haproxy实例名称
        :param instance_uuid: 实例编号
        """
        action = "ModifyLoadBalancerName"
        method = "POST"
        param = {}
        url = get_signature(action, AK, AccessKeySecret, method, HAPROXY_URL, param=param)
        body = {
            "InstanceUuid": instance_uuid,
            "InstanceName": "HaProxy"
        }
    
        res = requests.post(url, json=body)
        result = json.loads(res.content)
    
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16

    返回示例

    {
        "Code": "Success",
        "Message": "Success."
    }
    
    1
    2
    3
    4

    返回参数说明

    参数名 类型 说明
    Message string 信息描述
    Code string 状态码
    对象存储(v1.1)
    新版MongoDB

    ← 对象存储(v1.1) 新版MongoDB→