├── .DS_Store ├── .gitignore ├── CDN概览.md ├── GPU服务器概览.md ├── Kafka概览.md ├── Memcached概览.md ├── MongoDB概览.md ├── MySQL概览.md ├── NAS对外open-api.md ├── README.md ├── Redis概览.md ├── cck概览.md ├── example ├── Golang │ ├── VDC │ │ ├── model │ │ │ ├── BillsExample.go │ │ │ ├── CommonExample.go │ │ │ ├── EcsExample.go │ │ │ ├── InstanceExample.go │ │ │ ├── VdcExample.go │ │ │ └── utils.go │ │ └── test │ │ │ ├── bills_test.go │ │ │ ├── ecs_test.go │ │ │ ├── instance_test.go │ │ │ └── vdc_test.go │ ├── VPC │ │ ├── README.md │ │ ├── common │ │ │ ├── README.md │ │ │ ├── utils.go │ │ │ └── utils_test.go │ │ ├── ebs │ │ │ ├── README.md │ │ │ ├── ebs.go │ │ │ └── ebs_test.go │ │ ├── ecs │ │ │ ├── README.md │ │ │ ├── ecs.go │ │ │ └── ecs_test.go │ │ └── sg │ │ │ ├── README.md │ │ │ ├── sg.go │ │ │ └── sg_test.go │ ├── go.mod │ └── go.sum └── Python │ └── template_example.py ├── 云主机概览.md ├── 云桌面.md ├── 告警概览.md ├── 宿迁对象存储OpenAPI文档(v1.0)【废弃】.md ├── 宿迁对象存储OpenAPI文档(v1.1)【废弃】.md ├── 对象存储OSS OpenAPI文档(v1.2).md ├── 对象存储概览(v1.1).md ├── 弹性云服务器ECS相关.md ├── 新版MongoDB概览.md ├── 私有网络概览.md ├── 虚拟数据中心概览.md ├── 负载均衡概览.md └── 首云OpenAPI(v1.2).md /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/capitalonline/openapi/7dbc84191518084d27e21d303e6d9d7daddf0bf9/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/* -------------------------------------------------------------------------------- /Kafka概览.md: -------------------------------------------------------------------------------- 1 | Kafka 公开API目录 2 | ================= 3 | * [API概览](#api概览) 4 | * [认证方式](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#认证方式) 5 | * [1.公共请求参数](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#1公共请求参数) 6 | * [2.签名机制](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2签名机制) 7 | * [步骤一:构造规范化请求字符串](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#步骤一构造规范化请求字符串) 8 | * [步骤二:构造签名字符串](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#步骤二构造签名字符串) 9 | * [3.获取签名代码](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2获取签名代码) 10 | * [错误码](#错误码) 11 | * [访问地址](#访问地址) 12 | * [实例](#实例) 13 | * [1.GetKafkaList](#1getkafkalist) 14 | 15 | ### API概览 16 | 17 | Kafka产品提供以下相关API接口。 18 | 19 | #### 实例 20 | 21 | | API | 描述 | 22 | | ------------------- | ----------------------------------------- | 23 | | GetKafkaList | 获取Kafka实例列表 | 24 | 25 | 26 | ### 访问地址 27 | 28 | 29 | | 地区 | 访问地址 | 30 | | -------- | ----------------------------- | 31 | | 中国大陆 | cdsapi.capitalonline.net | 32 | | 亚太地区 | cdsapi-asia.capitalonline.net | 33 | | 欧美地区 | cdsapi-us.capitalonline.net | 34 | 35 | ### 1.GetKafkaList 36 | 37 | **Action:** GetKafkaList 38 | 39 | **描述:** 获取Kafka实例列表 40 | 41 | **请求地址:** cdsapi.capitalonline.net/kafka 42 | 43 | **请求方法:** POST 44 | 45 | **请求参数:** 46 | 47 | | 参数名 | 必选 | 类型 | 说明 | 48 | | :----------- | :--- | :----- | ---------------------------------------------- | 49 | | RegionId | 否 | string | 站点编号 | 50 | | VdcId | 否 | string | 数据中心的编号 | 51 | | ProjectId | 否 | string | 项目编号 | 52 | | InstanceId | 否 | list | 目标实例编号列表 | 53 | 54 | **请求示例:** 55 | 56 | ```python 57 | def get_kafka_list(): 58 | """ 59 | 获取Kafka实例列表 60 | """ 61 | action = "GetKafkaList" 62 | method = "POST" 63 | param = { 64 | } 65 | url = get_signature(action, self.AK, self.AccessKeySecret, method, self.KafkaUrl, param) 66 | body = { 67 | "ProjectId": "b9661xxx-59fe-11eb-b7e7-46d055d59xxx", 68 | "RegionId": "APAC_Singapore_D", 69 | "InstanceId": ["94c08xxx-6095-11eb-b408-0242ac11xxxx"] 70 | } 71 | res = requests.post(url, json=body) 72 | print(res.content) 73 | result = json.loads(res.content) 74 | print(result) 75 | ``` 76 | 77 | **返回示例:** 78 | 79 | ```json 80 | { 81 | "Code": "Success", 82 | "Data": [ 83 | { 84 | "CreateTime": "2021-03-05 15:22:48", 85 | "DiskSize": 100, 86 | "DiskType": "ssd_disk", 87 | "Endpoint": "xxxxxx1.kafka.yun-paas.com.:9093,xxxxxxxx2.kafka.yun-paas.com.:9093,xxxxxxxx3.kafka.yun-paas.com.:9093", 88 | "ExpiredTime": "2099-01-01T00:00:00Z", 89 | "InstanceDeployType": "公网", 90 | "InstanceId": "968f8714-7d83-11eb-8946-xxxxxxxxxx", 91 | "InstanceName": "Test", 92 | "IopsPkg": "1个", 93 | "KafkaSpec": "4C8G", 94 | "KafkaVersion": "v2.2.0", 95 | "MsgRetain": "24小时", 96 | "NodeNumber": 3, 97 | "NodesList": [ 98 | { 99 | "BrokerId": 1, 100 | "CreateTime": "2021-03-05 15:22:48", 101 | "NodeId": "0322b342-5ec3-4511-9397-xxxxxxxxxx", 102 | "NodeSpec": "4C8G", 103 | "NodeStatus": "run", 104 | "PrivateIP": "10.240.xx.xx", 105 | "UpdateTime": "2021-03-05 15:27:26" 106 | }, 107 | { 108 | "BrokerId": 2, 109 | "CreateTime": "2021-03-05 15:22:48", 110 | "NodeId": "1865d66b-c84d-4b87-bcfa-xxxxxxxxxx", 111 | "NodeSpec": "4C8G", 112 | "NodeStatus": "run", 113 | "PrivateIP": "10.240.xx.xx", 114 | "UpdateTime": "2021-03-05 15:27:26" 115 | }, 116 | { 117 | "BrokerId": 3, 118 | "CreateTime": "2021-03-05 15:22:48", 119 | "NodeId": "9be45f93-6818-4ed1-bad9-xxxxxxxxxx", 120 | "NodeSpec": "4C8G", 121 | "NodeStatus": "run", 122 | "PrivateIP": "10.240.xx.xx", 123 | "UpdateTime": "2021-03-05 15:27:26" 124 | } 125 | ], 126 | "PayType": "按需", 127 | "RegionId": "CN_Guangzhou_A", 128 | "RegionName": "中国大陆-广州-可用区A", 129 | "ServiceStatus": "run", 130 | "UpdateTime": "2021-03-05 15:27:26", 131 | "VdcId": "4538821a-5bea-42be-b255-xxxxxxxxxx", 132 | "VdcName": "TestGuangZhou" 133 | } 134 | ], 135 | "Message": "获取kafka集群列表成功!" 136 | } 137 | 138 | ``` 139 | 140 | **返回参数说明:** 141 | 142 | | 参数名 | 类型 | 说明 | 143 | | :--------- | :----- | ------------------------------------------------------ | 144 | | Code | string | 状态码 | 145 | | Data | dict | 数据 | 146 | | CreateTime | string | 创建时间 | 147 | | DiskSize | int | 磁盘大小 | 148 | | DiskType | string | 磁盘类型 | 149 | | Endpoint | string | 链接地址 | 150 | | ExpiredTime | string | 过期时间 | 151 | | InstanceId | string | 实例ID | 152 | | InstanceName | string | 名称 | 153 | | IopsPkg | string | IO增强包数量 | 154 | | KafkaSpec | string | 实例规格 | 155 | | KafkaVersion | string | 实例版本 | 156 | | MsgRetain | string | 消息保留时长 | 157 | | NodeNumber | string | 节点数量 | 158 | | NodesList | list | 节点列表 | 159 | | BrokerId | int | Broker ID | 160 | | NodeId | string | 节点ID | 161 | | NodeSpec | string | 节点规格 | 162 | | NodeStatus | string | 节点状态 | 163 | | PrivateIP | string | 节点内网IP | 164 | | UpdateTime | string | 更新时间 | 165 | | PayType | string | 计费类型:按需,包年包月 | 166 | | RegionId | string | 可用区ID | 167 | | RegionName | string | 可用区名称 | 168 | | ServiceStatus | string | 实例状态 | 169 | | VdcId | string | VDC ID | 170 | | VdcName | string | VDC名称 | 171 | | Message | string | 信息描述 | 172 | 173 | **状态码说明:** 174 | | 错误码 | 错误信息 | 说明 | 175 | | :----------- | :--- | ---------------------------------------------- | 176 | | 20001 | 参数错误 | 请确认VDC信息 | 177 | 178 | -------------------------------------------------------------------------------- /Memcached概览.md: -------------------------------------------------------------------------------- 1 | Memcached 公开API目录 2 | ================= 3 | * [API概览](#api概览) 4 | * [认证方式](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#认证方式) 5 | * [1.公共请求参数](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#1公共请求参数) 6 | * [2.签名机制](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2签名机制) 7 | * [步骤一:构造规范化请求字符串](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#步骤一构造规范化请求字符串) 8 | * [步骤二:构造签名字符串](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#步骤二构造签名字符串) 9 | * [3.获取签名代码](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2获取签名代码) 10 | * [访问地址](#访问地址) 11 | * [实例](#实例) 12 | * [1.CreateMemcachedInstance](#1creatememcachedinstance) 13 | * [2.MemcachedInstanceList](#2memcachedinstancelist) 14 | * [3.DescribeMemcachedInstance](#3describememcachedinstance) 15 | * [4.DeleteMemcachedInstance](#4deletememcachedinstance) 16 | * [5.ClearMemcachedInstance](#5clearmemcachedinstance) 17 | * [6.UpdateMemcachedInstance](#6updatememcachedinstance) 18 | 19 | ### API概览 20 | 21 | Memcached产品提供以下相关API接口。 22 | 23 | #### 实例 24 | 25 | | API | 描述 | 26 | | ------------------- | ------------------------------------- | 27 | | CreateMemcachedInstance |创建一台或多台按需计费的memcached的机器 | 28 | | MemcachedInstanceList | 获取memcached数据库实例列表页 | 29 | | DescribeMemcachedInstance | 获取memcached数据库实例详情页 | 30 | | DeleteMemcachedInstance | 删除memcached数据库实例 | 31 | | ClearMemcachedInstance | 清空memcached数据库实例 | 32 | | UpdateMemcachedInstance | 更新memcached数据库实例配置 | 33 | 34 | ### 访问地址 35 | 36 | 37 | | 地区 | 访问地址 | 38 | | -------- | ----------------------------- | 39 | | 中国大陆 | cdsapi.capitalonline.net | 40 | | 亚太地区 | cdsapi-asia.capitalonline.net | 41 | | 欧美地区 | cdsapi-us.capitalonline.net | 42 | 43 | 44 | ### 1.CreateMemcachedInstance 45 | 46 | **Action:CreateMemcached** 47 | 48 | **描述** 创建一台或多台按需计费的memcached的机器。 49 | 50 | **请求地址:** cdsapi.capitalonline.net/memcached 51 | 52 | **请求方法:POST** 53 | 54 | **请求参数:** 55 | 56 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 57 | | ------------ | ------ |------|--------------------------------------| -------------------------------- | 58 | | InstanceName | String | 否 | test | memcached实例名称 | 59 | | ConfSize | String | 是 | 1G | memcached配置大小 可选大小1G-10G | 60 | | VdcId | string | 是 | a58052bf-3bfc-4d0c-a3a5-0bcca72589f5 | 虚拟数据中心id | 61 | | PipeId | string | 是 | 48de2f3c-b3df-11ec-8bed-e6717c813be8 | 虚拟数据中心网段主键ID | 62 | | Amount | int | 否 | 1 | 创建的数据 可选1-10 | 63 | | RegionId | string | 是 | CN_Beijing_H | 区域id | 64 | 65 | **代码调用示例:** 66 | 67 | ~~~python 68 | def create_memcached_instance(ConfSize, VdcId, PipeId, RegionId, InstanceName="", Amount=1): 69 | action = "CreateMemcachedInstance" 70 | method = "POST" 71 | url = get_signature(action, AK, AccessKeySecret, method, CCS_URL, param={}) 72 | body = {"ConfSize": ConfSize, 73 | "VdcId": VdcId, 74 | "PipeId": PipeId, 75 | "RegionId": RegionId} 76 | if InstanceName: 77 | body["InstanceName"] = InstanceName 78 | if Amount: 79 | body["Amount"] = Amount 80 | res = requests.post(url, json=body) 81 | result = json.loads(res.content) 82 | return result 83 | ~~~ 84 | 85 | **返回示例:** 86 | 87 | ~~~json 88 | { 89 | "Code":"Success", 90 | "Data":{ 91 | "InstanceIds":[ 92 | "4e3bb828-c6a4-11ec-95eb-b2d9e44608b0" 93 | ], 94 | "TaskIds":[ 95 | 915 96 | ] 97 | }, 98 | "Message":"任务下发成功!" 99 | } 100 | ~~~ 101 | 102 | **返回参数:** 103 | 104 | | 名称 | 类型 | 示例值 | 描述 | 105 | | ----------- | ------ | ---------------------------------------- | -------- | 106 | | Code | string | 0000 | 错误码 | 107 | | message | string | 任务下发成功! | 任务信息 | 108 | | InstanceIds | List | ['285656f8-c547-11ec-8cc4-4279b2da6491'] | 实例id | 109 | | TaskIds | list | [857] | 任务id | 110 | 111 | **错误码:** 112 | 113 | | httpcode | 错误码 | 错误信息 | 描述 | 114 | | -------- | -------- | --------------------------------------------------------- | ------------ | 115 | | 20001 | 参数错误 | 参数缺失,conf_size,site_id ,app_id, pipe_id为必传参数 | 请求参数错误 | 116 | 117 | ### 2.MemcachedInstanceList 118 | 119 | **Action:MemcachedInstanceList** 120 | 121 | **描述** 获取memcached数据库实例列表页。 122 | 123 | **请求地址:** cdsapi.capitalonline.net/memcached 124 | 125 | **请求方法:POST** 126 | 127 | **请求参数:** 128 | 129 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 130 | | ------- | ------ | -------- | ------------------------------------ | -------------------------------------- | 131 | | VdcId | string | 否 | a58052bf-3bfc-4d0c-a3a5-0bcca72589f5 | 虚拟数据中心id | 132 | | Keyword | string | 否 | Test | 关键字查询,可以查ip,实例名称和实例id | 133 | 134 | **代码调用示例:** 135 | 136 | ~~~python 137 | def memcached_instance_list(VdcId="", Keyword=""): 138 | 139 | action = "MemcachedInstanceList" 140 | method = "POST" 141 | url = get_signature(action, AK, AccessKeySecret, method, CCS_URL, param={}) 142 | body = {} 143 | if VdcId: 144 | body["VdcId"] = VdcId 145 | if Keyword: 146 | body["Keyword"] = Keyword 147 | res = requests.post(url, json=body) 148 | result = json.loads(res.content) 149 | return result 150 | ~~~ 151 | 152 | **返回示例:** 153 | 154 | ~~~json 155 | { 156 | "Code":"Success", 157 | "Data":{ 158 | "CreatingTotal":0, 159 | "DeletingTotal":0, 160 | "ErrorTotal":0, 161 | "InstanceList":[ 162 | { 163 | "Address":"10.240.166.8", 164 | "AppName":"wx-memcache", 165 | "BillMethod":"0", 166 | "ConfName":"Memcached单机版", 167 | "CreateTime":"2022-04-27 18:13:30", 168 | "InstanceConf":"1G", 169 | "InstanceId":"439b83f4-c612-11ec-95eb-b2d9e44608b0", 170 | "InstanceName":"api测试11-pre", 171 | "Port":"11211", 172 | "SiteName":"中国大陆-北京-可用区H", 173 | "Status":"running", 174 | "UpdateTime":"2022-04-27 18:10:28", 175 | "Version":"Memcached1.6" 176 | } 177 | ], 178 | "RunningTotal":1, 179 | "Total":1, 180 | "UpdatingTotal":0 181 | }, 182 | "Message":"获取memcached列表成功!" 183 | } 184 | ~~~ 185 | 186 | **返回参数:** 187 | 188 | | 名称 | 类型 | 示例值 | 描述 | 189 | | ------------- | ------ | ------------------------------------ | ------------------ | 190 | | CreatingTotal | Int | 0 | 创建中实例的数量 | 191 | | DeletingTotal | Int | 0 | 删除中实例的数量 | 192 | | ErrorTotal | Int | 0 | 错误实例的数量 | 193 | | RunningTotal | Int | 0 | 运行中实例的数量 | 194 | | Total | Int | 0 | 实例的总数量 | 195 | | UpdatingTotal | Int | 0 | 更新中实例的总数量 | 196 | | SiteName | string | 亚太地区-中国香港-可用区B | 节点信息 | 197 | | AppName | string | memcached服务端测试 | vdc名称 | 198 | | InstanceId | string | 4733bae6-bc84-11ec-8ced-acde48001122 | 实例id | 199 | | InstanceName | string | zn-test | 实例名称 | 200 | | CreateTime | string | 2022-04-15 13:21:25 | 创建时间 | 201 | | UpdateTime | string | 2022-04-15 14:21:25 | 更新时间 | 202 | | BillMethod | string | 0 | 计费方式 | 203 | | Status | string | running | 实例状态 | 204 | | Version | string | Memcached1.6 | 版本 | 205 | | ConfName | string | Memcached单机版 | 配置信息 | 206 | | Address | string | 10.240.12.29 | 内网地址 | 207 | | Port | int | 11211 | 端口 | 208 | | InstanceConf | string | 1G | 实例配置 | 209 | 210 | **错误码:** 211 | 212 | | httpcode | 错误码 | 错误信息 | 描述 | 213 | | -------- | -------- | ------------------------------ | ------------ | 214 | | 20001 | 参数错误 | customer_id和user_id为必传参数 | 请求参数错误 | 215 | 216 | ### 3.DescribeMemcachedInstance 217 | 218 | **Action:DescribeMemcachedInstance** 219 | 220 | **描述** 获取memcached数据库实例详情页。 221 | 222 | **请求地址:** cdsapi.capitalonline.net/memcached 223 | 224 | **请求方法:POST** 225 | 226 | **请求参数:** 227 | 228 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 229 | | ---------- | ------ | -------- | ------------------------------------ | ------ | 230 | | InstanceId | string | 是 | a58052bf-3bfc-4d0c-a3a5-0bcca72589f5 | 实例id | 231 | 232 | **代码调用示例:** 233 | 234 | ~~~python 235 | def describe_memcached_instance(InstanceId=""): 236 | action = "DescribeMemcachedInstance" 237 | method = "POST" 238 | url = get_signature(action, AK, AccessKeySecret, method, CCS_URL, param={}) 239 | body = {"InstanceId": InstanceId} 240 | res = requests.post(url, json=body) 241 | result = json.loads(res.content) 242 | return result 243 | ~~~ 244 | 245 | **返回示例:** 246 | 247 | ~~~json 248 | { 249 | "Code":"Success", 250 | "Data":{ 251 | "Address":"10.240.166.7", 252 | "AppName":"wx-memcache", 253 | "BillMethod":"0", 254 | "Coon":10000, 255 | "CreateTime":"2022-04-27 10:31:39", 256 | "GoodsId":"17129", 257 | "InstanceConf":"2G", 258 | "InstanceId":"d37e3944-c5d1-11ec-b023-d21e41ec5741", 259 | "InstanceName":"api测试11-pre", 260 | "Port":"11211", 261 | "RunningTime":"0个月1天1小时1分47秒", 262 | "SiteId":"CN_Beijing_H", 263 | "SiteName":"中国大陆-北京-可用区H", 264 | "Status":"running", 265 | "Version":"Memcached1.6" 266 | }, 267 | "Message":"获取Memcached详情成功!" 268 | } 269 | ~~~ 270 | 271 | **返回参数:** 272 | 273 | | 名称 | 类型 | 示例值 | 描述 | 274 | | ------------ | ------ | ------------------------------------ | ---------- | 275 | | SiteName | string | 亚太地区-中国香港-可用区B | 节点信息 | 276 | | SiteId | String | CN_Beijing_H | 地域id | 277 | | AppName | string | memcached服务端测试 | vdc名称 | 278 | | InstanceId | string | 4733bae6-bc84-11ec-8ced-acde48001122 | 实例id | 279 | | InstanceName | string | zn-test | 实例名称 | 280 | | CreateTime | string | 2022-04-15 13:21:25 | 创建时间 | 281 | | update_time | string | 2022-04-15 14:21:25 | 更新时间 | 282 | | BillMethod | string | 0 | 计费方式 | 283 | | Status | string | running | 实例状态 | 284 | | Version | string | Memcached1.6 | 版本 | 285 | | conf_name | string | Memcached单机版 | 配置信息 | 286 | | Address | string | 10.240.12.29 | 内网地址 | 287 | | Port | int | 11211 | 端口 | 288 | | InstanceConf | string | 1G | 实例配置 | 289 | | Coon | int | 10000 | 最大连接数 | 290 | | RunningTime | string | 0个月2天0小时0分15秒 | 运行时间 | 291 | | GoodsId | string | 6055 | 商品id | 292 | 293 | **错误码:** 294 | 295 | | httpcode | 错误码 | 错误信息 | 描述 | 296 | | -------- | -------- | ------------------------------ | ------------ | 297 | | 20001 | 参数错误 | customer_id和user_id为必传参数 | 请求参数错误 | 298 | 299 | ### 4.DeleteMemcachedInstance 300 | 301 | **Action:DeleteMemcachedInstance** 302 | 303 | **描述** 删除memcached数据库实例。 304 | 305 | **请求地址:** cdsapi.capitalonline.net/memcached 306 | 307 | **请求方法:POST** 308 | 309 | **请求参数:** 310 | 311 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 312 | | ---------- | ------ | -------- | ------------------------------------ | ------ | 313 | | InstanceId | string | 是 | a58052bf-3bfc-4d0c-a3a5-0bcca72589f5 | 实例id | 314 | 315 | **代码调用示例:** 316 | 317 | ~~~python 318 | def delete_memcached_instance(InstanceId): 319 | action = "DeleteMemcachedInstance" 320 | method = "POST" 321 | url = get_signature(action, AK, AccessKeySecret, method, CCS_URL, param={}) 322 | body = {"InstanceId": InstanceId} 323 | res = requests.post(url, json=body) 324 | result = json.loads(res.content) 325 | return result 326 | ~~~ 327 | 328 | **返回示例:** 329 | 330 | ~~~json 331 | { 332 | "Code":"Success", 333 | "Data":{ 334 | "TaskId":918 335 | }, 336 | "Message":"删除实例任务下发成功!" 337 | } 338 | ~~~ 339 | 340 | **返回参数:** 341 | 342 | | 名称 | 类型 | 示例值 | 描述 | 343 | | ------- | ------ | -------------- | -------- | 344 | | Code | string | 0000 | 错误码 | 345 | | Message | string | 任务下发成功! | 任务信息 | 346 | | TaskId | int | 889 | 任务id | 347 | 348 | **错误码:** 349 | 350 | | httpcode | 错误码 | 错误信息 | 描述 | 351 | | -------- | -------- | ------------------------------ | ------------ | 352 | | 20001 | 参数错误 | customer_id和user_id为必传参数 | 请求参数错误 | 353 | 354 | ### 5.ClearMemcachedInstance 355 | 356 | **Action:ClearMemcachedInstance** 357 | 358 | **描述** 清空memcached数据库实例。 359 | 360 | **请求地址:** cdsapi.capitalonline.net/memcached 361 | 362 | **请求方法:POST** 363 | 364 | **请求参数:** 365 | 366 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 367 | | ---------- | ------ | -------- | ------------------------------------ | ------ | 368 | | InstanceId | string | 是 | a58052bf-3bfc-4d0c-a3a5-0bcca72589f5 | 实例id | 369 | 370 | **代码调用示例:** 371 | 372 | ~~~python 373 | def clear_memcached_instance(InstanceId): 374 | action = "ClearMemcachedInstance" 375 | method = "POST" 376 | url = get_signature(action, AK, AccessKeySecret, method, CCS_URL, param={}) 377 | body = {"InstanceId": InstanceId} 378 | res = requests.post(url, json=body) 379 | result = json.loads(res.content) 380 | return result 381 | ~~~ 382 | 383 | **返回示例:** 384 | 385 | ~~~json 386 | { 387 | "Code":"Success", 388 | "Data":{ 389 | "TaskId":917 390 | }, 391 | "Message":"清空memcached的数据信息成功" 392 | } 393 | ~~~ 394 | 395 | **返回参数:** 396 | 397 | | 名称 | 类型 | 示例值 | 描述 | 398 | | ------- | ------ | -------------- | -------- | 399 | | Code | string | 0000 | 错误码 | 400 | | Message | string | 任务下发成功! | 任务信息 | 401 | | TaskId | Int | 888 | 任务id | 402 | 403 | **错误码:** 404 | 405 | | httpcode | 错误码 | 错误信息 | 描述 | 406 | | -------- | -------- | ------------------------------ | ------------ | 407 | | 20001 | 参数错误 | customer_id和user_id为必传参数 | 请求参数错误 | 408 | 409 | ### 6.UpdateMemcachedInstance 410 | 411 | **Action:UpdateMemcachedInstance** 412 | 413 | **描述** 更新memcached数据库实例配置。 414 | 415 | **请求地址:** cdsapi.capitalonline.net/memcached 416 | 417 | **请求方法:POST** 418 | 419 | **请求参数:** 420 | 421 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 422 | | ---------- | ------ | -------- | ------------------------------------ | ------------ | 423 | | InstanceId | string | 是 | a58052bf-3bfc-4d0c-a3a5-0bcca72589f5 | 实例id | 424 | | ConfSize | string | 是 | 2G | 实例配置大小 | 425 | 426 | **代码调用示例:** 427 | 428 | ~~~python 429 | def UpdateMemcachedInstance(InstanceId, ConfSize): 430 | action = "UpdateMemcachedInstance" 431 | method = "POST" 432 | url = get_signature(action, AK, AccessKeySecret, method, CCS_URL, param={}) 433 | body = {"InstanceId": InstanceId, "ConfSize": ConfSize} 434 | res = requests.post(url, json=body) 435 | result = json.loads(res.content) 436 | return result 437 | ~~~ 438 | 439 | **返回示例:** 440 | 441 | ~~~json 442 | { 443 | "Code":"Success", 444 | "Data":{ 445 | "TaskId":916 446 | }, 447 | "Message":"清空memcached的数据信息成功" 448 | } 449 | ~~~ 450 | 451 | **返回参数:** 452 | 453 | | 名称 | 类型 | 示例值 | 描述 | 454 | | ------- | ------ | -------------- | -------- | 455 | | Code | string | 0000 | 错误码 | 456 | | Message | string | 任务下发成功! | 任务信息 | 457 | | TaskId | int | 885 | 任务id | 458 | 459 | **错误码:** 460 | 461 | | httpcode | 错误码 | 错误信息 | 描述 | 462 | | -------- | -------- | ------------------------------ | ------------ | 463 | | 20001 | 参数错误 | customer_id和user_id为必传参数 | 请求参数错误 | 464 | -------------------------------------------------------------------------------- /MongoDB概览.md: -------------------------------------------------------------------------------- 1 | MongoDB 公开API目录 2 | ================= 3 | * [API概览](#api概览) 4 | * [认证方式](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#认证方式) 5 | * [1.公共请求参数](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#1公共请求参数) 6 | * [2.签名机制](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2签名机制) 7 | * [步骤一:构造规范化请求字符串](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#步骤一构造规范化请求字符串) 8 | * [步骤二:构造签名字符串](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#步骤二构造签名字符串) 9 | * [3.获取签名代码](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2获取签名代码) 10 | * [错误码](#错误码) 11 | * [访问地址](#访问地址) 12 | * [实例](#实例) 13 | * [1.DescribeZones](#1describezones) 14 | * [2.DescribeSpecInfo](#2describespecinfo) 15 | * [3.CreateDBInstance](#3createdbinstance) 16 | * [4.DescribeDBInstances](#4describedbinstances) 17 | * [5.DeleteDBInstance](#5deletedbinstance) 18 | 19 | ### API概览 20 | 21 | MongoDB产品提供以下相关API接口。 22 | 23 | #### 实例 24 | 25 | | API | 描述 | 26 | | ------------------- | ----------------------------------------- | 27 | | DescribeZones | 获取云数据库MongoDB支持的站点区域 | 28 | | DescribeSpecInfo | 获取某个站点支持的MongoDB产品类型以及规格 | 29 | | CreateDBInstance | 创建MongoDB云数据库实例 | 30 | | DescribeDBInstances | 获取MongoDB实例列表 | 31 | | DeleteDBInstance | 删除MongoDB实例 | 32 | 33 | #### 错误码 34 | 35 | | **HttpCode** | **错误码** | **描述** | 36 | | ------------ | -------------------- | -------------------------------- | 37 | | 400 | ArgMissing | 缺少参数错误 | 38 | | 400 | InvalidParameter | 参数错误 | 39 | | 400 | BadArgs | 参数错误 | 40 | | 400 | UnsupportedOperation | 操作不支持 | 41 | | 404 | ResourceNotFound | 资源不存在 | 42 | | 409 | ResourceInUse | 资源正在被其他任务占用,操作冲突 | 43 | | 500 | InternalError | 内部错误 | 44 | | 500 | CreateOrderExcept | 创建订单异常 | 45 | 46 | ### 访问地址 47 | 48 | 49 | | 地区 | 访问地址 | 50 | | -------- | ----------------------------- | 51 | | 中国大陆 | cdsapi.capitalonline.net | 52 | | 亚太地区 | cdsapi-asia.capitalonline.net | 53 | | 欧美地区 | cdsapi-us.capitalonline.net | 54 | 55 | ### 1.DescribeZones 56 | 57 | **Action:** DescribeZones 58 | 59 | **描述:** 获取云数据库MongoDB支持的站点区域 60 | 61 | **请求地址:** cdsapi.capitalonline.net/mongodb 62 | 63 | **请求方法:** GET 64 | 65 | **请求参数:** 66 | 67 | 无 68 | 69 | **请求示例:** 70 | 71 | ```python 72 | def get_mongodb_Zones(): 73 | """ 74 | 获取云数据库Mongodb支持的站点区域 75 | """ 76 | action = "DescribeZones" 77 | method = "GET" 78 | param = { 79 | } 80 | url = get_signature(action, AK, AccessKeySecret, method, MONGODB_URL, param) 81 | res = requests.get(url) 82 | result = json.loads(res.content) 83 | result = json.dumps(result) # json格式化 84 | print(result) 85 | ``` 86 | 87 | **返回示例:** 88 | 89 | ```json 90 | { 91 | "Code": "Success", 92 | "Data": [{ 93 | "CityId": "3082f45e-306e-11e7-9796-0050569b4d9c", 94 | "CityName": "洛杉矶", 95 | "IsSaling": 1, 96 | "RegionId": "US_LosAngeles_A", 97 | "RegionName": "北美地区", 98 | "SiteName": "洛杉矶1" 99 | }, { 100 | "CityId": "7b98a5d1-306e-11e7-9796-0050569b4d9c", 101 | "CityName": "法兰克福", 102 | "IsSaling": 1, 103 | "RegionId": "EUR_Germany_A", 104 | "RegionName": "欧洲地区", 105 | "SiteName": "德国1" 106 | }, { 107 | "CityId": "8737606f-306d-11e7-9796-0050569b4d9c", 108 | "CityName": "东京", 109 | "IsSaling": 1, 110 | "RegionId": "APAC_Tokyo_A", 111 | "RegionName": "亚太地区", 112 | "SiteName": "东京1" 113 | }, { 114 | "CityId": "27b57297-306d-11e7-9796-0050569b4d9c", 115 | "CityName": "香港", 116 | "IsSaling": 1, 117 | "RegionId": "CN_Hongkong_A", 118 | "RegionName": "亚太地区", 119 | "SiteName": "香港1" 120 | }, { 121 | "CityId": "a8937b00-306d-11e7-9796-0050569b4d9c", 122 | "CityName": "新加坡", 123 | "IsSaling": 1, 124 | "RegionId": "APAC_Singapore_A", 125 | "RegionName": "亚太地区", 126 | "SiteName": "新加坡1" 127 | }, { 128 | "CityId": "5c432e0e-306e-11e7-9796-0050569b4d9c", 129 | "CityName": "阿姆斯特丹", 130 | "IsSaling": 1, 131 | "RegionId": "EUR_Netherlands_A", 132 | "RegionName": "欧洲地区", 133 | "SiteName": "荷兰1" 134 | }, { 135 | "CityId": "154ed19e-306e-11e7-9796-0050569b4d9c", 136 | "CityName": "纽约", 137 | "IsSaling": 1, 138 | "RegionId": "US_NewYork_A", 139 | "RegionName": "北美地区", 140 | "SiteName": "纽约1" 141 | }, { 142 | "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c", 143 | "CityName": "北京", 144 | "IsSaling": 1, 145 | "RegionId": "CN_Beijing_B", 146 | "RegionName": "中国大陆", 147 | "SiteName": "北京2" 148 | }, { 149 | "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c", 150 | "CityName": "北京", 151 | "IsSaling": 1, 152 | "RegionId": "CN_Beijing_E", 153 | "RegionName": "中国大陆", 154 | "SiteName": "北京5" 155 | }, { 156 | "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c", 157 | "CityName": "北京", 158 | "IsSaling": 1, 159 | "RegionId": "CN_Beijing_A", 160 | "RegionName": "中国大陆", 161 | "SiteName": "北京1" 162 | }, { 163 | "CityId": "e48e2312-306d-11e7-9796-0050569b4d9c", 164 | "CityName": "达拉斯", 165 | "IsSaling": 1, 166 | "RegionId": "US_Dallas_A", 167 | "RegionName": "北美地区", 168 | "SiteName": "达拉斯1" 169 | }, { 170 | "CityId": "713d3745-306d-11e7-9796-0050569b4d9c", 171 | "CityName": "台北", 172 | "IsSaling": 1, 173 | "RegionId": "CN_Taipei_A", 174 | "RegionName": "亚太地区", 175 | "SiteName": "台北1" 176 | }, { 177 | "CityId": "123d0d01-306d-11e7-9796-0050569b4d9c", 178 | "CityName": "无锡", 179 | "IsSaling": 1, 180 | "RegionId": "CN_Wuxi_A", 181 | "RegionName": "中国大陆", 182 | "SiteName": "无锡1" 183 | }, { 184 | "CityId": "87fcbbd6-be0a-11e7-9d6b-0242ac110004", 185 | "CityName": "首尔", 186 | "IsSaling": 1, 187 | "RegionId": "APAC_Seoul_A", 188 | "RegionName": "亚太地区", 189 | "SiteName": "首尔1" 190 | }, { 191 | "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c", 192 | "CityName": "北京", 193 | "IsSaling": 1, 194 | "RegionId": "CN_Beijing_C", 195 | "RegionName": "中国大陆", 196 | "SiteName": "北京3" 197 | }, { 198 | "CityId": "c11a5abe-3f7e-11e7-86b1-0242ac11000e", 199 | "CityName": "广州", 200 | "IsSaling": 1, 201 | "RegionId": "CN_Guangzhou_A", 202 | "RegionName": "中国大陆", 203 | "SiteName": "广州1" 204 | }, { 205 | "CityId": "b44355d0-65e7-11e7-8ea9-0050569b651c", 206 | "CityName": "上海", 207 | "IsSaling": 1, 208 | "RegionId": "CN_Shanghai_A", 209 | "RegionName": "中国大陆", 210 | "SiteName": "上海1" 211 | }, { 212 | "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c", 213 | "CityName": "北京", 214 | "IsSaling": 1, 215 | "RegionId": "", 216 | "RegionName": "中国大陆", 217 | "SiteName": "北京8" 218 | }], 219 | "Message": "Success." 220 | } 221 | ``` 222 | 223 | **返回参数说明:** 224 | 225 | | 参数名 | 类型 | 说明 | 226 | | :--------- | :----- | ------------------------------------------------------ | 227 | | Code | string | 状态码 | 228 | | Data | dict | 数据 | 229 | | CityId | string | 城市编号 | 230 | | CityName | string | 城市名称 | 231 | | IsSaling | int | 站点是否能购买服务,1:站点支持购买;0:资源不足以下线 | 232 | | RegionId | string | 区域编号 | 233 | | RegionName | string | 区域名称 | 234 | | SiteName | string | 站点名称 | 235 | | Message | string | 信息描述 | 236 | 237 | 238 | 239 | ### 2.DescribeSpecInfo 240 | 241 | **Action:** DescribeSpecInfo 242 | 243 | **描述:** 获取某个站点支持的MongoDB产品类型以及规格 244 | 245 | **请求地址:** cdsapi.capitalonline.net/mongodb 246 | 247 | **请求方法:** GET 248 | 249 | **请求参数:** 250 | 251 | | 参数名 | 必选 | 类型 | 说明 | 252 | | :------- | :--- | :----- | -------- | 253 | | RegionId | 是 | string | 站点编号 | 254 | 255 | **请求示例:** 256 | 257 | ```python 258 | def get_mongodb_spec_info(RegionId): 259 | """ 260 | 获取某个站点支持的Mongodb产品类型以及规格 261 | :param RegionId: 262 | """ 263 | action = "DescribeSpecInfo" 264 | method = "GET" 265 | param = { 266 | "RegionId": RegionId 267 | } 268 | url = get_signature(action, AK, AccessKeySecret, method, MONGODB_URL, param) 269 | res = requests.get(url) 270 | result = json.loads(res.content) 271 | result = json.dumps(result) # json格式化 272 | print(result) 273 | ``` 274 | 275 | **返回示例:** 276 | 277 | ```json 278 | { 279 | "Code": "Success", 280 | "Data": { 281 | "ProductName": "mongodb", 282 | "Products": [{ 283 | "Architectures": [{ 284 | "ArchitectureName": "副本集", 285 | "ComputeRoles": [{ 286 | "ComputeName": "高性能型", 287 | "Standards": { 288 | "AttachDisk": [{ 289 | "BasicIops": "3000", 290 | "DiskMax": 2000, 291 | "DiskMaxExpand": 2000, 292 | "DiskMin": 100, 293 | "DiskName": "性能型", 294 | "DiskStep": 100, 295 | "DiskUnit": "G", 296 | "DiskValue": "high_disk" 297 | }], 298 | "CpuRam": [{ 299 | "CPU": 1, 300 | "Name": "1C2G", 301 | "PaasGoodsId": 7292, 302 | "RAM": 2 303 | }, { 304 | "CPU": 2, 305 | "Name": "2C4G", 306 | "PaasGoodsId": 7295, 307 | "RAM": 4 308 | }, { 309 | "CPU": 4, 310 | "Name": "4C8G", 311 | "PaasGoodsId": 7298, 312 | "RAM": 8 313 | }, { 314 | "CPU": 8, 315 | "Name": "8C16G", 316 | "PaasGoodsId": 7301, 317 | "RAM": 16 318 | }, { 319 | "CPU": 8, 320 | "Name": "8C32G", 321 | "PaasGoodsId": 7307, 322 | "RAM": 32 323 | }, { 324 | "CPU": 8, 325 | "Name": "8C24G", 326 | "PaasGoodsId": 7304, 327 | "RAM": 24 328 | }] 329 | } 330 | }], 331 | "EnginesType": ["WiredTiger"], 332 | "NetworkLinks": [{ 333 | "DescDetail": "默认链路:服务实例占用VDC私有网络IP地址,适用于对延迟敏感类型的应用。", 334 | "LinkType": "default_link", 335 | "Name": "默认链路", 336 | "SplitRwSwitch": 1 337 | }], 338 | "SubProductName": "MongoDB 副本集版" 339 | }], 340 | "Version": "3.4.21" 341 | }], 342 | "RegionId": "CN_Hongkong_A" 343 | }, 344 | "Message": "Success.", 345 | "TaskId": "" 346 | } 347 | ``` 348 | 349 | **返回参数说明:** 350 | 351 | | 参数名 | 类型 | 说明 | 352 | | :--------------- | :----- | ------------------------------------------------------------ | 353 | | Message | string | 信息描述 | 354 | | Code | string | 状态码 | 355 | | TaskId | string | 任务Id | 356 | | Data | dict | 数据 | 357 | | Products | list | 该类产品支持的产品列表 | 358 | | ProductName | string | 产品名称 | 359 | | SubProductName | string | 子产品名称 | 360 | | Version | string | 产品支持的版本 | 361 | | Architectures | string | 产品支持的架构 | 362 | | ArchitectureName | string | 架构名称 | 363 | | NetworkLinks | list | 此架构支持的链路类型 | 364 | | DescDetail | string | 链路类型描述 | 365 | | LinkType | string | 链路类型“英文” | 366 | | Name | string | 链路类型“中文” | 367 | | ComputeRoles | list | 支持的计算类型,不同的计算类型支持不同规格,并支持添加不同类型的硬盘 | 368 | | Standards | dict | 该类型支持的规格 | 369 | | CpuRam | list | 支持的规格列表 | 370 | | CPU | int | 规格CPU大小 | 371 | | RAM | int | 规格RAM大小 | 372 | | Name | string | 规格名称 | 373 | | PaasGoodsId | int | 具体的产品编号,根据产品编号确定购买哪一种规格 | 374 | | AttachDisk | list | 该类型规格能够添加的磁盘类型列表 | 375 | | DiskMax | int | 单次支持最大规格的磁盘 | 376 | | DiskValue | string | 磁盘类型,用于创建服务实例指定磁盘类型 (创建服务时候使用) | 377 | | BasicIops | string | 基础的磁盘的iops | 378 | | DiskUnit | string | 磁盘规格单位 | 379 | | DiskName | string | 磁盘类型名称 | 380 | | DiskMaxExpand | string | 磁盘最大可扩容大小 | 381 | | DiskMin | string | 磁盘最小大小 | 382 | | DiskStep | string | 磁盘扩容大小 | 383 | | EnginesType | string | 引擎类型 | 384 | 385 | 386 | 387 | ### 3.CreateDBInstance 388 | 389 | **Action:** CreateDBInstance 390 | 391 | **描述:** 创建MongoDB云数据库实例 392 | 393 | **请求地址:** cdsapi.capitalonline.net/mongodb 394 | 395 | **请求方法:** POST 396 | 397 | **请求参数:** 398 | 399 | | 参数名 | 必选 | 类型 | 说明 | 400 | | :----------- | :--- | :----- | ---------------------------------------------- | 401 | | RegionId | 是 | string | 站点编号 | 402 | | VdcId | 是 | string | 数据中心的编号 | 403 | | BasePipeId | 是 | string | 数据中心的私网编号,创建服务将按这个私网分配id | 404 | | InstanceName | 是 | string | 实例名称 | 405 | | PaasGoodsId | 是 | string | 产品的规格编号 | 406 | | DiskType | 是 | string | 磁盘类型 | 407 | | DiskValue | 是 | int | 磁盘大小 | 408 | | Password | 是 | string | Mongodb 最高权限数据库密码 | 409 | | Amount | 否 | int | 购买的数量一次最多购买三个 | 410 | 411 | **请求示例:** 412 | 413 | ```python 414 | def create_mongodb(): 415 | """ 416 | 创建MongoDB实例 417 | """ 418 | action = "CreateDBInstance" 419 | method = "POST" 420 | param = {} 421 | url = get_signature(action, AK, AccessKeySecret, method, MONGODB_URL, param=param) 422 | body = { 423 | "RegionId": "******", 424 | "VdcId": "*******", 425 | "BasePipeId": "******", 426 | "InstanceName": "******", 427 | "PaasGoodsId": "******", 428 | "DiskType": "high_disk", 429 | "DiskValue": 100, 430 | "Password": "******", 431 | } 432 | 433 | res = requests.post(url, json=body) 434 | result = json.loads(res.content) 435 | print(result) 436 | ``` 437 | 438 | **返回示例:** 439 | 440 | ```json 441 | { 442 | "Code": "Success", 443 | "Data": {}, 444 | "Message": "Success.", 445 | "TaskId": "" 446 | } 447 | ``` 448 | 449 | **返回参数说明:** 450 | 451 | | 参数名 | 类型 | 说明 | 452 | | :------ | :----- | -------- | 453 | | Code | string | 状态码 | 454 | | Data | dict | 数据 | 455 | | Message | string | 信息描述 | 456 | | TaskId | string | 任务id | 457 | 458 | 459 | 460 | ### 4.DescribeDBInstances 461 | 462 | **Action:** DescribeDBInstances 463 | 464 | **描述:** 获取MongoDB实例列表(支持常见字段过滤:实例编号、实例名称、实例IP) 465 | 466 | **请求地址:** cdsapi.capitalonline.net/mongodb 467 | 468 | **请求方法:** GET 469 | 470 | **请求参数:** 471 | 472 | | 参数名 | 必选 | 类型 | 说明 | 473 | | :----------- | :--- | :----- | ---------------- | 474 | | InstanceUuid | 否 | string | 要过滤的实例编号 | 475 | | InstanceName | 否 | string | 要过滤的实例名称 | 476 | | IP | 否 | string | 要过滤的实例ip | 477 | 478 | **请求示例:** 479 | 480 | ```python 481 | def get_mongodb_instances_list(): 482 | """ 483 | 获取Mongodb实例列表(可根据ip、instance_uuid、instance_name过滤) 484 | """ 485 | action = "DescribeDBInstances" 486 | method = "GET" 487 | param = { 488 | "IP": "66.66" 489 | } 490 | url = get_signature(action, AK, AccessKeySecret, method, MONGODB_URL, param) 491 | res = requests.get(url) 492 | result = json.loads(res.content) 493 | print(result) 494 | ``` 495 | 496 | **返回示例:** 497 | 498 | ```json 499 | { 500 | "Code": "Success", 501 | "Data": [{ 502 | "CloneServices": null, 503 | "DisplayName": "亚太地区-香港-可用区A", 504 | "IP": "66.66.0.44", 505 | "InstanceName": "test-mongodb", 506 | "InstanceUuid": "9a5a796c-78ab-4b1c-88a4-ba9d9e8c996b", 507 | "LinkType": "default_link", 508 | "LinkTypeStr": "默认链路", 509 | "MasterInfo": "", 510 | "Port": 27017, 511 | "Ram": 2048, 512 | "RegionId": "CN_Hongkong_A", 513 | "RelationService": null, 514 | "ResourceId": "71bf731e-7cc8-4307-8408-4952e4dcd470", 515 | "Status": "RUNNING", 516 | "StatusStr": "运行中", 517 | "SubProductName": "MongoDB 副本集版", 518 | "VdcId": "d459c74b-d60e-4f28-adbb-67be402f76f3", 519 | "VdcName": "香港PaaS", 520 | "Version": "3.4.21" 521 | }], 522 | "Message": "Success." 523 | } 524 | ``` 525 | 526 | **返回参数说明:** 527 | 528 | | 参数名 | 类型 | 说明 | 529 | | :-------------- | :----- | ------------------------ | 530 | | Code | string | 状态码 | 531 | | Data | dict | 数据 | 532 | | CloneServices | list | 克隆的临时实例列表 | 533 | | DisplayName | string | 可用区 | 534 | | IP | string | 数据库的连接的IP | 535 | | InstanceName | string | 实例名称 | 536 | | InstanceUuid | string | 实例编号 | 537 | | LinkType | string | 链路类型名称 | 538 | | LinkTypeStr | string | 链路类型名称对应中文 | 539 | | MasterInfo | dict | 从属集群,只读服务会有值 | 540 | | Port | int | 连接的端口 | 541 | | Ram | int | 内存 单位M | 542 | | RegionId | string | 站点编号 | 543 | | RelationService | dict | 相关联的服务实例 | 544 | | Status | string | 实例状态 | 545 | | StatusStr | string | 状态对应的中文 | 546 | | SubProductName | string | 子产品的名字 | 547 | | VdcId | string | 数据中心的编号 | 548 | | VdcName | string | 数据中心名称 | 549 | | Version | string | 服务版本 | 550 | | Message | string | 信息描述 | 551 | 552 | 553 | 554 | ### 5.DeleteDBInstance 555 | 556 | **Action:** DeleteDBInstance 557 | 558 | **描述:** 删除MongoDB实例 559 | 560 | **请求地址:** cdsapi.capitalonline.net/mongodb 561 | 562 | **请求方法:** POST 563 | 564 | **请求参数:** 565 | 566 | | 参数名 | 必选 | 类型 | 说明 | 567 | | :----------- | :--- | :----- | -------- | 568 | | InstanceUuid | 否 | string | 实例编号 | 569 | 570 | **请求示例:** 571 | 572 | ```python 573 | def delete_mongodb(instance_uuid, ): 574 | """ 575 | 删除MongoDB实例 576 | :param instance_uuid: 577 | """ 578 | action = "DeleteDBInstance" 579 | method = "POST" 580 | param = {} 581 | url = get_signature(action, AK, AccessKeySecret, method, MONGODB_URL, param=param) 582 | body = { 583 | "InstanceUuid": instance_uuid, 584 | } 585 | 586 | res = requests.post(url, json=body) 587 | result = json.loads(res.content) 588 | print(result) 589 | ``` 590 | 591 | **返回示例:** 592 | 593 | ```json 594 | { 595 | "Code": "Success", 596 | "Data": {}, 597 | "Message": "Success.", 598 | "TaskId": "***************" 599 | } 600 | ``` 601 | 602 | **返回参数说明:** 603 | 604 | | 参数名 | 类型 | 说明 | 605 | | :------ | :----- | -------- | 606 | | Code | string | 状态码 | 607 | | Data | dict | 数据 | 608 | | Message | string | 信息描述 | 609 | | TaskId | string | 任务编号 | 610 | -------------------------------------------------------------------------------- /NAS对外open-api.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | # Nas openapi文档 4 | 5 | ### 1.OpenNasService 6 | 7 | **Action**: OpenNasService 8 | 9 | **描述**: 开通NAS服务 10 | 11 | **请求地址**:api.capitalonline.net/nas/v1 12 | 13 | **请求方法**:POST 14 | 15 | **请求参数**: 16 | 17 | 无 18 | 19 | **返回参数**: 20 | 21 | | 参数 | 类型 | 示例 | 说明 | 22 | | ------- | ------ | --------------- | ------------------ | 23 | | Code | string | success | 返回码对应基础信息 | 24 | | Message | string | 开通NAS服务成功 | 返回详细描述信息 | 25 | 26 | **调用代码示例**: 27 | 28 | ```python 29 | def open_nas(): 30 | """ 31 | 开通nas服务 32 | @params: 33 | """ 34 | nas_url = "http://api.capitalonline.net/nas/v1" 35 | action = "OpenNasService" 36 | method = "POST" 37 | url = get_signature(action, AK, AccessKeySecret, method, nas_url) 38 | res = requests.post(url) 39 | result = json.loads(res.content) 40 | return result 41 | ``` 42 | 43 | **返回示例**: 44 | 45 | ```json 46 | { 47 | "Code": "Success", 48 | "Msg": "nas开通成功!", 49 | "Data": {}, 50 | "RequestId": "8a55f46ddad011ee85800456e5321350" 51 | } 52 | ``` 53 | 54 | ### 2.DescribeRegions 55 | 56 | **Action**: DescribeRegions 57 | 58 | **描述**: 查询NAS可以使用的地域及可用区 59 | 60 | **请求地址**:api.capitalonline.net/nas/v1 61 | 62 | **请求方法**:GET 63 | 64 | **请求参数**: 65 | 66 | | 参数 | 说明 | 类型 | 是否必传 | 示例 | 67 | | -------------- | ---------- | -------- | -------- | ------------------------------- | 68 | | FileSystemType | string | standard | 否 | standard:通用型,默认为standard | 69 | | PageNumber | 页码 | int | 否 | 1,不传值默认为1 | 70 | | PageSize | 每页记录数 | int | 否 | 20,不传值默认为所有 | 71 | 72 | **返回参数**: 73 | 74 | | 参数 | 类型 | 示例 | 说明 | 75 | | ---------- | ---- | -------- | ------------ | 76 | | PageNumber | int | 1 | 当前页数 | 77 | | PageSize | int | 1 | 每页数据条数 | 78 | | TotalCount | int | 10 | 总记录数 | 79 | | Regions | list | object[] | 地域列表 | 80 | 81 | Object参数为: 82 | 83 | | 参数 | 类型 | 示例 | 说明 | 84 | | ---------- | ------ | ------------------------------------ | ---------- | 85 | | RegionId | string | 39c6ed64-8d5f-11ec-9247-5293695d0ddd | 地域ID | 86 | | RegionCode | String | CN_Huhhot | 地域Code | 87 | | RegionName | String | 呼和浩特 | 地域名称 | 88 | | AZList | list | Object[] | 可用区列表 | 89 | 90 | 其中AZList对应的参数为: 91 | 92 | | 参数 | 类型 | 示例 | 说明 | 93 | | ----------------- | ------ | ------------------------------------ | ------------------------------------------------------------ | 94 | | AzId | string | f7c3c7a6-8d5f-11ec-9311-5293695d0ddd | 可用区ID | 95 | | AvailableZoneCode | String | CN_Hohhot_B | 可用区Code(参考[附件一](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#%E9%99%84%E4%BB%B6%E4%B8%80)RegionId字段) | 96 | | AzName | String | 呼和浩特B | 可用区名称 | 97 | 98 | **返回参数**: 99 | 100 | | 参数 | 类型 | 示例 | 说明 | 101 | | ------- | ------ | --------------- | ------------------ | 102 | | Code | string | success | 返回码对应基础信息 | 103 | | Message | string | 开通NAS服务成功 | 返回详细描述信息 | 104 | 105 | **调用代码示例**: 106 | 107 | ```python 108 | def describe_regions(): 109 | """ 110 | 显示区域列表 111 | @params: 112 | """ 113 | nas_url = "http://api.capitalonline.net/nas/v1" 114 | action = "DescribeRegions" 115 | method = "GET" 116 | body = { 117 | "FileSystemType": "standard", 118 | "PageNumber": 1, 119 | "PageSize": 5 120 | } 121 | url = get_signature(action, AK, AccessKeySecret, method, nas_url, param=body) 122 | res = requests.get(url) 123 | result = json.loads(res.content) 124 | return result 125 | ``` 126 | 127 | **返回示例**: 128 | 129 | ```json 130 | { 131 | "Code": "Success", 132 | "Msg": "查询nas地域成功!", 133 | "Data": { 134 | "PageNumber": 1, 135 | "PageSize": 1, 136 | "TotalCount": 1, 137 | "Regions": [ 138 | { 139 | "RegionId": "339baef4-c76f-11eb-b5be-5e439efe35c4", 140 | "RegionName": "石家庄2", 141 | "AzList": [ 142 | { 143 | "AzId": "c79d830f-06b9-4e83-96b0-24aa2460867a", 144 | "AzName": "石家庄F", 145 | "AvailableZoneCode": "CN_SJZ_B" 146 | } 147 | ], 148 | "RegionCode": "CN_SJZ" 149 | } 150 | ] 151 | }, 152 | "RequestId": "637c4ecddac911eeb42b0456e5321350" 153 | } 154 | ``` 155 | 156 | ### 3.DescribeFileSystems 157 | 158 | **Action**: DescribeFileSystems 159 | 160 | **描述**: 查询文件系统信息 161 | 162 | **请求地址**:api.capitalonline.net/nas/v1 163 | 164 | **请求方法**:GET 165 | 166 | **请求参数**: 167 | 168 | | 参数 | 说明 | 类型 | 是否必传 | 示例 | 169 | | ----------------- | ------------------------------------------------------------ | ------ | -------- | ------------------------------------ | 170 | | AvailableZoneCode | 可用区Code(参考[附件一](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#%E9%99%84%E4%BB%B6%E4%B8%80)RegionId字段) | string | 否 | CN_Suqian_A | 171 | | RegionCode | 地域Code | string | 否 | CN_Suqian | 172 | | FileSystemIds | 文件系统ID | string | 否 | nas-123,nas-324 | 173 | | VpcId | 私有网络ID | string | 否 | 2efde1b2-76cf-11ed-aae3-46c53bbd2344 | 174 | | PageNumber | 页码 | int | 否 | 1,不传值默认为1 | 175 | | PageSize | 每页记录数 | int | 否 | 20,不传值默认为所有 | 176 | 177 | **返回参数**: 178 | 179 | | 参数 | 类型 | 示例 | 说明 | 180 | | ----------- | ---- | -------- | ------------ | 181 | | PageNumber | int | 1 | 当前页数 | 182 | | PageSize | int | 1 | 每页数据条数 | 183 | | TotalCount | int | 10 | 总记录数 | 184 | | FileSystems | list | object[] | 文件系统列表 | 185 | 186 | 187 | 188 | Object参数为: 189 | 190 | | 参数 | 类型 | 示例 | 说明 | 191 | | ----------------- | -------- | ------------------------------------ | ------------------------------------------------------------ | 192 | | RegionCode | string | CN_Suqian | 地域Code | 193 | | AvailableZoneCode | string | CN_Suqian_A | 可用区Code(参考[附件一](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#%E9%99%84%E4%BB%B6%E4%B8%80)RegionId字段) | 194 | | FileSystemId | string | nas-** | 文件系统ID | 195 | | FileSystemName | string | nas-** | 文件系统名称 | 196 | | Status | string | Running | 文件系统状态 | 197 | | FileSystemType | string | standard | standard:通用型 | 198 | | Capacity | int | 1024 | 文件系统容量,单位为GB | 199 | | MeteredSize | Long | 1611661312 | 文件系统使用量,为当前最新采集的使用量数据,单位为Byte | 200 | | ProtocolType | string | NFS | NFS:NFS文件协议,SMB:SMB文件协议 | 201 | | VpcId | string | 2efde1b2-76cf-11ed-aae3-46c53bbd2344 | VPC ID | 202 | | VpcName | String | VPC名称 | VPC 名称 | 203 | | SubnetId | String | 2f048df0-76cf-11ed-aae3-46c53bbd46d9 | 子网ID | 204 | | SubnetName | String | 子网名称 | 子网名称 | 205 | | MountedPath | List | ["10.26.0.38:/1a8c9123"] | 挂载地址 | 206 | | BillingMethod | string | 0 | 计费方式,0:按需计费 | 207 | | CreateTime | datetime | 2022-07-22 16:41:28 | 创建时间 | 208 | 209 | **调用代码示例**: 210 | 211 | ```python 212 | def describe_file_systems(): 213 | """ 214 | 显示文件系统列表 215 | @params: 216 | """ 217 | nas_url = "http://api.capitalonline.net/nas/v1" 218 | action = "DescribeFileSystems" 219 | method = "GET" 220 | body = { 221 | "AvailableZoneCode": "CN_SJZ_B", 222 | "RegionCode": "CN_SJZ", 223 | "FileSystemIds": "nas-r67erbfs943444tm,nas-lr8src9syfk7iw8m", 224 | "VpcId": "VpcId", 225 | "PageNumber": 1, 226 | "PageSize": 5 227 | } 228 | url = get_signature(action, AK, AccessKeySecret, method, nas_url, param=body) 229 | res = requests.get(url) 230 | result = json.loads(res.content) 231 | return result 232 | ``` 233 | 234 | **返回示例**: 235 | 236 | ```json 237 | { 238 | "Code": "Success", 239 | "Msg": "查询nas列表成功!", 240 | "Data": { 241 | "FileSystems": [ 242 | { 243 | "AvailableZoneCode": "CN_SJZ_B", 244 | "RegionCode": "CN_SJZ", 245 | "FileSystemIds": "nas-r67erbfs943444tm", 246 | "FileSystemName": "nas-r67erbfs943444tm", 247 | "Status": "running", 248 | "FileSystemType": "文件存储-通用型", 249 | "Capacity": 100.0, 250 | "MeteredSize": 0, 251 | "ProtocolType": "NFS", 252 | "VpcId": "e3f66ae0-b8d6-11ee-a6f1-b6e5ad6f00f4", 253 | "VpcName": "EKS-TEST", 254 | "SubnetId": "e3f8b778-b8d6-11ee-a6f1-b6e5ad6f00f4", 255 | "SubnetName": "EKS-SUB1", 256 | "MountedPath": [ 257 | "10.33.24.32:/ecf199e5" 258 | ], 259 | "BillingMethod": "0", 260 | "CreateTime": "2024-03-01T10:11:41" 261 | }, 262 | { 263 | "AvailableZoneCode": "CN_SJZ_B", 264 | "RegionCode": "CN_SJZ", 265 | "FileSystemIds": "nas-lr8src9syfk7iw8m", 266 | "FileSystemName": "nas-lr8src9syfk7iw8m", 267 | "Status": "building", 268 | "FileSystemType": "文件存储-性能型", 269 | "Capacity": 100.0, 270 | "MeteredSize": 0, 271 | "ProtocolType": "NFS", 272 | "VpcId": "e3f66ae0-b8d6-11ee-a6f1-b6e5ad6f00f4", 273 | "VpcName": "EKS-TEST", 274 | "SubnetId": "e3f8b778-b8d6-11ee-a6f1-b6e5ad6f00f4", 275 | "SubnetName": "EKS-SUB1", 276 | "MountedPath": [ 277 | "10.33.24.23" 278 | ], 279 | "BillingMethod": "", 280 | "CreateTime": "2024-02-04T15:56:42" 281 | } 282 | ], 283 | "PageNumber": 1, 284 | "PageSize": 20, 285 | "TotalCount": 2 286 | }, 287 | "RequestId": "c7fce8b5daca11ee850c0456e5321350" 288 | } 289 | ``` 290 | 291 | ### 4.CreateFileSystem 292 | 293 | **Action**: CreateFileSystem 294 | 295 | **描述**: 创建一个文件系统 296 | 297 | **请求地址**:api.capitalonline.net/nas/v1 298 | 299 | **请求方法**:POST 300 | 301 | **请求参数**: 302 | 303 | | 参数 | 说明 | 类型 | 是否必传 | 示例 | 304 | | ----------------- | ------------------------------------------------------------ | ------ | -------- | ------------------------------------ | 305 | | AvailableZoneCode | 可用区Code(参考[附件一](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#%E9%99%84%E4%BB%B6%E4%B8%80)RegionId字段) | string | 是 | CN_Suqian_A | 306 | | FileSystemType | 文件系统类型,standard:通用型 | string | 是 | standard | 307 | | ProtocolType | NFS:NFS文件协议,SMB:SMB文件协议 | String | 是 | NFS | 308 | | VpcId | VPC ID | String | 是 | 2efde1b2-76cf-11ed-aae3-46c53bbd2344 | 309 | | SubnetId | 子网ID | string | 是 | 2f048df0-76cf-11ed-aae3-46c53bbd46d9 | 310 | 311 | **返回参数**: 312 | 313 | | 参数 | 类型 | 示例 | 说明 | 314 | | ------------ | ------ | ------------------------------------ | ---------- | 315 | | EventId | String | 11c4ad90-122c-11ed-b996-7ae483eaf4a2 | 事件ID | 316 | | FileSystemId | String | nas-** | 文件系统ID | 317 | 318 | **调用代码示例**: 319 | 320 | ```python 321 | def create_file_system(): 322 | """ 323 | 创建文件系统 324 | @params: 325 | """ 326 | nas_url = "http://api.capitalonline.net/nas/v1" 327 | action = "CreateFileSystem" 328 | method = "POST" 329 | body = { 330 | "AvailableZoneCode": "CN_SJZ_B", 331 | "FileSystemType": "standard", 332 | "ProtocolType": "NFS", 333 | "VpcId": "VpcId", 334 | "SubnetId": "SubnetId" 335 | } 336 | url = get_signature(action, AK, AccessKeySecret, method, nas_url) 337 | res = requests.post(url, json=body) 338 | result = json.loads(res.content) 339 | return result 340 | ``` 341 | 342 | **返回示例**: 343 | 344 | ```json 345 | { 346 | "Code": "Success", 347 | "Msg": "创建nas成功!", 348 | "Data": { 349 | "EventId": "0b14e376-d771-11ee-bfd7-0456e5321350", 350 | "NasId": "nas-r67erbfs943444tm", 351 | "FileSystemId": "nas-r67erbfs943444tm" 352 | }, 353 | "RequestId": "04affc05d77111ee88920456e5321350" 354 | } 355 | ``` 356 | 357 | ### 5.ModifyFileSystem 358 | 359 | **Action**: ModifyFileSystem 360 | 361 | **描述**: 修改一个文件系统 362 | 363 | **请求地址**:api.capitalonline.net/nas/v1 364 | 365 | **请求方法**:POST 366 | 367 | **请求参数**: 368 | 369 | | 参数 | 说明 | 类型 | 是否必传 | 示例 | 370 | | -------------- | ------------ | ------ | -------- | ------------------------------------------------------------ | 371 | | FileSystemId | 文件系统ID | string | 是 | nas-** | 372 | | FileSystemName | 文件系统名称 | string | 是 | 文件系统名称,2-128个字符,只允许大小写字母或者中文和数字、_或-,以大小写字母或中文开头 | 373 | 374 | **返回参数**: 375 | 376 | | 参数 | 类型 | 示例 | 说明 | 377 | | ---- | ------ | ------ | ---- | 378 | | code | String | nas-** | | 379 | 380 | **调用代码示例**: 381 | 382 | ```python 383 | def modify_file_system(): 384 | """ 385 | 更改文件系统名称 386 | @params: 387 | """ 388 | nas_url = "http://api.capitalonline.net/nas/v1" 389 | action = "ModifyFileSystem" 390 | method = "POST" 391 | body = { 392 | "FileSystemId": "nas-r67erbfs943444tm", 393 | "FileSystemName": "test" 394 | } 395 | url = get_signature(action, AK, AccessKeySecret, method, nas_url) 396 | res = requests.post(url, json=body) 397 | result = json.loads(res.content) 398 | return result 399 | ``` 400 | 401 | **返回示例**: 402 | 403 | ```json 404 | { 405 | "Code": "Success", 406 | "Msg": "修改nas成功!", 407 | "Data": {}, 408 | "RequestId": "8a55f46ddad011ee85800456e5321350" 409 | } 410 | ``` 411 | 412 | ### 6.DeleteFileSystem 413 | 414 | **Action**: DeleteFileSystem 415 | 416 | **描述**: 删除文件系统 417 | 418 | **请求地址**:api.capitalonline.net/nas/v1 419 | 420 | **请求方法**:POST 421 | 422 | **请求参数**: 423 | 424 | | 参数 | 说明 | 类型 | 是否必传 | 示例 | 425 | | ------------- | ---------- | ---- | -------- | --------------------------- | 426 | | FileSystemIds | 文件系统ID | list | 是 | ["nas-11....","nas-12...."] | 427 | 428 | **返回参数**: 429 | 430 | | 参数 | 类型 | 示例 | 说明 | 431 | | ------- | ------ | ------------------------------------ | ------ | 432 | | EventId | String | 11c4ad90-122c-11ed-b996-7ae483eaf4a2 | 事件ID | 433 | 434 | **调用代码示例**: 435 | 436 | ```python 437 | def delete_file_system(): 438 | """ 439 | 删除文件系统 440 | @params: 441 | """ 442 | nas_url = "http://api.capitalonline.net/nas/v1" 443 | action = "DeleteFileSystem" 444 | method = "POST" 445 | body = { 446 | "FileSystemIds": ["nas-r67erbfs943444tm"] 447 | } 448 | url = get_signature(action, AK, AccessKeySecret, method, nas_url) 449 | res = requests.post(url, json=body) 450 | result = json.loads(res.content) 451 | return result 452 | ``` 453 | 454 | **返回示例**: 455 | 456 | ```json 457 | { 458 | "Code": "Success", 459 | "Msg": "删除nas成功!", 460 | "Data": { 461 | "EventId": "c64e21ea-dad0-11ee-8f63-0456e5321350" 462 | }, 463 | "RequestId": "c4663843dad011eebb7c0456e5321350" 464 | } 465 | ``` 466 | -------------------------------------------------------------------------------- /cck概览.md: -------------------------------------------------------------------------------- 1 | cck容器集群公开API目录 2 | ================= 3 | * [认证方式](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#认证方式) 4 | * [1.公共请求参数](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#1公共请求参数) 5 | * [2.签名机制](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2签名机制) 6 | * [步骤一:构造规范化请求字符串](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#步骤一构造规范化请求字符串) 7 | * [步骤二:构造签名字符串](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#步骤二构造签名字符串) 8 | * [3.获取签名代码](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2获取签名代码) 9 | * [API概览](#api概览) 10 | * [1.DescribeTask](#1DescribeTask) 11 | * [2.DescribeClusters](#2DescribeClusters) 12 | * [3.DescribeClusterNodes](#3DescribeClusterNodes) 13 | * [4.DescribeClusterNats](#4DescribeClusterNats) 14 | * [5.CreateClusterNodes](#5CreateClusterNodes) 15 | * [6.StartClusterNodes](#6StartClusterNodes) 16 | * [7.StopClusterNodes](#7StopClusterNodes) 17 | * [8.DeleteClusterNodes](#8DeleteClusterNodes) 18 | 19 | ## cck容器集群 20 | 21 | ### 节点配置表 22 | 23 | 规格类型 24 | 25 | | 规格名称 | 规格配置id | 支持的配置 | 26 | | -------------- | ------------ | ------------------------------------------------------------ | 27 | | **密集计算型** | CCK.CpuHigh | [{"cpu":8,"ram":8},{"cpu":16,"ram":16},{"cpu":32,"ram":32},{"cpu":64,"ram":64}] | 28 | | **计算型** | CCK.Cpu | [{"cpu":8,"ram":16},{"cpu":16,"ram":32},{"cpu":32,"ram":64},{"cpu":64,"ram":128}] | 29 | | **通用型** | CCK.Standard | [{"cpu":8,"ram":32},{"cpu":16,"ram":64},{"cpu":32,"ram":128}] | 30 | | **内存型** | CCK.Memory | [{"cpu":8,"ram":64},{"cpu":16,"ram":128}] | 31 | 32 | ### 1.DescribeTask 33 | 34 | **Action** : DescribeTask 35 | 36 | **描述**:查询任务 37 | 38 | **请求地址**: https://api.capitalonline.net/cck/v1 39 | 40 | **请求方法**: GET 41 | 42 | **请求参数** 43 | 44 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 45 | | ------ | ------ | -------- | ------------------------------------ | ------ | 46 | | TaskId | string | 是 | d6d2scdr-96f3-4d50-a6b1-6c373d7dfb8s | 集群id | 47 | 48 | **返回参数** 49 | 50 | | 名称 | 类型 | 示例值 | 描述 | 51 | | ---- | ------ | ---------- | ---------- | 52 | | Code | string | Success | 错误码 | 53 | | Data | object | | 返回的数据 | 54 | | Msg | string | 查询成功! | 提示信息 | 55 | 56 | **Data对象** 57 | 58 | | 名称 | 类型 | 示例值 | 描述 | 59 | | ------ | ------ | ------ | ---------------------- | 60 | | Status | string | | 任务状态 | 61 | | ErrMsg | string | | 任务失败时,失败的原因 | 62 | 63 | **请求示例:** 64 | 65 | ```python 66 | def describe_task(): 67 | action = "DescribeTask" 68 | method = "GET" 69 | body = { 70 | "TaskId": "f9ef5c64-fbb5-11ed-a819-9ea198d57e15", 71 | } 72 | 73 | url = get_signature(action, AK, AccessKeySecret, method, CCK_URL, param=body) 74 | response = requests.get(url) 75 | result = response.json() 76 | print(json.dumps(result, ensure_ascii=False)) 77 | ``` 78 | 79 | **返回示例:** 80 | 81 | ```json 82 | { 83 | "Code":"Success", 84 | "Msg":"查询成功", 85 | "Data":{ 86 | "Status":"Finish" 87 | }, 88 | "RequestId":"2acc9bdd-6841-449f-9912-0629e8bcca25" 89 | } 90 | ``` 91 | 92 | ### 2.DescribeClusters 93 | 94 | **Action** : DescribeClusters 95 | 96 | **描述**:查询cck集群列表 97 | 98 | **请求地址**: https://api.capitalonline.net/cck/v1 99 | 100 | **请求方法**: GET 101 | 102 | **请求参数** 103 | 104 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 105 | | ----------- | ------ | -------- | ------------------------------------ | --------------------------- | 106 | | RegionId | string | 否 | CN_Hongkong_B | 区域id与vdc版本产品保持一致 | 107 | | VdcId | string | 否 | d6d2bf8c-96f3-4d50-a6b1-6c373d7dfb56 | vdc id | 108 | | ClusterName | string | 否 | cck-cluster1 | 集群名称,可模糊匹配 | 109 | | ClusterId | string | 否 | 96fd21ae-fb8d-11ed-b833-060b6f41d883 | 集群id | 110 | 111 | **返回参数** 112 | 113 | | 名称 | 类型 | 示例值 | 描述 | 114 | | ---- | ------ | ---------- | ---------- | 115 | | Code | string | Success | 错误码 | 116 | | Data | list | | 返回的数据 | 117 | | Msg | string | 查询成功! | 提示信息 | 118 | 119 | data对象字段 120 | 121 | | 名称 | 类型 | 示例值 | 描述 | 122 | | ----------- | ------ | ------ | -------------------------------------------- | 123 | | VdcId | string | | vdc id | 124 | | VdcName | string | | vdc 名称 | 125 | | ClusterId | string | | 集群id | 126 | | ClusterName | string | | 集群名称 | 127 | | NodeNum | int | | 节点总数量 | 128 | | K8sVersion | string | | K8s版本 | 129 | | HaproxyIp | string | | 集群ha的ip | 130 | | Status | string | | 集群的状态Ok/Error/Pending/Updating/Creating | 131 | | Domain | string | | 集群访问域名 | 132 | | Snats | list | | 集群出网网关 | 133 | | ErrorMsg | string | | 当集群错误时,错误的原因 | 134 | | CreateTime | string | | 创建时间 | 135 | 136 | Snats对象字段 137 | 138 | | 名称 | 类型 | 示例值 | 描述 | 139 | | ---------- | ------ | ------ | -------------- | 140 | | Id | string | | 出网关网关id | 141 | | Name | string | | 出网关网关名称 | 142 | | PublicIp | string | | 出网网关公网ip | 143 | | PrivateIp | string | | 出网网关私网ip | 144 | | UsedNum | int | | nat使用量 | 145 | | CreateTime | string | | 创建时间 | 146 | 147 | **请求示例:** 148 | 149 | ```python 150 | def describe_clusters(): 151 | action = "DescribeClusters" 152 | method = "GET" 153 | body = { 154 | "ClusterId": "96fd21ae-fb8d-11ed-b833-060b6f41d883" 155 | } 156 | url = get_signature(action, AK, AccessKeySecret, method, CCK_URL, param=body) 157 | response = requests.get(url) 158 | result = response.json() 159 | print(json.dumps(result, ensure_ascii=False)) 160 | ``` 161 | 162 | **返回示例:** 163 | 164 | ```json 165 | { 166 | "Code":"Success", 167 | "Msg":"查询成功!", 168 | "Data":[ 169 | { 170 | "VdcId":"e8dc80d9-f790-4038-b3a7-42b2689113be", 171 | "VdcName":"vdc-Hongkong", 172 | "ClusterId":"96fd21ae-fb8d-11ed-b833-060b6f41d883", 173 | "ClusterName":"cck-Hongkong", 174 | "NodeNum":4, 175 | "K8SVersion":"1.19.3", 176 | "HaproxyIp":"223.255.250.82", 177 | "Status":"Ok", 178 | "Domain":"dashboard-5xqmqi.yun-paas.com", 179 | "ErrorMsg":"", 180 | "CreateTime":"2023-05-26 14:21:46", 181 | "Snats":[ 182 | { 183 | "Id":"96fda1b0-fb8d-11ed-b833-060b6f41d883", 184 | "Name":"default", 185 | "PublicIp":"223.255.250.16", 186 | "PrivateIp":"10.241.178.10", 187 | "UsedNum":4, 188 | "CreateTime":"2023-05-26 14:21:46" 189 | } 190 | ] 191 | } 192 | ], 193 | "RequestId":"d28362c9-b406-49b9-83c0-025e195fa13f" 194 | } 195 | ``` 196 | 197 | 198 | 199 | ### 3.DescribeClusterNodes 200 | 201 | **Action** : DescribeClusterNodes 202 | 203 | **描述**:查询集群节点详情 204 | 205 | **请求地址**: https://api.capitalonline.net/cck/v1 206 | 207 | **请求方法**: GET 208 | 209 | **请求参数** 210 | 211 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 212 | | ---------- | ------ | -------- | ------------------------------------ | ---------------- | 213 | | ClusterId | string | 是 | d6d2scdr-96f3-4d50-a6b1-6c373d7dfb8s | 集群id | 214 | | PageSize | int | 否 | 20 | 页面大小,默认20 | 215 | | PageNumber | int | 否 | 1 | 页码,默认1 | 216 | 217 | **返回参数** 218 | 219 | | 名称 | 类型 | 示例值 | 描述 | 220 | | ---------- | ------ | ---------- | ---------- | 221 | | Code | string | Success | 错误码 | 222 | | Data | object | | 返回的数据 | 223 | | Msg | string | 查询成功! | 提示信息 | 224 | | PageSize | int | 否 | 页面大小 | 225 | | PageNumber | int | 否 | 页码 | 226 | | Total | int | 否 | 总数 | 227 | 228 | **Data对象** 229 | 230 | | 名称 | 类型 | 示例值 | 描述 | 231 | | ----- | ---- | ------ | ---------- | 232 | | Nodes | list | | 节点列表 | 233 | | Total | int | | 节点总数量 | 234 | 235 | **Nodes对象** 236 | 237 | | 名称 | 类型 | 示例值 | 描述 | 238 | | ----------- | ------ | ------ | ---------------------------------- | 239 | | VdcId | string | | vdc id | 240 | | VdcName | string | | vdc 名称 | 241 | | NodeId | string | | 节点id | 242 | | NodeName | string | | 节点名称 | 243 | | Type | string | | Master/Worker | 244 | | Cpu | int | | cpu核数 | 245 | | Memory | int | | 内存 | 246 | | Status | string | | Ok/Error/Pending/Updating/Creating | 247 | | Schedulable | bool | | 是否可调度 | 248 | | PrivateIp | string | | 节点私网ip | 249 | | PublicIp | string | | 节点公网ip | 250 | | PublicId | string | | 公网id | 251 | | SnatId | string | | 节点出网网关id | 252 | | SnatName | string | | 节点出网网关名称 | 253 | | CreateTime | string | | 创建时间 | 254 | 255 | **请求示例:** 256 | 257 | ```python 258 | def describe_cluster_nodes(): 259 | action = "DescribeClusterNodes" 260 | method = "GET" 261 | body = { 262 | "ClusterId": "96fd21ae-fb8d-11ed-b833-060b6f41d883", 263 | } 264 | url = get_signature(action, AK, AccessKeySecret, method, CCK_URL, param=body) 265 | response = requests.get(url) 266 | result = response.json() 267 | print(json.dumps(result, ensure_ascii=False)) 268 | ``` 269 | 270 | **返回示例:** 271 | 272 | ```json 273 | { 274 | "Code":"Success", 275 | "Msg":"查询成功!", 276 | "Data":{ 277 | "Nodes":[ 278 | { 279 | "VdcId":"e8dc80d9-f790-4038-b3a7-42b2689113be", 280 | "VdcName":"vdc-Hongkong", 281 | "NodeId":"9721908e-fb8d-11ed-b833-060b6f41d883", 282 | "NodeName":"cck-Hongkong-master001", 283 | "Type":"Master", 284 | "Cpu":8, 285 | "Memory":32, 286 | "Status":"Ok", 287 | "Schedulable":false, 288 | "PrivateIp":"10.241.178.11", 289 | "PublicIp":"", 290 | "PublicId":"", 291 | "SnatId":"96fda1b0-fb8d-11ed-b833-060b6f41d883", 292 | "SnatName":"default", 293 | "CreateTime":"2023-05-26 14:21:46" 294 | }, 295 | { 296 | "VdcId":"e8dc80d9-f790-4038-b3a7-42b2689113be", 297 | "VdcName":"vdc-Hongkong", 298 | "NodeId":"9732a856-fb8d-11ed-b833-060b6f41d883", 299 | "NodeName":"cck-Hongkong-master002", 300 | "Type":"Master", 301 | "Cpu":8, 302 | "Memory":32, 303 | "Status":"Ok", 304 | "Schedulable":false, 305 | "PrivateIp":"10.241.178.12", 306 | "PublicIp":"", 307 | "PublicId":"", 308 | "SnatId":"96fda1b0-fb8d-11ed-b833-060b6f41d883", 309 | "SnatName":"default", 310 | "CreateTime":"2023-05-26 14:21:46" 311 | }, 312 | { 313 | "VdcId":"e8dc80d9-f790-4038-b3a7-42b2689113be", 314 | "VdcName":"vdc-Hongkong", 315 | "NodeId":"974451a0-fb8d-11ed-b833-060b6f41d883", 316 | "NodeName":"cck-Hongkong-master003", 317 | "Type":"Master", 318 | "Cpu":8, 319 | "Memory":32, 320 | "Status":"Ok", 321 | "Schedulable":false, 322 | "PrivateIp":"10.241.178.13", 323 | "PublicIp":"", 324 | "PublicId":"", 325 | "SnatId":"96fda1b0-fb8d-11ed-b833-060b6f41d883", 326 | "SnatName":"default", 327 | "CreateTime":"2023-05-26 14:21:47" 328 | }, 329 | { 330 | "VdcId":"e8dc80d9-f790-4038-b3a7-42b2689113be", 331 | "VdcName":"vdc-Hongkong", 332 | "NodeId":"975a96ea-fb8d-11ed-b833-060b6f41d883", 333 | "NodeName":"cck-Hongkong-worker001", 334 | "Type":"Worker", 335 | "Cpu":8, 336 | "Memory":32, 337 | "Status":"Ok", 338 | "Schedulable":true, 339 | "PrivateIp":"10.241.178.14", 340 | "PublicIp":"", 341 | "PublicId":"", 342 | "SnatId":"96fda1b0-fb8d-11ed-b833-060b6f41d883", 343 | "SnatName":"default", 344 | "CreateTime":"2023-05-26 14:21:47" 345 | } 346 | ], 347 | "Total":4 348 | }, 349 | "PageSize":20, 350 | "PageNumber":1, 351 | "Total":4, 352 | "RequestId":"2b1b4a2d-ee2d-4763-9a89-ef24d558c2c8" 353 | } 354 | ``` 355 | 356 | ### 4.DescribeClusterNats 357 | 358 | **Action** : DescribeClusterNats 359 | 360 | **描述**:查询集群网关 361 | 362 | **请求地址**: https://api.capitalonline.net/cck/v1 363 | 364 | **请求方法**: GET 365 | 366 | **请求参数** 367 | 368 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 369 | | --------- | ------ | -------- | ------------------------------------ | ------ | 370 | | ClusterId | string | 是 | d6d2scdr-96f3-4d50-a6b1-6c373d7dfb8s | 集群id | 371 | 372 | **返回参数** 373 | 374 | | 名称 | 类型 | 示例值 | 描述 | 375 | | ---- | ------ | ---------- | ---------- | 376 | | Code | string | Success | 错误码 | 377 | | Data | list | | 返回的数据 | 378 | | Msg | string | 查询成功! | 提示信息 | 379 | 380 | **Data对象** 381 | 382 | | 名称 | 类型 | 示例值 | 描述 | 383 | | ---------- | ------ | ------ | ----------- | 384 | | Id | string | | nat网关id | 385 | | Name | string | | nat网关名称 | 386 | | ClusterId | string | | 集群id | 387 | | PublicIp | string | | 公网ip | 388 | | PrivateIp | string | | 私网ip | 389 | | UsedNum | int | | 使用量 | 390 | | CreateTime | string | | 创建时间 | 391 | | UpdateTime | string | | 更新时间 | 392 | 393 | **请求示例:** 394 | 395 | ```python 396 | def describe_cluster_nats(): 397 | action = "DescribeClusterNats" 398 | method = "GET" 399 | body = { 400 | "ClusterId": "96fd21ae-fb8d-11ed-b833-060b6f41d883", 401 | } 402 | url = get_signature(action, AK, AccessKeySecret, method, CCK_URL, param=body) 403 | response = requests.get(url) 404 | result = response.json() 405 | print(json.dumps(result, ensure_ascii=False)) 406 | ``` 407 | 408 | **返回示例:** 409 | 410 | ```json 411 | { 412 | "Code":"Success", 413 | "Msg":"查询成功!", 414 | "Data":[ 415 | { 416 | "Id":"96fda1b0-fb8d-11ed-b833-060b6f41d883", 417 | "Name":"default", 418 | "ClusterId":"96fd21ae-fb8d-11ed-b833-060b6f41d883", 419 | "VmId":"eeb424e3-998e-4380-8fcf-22deb418e718", 420 | "PublicIp":"223.255.250.16", 421 | "PrivateIp":"10.241.178.10", 422 | "UsedNum":4, 423 | "CreateTime":"2023-05-26 14:21:46", 424 | "UpdateTime":"2023-05-26 14:26:39" 425 | } 426 | ], 427 | "RequestId":"0b3d9916-5a37-435e-8cc1-1278181cfc12" 428 | } 429 | ``` 430 | 431 | ### 5.CreateClusterNodes 432 | 433 | **Action**: CreateClusterNodes 434 | 435 | **描述**:批量创建cck集群worker节点 436 | 437 | **请求地址**: https://api.capitalonline.net/cck/v1 438 | 439 | **请求方法**: POST 440 | 441 | **请求参数** 442 | 443 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 444 | | ------------ | ------ | -------- | ---------------------------------------- | ------------------------------------------------------------ | 445 | | ClusterId | string | 是 | 1b68fbe2-9c4d-4c1e-a1f8-6a25a29df2d3 | 集群id | 446 | | Cpu | int | 是 | 8 | 节点cpu核数 | 447 | | Memory | int | 是 | 16 | 节点内存大小 | 448 | | AttachDisks | list | 是 | | 节点的数据盘,最少要有一块数据盘 | 449 | | Num | int | 是 | 3 | 创建的节点数量 | 450 | | Password | string | 是 | | 节点的密码 | 451 | | Type | string | 是 | Worker | 节点类型:Mater/Worker 目前只支持Worker | 452 | | InstanceType | string | 是 | CCK.Memory | 节点配置类型,参考 [节点配置表](#节点配置表) | 453 | | PublicId | string | 否 | 11d31d29-5897-4a71-a656-af6e59ddfe3c | 公网id,与SnatIds二选一 | 454 | | Lsb | string | 否 | Ubuntu | 节点的操作系统Ubuntu,默认Ubuntu,当前只支持Ubuntu | 455 | | SnatIds | list | 否 | ["9cfb7b80-ee10-11ed-b152-de8c6b7a0fa0"] | | 456 | | SnatType | int | 否 | 1 | snat出网网关类型,默认1。0:不指定snat网关,自动从默认网关中选择一个最近最少使用的。1:使用指定的出网网关,SnatIds必须是合法的出网网关id | 457 | 458 | **AttachDisks**对象 459 | 460 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 461 | | -------- | ------ | -------- | -------- | ----------------------------- | 462 | | DiskType | string | 是 | HighDisk | HighDisk:性能型,当前只有一种 | 463 | | DiskSize | int | 否 | 100 | 100-4000GB,步长100。默认100 | 464 | | Iops | int | 否 | 3000 | 当前取值3000,默认3000 | 465 | 466 | **返回参数** 467 | 468 | | 名称 | 类型 | 示例值 | 描述 | 469 | | ---- | ------ | --------------------------------------------------- | ---------- | 470 | | Code | string | Success | 错误码 | 471 | | Data | object | { "TaskId":"d154475e-e70f-41b5-b464-4ebf279622c6" } | 返回的数据 | 472 | | Msg | string | 节点扩容任务已下发,请等待完成! | 提示信息 | 473 | 474 | **请求示例:** 475 | 476 | ```python 477 | def create_cluster_nodes(): 478 | action = "CreateClusterNodes" 479 | method = "POST" 480 | body = { 481 | "ClusterId": "96fd21ae-fb8d-11ed-b833-060b6f41d883", 482 | "Cpu": 8, 483 | "Memory": 64, 484 | "AttachDisks": [{ 485 | "DiskType": "HighDisk", 486 | "DiskSize": 100, 487 | "Iops": 3000 488 | }], 489 | "Num": 1, 490 | "Password": "cck@passHonkong1", 491 | "Type": "Worker", 492 | "InstanceType": "CCK.Memory", 493 | "Command": "ZWNobyAiMTIzIiA+IC9yb290LzEudHh0", 494 | "PublicId": "", 495 | "SnatIds": [], 496 | "SnatType": 0, 497 | "Lsb": "Ubuntu" 498 | } 499 | url = get_signature(action, AK, AccessKeySecret, method, CCK_URL, param=None) 500 | response = requests.post(url, json=body) 501 | result = response.json() 502 | print(json.dumps(result, ensure_ascii=False)) 503 | ``` 504 | 505 | **返回示例:** 506 | 507 | ```json 508 | { 509 | "Code":"Success", 510 | "Msg":"节点扩容任务已下发,请等待完成!", 511 | "Data":{ 512 | "TaskId":"78e534de-fbb7-11ed-9398-9ea198d57e15" 513 | }, 514 | "RequestId":"4d23aa0d-66c8-46de-a738-e998b96013bd" 515 | } 516 | ``` 517 | 518 | ### 6.StartClusterNodes 519 | 520 | **Action** : StartClusterNodes 521 | 522 | **描述**:cck集群worker节点批量开机 523 | 524 | **请求地址**: https://api.capitalonline.net/cck/v1 525 | 526 | **请求方法**: POST 527 | 528 | **请求参数** 529 | 530 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 531 | | --------- | ------ | -------- | ---------------------------------------- | ---- | 532 | | ClusterId | string | 是 | 96fd21ae-fb8d-11ed-b833-060b6f41d883 | | 533 | | NodeIds | list | 是 | ["d6d2bf8c-96f3-4d50-a6b1-6c373d7dfb56"] | | 534 | 535 | **返回参数** 536 | 537 | | 名称 | 类型 | 示例值 | 描述 | 538 | | ---- | ------ | ------------------------------------------------- | ---------- | 539 | | Code | string | Success | 错误码 | 540 | | Data | object | {"TaskId":"3b0a0238-eede-11ed-8815-4e97c0f3d95d"} | 返回的数据 | 541 | | Msg | string | 节点批量开机任务已下发,请等待执行! | 提示信息 | 542 | 543 | **请求示例:** 544 | 545 | ```python 546 | def start_cluster_nodes(): 547 | action = "StartClusterNodes" 548 | method = "POST" 549 | body = { 550 | "ClusterId": "96fd21ae-fb8d-11ed-b833-060b6f41d883", 551 | "NodeIds": ["975a96ea-fb8d-11ed-b833-060b6f41d883"] 552 | } 553 | url = get_signature(action, AK, AccessKeySecret, method, CCK_URL, param=None) 554 | response = requests.post(url, json=body) 555 | result = response.json() 556 | print(json.dumps(result, ensure_ascii=False)) 557 | 558 | ``` 559 | 560 | **返回示例:** 561 | 562 | ```json 563 | { 564 | "Code":"Success", 565 | "Msg":"节点批量开机任务已下发,请等待执行!", 566 | "Data":{ 567 | "TaskId":"f9ef5c64-fbb5-11ed-a819-9ea198d57e15" 568 | }, 569 | "RequestId":"62de1628-ef3a-452f-816e-a4854c867c2c" 570 | } 571 | ``` 572 | 573 | ### 7.StopClusterNodes 574 | 575 | **Action** : StopClusterNodes 576 | 577 | **描述**:cck集群worker节点批量关机 578 | 579 | **请求地址**: https://api.capitalonline.net/cck/v1 580 | 581 | **请求方法**: POST 582 | 583 | **请求参数** 584 | 585 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 586 | | --------- | ------ | -------- | ---------------------------------------- | ---- | 587 | | ClusterId | string | 是 | 96fd21ae-fb8d-11ed-b833-060b6f41d88 | | 588 | | NodeIds | list | 是 | ["975a96ea-fb8d-11ed-b833-060b6f41d883"] | | 589 | 590 | **返回参数** 591 | 592 | | 名称 | 类型 | 示例值 | 描述 | 593 | | ---- | ------ | ------------------------------------------------- | ---------- | 594 | | Code | string | Success | 错误码 | 595 | | Data | object | {"TaskId":"3b0a0238-eede-11ed-8815-4e97c0f3d95d"} | 返回的数据 | 596 | | Msg | string | 节点批量关机任务已下发,请等待执行! | 提示信息 | 597 | 598 | **请求示例:** 599 | 600 | ```python 601 | def stop_cluster_nodes(): 602 | action = "StopClusterNodes" 603 | method = "POST" 604 | body = { 605 | "ClusterId": "96fd21ae-fb8d-11ed-b833-060b6f41d883", 606 | "NodeIds": ["975a96ea-fb8d-11ed-b833-060b6f41d883"] 607 | } 608 | url = get_signature(action, AK, AccessKeySecret, method, CCK_URL, param=None) 609 | response = requests.post(url, json=body) 610 | result = response.json() 611 | print(json.dumps(result, ensure_ascii=False)) 612 | 613 | ``` 614 | 615 | **返回示例:** 616 | 617 | ```json 618 | { 619 | "Code":"Success", 620 | "Msg":"节点批量关机任务已下发,请等待执行!", 621 | "Data":{ 622 | "TaskId":"ab738e02-fbb5-11ed-9dcc-5ad8d6a7f4dc" 623 | }, 624 | "RequestId":"94249551-f608-46c0-8a12-45915a49f0ee" 625 | } 626 | ``` 627 | 628 | ### 8.DeleteClusterNodes 629 | 630 | **Action** : DeleteClusterNodes 631 | 632 | **描述**:cck集群worker节点批量回收 633 | 634 | **请求地址**: https://api.capitalonline.net/cck/v1 635 | 636 | **请求方法**: POST 637 | 638 | **请求参数** 639 | 640 | | 名称 | 类型 | 是否必选 | 示例 | 描述 | 641 | | --------- | ------ | -------- | ---------------------------------------- | ---- | 642 | | ClusterId | string | 是 | 96fd21ae-fb8d-11ed-b833-060b6f41d883 | | 643 | | NodeIds | list | 是 | ["975a96ea-fb8d-11ed-b833-060b6f41d883"] | | 644 | 645 | **返回参数** 646 | 647 | | 名称 | 类型 | 示例值 | 描述 | 648 | | ---- | ------ | ------------------------------------------------- | ---------- | 649 | | Code | string | Success | 错误码 | 650 | | Data | object | {"TaskId":"3b0a0238-eede-11ed-8815-4e97c0f3d95d"} | 返回的数据 | 651 | | Msg | string | 节点批量回收任务已下发,请等待执行! | 提示信息 | 652 | 653 | **请求示例:** 654 | 655 | ```python 656 | def delete_cluster_nodes(): 657 | action = "DeleteClusterNodes" 658 | method = "POST" 659 | body = { 660 | "ClusterId": "96fd21ae-fb8d-11ed-b833-060b6f41d883", 661 | "NodeIds": ["975a96ea-fb8d-11ed-b833-060b6f41d883"] 662 | } 663 | url = get_signature(action, AK, AccessKeySecret, method, CCK_URL, param=None) 664 | response = requests.post(url, json=body) 665 | result = response.json() 666 | print(json.dumps(result, ensure_ascii=False)) 667 | ``` 668 | 669 | **返回示例:** 670 | 671 | ```json 672 | { 673 | "Code":"Success", 674 | "Msg":"节点批量回收任务已下发,请等待执行!", 675 | "Data":{ 676 | "TaskId":"d6bf9040-fbb7-11ed-9398-9ea198d57e15" 677 | }, 678 | "RequestId":"da0260a1-07e4-4db2-8017-85108fa5c715" 679 | } 680 | ``` 681 | 682 | -------------------------------------------------------------------------------- /example/Golang/VDC/model/BillsExample.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | var ( 9 | billing bill 10 | 11 | accountInfo acInfo 12 | bInfo billInfo 13 | bDetail billDetail 14 | ) 15 | 16 | const BillsUrl = "https://cdsapi.capitalonline.net/billing" 17 | 18 | type acInfo struct { 19 | CostCount int `json:"CostCount"` 20 | CostRecords []struct { 21 | Amount float64 `json:"Amount"` 22 | Currency string `json:"Currency"` 23 | Month string `json:"Month"` 24 | } `json:"CostRecords"` 25 | CreditLine float64 `json:"CreditLine"` 26 | MasterTotalBalance float64 `json:"MasterTotalBalance"` 27 | MasterTotalCost float64 `json:"MasterTotalCost"` 28 | RechargeCount int `json:"RechargeCount"` 29 | RechargeRecord []struct { 30 | Amount float64 `json:"Amount"` 31 | CreateDate string `json:"CreateDate"` 32 | Currency string `json:"Currency"` 33 | SwiftNumber string `json:"SwiftNumber"` 34 | Type string `json:"Type"` 35 | } `json:"RechargeRecord"` 36 | ToDeduct float64 `json:"ToDeduct"` 37 | } 38 | type bill struct { 39 | BillInfo []struct { 40 | CreateTime string `json:"CreateTime"` 41 | DeleteTime string `json:"DeleteTime"` 42 | RegionID string `json:"RegionId"` 43 | ResourceID string `json:"ResourceId"` 44 | ResourceName string `json:"ResourceName"` 45 | ResourceType string `json:"ResourceType"` 46 | TotalCost float64 `json:"TotalCost"` 47 | VdcID string `json:"VdcId"` 48 | VdcName string `json:"VdcName"` 49 | } `json:"BillInfo"` 50 | TotalMasterCost float64 `json:"TotalMasterCost"` 51 | TotalViceCost float64 `json:"TotalViceCost"` 52 | } 53 | type billInfo struct { 54 | BillDetail []struct { 55 | Configuration string `json:"Configuration"` 56 | CostDetail string `json:"CostDetail"` 57 | CreateTime string `json:"CreateTime"` 58 | EndTime string `json:"EndTime"` 59 | IPs []string `json:"IPs"` 60 | PayDesc string `json:"PayDesc"` 61 | PayType string `json:"PayType"` 62 | RegionID string `json:"RegionId"` 63 | ResourceID string `json:"ResourceId"` 64 | ResourceName string `json:"ResourceName"` 65 | StartTime string `json:"StartTime"` 66 | Status string `json:"Status"` 67 | TotalCost float64 `json:"TotalCost"` 68 | UnitPrice float64 `json:"UnitPrice"` 69 | VdcID string `json:"VdcId"` 70 | VdcName string `json:"VdcName"` 71 | } `json:"BillDetail"` 72 | TotalCost float64 `json:"TotalCost"` 73 | } 74 | type billDetail struct { 75 | BeginTime string `json:"BeginTime"` 76 | BillDetail []struct { 77 | APP string `json:"APP"` 78 | BeginTime string `json:"BeginTime"` 79 | BillType string `json:"BillType"` 80 | CloudID string `json:"CloudId"` 81 | Config string `json:"Config"` 82 | Currency string `json:"Currency"` 83 | EndTime string `json:"EndTime"` 84 | GoodsType string `json:"GoodsType"` 85 | Label string `json:"Label"` 86 | Product string `json:"Product"` 87 | Project string `json:"Project"` 88 | Resource string `json:"Resource"` 89 | Site string `json:"Site"` 90 | TotalCost float64 `json:"TotalCost"` 91 | } `json:"BillDetail"` 92 | EndTime string `json:"EndTime"` 93 | TotalRecords int `json:"TotalRecords"` 94 | TotalSummary struct { 95 | Currency string `json:"Currency"` 96 | MasterCost float64 `json:"MasterCost"` 97 | ToDeduct float64 `json:"ToDeduct"` 98 | TotalCost float64 `json:"TotalCost"` 99 | ViceCost float64 `json:"ViceCost"` 100 | } `json:"TotalSummary"` 101 | } 102 | 103 | func DescribeBill() (CommonReturn, error) { 104 | action := "DescribeBill" 105 | method := "GET" 106 | body, err := json.Marshal(map[string]interface{}{ 107 | "DateFromTo": "2022.08.02 - 2022.08.03", 108 | "Currency": "CN", 109 | }) 110 | res := doHttpPost(action, BillsUrl, method, body) 111 | fmt.Printf(">>>>>>> request result: %v", res) 112 | bytes, _ := json.Marshal(res.Data) 113 | json.Unmarshal(bytes, &billing) 114 | return res, err 115 | } 116 | func DescribeBillInfo() (CommonReturn, error) { 117 | action := "DescribeBillInfo" 118 | method := "GET" 119 | body, err := json.Marshal(map[string]interface{}{ 120 | "DateFrom": "2019.09.02", 121 | "DateTo": "2019.09.03", 122 | "ResourceId": "XXXXX", 123 | "Currency": "CN", 124 | }) 125 | res := doHttpPost(action, BillsUrl, method, body) 126 | fmt.Printf(">>>>>>> request result: %v", res) 127 | bytes, _ := json.Marshal(res.Data) 128 | json.Unmarshal(bytes, &bInfo) 129 | return res, err 130 | } 131 | func DescribeBillDetail() (CommonReturn, error) { 132 | action := "DescribeBillDetail" 133 | method := "GET" 134 | body, err := json.Marshal(map[string]interface{}{ 135 | "DateFrom": "2022.07.01", 136 | "DateTo": "2022.07.03", 137 | "ProjectName": "默认项目组", 138 | }) 139 | res := doHttpPost(action, BillsUrl, method, body) 140 | fmt.Printf(">>>>>>> request result: %v", res) 141 | bytes, _ := json.Marshal(res.Data) 142 | json.Unmarshal(bytes, &bDetail) 143 | return res, err 144 | } 145 | func DescribeAccountInfo() (CommonReturn, error) { 146 | action := "DescribeAccountInfo" 147 | method := "GET" 148 | 149 | res := doHttpPost(action, BillsUrl, method, nil) 150 | fmt.Printf(">>>>>>> request result: %v", res) 151 | bytes, _ := json.Marshal(res.Data) 152 | json.Unmarshal(bytes, &accountInfo) 153 | return res, nil 154 | } 155 | -------------------------------------------------------------------------------- /example/Golang/VDC/model/CommonExample.go: -------------------------------------------------------------------------------- 1 | package model 2 | -------------------------------------------------------------------------------- /example/Golang/VDC/model/EcsExample.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | const EcsUrl = "https://api.capitalonline.net/ecs/v1" 9 | 10 | func CreateInstanceEcs() (CommonReturn, error) { 11 | action := "CreateInstance" 12 | method := "POST" 13 | body, err := json.Marshal(map[string]interface{}{ 14 | "AvailableZoneCode": "CN_Suqian_B", 15 | "EcsFamilyName": "CPU计算型C1", 16 | "Cpu": 2, 17 | "Ram": 4, 18 | "Gpu": 0, 19 | "Number": 1, 20 | "BillingMethod": "0", 21 | "ImageId": "ee300237-0ef4-40a9-ad79-7470262d4a2f", 22 | "SystemDisk": map[string]interface{}{ 23 | "DiskFeature": "local", 24 | "Size": 50, 25 | }, 26 | "VpcInfo": map[string]interface{}{ 27 | "VpcId": "xxx", 28 | }, 29 | "SubnetInfo": map[string]interface{}{ 30 | "SubnetId": "xxx", 31 | }, 32 | "Name": "ecs-test-golang", 33 | "StartNumber": 0, 34 | "Password": "123QWEqwe", 35 | }, 36 | ) 37 | if err != nil { 38 | return CommonReturn{}, err 39 | } 40 | res := doHttpPost(action, EcsUrl, method, body) 41 | fmt.Printf(">>>>>>> request result: %v", res) 42 | return res, nil 43 | } 44 | 45 | func DescribeRegions() (CommonReturn, error) { 46 | action := "DescribeRegions" 47 | method := "GET" 48 | 49 | res := doHttpPost(action, EcsUrl, method, nil) 50 | fmt.Printf(">>>>>>> request result: %v", res) 51 | return res, nil 52 | } 53 | 54 | func DescribeEcsFamilyInfo() (CommonReturn, error) { 55 | action := "DescribeEcsFamilyInfo" 56 | method := "GET" 57 | body, err := json.Marshal(map[string]interface{}{ 58 | "AvailableZoneCode": "CN_Suqian_B", 59 | "BillingMethod": "0", 60 | }, 61 | ) 62 | if err != nil { 63 | return CommonReturn{}, err 64 | } 65 | res := doHttpPost(action, EcsUrl, method, body) 66 | fmt.Printf(">>>>>>> request result: %v", res) 67 | return res, nil 68 | } 69 | 70 | func DescribeImage() (CommonReturn, error) { 71 | action := "DescribeImage" 72 | method := "GET" 73 | body, err := json.Marshal(map[string]interface{}{ 74 | "AvailableZoneCode": "CN_Suqian_B", 75 | }, 76 | ) 77 | if err != nil { 78 | return CommonReturn{}, err 79 | } 80 | res := doHttpPost(action, EcsUrl, method, body) 81 | fmt.Printf(">>>>>>> request result: %v", res) 82 | return res, nil 83 | } 84 | -------------------------------------------------------------------------------- /example/Golang/VDC/model/InstanceExample.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | ) 7 | 8 | var CcsUrl = "https://cdsapi.capitalonline.net/ccs" 9 | 10 | func CreateInstance(RegionId, VdcId, InstanceName, InstanceType, ImageId, Password string, Cpu, Ram, Amount int) CommonReturn { 11 | action := "CreateInstance" 12 | method := "POST" 13 | 14 | var PublicIp []string 15 | var PrivateIp, DataDisk []interface{} 16 | 17 | body, err := json.Marshal(map[string]interface{}{ 18 | "RegionId": RegionId, 19 | "VdcId": VdcId, 20 | "InstanceName": InstanceName, 21 | "Cpu": Cpu, 22 | "Ram": Ram, 23 | "InstanceType": InstanceType, 24 | "ImageId": ImageId, 25 | "DataDisk": DataDisk, 26 | "InstanceChargeType": "PostPaid", 27 | "Password": Password, 28 | "AutoRenew": 1, 29 | "PrepaidMonth": 1, 30 | "Amount": Amount, 31 | "PublicIp": PublicIp, 32 | "PrivateIp": PrivateIp, 33 | }) 34 | if err != nil { 35 | panic(err) 36 | } 37 | res := doHttpPost(action, CcsUrl, method, body) 38 | return res 39 | } 40 | 41 | func DescribeInstances(InstanceId string) CommonReturn { 42 | action := "DescribeInstances" 43 | method := "POST" 44 | 45 | body, err := json.Marshal(map[string]string{ 46 | "InstanceId": InstanceId, 47 | }) 48 | if err != nil { 49 | panic(err) 50 | } 51 | 52 | res := doHttpPost(action, CcsUrl, method, body) 53 | return res 54 | } 55 | 56 | func DeleteInstance(InstanceIds []string) CommonReturn { 57 | action := "DeleteInstance" 58 | method := "POST" 59 | 60 | body, err := json.Marshal(map[string][]string{ 61 | "InstanceIds": InstanceIds, 62 | }) 63 | if err != nil { 64 | panic(err) 65 | } 66 | res := doHttpPost(action, CcsUrl, method, body) 67 | return res 68 | } 69 | 70 | func StopInstance(InstanceId string) CommonReturn { 71 | action := "StopInstance" 72 | method := "GET" 73 | 74 | body, err := json.Marshal(map[string]string{ 75 | "InstanceId": InstanceId, 76 | }) 77 | if err != nil { 78 | panic(err) 79 | } 80 | res := doHttpPost(action, CcsUrl, method, body) 81 | return res 82 | } 83 | 84 | func StartInstance(InstanceId string) CommonReturn { 85 | action := "StartInstance" 86 | method := "GET" 87 | 88 | body, err := json.Marshal(map[string]string{ 89 | "InstanceId": InstanceId, 90 | }) 91 | if err != nil { 92 | panic(err) 93 | } 94 | res := doHttpPost(action, CcsUrl, method, body) 95 | return res 96 | } 97 | 98 | func RebootInstance(InstanceId string) CommonReturn { 99 | action := "RebootInstance" 100 | method := "GET" 101 | 102 | body, err := json.Marshal(map[string]string{ 103 | "InstanceId": InstanceId, 104 | }) 105 | if err != nil { 106 | panic(err) 107 | } 108 | res := doHttpPost(action, CcsUrl, method, body) 109 | return res 110 | } 111 | 112 | func ModifyInstanceSpec(InstanceId string, Cpu, Ram int) CommonReturn { 113 | action := "ModifyInstanceSpec" 114 | method := "POST" 115 | 116 | body, err := json.Marshal(map[string]interface{}{ 117 | "InstanceId": InstanceId, 118 | "Cpu": Cpu, 119 | "Ram": Ram, 120 | }) 121 | if err != nil { 122 | panic(err) 123 | } 124 | res := doHttpPost(action, CcsUrl, method, body) 125 | return res 126 | } 127 | 128 | type DiskParam struct { 129 | Size int 130 | Type string 131 | } 132 | 133 | func CreateDisk(InstanceId string) CommonReturn { 134 | action := "CreateDisk" 135 | method := "POST" 136 | 137 | param := make([]DiskParam, 1) 138 | param[0].Size = 100 139 | param[0].Type = "high_disk" 140 | 141 | fmt.Println(param) 142 | body, err := json.Marshal(map[string]interface{}{ 143 | "InstanceId": InstanceId, 144 | "DataDisks": param, 145 | }) 146 | if err != nil { 147 | panic(err) 148 | } 149 | res := doHttpPost(action, CcsUrl, method, body) 150 | return res 151 | } 152 | 153 | func ResizeDisk(InstanceId, DiskId string, Size int) CommonReturn { 154 | action := "ResizeDisk" 155 | method := "POST" 156 | 157 | body, err := json.Marshal(map[string]interface{}{ 158 | "InstanceId": InstanceId, 159 | "DiskId": DiskId, 160 | "DataSize": Size, 161 | }) 162 | if err != nil { 163 | panic(err) 164 | } 165 | res := doHttpPost(action, CcsUrl, method, body) 166 | return res 167 | } 168 | 169 | func DeleteDisk(InstanceId string, DiskIds []string) CommonReturn { 170 | action := "DeleteDisk" 171 | method := "POST" 172 | 173 | body, err := json.Marshal(map[string]interface{}{ 174 | "InstanceId": InstanceId, 175 | "DiskIds": DiskIds, 176 | }) 177 | if err != nil { 178 | panic(err) 179 | } 180 | res := doHttpPost(action, CcsUrl, method, body) 181 | return res 182 | } 183 | 184 | func ResetImage(InstanceId, ImageId, Password, PublicKey string) CommonReturn { 185 | action := "ResetImage" 186 | method := "POST" 187 | if Password == "" && PublicKey == "" { 188 | panic("not password or publicKey") 189 | } 190 | param := map[string]interface{}{ 191 | "InstanceId": InstanceId, 192 | "ImageId": ImageId, 193 | } 194 | if Password != "" { 195 | param["Password"] = Password 196 | } 197 | if PublicKey != "" { 198 | param["PublicKey"] = PublicKey 199 | } 200 | body, err := json.Marshal(param) 201 | if err != nil { 202 | panic(err) 203 | } 204 | res := doHttpPost(action, CcsUrl, method, body) 205 | return res 206 | } 207 | 208 | func ModifyIpAddress(InstanceId, InterfaceId, Address string) CommonReturn { 209 | action := "ModifyIpAddress" 210 | method := "POST" 211 | body, err := json.Marshal(map[string]string{ 212 | "InstanceId": InstanceId, 213 | "InterfaceId": InterfaceId, 214 | "Address": Address, 215 | }) 216 | if err != nil { 217 | panic(err) 218 | } 219 | res := doHttpPost(action, CcsUrl, method, body) 220 | return res 221 | } 222 | 223 | func ModifyInstanceName(InstanceId, InstanceName string) CommonReturn { 224 | action := "ModifyInstanceName" 225 | method := "POST" 226 | body, err := json.Marshal(map[string]string{ 227 | "InstanceId": InstanceId, 228 | "InstanceName": InstanceName, 229 | }) 230 | if err != nil { 231 | panic(err) 232 | } 233 | res := doHttpPost(action, CcsUrl, method, body) 234 | return res 235 | } 236 | 237 | // 获取历史实例信息 238 | type HistoryInstance struct { 239 | InstanceName string 240 | InstanceId string 241 | VdcName string 242 | VdcId string 243 | InstanceStatus string 244 | CreateTime string 245 | Cpu int 246 | Ram int 247 | RegionId string 248 | TotalDiskSize int 249 | } 250 | 251 | type Result struct { 252 | Date string 253 | InstanceInfo []HistoryInstance 254 | PageNumber int 255 | PageCount int 256 | } 257 | 258 | func GetHistoryInstance(Date string, PageSize, PageNum int) *Result { 259 | if Date == "" { 260 | return nil 261 | } 262 | 263 | action := "DescribeHistoryInstance" 264 | body, err := json.Marshal(map[string]interface{}{ 265 | "Date": Date, 266 | "PageSize": PageSize, 267 | "PageNumber": PageNum, 268 | }) 269 | if err != nil { 270 | panic(err) 271 | } 272 | res := doHttpPost(action, CcsUrl, "POST", body) 273 | if res.Code != "Success" { 274 | panic(res.Message) 275 | } 276 | resByte, _ := json.Marshal(res.Data) 277 | result := Result{ 278 | PageCount: res.PageCount, 279 | PageNumber: res.PageNumber, 280 | } 281 | json.Unmarshal(resByte, &result) 282 | return &result 283 | } 284 | -------------------------------------------------------------------------------- /example/Golang/VDC/model/VdcExample.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "encoding/json" 5 | ) 6 | 7 | var NetworkUrl = "https://cdsapi.capitalonline.net/network" 8 | 9 | func DescribeVdc(RegionId, VdcId, Keyword string) CommonReturn { 10 | action := "DescribeVdc" 11 | method := "GET" 12 | 13 | var param = map[string]string{} 14 | if RegionId != "" { 15 | param["RegionId"] = RegionId 16 | } 17 | if VdcId != "" { 18 | param["VdcId"] = VdcId 19 | } 20 | if Keyword != "" { 21 | param["Keyword"] = Keyword 22 | } 23 | body, err := json.Marshal(param) 24 | if err != nil { 25 | panic(err) 26 | } 27 | res := doHttpPost(action, NetworkUrl, method, body) 28 | return res 29 | } 30 | 31 | type PublicNetworkInfo struct { 32 | Name string 33 | Type string 34 | BillingMethod string 35 | Qos int 36 | IPNum int 37 | } 38 | 39 | func CreateVdc(RegionId, VdcName string, info PublicNetworkInfo) CommonReturn { 40 | action := "CreateVdc" 41 | method := "POST" 42 | 43 | param := map[string]interface{}{ 44 | "RegionId": RegionId, 45 | "VdcName": VdcName, 46 | "PublicNetwork": info, 47 | } 48 | body, err := json.Marshal(param) 49 | if err != nil { 50 | panic(err) 51 | } 52 | res := doHttpPost(action, NetworkUrl, method, body) 53 | return res 54 | } 55 | 56 | func AddPublicIp(PublicId string, Number string) CommonReturn { 57 | action := "AddPublicIp" 58 | method := "GET" 59 | 60 | param := map[string]interface{}{ 61 | "PublicId": PublicId, 62 | "Number": Number, 63 | } 64 | body, err := json.Marshal(param) 65 | if err != nil { 66 | panic(err) 67 | } 68 | res := doHttpPost(action, NetworkUrl, method, body) 69 | return res 70 | } 71 | 72 | func DeletePublicIp(SegmentId string) CommonReturn { 73 | action := "DeletePublicIp" 74 | method := "GET" 75 | param := map[string]string{ 76 | "SegmentId": SegmentId, 77 | } 78 | body, err := json.Marshal(param) 79 | if err != nil { 80 | panic(err) 81 | } 82 | res := doHttpPost(action, NetworkUrl, method, body) 83 | return res 84 | } 85 | 86 | func DescribeBandwidthTraffic(NetworkId string) CommonReturn { 87 | action := "DescribeBandwidthTraffic" 88 | method := "GET" 89 | param := map[string]string{ 90 | "NetworkId": NetworkId, 91 | } 92 | body, err := json.Marshal(param) 93 | if err != nil { 94 | panic(err) 95 | } 96 | res := doHttpPost(action, NetworkUrl, method, body) 97 | return res 98 | } 99 | -------------------------------------------------------------------------------- /example/Golang/VDC/model/utils.go: -------------------------------------------------------------------------------- 1 | package model 2 | 3 | import ( 4 | "bytes" 5 | "crypto/hmac" 6 | "crypto/sha1" 7 | "encoding/base64" 8 | "fmt" 9 | "io/ioutil" 10 | "net/http" 11 | "net/url" 12 | "sort" 13 | "strings" 14 | "time" 15 | 16 | "encoding/json" 17 | "github.com/google/uuid" 18 | ) 19 | 20 | var ( 21 | SecretId = "" 22 | SecretKey = "" 23 | ) 24 | 25 | func percentEncode(str string) string { 26 | str = url.QueryEscape(str) 27 | str = strings.Replace(str, "+", "%20", -1) 28 | str = strings.Replace(str, "*", "%2A", -1) 29 | str = strings.Replace(str, "%7E", "~", -1) 30 | return str 31 | } 32 | 33 | func getUrlQueriesEncoded(params map[string]string) string { 34 | values := url.Values{} 35 | for key, value := range params { 36 | if value != "" && key != "SecretId" { 37 | values.Add(key, value) 38 | } 39 | } 40 | return values.Encode() 41 | } 42 | 43 | func sign(method, secretKey string, params map[string]string) string { 44 | var paramsKeys sort.StringSlice 45 | for k, _ := range params { 46 | paramsKeys = append(paramsKeys, k) 47 | } 48 | sort.Sort(paramsKeys) 49 | var urlStr string 50 | for _, k := range paramsKeys { 51 | urlStr += "&" + percentEncode(k) + "=" + percentEncode(params[k]) 52 | } 53 | s := method + "&%2F&" + percentEncode(urlStr[1:]) 54 | 55 | hashed := hmac.New(sha1.New, []byte(secretKey)) 56 | hashed.Write([]byte(s)) 57 | return base64.StdEncoding.EncodeToString(hashed.Sum(nil)) 58 | } 59 | 60 | func getSignedURL(action, url, reqMethod string, param []byte) string { 61 | signMethod := "HMAC-SHA1" 62 | request := map[string]string{ 63 | "AccessKeyId": SecretId, 64 | "Action": action, 65 | "Timestamp": time.Now().UTC().Format("2006-01-02T15:04:05Z"), 66 | "SignatureMethod": signMethod, 67 | "SignatureNonce": uuid.New().String(), 68 | "SignatureVersion": "1.0", 69 | "Version": "2019-08-08", 70 | } 71 | 72 | if len(param) > 0 && reqMethod == "GET" { 73 | par := make(map[string]string) 74 | err := json.Unmarshal(param, &par) 75 | if err != nil { 76 | panic(err) 77 | } 78 | for k, v := range par { 79 | request[k] = v 80 | } 81 | } 82 | 83 | signature := sign(reqMethod, SecretKey, request) 84 | request["Signature"] = signature 85 | signedURL := url + "?" + getUrlQueriesEncoded(request) 86 | return signedURL 87 | } 88 | 89 | type CommonReturn struct { 90 | Code string 91 | Data interface{} 92 | Message string 93 | PageCount int 94 | PageNumber int 95 | TaskId string 96 | } 97 | 98 | func doHttpPost(action, url, method string, reqBody []byte) CommonReturn { 99 | fmt.Println("ReqBody: ", string(reqBody)) 100 | 101 | signedURL := getSignedURL(action, url, method, reqBody) 102 | req, _ := http.NewRequest(method, signedURL, bytes.NewBuffer(reqBody)) 103 | req.Header.Set("Content-Type", "application/json") 104 | client := &http.Client{} 105 | resp, err := client.Do(req) 106 | if err != nil { 107 | panic(err) 108 | } 109 | defer resp.Body.Close() 110 | 111 | fmt.Println("response Status:", resp.Status) 112 | fmt.Println("response Headers:", resp.Header) 113 | body, _ := ioutil.ReadAll(resp.Body) 114 | fmt.Println("response Body:", string(body)) 115 | 116 | commonReturn := CommonReturn{} 117 | json.Unmarshal(body, &commonReturn) 118 | return commonReturn 119 | } 120 | -------------------------------------------------------------------------------- /example/Golang/VDC/test/bills_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "example/VDC/model" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestDescribeBill(t *testing.T) { 10 | res, _ := model.DescribeBill() 11 | fmt.Println(res) 12 | } 13 | 14 | func TestDescribeBillInfo(t *testing.T) { 15 | res, _ := model.DescribeBillInfo() 16 | fmt.Println(res) 17 | } 18 | 19 | func TestDescribeBillDetail(t *testing.T) { 20 | res, _ := model.DescribeBillDetail() 21 | fmt.Println(res) 22 | } 23 | func TestDescribeAccountInfo(t *testing.T) { 24 | res, _ := model.DescribeAccountInfo() 25 | fmt.Println(res) 26 | } 27 | -------------------------------------------------------------------------------- /example/Golang/VDC/test/ecs_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "example/VDC/model" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestCreateInstanceEcs(t *testing.T) { 10 | res, _ := model.CreateInstanceEcs() 11 | fmt.Println(res) 12 | } 13 | 14 | func TestDescribeRegions(t *testing.T) { 15 | res, _ := model.DescribeRegions() 16 | fmt.Println(res) 17 | } 18 | 19 | func TestDescribeEcsFamilyInfo(t *testing.T) { 20 | res, _ := model.DescribeEcsFamilyInfo() 21 | fmt.Println(res) 22 | } 23 | 24 | func TestDescribeImage(t *testing.T) { 25 | res, _ := model.DescribeImage() 26 | fmt.Println(res) 27 | } 28 | -------------------------------------------------------------------------------- /example/Golang/VDC/test/instance_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "example/VDC/model" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestDescribeInstance(t *testing.T) { 10 | result := model.DescribeInstances("f6124738-346d-4b21-8a7c-f86bf04b76ed") 11 | fmt.Printf("%v", result) 12 | } 13 | 14 | func TestCreateInstance(t *testing.T) { 15 | t.Log("Start Test Create Instance") 16 | RegionId := "APAC_Seoul_A" 17 | VdcId := "c603ee06-cef3-439d-bdea-fd72768ecb77" 18 | InstanceName := "go-api" 19 | InstanceType := "High" 20 | ImageId := "Centos_7.6_64" 21 | Password := "!QAZ2wsx" 22 | 23 | res := model.CreateInstance(RegionId, VdcId, InstanceName, InstanceType, ImageId, Password, 4, 4, 1) 24 | fmt.Println(res) 25 | } 26 | 27 | func TestDeleteInstance(t *testing.T) { 28 | instanceId := "65929a1b-4083-4622-856e-01818dd0a6b2" 29 | var param = []string{instanceId} 30 | res := model.DeleteInstance(param) 31 | fmt.Println(res) 32 | } 33 | 34 | func TestStopInstance(t *testing.T) { 35 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 36 | res := model.StopInstance(instanceId) 37 | fmt.Println(res) 38 | } 39 | 40 | func TestStartInstance(t *testing.T) { 41 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 42 | res := model.StartInstance(instanceId) 43 | fmt.Println(res) 44 | } 45 | 46 | func TestRebootInstance(t *testing.T) { 47 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 48 | res := model.RebootInstance(instanceId) 49 | fmt.Println(res) 50 | } 51 | 52 | func TestModifyInstanceSpec(t *testing.T) { 53 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 54 | res := model.ModifyInstanceSpec(instanceId, 4, 8) 55 | fmt.Println(res) 56 | } 57 | 58 | func TestCreateDisk(t *testing.T) { 59 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 60 | res := model.CreateDisk(instanceId) 61 | fmt.Println(res) 62 | } 63 | 64 | func TestResizeDisk(t *testing.T) { 65 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 66 | diskId := "22b01c34-b9ff-11ea-b1f3-0242ac110002" 67 | size := 200 68 | res := model.ResizeDisk(instanceId, diskId, size) 69 | fmt.Println(res) 70 | } 71 | 72 | func TestDeleteDisk(t *testing.T) { 73 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 74 | diskIds := []string{"22b01c34-b9ff-11ea-b1f3-0242ac110002"} 75 | res := model.DeleteDisk(instanceId, diskIds) 76 | fmt.Println(res) 77 | } 78 | 79 | func TestResetImageByPassword(t *testing.T) { 80 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 81 | imageId := "Centos_7.6_64" 82 | Password := "123abc,.;" 83 | res := model.ResetImage(instanceId, imageId, Password, "") 84 | fmt.Println(res) 85 | } 86 | 87 | func TestResetImageByPublicKey(t *testing.T) { 88 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 89 | imageId := "Centos_7.6_64" 90 | PublicKey := "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQClyx+YOk31Ga8U+QFKTgfYm2M+xKOnBTS4LHYJEnxLNJj0rvZGPZ0qQHHBCBMnB5gVgs3Zo59hUEkcy9LiyN3qiEWsam7ya38ePXQ5h8z/AN2JHeEedShlGCEJ/sKRWzqnsPYKvgJw/JTKz/EFExFCqPjFpdHsRedBM6IisK/1v1dSusvOV7Jbh6aApXi+1oml4brpmHYqsHrg+o6AT+7yGlBryA5pUUDqMjkauCc/Pugm/VcleOuhf0UCaK01b1l7nEgvkoqbBBGuPNn6XjBVoimjmRXGxGnyo9QYTpx8cxrXUTzN2G8XkBjqV4c5Xim49psGQKHKoApSarGXPlhd jian.jiao@capitalonline.net" 91 | res := model.ResetImage(instanceId, imageId, "", PublicKey) 92 | fmt.Println(res) 93 | } 94 | 95 | func TestModifyIpAddress(t *testing.T) { 96 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 97 | interfaceId := "36457034-baa2-11ea-8771-c60e117040ec" 98 | address := "164.52.56.162" 99 | res := model.ModifyIpAddress(instanceId, interfaceId, address) 100 | fmt.Println(res) 101 | } 102 | 103 | func TestModifyIpAddressToNull(t *testing.T) { 104 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 105 | interfaceId := "36457034-baa2-11ea-8771-c60e117040ec" 106 | address := "" 107 | res := model.ModifyIpAddress(instanceId, interfaceId, address) 108 | fmt.Println(res) 109 | } 110 | 111 | func TestModifyInstanceName(t *testing.T) { 112 | instanceId := "f6124738-346d-4b21-8a7c-f86bf04b76ed" 113 | instanceName := "TestGoApi" 114 | res := model.ModifyInstanceName(instanceId, instanceName) 115 | fmt.Println(res) 116 | } 117 | 118 | func TestGetHistoryInstance(t *testing.T) { 119 | res := model.GetHistoryInstance("2020-12-30", 10, 1) 120 | fmt.Println(res) 121 | } 122 | -------------------------------------------------------------------------------- /example/Golang/VDC/test/vdc_test.go: -------------------------------------------------------------------------------- 1 | package test 2 | 3 | import ( 4 | "example/VDC/model" 5 | "fmt" 6 | "testing" 7 | ) 8 | 9 | func TestDescribeVdc(t *testing.T) { 10 | result := model.DescribeVdc("APAC_Seoul_A", "8cf43b43-7920-4478-acf6-969245dcec14", "") 11 | fmt.Printf("%v", result) 12 | } 13 | 14 | func TestCreateVdc(t *testing.T) { 15 | info := model.PublicNetworkInfo{ 16 | Name: "TestGoPublic", 17 | Type: "Bandwidth_BGP", 18 | BillingMethod: "BandwIdth", 19 | Qos: 5, 20 | IPNum: 4, 21 | } 22 | result := model.CreateVdc("APAC_Seoul_A", "TestGo", info) 23 | fmt.Println(result) 24 | } 25 | 26 | func TestAddPublicIp(t *testing.T) { 27 | result := model.AddPublicIp("adcb9736-c64c-11ea-aaab-0242ac110002", "4") 28 | fmt.Println(result) 29 | } 30 | 31 | func TestDeletePublicIp(t *testing.T) { 32 | result := model.DeletePublicIp("286bc11c-c64f-11ea-b707-0242ac110002") 33 | fmt.Println(result) 34 | } 35 | 36 | func TestDescribeBandwidthTraffic(t *testing.T) { 37 | result := model.DescribeBandwidthTraffic("adcb9736-c64c-11ea-aaab-0242ac110002") 38 | fmt.Println(result) 39 | } 40 | -------------------------------------------------------------------------------- /example/Golang/VPC/README.md: -------------------------------------------------------------------------------- 1 | ## 首云·产品列表 2 | 3 | 4 | 5 | | 产品 | 名称标记 | 6 | |---------|------| 7 | | 弹性云服务器 | ECS | 8 | | 云盘(含快照) | EBS | 9 | | 安全组 | sg | 10 | 11 | -------------------------------------------------------------------------------- /example/Golang/VPC/common/README.md: -------------------------------------------------------------------------------- 1 | ## 首云·openapi调用示例 2 | 3 | 此目录文件为调用示例公共定义 -------------------------------------------------------------------------------- /example/Golang/VPC/common/utils.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "bytes" 5 | "crypto/hmac" 6 | "crypto/sha1" 7 | "encoding/base64" 8 | "fmt" 9 | "io" 10 | "net/http" 11 | "net/url" 12 | "sort" 13 | "strings" 14 | "time" 15 | 16 | "encoding/json" 17 | 18 | "github.com/google/uuid" 19 | ) 20 | 21 | var ( 22 | SecretId = "ak" 23 | SecretKey = "sk" 24 | ) 25 | 26 | const EbsUrl = "https://api.capitalonline.net/ebs/v1" 27 | const EcsUrl = "https://api.capitalonline.net/ecs/v1" 28 | 29 | func percentEncode(str string) string { 30 | str = url.QueryEscape(str) 31 | str = strings.Replace(str, "+", "%20", -1) 32 | str = strings.Replace(str, "*", "%2A", -1) 33 | str = strings.Replace(str, "%7E", "~", -1) 34 | return str 35 | } 36 | 37 | func getUrlQueriesEncoded(params map[string]string) string { 38 | values := url.Values{} 39 | for key, value := range params { 40 | if value != "" && key != "SecretId" { 41 | values.Add(key, value) 42 | } 43 | } 44 | return values.Encode() 45 | } 46 | 47 | func sign(method, secretKey string, params map[string]string) string { 48 | var paramsKeys sort.StringSlice 49 | for k, _ := range params { 50 | paramsKeys = append(paramsKeys, k) 51 | } 52 | sort.Sort(paramsKeys) 53 | var urlStr string 54 | for _, k := range paramsKeys { 55 | urlStr += "&" + percentEncode(k) + "=" + percentEncode(params[k]) 56 | } 57 | s := method + "&%2F&" + percentEncode(urlStr[1:]) 58 | 59 | hashed := hmac.New(sha1.New, []byte(secretKey)) 60 | hashed.Write([]byte(s)) 61 | return base64.StdEncoding.EncodeToString(hashed.Sum(nil)) 62 | } 63 | 64 | func getSignedURL(action, url, reqMethod string, param []byte) string { 65 | signMethod := "HMAC-SHA1" 66 | request := map[string]string{ 67 | "AccessKeyId": SecretId, 68 | "Action": action, 69 | "Timestamp": time.Now().UTC().Format("2006-01-02T15:04:05Z"), 70 | "SignatureMethod": signMethod, 71 | "SignatureNonce": uuid.New().String(), 72 | "SignatureVersion": "1.0", 73 | "Version": "2019-08-08", 74 | } 75 | 76 | if len(param) > 0 && reqMethod == "GET" { 77 | par := make(map[string]interface{}) 78 | err := json.Unmarshal(param, &par) 79 | if err != nil { 80 | panic(err) 81 | } 82 | for k, v := range par { 83 | request[k] = fmt.Sprintf("%v", v) 84 | } 85 | } 86 | 87 | signature := sign(reqMethod, SecretKey, request) 88 | request["Signature"] = signature 89 | signedURL := url + "?" + getUrlQueriesEncoded(request) 90 | return signedURL 91 | } 92 | 93 | type CommonReturn struct { 94 | Code string 95 | Data interface{} 96 | Message string 97 | PageCount int 98 | PageNumber int 99 | TaskId string 100 | } 101 | 102 | func DoHttpPost(action, url, method string, reqBody []byte) CommonReturn { 103 | fmt.Println("ReqBody: ", string(reqBody)) 104 | 105 | signedURL := getSignedURL(action, url, method, reqBody) 106 | req, _ := http.NewRequest(method, signedURL, bytes.NewBuffer(reqBody)) 107 | req.Header.Set("Content-Type", "application/json") 108 | client := &http.Client{} 109 | resp, err := client.Do(req) 110 | if err != nil { 111 | panic(err) 112 | } 113 | defer resp.Body.Close() 114 | 115 | fmt.Println("response Status:", resp.Status) 116 | // fmt.Println("response Headers:", resp.Header) 117 | body, _ := io.ReadAll(resp.Body) 118 | //fmt.Println("response Body:", string(body)) 119 | 120 | commonReturn := CommonReturn{} 121 | json.Unmarshal(body, &commonReturn) 122 | return commonReturn 123 | } 124 | 125 | /* 126 | 事件接口示例说明:首云大多数响应都是返回一个事件id,然后根据事件id来查询相应的资源id 127 | */ 128 | 129 | // DescribeEvent 事件查询 https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#10describeevent 130 | 131 | type EventResp struct { // Event响应结构(若需则使用),也可以使用map接受映射 132 | EventId string `json:"EventId"` // 事件id 133 | EventStatus string `json:"EventStatus"` // 事件状态 134 | EventStatusDisplay string `json:"EventStatusDisplay"` // 事件中文名称 135 | EventType string `json:"EventType"` // 事件类型 136 | EventTypeDisplay string `json:"EventTypeDisplay"` // 事件类型中文名称 137 | CreateTime string `json:"CreateTime"` // 创建时间 138 | TaskList []struct { // 事件下的任务列表 139 | TaskId string `json:"TaskId"` // 任务id 140 | Status string `json:"Status"` // 任务状态 141 | StatusDisplay string `json:"StatusDisplay"` // 任务中文状态 142 | ResourceId string `json:"ResourceId"` // *任务对应的资源id 143 | CreateTime string `json:"CreateTime"` // 任务创建时间 144 | UpdateTime string `json:"UpdateTime"` // 任务更新时间 145 | EndTime string `json:"EndTime"` // 任务完成时间,未完成则为空 146 | ResourceType string `json:"ResourceType"` // 资源类型 147 | ResourceDisplay string `json:"ResourceDisplay"` // 资源类型中文名称 148 | TaskType string `json:"TaskType"` // 任务类型 149 | TaskTypeDisplay string `json:"TaskTypeDisplay"` // 任务类型中文名称 150 | } `json:"TaskList"` 151 | } 152 | 153 | func DescribeEvent(eventId string) (CommonReturn, error) { 154 | var ( 155 | action = "DescribeEvent" 156 | params = map[string]interface{}{ 157 | "EventId": eventId, 158 | } 159 | ) 160 | 161 | body, err := json.Marshal(params) 162 | if err != nil { 163 | fmt.Println("反序列化失败:", err.Error()) 164 | } 165 | 166 | res := DoHttpPost(action, EbsUrl, http.MethodGet, body) 167 | return res, nil 168 | } 169 | -------------------------------------------------------------------------------- /example/Golang/VPC/common/utils_test.go: -------------------------------------------------------------------------------- 1 | package common 2 | 3 | import ( 4 | "log" 5 | "testing" 6 | ) 7 | 8 | // 事件测试 9 | func TestDescribeEvent(t *testing.T) { 10 | if eventResp, err := DescribeEvent("xxxx"); err == nil { 11 | if eventResp.Code == "Success" && eventResp.Data != nil { 12 | log.Printf("%#v /n", eventResp) 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /example/Golang/VPC/ebs/README.md: -------------------------------------------------------------------------------- 1 | ## 首云·云盘(ebs)调用示例 2 | 3 | ebs包含 云盘,快照 -------------------------------------------------------------------------------- /example/Golang/VPC/ebs/ebs.go: -------------------------------------------------------------------------------- 1 | package ebs 2 | 3 | import ( 4 | "encoding/json" 5 | "example/VPC/common" 6 | "fmt" 7 | "net/http" 8 | ) 9 | 10 | type CreateDiskReq struct { 11 | AvailableZoneCode string `json:"AvailableZoneCode"` // 可用区Code 12 | EcsId string `json:"EcsId,omitempty"` // 挂载到云主机的实例(支持创建即挂载) 13 | ReleaseWithInstance int `json:"ReleaseWithInstance,omitempty"` // 是否随实例删除(支持创建即挂载) 14 | DiskName string `json:"DiskName"` //设置的云盘名称 15 | DiskFeature string `json:"DiskFeature"` // 盘类型(目前只支持SSD) 16 | Size int `json:"Size"` // 盘容量 单位:GB,容量为8的倍数,且最小24GB起 17 | Number int `json:"Number"` // 创建数量 18 | BillingMethod string `json:"BillingMethod"` // 计费方式 19 | } 20 | 21 | type CreateDiskResp struct { 22 | DiskIdSet []interface{} `json:"DiskIdSet"` 23 | EventId string `json:"EventId"` 24 | } 25 | 26 | // CreateDisk 创建云盘示例 说明:https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#1createdisk-1 27 | func CreateDisk(params CreateDiskReq) (common.CommonReturn, error) { 28 | var ( 29 | action = "CreateDisk" 30 | // map类型 31 | /* 32 | params = map[string]interface{}{ 33 | "AvailableZoneCode": "CN_Hohhot_B", 34 | "DiskName": "demo", 35 | "DiskFeature": "SSD", 36 | "Size": 32, 37 | "Number": 1, 38 | "BillingMethod": "0", 39 | } 40 | */ 41 | ) 42 | 43 | body, err := json.Marshal(params) 44 | if err != nil { 45 | fmt.Println("反序列化失败:", err.Error()) 46 | } 47 | 48 | res := common.DoHttpPost(action, common.EbsUrl, http.MethodPost, body) 49 | return res, nil 50 | } 51 | 52 | type AttachDiskReq struct { 53 | DiskIds []string `json:"DiskIds"` // 挂载的云盘id列表 54 | EcsId string `json:"EcsId"` // 挂载的目标实例id 55 | ReleaseWithInstance int `json:"ReleaseWithInstance"` // 是否随实例删除 56 | } 57 | 58 | // AttachDisk 挂载云盘示例 说明:https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#4attachdisk 59 | func AttachDisk(params AttachDiskReq) (common.CommonReturn, error) { 60 | var ( 61 | action = "AttachDisk" 62 | // map类型 63 | /* 64 | params = map[string]interface{}{ 65 | "DiskIds": []string{"disk1", "disk2"}, 66 | "EcsId": "ins-cplc7w0rfmy7sb1g", 67 | } 68 | */ 69 | ) 70 | 71 | body, err := json.Marshal(params) 72 | if err != nil { 73 | fmt.Println("反序列化失败:", err.Error()) 74 | } 75 | 76 | res := common.DoHttpPost(action, common.EbsUrl, http.MethodPost, body) 77 | return res, nil 78 | } 79 | 80 | type DetachDiskReq struct { 81 | DiskIds []string `json:"DiskIds"` 82 | } 83 | 84 | // DetachDisk 卸载云盘示例 说明:https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#3detachdisk-1 85 | func DetachDisk(params AttachDiskReq) (common.CommonReturn, error) { 86 | var ( 87 | action = "DetachDisk" 88 | // map类型 89 | /* 90 | params = map[string]interface{}{ 91 | "DiskIds": []string{"disk1", "disk2"}, 92 | } 93 | */ 94 | ) 95 | 96 | body, err := json.Marshal(params) 97 | if err != nil { 98 | fmt.Println("反序列化失败:", err.Error()) 99 | } 100 | 101 | res := common.DoHttpPost(action, common.EbsUrl, http.MethodPost, body) 102 | return res, nil 103 | } 104 | 105 | type TerminateDisksRequest struct { 106 | DiskIds []string `json:"DiskIds"` 107 | } 108 | 109 | // TerminateDisks 删除云盘示例 说明:https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2deletedisk 110 | func TerminateDisks(request TerminateDisksRequest) (common.CommonReturn, error) { 111 | action := "DeleteDisk" 112 | 113 | // map方式传参 114 | params := map[string]interface{}{ 115 | "DiskIds": request.DiskIds, 116 | } 117 | 118 | // 结构体传参方式实例 119 | // params := request 120 | 121 | body, err := json.Marshal(params) 122 | if err != nil { 123 | fmt.Println("反序列化失败:", err.Error()) 124 | } 125 | 126 | res := common.DoHttpPost(action, common.EbsUrl, http.MethodPost, body) 127 | return res, nil 128 | } 129 | 130 | type DescribeDiskRequest struct { 131 | DiskId string `json:"DiskId"` //云盘id 132 | } 133 | 134 | type DescribeDiskResp struct { 135 | DiskInfo Disk `json:"DiskInfo"` 136 | } 137 | 138 | type Disk struct { 139 | DiskId string `json:"DiskId"` //地域code 140 | DiskName string `json:"DiskName"` //云盘名称 141 | Size int `json:"Size"` //云盘ID 142 | EcsId string `json:"EcsId"` //挂载的实例,未挂载为空 143 | EcsName string `json:"EcsName"` //挂载实例的名称,未挂载为空 144 | BillingMethod string `json:"BillingMethod"` //0:按需计费, 1:包年包月 145 | ReleaseWithInstance int `json:"ReleaseWithInstance"` //是否随实例删除,1:是,0:否 146 | RegionCode string `json:"RegionCode"` //地域code 147 | AvailableZoneCode string `json:"AvailableZoneCode"` //可用区code 148 | Status string `json:"Status"` //状态code 149 | StatusDisplay string `json:"StatusDisplay"` //状态说明 150 | DiskFeature string `json:"DiskFeature"` //盘类型 151 | Property string `json:"Property"` //system:系统盘 data:数据盘 152 | } 153 | 154 | // DescribeDisk 云盘详情示例 说明:https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#8describedisk 155 | func DescribeDisk(diskId string) (common.CommonReturn, error) { 156 | action := "DescribeDisk" 157 | body, err := json.Marshal(map[string]interface{}{ 158 | "DiskId": diskId, 159 | }) 160 | if err != nil { 161 | return common.CommonReturn{}, err 162 | } 163 | res := common.DoHttpPost(action, common.EbsUrl, http.MethodGet, body) 164 | return res, nil 165 | } 166 | 167 | // DescribeDiskQuota 查询云盘配额示例 说明:https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#6describediskquota 168 | 169 | // DescribeDiskQuotaRequest 查询云盘配额入参 170 | type DescribeDiskQuotaRequest struct { 171 | AvailableZoneCode string `json:"AvailableZoneCode"` 172 | } 173 | 174 | // DescribeDiskQuotaData 查询云盘配额返回data结构 175 | type DescribeDiskQuotaData struct { 176 | // 配额列表 177 | QuotaList []QuotaList `json:"QuotaList"` 178 | } 179 | type QuotaList struct { 180 | TotalQuota int `json:"TotalQuota"` // 总配额,单位:GB 181 | UsedQuota int `json:"UsedQuota"` // 已用配额,单位:GB 182 | FreeQuota int `json:"FreeQuota"` // 剩余配额,单位:GB 183 | DiskFeature string `json:"DiskFeature"` // 云盘类型 184 | } 185 | 186 | // DescribeDiskQuotaData 查询云盘配额 187 | func DescribeDiskQuota(availableZoneCode string) (common.CommonReturn, error) { 188 | action := "DescribeDiskQuota" 189 | params := map[string]interface{}{ 190 | // 可用区Code 必传项,首云接口目前只支持根据可用区查云盘配额 191 | "AvailableZoneCode": availableZoneCode, 192 | } 193 | 194 | // 结构体传参方式实例 195 | //params := DescribeDiskQuotaRequest{ 196 | // AvailableZoneCode: "CN_Suqian_A", 197 | //} 198 | 199 | body, err := json.Marshal(params) 200 | if err != nil { 201 | fmt.Println("反序列化失败:", err.Error()) 202 | } 203 | 204 | res := common.DoHttpPost(action, common.EbsUrl, http.MethodGet, body) 205 | // 将返回值反序列化为结构体 206 | bytes, err := json.Marshal(res.Data) 207 | data := DescribeDiskQuotaData{} 208 | err = json.Unmarshal(bytes, &data) 209 | 210 | return res, nil 211 | } 212 | 213 | // DescribeSnapshots 查询云盘快照列表 214 | func DescribeSnapshots() (common.CommonReturn, error) { 215 | action := "DescribeSnapshotList" 216 | method := "GET" 217 | params := map[string]interface{}{ 218 | "AvailableZoneCode": "CN_Suqian_A", 219 | "RegionCode": "CN_Suqian", 220 | // "DiskId": "", 221 | "PageNumber": 1, 222 | "PageSize": 20, 223 | } 224 | body, err := json.Marshal(params) 225 | if err != nil { 226 | fmt.Println("反序列化失败:", err.Error()) 227 | } 228 | res := common.DoHttpPost(action, common.EbsUrl, method, body) 229 | fmt.Printf(">>>>>>> request result: %v", res) 230 | return res, nil 231 | } 232 | 233 | // 获取快照列表请求体 234 | type DescribeSnapshotsRequest struct { 235 | AvailableZoneCode string `json:"AvailableZoneCode"` //可用区Code 236 | RegionCode string `json:"RegionCode"` //地域Code 237 | DiskId string `json:"DiskId"` //云盘ID 238 | PageNumber int `json:"PageNumber"` //页码 239 | PageSize int `json:"PageSize"` //每页记录数 240 | } 241 | 242 | // 获取快照列表返回数据体 243 | type DescribeSnapshotsData struct { 244 | SnapshotList []SnapshotList `json:"SnapshotList"` 245 | } 246 | 247 | // 快照数据 248 | type SnapshotList struct { 249 | SnapshotId string `json:"SnapshotId"` //快照ID 250 | SnapshotName string `json:"SnapshotName"` //快照名称 251 | DiskId string `json:"DiskId"` //云盘ID 252 | DiskName string `json:"DiskName"` //云盘名称 253 | DiskSize int `json:"DiskSize"` //盘容量,单位GB 254 | ReservedTime string `json:"ReservedTime"` //Forever:永久保留,当云盘删除时快照跟随云盘删除;具体数字为保留天数。 255 | SnapshotStatus string `json:"SnapshotStatus"` //快照状态 256 | CreateTime string `json:"CreateTime"` //快照创建时间 257 | RegionCode string `json:"RegionCode"` //地域Code 258 | AvailableZoneCode string `json:"AvailableZoneCode"` //可用区Code 259 | DiskProperty string `json:"DiskProperty"` //system:系统盘 data数据盘 260 | } 261 | 262 | // CreateSnapshot 创建单个云盘快照 263 | func CreateSnapshot() (common.CommonReturn, error) { 264 | action := "CreateSnapshot" 265 | method := "POST" 266 | params := map[string]interface{}{ 267 | "DiskId": "disk-xxx", 268 | "SnapshotName": "test-openapi-create", 269 | "ReservedTime": "1", 270 | } 271 | body, err := json.Marshal(params) 272 | if err != nil { 273 | fmt.Println("反序列化失败:", err.Error()) 274 | } 275 | res := common.DoHttpPost(action, common.EbsUrl, method, body) 276 | fmt.Printf(">>>>>>> request result: %v", res) 277 | return res, nil 278 | } 279 | 280 | // 创建快照请求体 281 | type CreateSnapshotRequest struct { 282 | DiskId string `json:"DiskId"` //云盘ID,必传字段 283 | SnapshotName string `json:"SnapshotName"` //快照名称,不传默认与快照id一致,快照名称允许使用2-128个字符,不允许使用auto作为开头,允许大小写字母、数字、汉字和“-”。 284 | ReservedTime string `json:"ReservedTime"` //快照保留时间,不传递该参数默认为1。Forever:永久保留,当云盘删除时快照跟随云盘删除;具体数字为保留天数。 285 | } 286 | 287 | // 创建快照返回数据体 288 | type CreateSnapshotData struct { 289 | EventId string `json:"EventId"` //事件ID 290 | SnapshotId string `json:"SnapshotId"` 291 | } 292 | 293 | // 删除快照请求体 294 | type DeleteSnapshotsRequest struct { 295 | // 想要删除的快照ID列表 296 | SnapshotIds []string `json:"SnapshotIds"` 297 | } 298 | 299 | // 删除快照返回数据结构体 300 | type DeleteSnapshotsResponse struct { 301 | EventId string `json:"EventId"` 302 | } 303 | 304 | // DeleteSnapshots 删除快照 305 | func DeleteSnapshots(request DeleteSnapshotsRequest) (DeleteSnapshotsResponse, error) { 306 | action := "DeleteSnapshot" 307 | method := "POST" 308 | 309 | // map方式传参 310 | params := map[string]interface{}{ 311 | "SnapshotIds": request.SnapshotIds, 312 | } 313 | 314 | // 结构体传参方式实例 315 | // params := DeleteSnapshotsRequest 316 | 317 | body, err := json.Marshal(params) 318 | if err != nil { 319 | fmt.Println("json序列化失败:", err.Error()) 320 | } 321 | 322 | res := common.DoHttpPost(action, common.EbsUrl, method, body) 323 | bytes, err := json.Marshal(res.Data) 324 | if err != nil { 325 | fmt.Println("json序列化失败:", err.Error()) 326 | } 327 | data := DeleteSnapshotsResponse{} 328 | err = json.Unmarshal(bytes, &data) 329 | if err != nil { 330 | fmt.Println("json反序列化失败:", err.Error()) 331 | } 332 | fmt.Printf(">>>>>>> request result: %v", res) 333 | return data, nil 334 | } 335 | 336 | // 云盘列表信息结构体 337 | type DiskInfo struct { 338 | DiskId string `json:"DiskId"` 339 | DiskName string `json:"DiskName"` 340 | Size int `json:"Size"` 341 | EcsId string `json:"EcsId"` 342 | EcsName string `json:"EcsName"` 343 | BillingMethod string `json:"BillingMethod"` 344 | ReleaseWithInstance int `json:"ReleaseWithInstance"` 345 | RegionCode string `json:"RegionCode"` 346 | AvailableZoneCode string `json:"AvailableZoneCode"` 347 | Status string `json:"Status"` 348 | StatusDisplay string `json:"StatusDisplay"` 349 | DiskFeature string `json:"DiskFeature"` 350 | Property string `json:"Property"` 351 | } 352 | 353 | func DescribeDiskList() (common.CommonReturn, error) { 354 | var ( 355 | action = "DescribeDiskList" 356 | params = map[string]interface{}{ 357 | "DiskIds": []string{"disk-r28if0vrh1e1auuw"}, 358 | } 359 | ) 360 | body, err := json.Marshal(params) 361 | if err != nil { 362 | fmt.Println("反序列化失败:", err.Error()) 363 | } 364 | res := common.DoHttpPost(action, common.EbsUrl, http.MethodPost, body) 365 | return res, nil 366 | } 367 | -------------------------------------------------------------------------------- /example/Golang/VPC/ebs/ebs_test.go: -------------------------------------------------------------------------------- 1 | package ebs 2 | 3 | import ( 4 | "encoding/json" 5 | "example/VPC/common" 6 | "fmt" 7 | "log" 8 | "testing" 9 | ) 10 | 11 | // 创建云盘测试 12 | func TestCreateDisk(t *testing.T) { 13 | var ( 14 | resp common.CommonReturn 15 | err error 16 | ) 17 | resp, err = CreateDisk(CreateDiskReq{ 18 | AvailableZoneCode: "CN_Suqian_B", 19 | EcsId: "", 20 | ReleaseWithInstance: 0, 21 | DiskName: "demo_gyx3", 22 | DiskFeature: "SSD", 23 | Size: 24, 24 | Number: 1, 25 | BillingMethod: "0", 26 | }) 27 | if err != nil { 28 | log.Fatalln(err) 29 | } 30 | if resp.Code == "Success" && resp.Data != nil { 31 | bytes, _ := json.Marshal(resp.Data) 32 | data := CreateDiskResp{} 33 | _ = json.Unmarshal(bytes, &data) 34 | fmt.Println(data) 35 | } 36 | } 37 | 38 | // 挂载云盘测试 39 | func TestAttachDiskReq(t *testing.T) { 40 | var ( 41 | resp common.CommonReturn 42 | err error 43 | ) 44 | resp, err = AttachDisk(AttachDiskReq{ 45 | DiskIds: []string{"disk-xxx"}, 46 | EcsId: "ins-xxx", 47 | ReleaseWithInstance: 1, 48 | }) 49 | if err != nil { 50 | log.Fatalln(err) 51 | } 52 | log.Printf("%#v\n", resp) 53 | 54 | } 55 | 56 | // 卸载云盘测试 57 | func TestDetachDiskReq(t *testing.T) { 58 | var ( 59 | resp common.CommonReturn 60 | err error 61 | ) 62 | resp, err = DetachDisk(AttachDiskReq{ 63 | DiskIds: []string{""}, 64 | }) 65 | if err != nil { 66 | log.Fatalln(err) 67 | } 68 | log.Printf("%#v\n", resp) 69 | 70 | } 71 | 72 | // 获取云盘详情测试 73 | func TestDescribeDisk(t *testing.T) { 74 | res, err := DescribeDisk("") 75 | if err != nil { 76 | } 77 | log.Println(res) 78 | } 79 | 80 | // 获取云盘配额测试 81 | func TestDescribeDiskQuota(t *testing.T) { 82 | res, err := DescribeDiskQuota("CN_Suqian_B") 83 | if err != nil { 84 | } 85 | log.Println(res) 86 | } 87 | 88 | // 删除云盘测试 89 | func TestTerminateDisks(t *testing.T) { 90 | res, err := TerminateDisks(TerminateDisksRequest{ 91 | DiskIds: []string{""}, 92 | }) 93 | if err != nil { 94 | } else { 95 | log.Println(res) 96 | } 97 | } 98 | 99 | // 获取快照信息测试 100 | func TestDescribeSnapshots(t *testing.T) { 101 | res, err := DescribeSnapshots() 102 | if err != nil { 103 | } 104 | fmt.Println(res) 105 | } 106 | 107 | // 创建快照测试 108 | func TestCreateSnapshot(t *testing.T) { 109 | resp, err := CreateSnapshot() 110 | if err != nil { 111 | if resp.Data != nil { 112 | bytes, _ := json.Marshal(resp.Data) 113 | data := CreateSnapshotData{} 114 | _ = json.Unmarshal(bytes, &data) 115 | fmt.Println(data) 116 | } 117 | } 118 | fmt.Println(resp) 119 | } 120 | 121 | // 删除快照测试 122 | func TestDeleteSnapshots(t *testing.T) { 123 | request := DeleteSnapshotsRequest{ 124 | SnapshotIds: []string{"s-disk-xxx1", "s-disk-xxx2"}, 125 | } 126 | res, err := DeleteSnapshots(request) 127 | if err != nil { 128 | } else { 129 | fmt.Println(res) 130 | } 131 | } 132 | 133 | func TestDescribeDiskList(t *testing.T) { 134 | res, err := DescribeDiskList() 135 | if err != nil { 136 | } else { 137 | fmt.Println(res) 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /example/Golang/VPC/ecs/README.md: -------------------------------------------------------------------------------- 1 | ## 首云·弹性云服务器(ecs)调用示例 -------------------------------------------------------------------------------- /example/Golang/VPC/ecs/ecs.go: -------------------------------------------------------------------------------- 1 | package ecs 2 | 3 | import ( 4 | "encoding/json" 5 | "example/VPC/common" 6 | "fmt" 7 | "net/http" 8 | ) 9 | 10 | /* 11 | CreateImage https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#16createimage 12 | */ 13 | 14 | type CreateImageReq struct { 15 | EcsId string `json:"EcsId"` 16 | Name string `json:"Name"` 17 | } 18 | 19 | type CreateImageResp struct { 20 | EventId string `json:"EventId"` 21 | ImageId string `json:"ImageId"` 22 | } 23 | 24 | func CreateImage(params CreateImageReq) (common.CommonReturn, error) { 25 | var ( 26 | action = "CreateImage" 27 | // map类型 28 | /* 29 | params = map[string]interface{}{ 30 | "EcsId": "ins-x", 31 | "Name":"私有镜像xx", 32 | } 33 | */ 34 | ) 35 | 36 | body, err := json.Marshal(params) 37 | if err != nil { 38 | fmt.Println("反序列化失败:", err.Error()) 39 | } 40 | 41 | res := common.DoHttpPost(action, common.EcsUrl, http.MethodPost, body) 42 | return res, nil 43 | } 44 | 45 | /* 46 | CreateInstance https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#11createinstance 47 | */ 48 | 49 | type CreateInstanceReq struct { 50 | AvailableZoneCode string `json:"AvailableZoneCode"` 51 | EcsFamilyName string `json:"EcsFamilyName"` 52 | Cpu int `json:"Cpu"` 53 | Ram int `json:"Ram"` 54 | Gpu int `json:"Gpu"` 55 | Number int `json:"Number"` 56 | BillingMethod string `json:"BillingMethod"` 57 | ImageId string `json:"ImageId"` 58 | SystemDiskBody SystemDisk `json:"SystemDisk"` 59 | DataDiskBody DataDisk `json:"DataDisk"` 60 | VpcInfoBody VpcInfo `json:"VpcInfo"` 61 | SubnetInfoBody SubnetInfo `json:"SubnetInfo"` 62 | Name string `json:"Name"` 63 | StartNumber int `json:"StartNumber"` 64 | Password string `json:"Password"` 65 | } 66 | 67 | type SystemDisk struct { 68 | DiskFeature string `json:"DiskFeature"` 69 | Size int `json:"Size"` 70 | } 71 | 72 | type DataDisk struct { 73 | DiskFeature string `json:"DiskFeature"` 74 | Size int `json:"Size"` 75 | ReleaseWithInstance int `json:"ReleaseWithInstance"` 76 | } 77 | type VpcInfo struct { 78 | VpcId string `json:"VpcId"` 79 | } 80 | 81 | type SubnetInfo struct { 82 | SubnetId string `json:"SubnetId"` 83 | } 84 | 85 | type CreateInstanceResp struct { 86 | EcsIdSet []interface{} `json:"EcsIdSet"` 87 | EventId string `json:"EventId"` 88 | } 89 | 90 | func CreateInstance(params CreateInstanceReq) (common.CommonReturn, error) { 91 | var ( 92 | action = "CreateInstance" 93 | ) 94 | 95 | body, err := json.Marshal(params) 96 | if err != nil { 97 | fmt.Println("反序列化失败:", err.Error()) 98 | } 99 | 100 | res := common.DoHttpPost(action, common.EcsUrl, http.MethodPost, body) 101 | return res, nil 102 | } 103 | -------------------------------------------------------------------------------- /example/Golang/VPC/ecs/ecs_test.go: -------------------------------------------------------------------------------- 1 | package ecs 2 | 3 | import ( 4 | "encoding/json" 5 | "example/VPC/common" 6 | "fmt" 7 | "log" 8 | "testing" 9 | ) 10 | 11 | func TestCreateImage(t *testing.T) { 12 | var ( 13 | resp common.CommonReturn 14 | err error 15 | ) 16 | resp, err = CreateImage(CreateImageReq{ 17 | EcsId: "ins-x", // 实例需要关机 18 | Name: "image_demo", 19 | }) 20 | if err != nil { 21 | log.Fatalln(resp, err) 22 | } 23 | log.Println(resp.Data) 24 | if resp.Code == "Success" && resp.Data != nil { 25 | bytes, _ := json.Marshal(resp.Data) 26 | data := CreateImageResp{} 27 | _ = json.Unmarshal(bytes, &data) 28 | fmt.Println(data) 29 | } 30 | } 31 | 32 | func TestCreateInstance(t *testing.T) { 33 | var ( 34 | resp common.CommonReturn 35 | err error 36 | ) 37 | resp, err = CreateInstance(CreateInstanceReq{}) 38 | if err != nil { 39 | log.Fatalln(resp, err) 40 | } 41 | log.Println(resp.Data) 42 | if resp.Code == "Success" && resp.Data != nil { 43 | bytes, _ := json.Marshal(resp.Data) 44 | data := CreateInstanceResp{} 45 | _ = json.Unmarshal(bytes, &data) 46 | fmt.Println(data) 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /example/Golang/VPC/sg/README.md: -------------------------------------------------------------------------------- 1 | ## 首云·openapi调用示例 2 | 3 | 使用说明: 4 | 5 | 1. 安全组配额:每个客户在一个区域内(region)可创建20个安全组,一个安全组可创建100条规则,一个实例最多绑定5个安全组,若需提升配额,联系对接人; 6 | 2. 当一个实例(云主机)绑定了安全组后,若此实例(云主机)有且只有这一个安全组,此安全组无法解绑; 7 | 3. 当实例(云主机)删除时,因现版本云主机侧未对接安全组,故请客户删除云主机后,联系对接人去后台此删除实例下所有安全组。云主机删除且解绑安全组的功能后续增加; 8 | 4. 用户在调用ecs安全组所有openapi接口时,建议留存每次请求返回的`RequestId`,若调用出现问题,方便拿`RequestId`找对接人排查问题; 9 | 5. 请关注接口文档中`注意`里面的说明,有助于开发效率; 10 | 6. 若安全组未配置任何规则,则该安全组启动默认规则:入站全拒绝,出站全允许; 11 | 7. 在配置规则端口号(Port)时,暂时尽量不要配置大范围的端口区间(例如:1/10000),这样安全组规则生效性能会较差。建议端口号在100个以内,此问题后续会优化。 12 | -------------------------------------------------------------------------------- /example/Golang/VPC/sg/sg.go: -------------------------------------------------------------------------------- 1 | package sg 2 | 3 | import ( 4 | "encoding/json" 5 | "example/VPC/common" 6 | "fmt" 7 | "net/http" 8 | ) 9 | 10 | const SgUrl = "http://api.capitalonline.net/sg/v1" 11 | 12 | func MakeArrayParam(l []string) string { 13 | if len(l) > 1 { 14 | b, _ := json.Marshal(l) 15 | return string(b) 16 | } else if len(l) == 1 { 17 | return l[0] 18 | } else { 19 | return "" 20 | } 21 | } 22 | 23 | // 查看安全组详情 24 | type DescribeSecurityGroupsResp struct { 25 | TotalCount int `json:"TotalCount"` 26 | SecurityGroupSet []DescribeSecurityGroupSetInfo `json:"SecurityGroupSet"` 27 | } 28 | 29 | type DescribeSecurityGroupSetInfo struct { 30 | SecurityGroupId string `json:"SecurityGroupId"` 31 | SecurityGroupName string `json:"SecurityGroupName"` 32 | SecurityGroupRegion string `json:"SecurityGroupRegion"` 33 | InstanceCount int `json:"InstanceCount"` 34 | IpCount int `json:"IpCount"` 35 | CreatedTime interface{} `json:"CreatedTime"` 36 | UpdateTime interface{} `json:"UpdateTime"` 37 | SecurityGroupDesc string `json:"SecurityGroupDesc"` 38 | GroupInterconnected bool `json:"GroupInterconnected"` 39 | } 40 | 41 | func DescribeSecurityGroups() (DescribeSecurityGroupsResp, error) { 42 | var ( 43 | action = "DescribeSecurityGroups" 44 | ) 45 | params := map[string]interface{}{ 46 | "RegionCode": "SR_SaintPaul", 47 | "PageNumber": 1, 48 | "PageSize": 10, 49 | // "SecurityGroupId": "sg-6gbo8grwf6mjndue", // 根据安全组单一请求 50 | // "SecurityGroupId": MakeArrayParam([]string{"sg-6gbo8grwf6mjndue", "sg-r3i1nkrgf4mcnxui"}), // 根据安全组批量请求 51 | } 52 | body, err := json.Marshal(params) 53 | if err != nil { 54 | fmt.Println("反序列化失败:", err.Error()) 55 | return DescribeSecurityGroupsResp{}, err 56 | } 57 | 58 | res := common.DoHttpPost(action, SgUrl, http.MethodGet, body) 59 | bytes, err := json.Marshal(res.Data) 60 | if err != nil { 61 | return DescribeSecurityGroupsResp{}, err 62 | } 63 | data := DescribeSecurityGroupsResp{} 64 | err = json.Unmarshal(bytes, &data) 65 | return data, err 66 | } 67 | 68 | // 创建安全组 69 | type CreateSecurityGroupReq struct { 70 | RegionCode string `json:"RegionCode"` 71 | GroupName string `json:"SecurityGroupName"` 72 | GroupDescription string `json:"SecurityGroupDescription"` 73 | GroupInterconnected bool `json:"GroupInterconnected"` 74 | } 75 | 76 | func CreateSecurityGroup() (common.CommonReturn, error) { 77 | var ( 78 | action = "CreateSecurityGroup" 79 | ) 80 | params := CreateSecurityGroupReq{ 81 | RegionCode: "SR_SaintPaul", 82 | GroupName: "gyx20221129", 83 | GroupDescription: "", 84 | GroupInterconnected: true, 85 | } 86 | body, err := json.Marshal(params) 87 | if err != nil { 88 | fmt.Println("反序列化失败:", err.Error()) 89 | return common.CommonReturn{}, err 90 | } 91 | res := common.DoHttpPost(action, SgUrl, http.MethodPost, body) 92 | return res, nil 93 | } 94 | 95 | // 修改安全组属性 96 | func ModifySecurityGroupAttribute() (common.CommonReturn, error) { 97 | var ( 98 | action = "ModifySecurityGroupAttribute" 99 | ) 100 | params := map[string]interface{}{ 101 | "SecurityGroupId": "sg-hnycxsrrdvszkzbn", 102 | "SecurityGroupDescription": "描述修改", 103 | } 104 | body, err := json.Marshal(params) 105 | if err != nil { 106 | fmt.Println("反序列化失败:", err.Error()) 107 | return common.CommonReturn{}, err 108 | } 109 | res := common.DoHttpPost(action, SgUrl, http.MethodPost, body) 110 | return res, nil 111 | } 112 | 113 | // 删除安全组 114 | func DeleteSecurityGroup() (common.CommonReturn, error) { 115 | var ( 116 | action = "DeleteSecurityGroup" 117 | ) 118 | params := map[string]interface{}{ 119 | "SecurityGroupId": "sg-em7aasr5cjhb4km3", 120 | } 121 | body, err := json.Marshal(params) 122 | if err != nil { 123 | fmt.Println("反序列化失败:", err.Error()) 124 | return common.CommonReturn{}, err 125 | } 126 | res := common.DoHttpPost(action, SgUrl, http.MethodPost, body) 127 | return res, nil 128 | } 129 | 130 | // 安全组新增规则 131 | type CreateSecurityGroupPoliciesReq struct { 132 | SecurityGroupId string `json:"SecurityGroupId" ` 133 | SecurityGroupPolicySet CreateSecurityGroupPolicySet `json:"SecurityGroupPolicySet"` 134 | } 135 | 136 | type CreateSecurityGroupPolicySet struct { 137 | Ingress []CreateSecurityPolicyInfo `json:"Ingress"` 138 | Egress []CreateSecurityPolicyInfo `json:"Egress"` 139 | } 140 | 141 | type CreateSecurityPolicyInfo struct { 142 | Protocol string `json:"Protocol"` 143 | PolicyDescription string `json:"PolicyDescription"` 144 | Port string `json:"Port"` 145 | CidrBlock string `json:"CidrBlock" ` 146 | Priority int `json:"Priority" ` 147 | Status bool `json:"Status" ` 148 | } 149 | 150 | func CreateSecurityGroupPolicies() (common.CommonReturn, error) { 151 | var ( 152 | action = "CreateSecurityGroupPolicies" 153 | ) 154 | params := CreateSecurityGroupPoliciesReq{ 155 | SecurityGroupId: "sg-hnycxsrrdvszkzbn", 156 | SecurityGroupPolicySet: CreateSecurityGroupPolicySet{ 157 | Ingress: []CreateSecurityPolicyInfo{ 158 | { 159 | Protocol: "tcp", 160 | PolicyDescription: "入站规则描述", 161 | Port: "80/90", 162 | CidrBlock: "0.0.0.0/0", 163 | Priority: 1, 164 | Status: true, 165 | }, 166 | { 167 | Protocol: "icmp", 168 | PolicyDescription: "入站规则描述", 169 | Port: "1/1", 170 | CidrBlock: "0.0.0.0/0", 171 | Priority: 2, 172 | Status: false, 173 | }, 174 | }, 175 | Egress: []CreateSecurityPolicyInfo{ 176 | { 177 | Protocol: "tcp", 178 | PolicyDescription: "出站规则描述", 179 | Port: "3306/3306", 180 | CidrBlock: "0.0.0.0/0", 181 | Priority: 1, 182 | Status: false, 183 | }, 184 | }, 185 | }, 186 | } 187 | body, err := json.Marshal(params) 188 | if err != nil { 189 | fmt.Println("反序列化失败:", err.Error()) 190 | return common.CommonReturn{}, err 191 | } 192 | res := common.DoHttpPost(action, SgUrl, http.MethodPost, body) 193 | return res, nil 194 | } 195 | 196 | // 查看安全组规则详情 197 | type SecurityGroupPoliciesResp struct { 198 | SecurityGroupId string `json:"SecurityGroupId"` 199 | SecurityGroupPolicySet SecurityGroupPolicySetResp `json:"SecurityGroupPolicySet"` 200 | } 201 | 202 | type SecurityGroupPolicySetResp struct { 203 | Ingress []SecurityPolicyInfoResp `json:"Ingress"` 204 | Egress []SecurityPolicyInfoResp `json:"Egress"` 205 | } 206 | 207 | type SecurityPolicyInfoResp struct { 208 | SecurityGroupId string `json:"SecurityGroupId"` 209 | PolicyID string `json:"PolicyId"` 210 | Protocol string `json:"Protocol"` 211 | PolicyDescription string `json:"PolicyDescription"` 212 | Port string `json:"Port"` 213 | CidrBlock string `json:"CidrBlock"` 214 | Priority int `json:"Priority"` 215 | Status bool `json:"Status"` 216 | } 217 | 218 | func DescribeSecurityGroupPolicies() (SecurityGroupPoliciesResp, error) { 219 | var ( 220 | action = "DescribeSecurityGroupPolicies" 221 | ) 222 | params := map[string]interface{}{ 223 | "SecurityGroupId": "sg-hnycxsrrdvszkzbn", // 根据安全组单一请求 224 | } 225 | body, err := json.Marshal(params) 226 | if err != nil { 227 | fmt.Println("反序列化失败:", err.Error()) 228 | return SecurityGroupPoliciesResp{}, err 229 | } 230 | 231 | res := common.DoHttpPost(action, SgUrl, http.MethodGet, body) 232 | bytes, err := json.Marshal(res.Data) 233 | if err != nil { 234 | return SecurityGroupPoliciesResp{}, err 235 | } 236 | data := SecurityGroupPoliciesResp{} 237 | err = json.Unmarshal(bytes, &data) 238 | return data, err 239 | } 240 | 241 | // 删除安全组规则 242 | type DelPolicyReq struct { 243 | SecurityGroupId string `json:"SecurityGroupId"` 244 | PolicyIds []string `json:"PolicyIds"` 245 | } 246 | 247 | func DeleteSecurityGroupPolicies() (common.CommonReturn, error) { 248 | var ( 249 | action = "DeleteSecurityGroupPolicies" 250 | ) 251 | params := DelPolicyReq{ 252 | SecurityGroupId: "sg-hnycxsrrdvszkzbn", 253 | PolicyIds: []string{"sp-v8m111r9lb1vafn0"}, 254 | } 255 | body, err := json.Marshal(params) 256 | if err != nil { 257 | fmt.Println("反序列化失败:", err.Error()) 258 | return common.CommonReturn{}, err 259 | } 260 | res := common.DoHttpPost(action, SgUrl, http.MethodPost, body) 261 | return res, nil 262 | } 263 | 264 | // 修改安全组规则 265 | type ModifySecurityGroupPoliciesReq struct { 266 | SecurityGroupId string `json:"SecurityGroupId"` 267 | SecurityGroupPolicySet ModifySecurityGroupPolicySet `json:"SecurityGroupPolicySet"` 268 | Reset bool `json:"Reset"` 269 | } 270 | 271 | type ModifySecurityGroupPolicySet struct { 272 | Ingress []ModifySecurityPolicyInfo `json:"Ingress"` 273 | Egress []ModifySecurityPolicyInfo `json:"Egress"` 274 | } 275 | 276 | type ModifySecurityPolicyInfo struct { 277 | Protocol string `json:"Protocol"` 278 | PolicyDescription string `json:"PolicyDescription" ` 279 | Port string `json:"Port"` 280 | CidrBlock string `json:"CidrBlock"` 281 | Priority int `json:"Priority"` 282 | Status bool `json:"Status"` 283 | PolicyID string `json:"PolicyId"` 284 | } 285 | 286 | func ModifySecurityGroupPolicies1() (common.CommonReturn, error) { 287 | var ( 288 | action = "ModifySecurityGroupPolicies" 289 | ) 290 | params := ModifySecurityGroupPoliciesReq{ 291 | SecurityGroupId: "sg-hnycxsrrdvszkzbn", 292 | Reset: true, // 覆盖之前规则 293 | SecurityGroupPolicySet: ModifySecurityGroupPolicySet{ 294 | Ingress: []ModifySecurityPolicyInfo{ 295 | { 296 | Protocol: "tcp", 297 | PolicyDescription: "入站规则描述", 298 | Port: "80/80", 299 | CidrBlock: "0.0.0.0/0", 300 | Priority: 1, 301 | Status: true, 302 | }, 303 | { 304 | Protocol: "icmp", 305 | PolicyDescription: "入站规则描述", 306 | Port: "1/1", 307 | CidrBlock: "0.0.0.0/0", 308 | Priority: 2, 309 | Status: false, 310 | }, 311 | }, 312 | Egress: []ModifySecurityPolicyInfo{}, 313 | }, 314 | } 315 | body, err := json.Marshal(params) 316 | if err != nil { 317 | fmt.Println("反序列化失败:", err.Error()) 318 | return common.CommonReturn{}, err 319 | } 320 | res := common.DoHttpPost(action, SgUrl, http.MethodPost, body) 321 | return res, nil 322 | } 323 | 324 | func ModifySecurityGroupPolicies2() (common.CommonReturn, error) { 325 | var ( 326 | action = "ModifySecurityGroupPolicies" 327 | ) 328 | params := ModifySecurityGroupPoliciesReq{ 329 | SecurityGroupId: "sg-hnycxsrrdvszkzbn", 330 | Reset: false, // 不覆盖之前规则,只修改指定id规则 331 | SecurityGroupPolicySet: ModifySecurityGroupPolicySet{ 332 | Ingress: []ModifySecurityPolicyInfo{ 333 | { 334 | PolicyID: "sp-hi7hfarnlx19axn0", 335 | Protocol: "tcp", 336 | PolicyDescription: "入站规则描述", 337 | Port: "8080/8080", 338 | CidrBlock: "0.0.0.0/0", 339 | Priority: 1, 340 | Status: true, 341 | }, 342 | }, 343 | }, 344 | } 345 | body, err := json.Marshal(params) 346 | if err != nil { 347 | fmt.Println("反序列化失败:", err.Error()) 348 | return common.CommonReturn{}, err 349 | } 350 | res := common.DoHttpPost(action, SgUrl, http.MethodPost, body) 351 | return res, nil 352 | } 353 | 354 | // 安装组绑定实例 355 | type AssociateSecurityGroupsReq struct { 356 | SecurityGroupId string `json:"SecurityGroupId"` 357 | RegionCode string `json:"RegionCode"` 358 | InstanceSet []InstanceSecurity `json:"InstanceSet"` 359 | } 360 | 361 | type InstanceSecurity struct { 362 | InstanceId string `json:"InstanceId"` 363 | SecurityGroupPriority int `json:"SecurityGroupPriority"` 364 | } 365 | 366 | func AssociateSecurityGroups() (common.CommonReturn, error) { 367 | var ( 368 | action = "AssociateSecurityGroups" 369 | ) 370 | params := AssociateSecurityGroupsReq{ 371 | SecurityGroupId: "sg-hnycxsrrdvszkzbn", 372 | RegionCode: "SR_SaintPaul", 373 | InstanceSet: []InstanceSecurity{ 374 | { 375 | InstanceId: "ins-ktqyh5rra9u7h6k1", 376 | SecurityGroupPriority: 5, 377 | }, 378 | }, 379 | } 380 | body, err := json.Marshal(params) 381 | if err != nil { 382 | fmt.Println("反序列化失败:", err.Error()) 383 | return common.CommonReturn{}, err 384 | } 385 | res := common.DoHttpPost(action, SgUrl, http.MethodPost, body) 386 | return res, nil 387 | } 388 | 389 | // 安全组解绑实例 390 | type DisassociateSecurityGroupsReq struct { 391 | SecurityGroupId string `json:"SecurityGroupId"` 392 | InstanceIds []string `json:"InstanceIds"` 393 | } 394 | 395 | func DisassociateSecurityGroups() (common.CommonReturn, error) { 396 | var ( 397 | action = "DisassociateSecurityGroups" 398 | ) 399 | params := DisassociateSecurityGroupsReq{ 400 | SecurityGroupId: "sg-hnycxsrrdvszkzbn", 401 | InstanceIds: []string{"ins-ktqyh5rra9u7h6k1"}, 402 | } 403 | body, err := json.Marshal(params) 404 | if err != nil { 405 | fmt.Println("反序列化失败:", err.Error()) 406 | return common.CommonReturn{}, err 407 | } 408 | res := common.DoHttpPost(action, SgUrl, http.MethodPost, body) 409 | return res, nil 410 | } 411 | 412 | type ModifySecurityGroupsPriorityReq struct { 413 | InstanceId string `json:"InstanceId"` 414 | RegionCode string `json:"RegionCode"` 415 | SecurityGroupSet []InstanceSecurityGroups `json:"SecurityGroupSet"` 416 | } 417 | 418 | type InstanceSecurityGroups struct { 419 | SecurityGroupId string `json:"SecurityGroupId"` 420 | Priority int `json:"Priority"` 421 | } 422 | 423 | // 修改/重置实例下安全组优先级 424 | func ModifySecurityGroupsPriority() (common.CommonReturn, error) { 425 | var ( 426 | action = "ModifySecurityGroupsPriority" 427 | ) 428 | params := ModifySecurityGroupsPriorityReq{ 429 | InstanceId: "ins-ktqyh5rra9u7h6k1", 430 | RegionCode: "SR_SaintPaul", 431 | SecurityGroupSet: []InstanceSecurityGroups{{ 432 | SecurityGroupId: "sg-hnycxsrrdvszkzbn", 433 | Priority: 1, 434 | }}, 435 | } 436 | body, err := json.Marshal(params) 437 | if err != nil { 438 | fmt.Println("反序列化失败:", err.Error()) 439 | return common.CommonReturn{}, err 440 | } 441 | res := common.DoHttpPost(action, SgUrl, http.MethodPost, body) 442 | return res, nil 443 | } 444 | 445 | // 查看安全组下实例详情 446 | func DescribeSecurityGroupAssociationStatistics() (common.CommonReturn, error) { 447 | var ( 448 | action = "DescribeSecurityGroupAssociationStatistics" 449 | ) 450 | params := map[string]interface{}{ 451 | "SecurityGroupId": "sg-hnycxsrrdvszkzbn", // 根据安全组单一请求 452 | } 453 | body, err := json.Marshal(params) 454 | if err != nil { 455 | fmt.Println("反序列化失败:", err.Error()) 456 | return common.CommonReturn{}, err 457 | } 458 | 459 | res := common.DoHttpPost(action, SgUrl, http.MethodGet, body) 460 | return res, err 461 | } 462 | -------------------------------------------------------------------------------- /example/Golang/VPC/sg/sg_test.go: -------------------------------------------------------------------------------- 1 | package sg 2 | 3 | import ( 4 | "fmt" 5 | "testing" 6 | ) 7 | 8 | func TestDescribeSecurityGroups(t *testing.T) { 9 | data, err := DescribeSecurityGroups() 10 | if err != nil { 11 | fmt.Println(err) 12 | } else { 13 | fmt.Println(data) 14 | } 15 | } 16 | 17 | func TestCreateSecurityGroup(t *testing.T) { 18 | data, err := CreateSecurityGroup() 19 | if err != nil { 20 | fmt.Println(err) 21 | } else { 22 | fmt.Println(data) 23 | } 24 | } 25 | 26 | func TestModifySecurityGroupAttribute(t *testing.T) { 27 | data, err := ModifySecurityGroupAttribute() 28 | if err != nil { 29 | fmt.Println(err) 30 | } else { 31 | fmt.Println(data) 32 | } 33 | } 34 | 35 | func TestDeleteSecurityGroup(t *testing.T) { 36 | data, err := DeleteSecurityGroup() 37 | if err != nil { 38 | fmt.Println(err) 39 | } else { 40 | fmt.Println(data) 41 | } 42 | } 43 | 44 | func TestCreateSecurityGroupPolicies(t *testing.T) { 45 | data, err := CreateSecurityGroupPolicies() 46 | if err != nil { 47 | fmt.Println(err) 48 | } else { 49 | fmt.Println(data) 50 | } 51 | } 52 | 53 | func TestDescribeSecurityGroupPolicies(t *testing.T) { 54 | data, err := DescribeSecurityGroupPolicies() 55 | if err != nil { 56 | fmt.Println(err) 57 | } else { 58 | fmt.Println(data) 59 | } 60 | } 61 | 62 | func TestDeleteSecurityGroupPolicies(t *testing.T) { 63 | data, err := DeleteSecurityGroupPolicies() 64 | if err != nil { 65 | fmt.Println(err) 66 | } else { 67 | fmt.Println(data) 68 | } 69 | } 70 | 71 | func TestModifySecurityGroupPolicies1(t *testing.T) { 72 | data, err := ModifySecurityGroupPolicies1() 73 | if err != nil { 74 | fmt.Println(err) 75 | } else { 76 | fmt.Println(data) 77 | } 78 | } 79 | 80 | func TestModifySecurityGroupPolicies2(t *testing.T) { 81 | data, err := ModifySecurityGroupPolicies2() 82 | if err != nil { 83 | fmt.Println(err) 84 | } else { 85 | fmt.Println(data) 86 | } 87 | } 88 | 89 | func TestAssociateSecurityGroups(t *testing.T) { 90 | data, err := AssociateSecurityGroups() 91 | if err != nil { 92 | fmt.Println(err) 93 | } else { 94 | fmt.Println(data) 95 | } 96 | } 97 | 98 | func TestDisassociateSecurityGroups(t *testing.T) { 99 | data, err := DisassociateSecurityGroups() 100 | if err != nil { 101 | fmt.Println(err) 102 | } else { 103 | fmt.Println(data) 104 | } 105 | } 106 | 107 | func TestModifySecurityGroupsPriority(t *testing.T) { 108 | data, err := ModifySecurityGroupsPriority() 109 | if err != nil { 110 | fmt.Println(err) 111 | } else { 112 | fmt.Println(data) 113 | } 114 | } 115 | 116 | func TestDescribeSecurityGroupAssociationStatistics(t *testing.T) { 117 | data, err := DescribeSecurityGroupAssociationStatistics() 118 | if err != nil { 119 | fmt.Println(err) 120 | } else { 121 | fmt.Println(data) 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /example/Golang/go.mod: -------------------------------------------------------------------------------- 1 | module example 2 | 3 | go 1.17 4 | 5 | require github.com/google/uuid v1.3.0 6 | -------------------------------------------------------------------------------- /example/Golang/go.sum: -------------------------------------------------------------------------------- 1 | github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= 2 | github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= 3 | -------------------------------------------------------------------------------- /example/Python/template_example.py: -------------------------------------------------------------------------------- 1 | # coding: utf-8 2 | import uuid 3 | import hmac 4 | import time 5 | import urllib2 6 | import urllib 7 | import sys, os 8 | import base64 9 | import hashlib 10 | from hashlib import sha1 11 | import requests 12 | import json 13 | 14 | 15 | CCS_URL = "http://cdsapi.capitalonline.net/ccs" 16 | NETWORK_URL = "http://cdsapi.capitalonline.net/network" 17 | 18 | # AK、SK 19 | AK = "您的AK" 20 | AccessKeySecret = "您的SK" 21 | 22 | 23 | def percentEncode(str): 24 | res = urllib.quote(str.decode(sys.stdin.encoding).encode('utf8'), '') 25 | res = res.replace('+', '%20') 26 | res = res.replace('*', '%2A') 27 | res = res.replace('%7E', '~') 28 | return res 29 | 30 | 31 | def get_signature(action, ak, access_key_secret, method, url, param={}): 32 | """ 33 | @params: action: 接口动作 34 | @params: ak: ak值 35 | @params: access_key_secret: ak秘钥 36 | @params: method: 接口调用方法(POST/GET) 37 | @params: param: 接口调用Query中参数(非POST方法Body中参数) 38 | @params: url: 接口调用路径 39 | """ 40 | timestamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) 41 | D = { 42 | 'Action': action, 43 | 'AccessKeyId': ak, 44 | 'SignatureMethod': 'HMAC-SHA1', 45 | 'SignatureNonce': str(uuid.uuid1()), 46 | 'SignatureVersion': "1.0", 47 | "Timestamp": timestamp, 48 | 'Version': '2019-08-08', 49 | } 50 | 51 | if param: 52 | D.update(param) 53 | 54 | sortedD = sorted(D.items(), key=lambda x: x[0]) 55 | canstring = '' 56 | for k, v in sortedD: 57 | canstring += '&' + percentEncode(k) + '=' + percentEncode(v) 58 | 59 | stringToSign = method + '&%2F&' + percentEncode(canstring[1:]) 60 | h = hmac.new(access_key_secret, stringToSign, sha1) 61 | signature = base64.encodestring(h.digest()).strip() 62 | D['Signature'] = signature 63 | url = url + '/?' + urllib.urlencode(D) 64 | return url 65 | 66 | def create_template(vm_id, name): 67 | """创建模板""" 68 | 69 | action = "CreateTemplate" 70 | method = "POST" 71 | 72 | # 获取签名自动生成请求url 73 | url = get_signature(action, AK, AccessKeySecret, method, CCS_URL) 74 | body = { 75 | "InstanceId": vm_id, 76 | "DisplayName": name 77 | } 78 | res = requests.post(url, json=body) 79 | result = json.loads(res.content) 80 | print result 81 | 82 | def delete_template(template_id, region_id): 83 | """删除模板"""" 84 | 85 | action = "DeleteTemplate" 86 | method = "POST" 87 | url = get_signature(action, AK, AccessKeySecret, method, CCS_URL) 88 | body = { 89 | "TemplateId": template_id, 90 | "RegionId": region_id 91 | } 92 | res = requests.post(url, json=body) 93 | result = json.loads(res.content) 94 | print result 95 | 96 | def list_template(): 97 | """模板列表""" 98 | 99 | action = "DescribeTemplateInfo" 100 | method = "POST" 101 | url = get_signature(action, AK, AccessKeySecret, method, CCS_URL) 102 | body = { 103 | "PageSize": 10, 104 | "PageNumber": 1, 105 | # "Keyword": "test" 106 | } 107 | res = requests.post(url, json=body) 108 | result = json.loads(res.content) 109 | task_id = result.get("TaskId") 110 | print result 111 | 112 | def sync_template(template_id, region_id): 113 | """同步模板"""" 114 | 115 | action = "SyncTemplate" 116 | method = "POST" 117 | url = get_signature(action, AK, AccessKeySecret, method, CCS_URL) 118 | body = { 119 | "TemplateId":template_id 120 | "RegionId": region_id 121 | } 122 | res = requests.post(url, json=body) 123 | result = json.loads(res.content) 124 | print result 125 | 126 | 127 | 128 | if __name__ == "__main__": 129 | 130 | # 1.定制模板 131 | create_template(vm_id="xxxx", name="display_name") 132 | 133 | # 2.删除模板 134 | # delete_template(template_id, region_id) 135 | 136 | # 3.模板列表 137 | # list_template() 138 | 139 | # 4.同步模板 140 | # sync_template(template_id, region_id) -------------------------------------------------------------------------------- /宿迁对象存储OpenAPI文档(v1.1)【废弃】.md: -------------------------------------------------------------------------------- 1 | # 对象存储公开API目录 2 | 3 | ## API概览 4 | 5 | OSS产品提供以下相关API接口 6 | 7 | | API | 描述 | 8 | | ------------------------ | ------------------------------------------------------------ | 9 | | GetAllBucketUsedCapacity | 统计所有存储桶(Bucket)最近一个5min时间的用量(具体时间按照调用结果为准),流入带宽,流出带宽,GET,PUT,HEAD,DELETE请求的时延、获取状态码个数等监控信息,时间颗粒度为5min。 | 10 | 11 | - 认证方式 12 | - [1.公共请求参数](https://github.com/capitalonline/openapi/blob/master/首云OpenAPI(v1.2).md#1公共请求参数) 13 | - 2.签名机制 14 | - [步骤一:构造规范化请求字符串](https://github.com/capitalonline/openapi/blob/master/首云OpenAPI(v1.2).md#步骤一构造规范化请求字符串) 15 | - [步骤二:构造签名字符串](https://github.com/capitalonline/openapi/blob/master/首云OpenAPI(v1.2).md#步骤二构造签名字符串) 16 | - [3.获取签名代码](https://github.com/capitalonline/openapi/blob/master/首云OpenAPI(v1.2).md#2获取签名代码) 17 | - [访问地址](https://github.com/capitalonline/openapi/blob/master/对象存储概览(v1.1).md#访问地址) 18 | 19 | ### 访问地址 20 | 21 | | 地区 | 访问地址 | 22 | | ---- | ---------------------------- | 23 | | 宿迁 | gic-ossapi.capitalonline.net | 24 | 25 | ## 实例 26 | 27 | ### GetAllBucketUsedCapacity 28 | 29 | **Action:**GetAllBucketUsedCapacity 30 | 31 | **数据时效:**每次请求都会返回一个监控开始时间start_time,该时间为最新数据的起点,监控数据为[start_time, start_time+5min]时间段的数据的计算值, 32 | 33 | 例如:当前时间18:40 34 | 35 | 调用接口后,监控开始时间start_time为18:20,监控数据为18:20-18:25之前的数据,带宽、时延、响应码个数,均为5min的时间颗粒度 36 | 37 | **描述:**统计存储桶(Bucket)的各项监控数据 38 | 39 | **请求方法:**POST 40 | 41 | **参数:**无 42 | 43 | **headers参数:** 44 | 45 | | 名称 | 类型 | 是否必需 | 描述 | 46 | | ---- | ------ | -------- | ------------------------------------------------------------ | 47 | | host | 字符串 | 是 | 存储空间所在节点endpoint地址。示例:{'host': 'oss-cnsq02.cdsgss.com'} 其中oss-cnsq02.cdsgss.com为宿迁节点的endpoint地址 | 48 | 49 | **响应参数:** 50 | 51 | | 名称 | 单位 | 含义 | 52 | | ------------- | ------------ | ---------------------------------------- | 53 | | bucket_name | / | 存储桶名称 | 54 | | capacity_used | KB | 存储桶已使用的容量 | 55 | | obj_count | 个 | 存储桶的对象数目 | 56 | | in_bandwidth | 字节(byte) | 上传带宽,支持周期:5minute | 57 | | out_bandwidth | 字节(byte) | 下载带宽,支持周期:5minute | 58 | | get_avg_time | 微秒(μs) | GET请求平均时延,支持周期:5minute | 59 | | put_avg_time | 微秒(μs) | PUT请求平均时延,支持周期:5minute | 60 | | head_avg_time | 微秒(μs) | HEAD请求平均时延,支持周期:5minute | 61 | | del_avg_time | 微秒(μs) | DELETE请求平均时延,支持周期:5minute | 62 | | 2xx | 个 | 2开头的响应码个数(时间颗粒度为5minute) | 63 | | 3xx | 个 | 3开头的响应码个数(时间颗粒度为5minute) | 64 | | 4xx | 个 | 4开头的响应码个数(时间颗粒度为5minute) | 65 | | 5xx | 个 | 5开头的响应码个数(时间颗粒度为5minute) | 66 | 67 | 68 | 69 | **注意事项:** 70 | 71 | - GetAllBucketUsedCapacity,有如下注意事项: 72 | - 仅限宿迁站点指定用户 73 | 74 | **请求示例demo(假如有2个桶):** 75 | 76 | 通过curl方式调用接口时,使用signature函数返回url替换即可 77 | 78 | ``` 79 | curl -X POST 'https://gic-ossapi.capitalonline.net/ossapi/GetAllBucketUsedCapacity/?Action=GetAllBucketUsedCapacity&AccessKeyId=XXXXXXXXXXXXXXXXXXXXXXXXXXXXX&SignatureMethod=HMAC-SHA1&SignatureNonce=XXXXXXXXXXXXXXXXXXXXXXXX&SignatureVersion=1.0&Timestamp=2024-04-09T10%3A53%3A12Z&Version=2019-08-08&Signature=XXXXXXXXXXXXXXXXXXXXXXXXX' -H 'content-type: application/json' -H 'host: oss-cnsq02.cdsgss.com' 80 | ``` 81 | 82 | **返回示例demo(假如有2个桶):** 83 | 84 | ``` 85 | { 86 | "Code": "Success", 87 | "Msg": "Success", 88 | "Data": { 89 | "start_time": "2024-04-29T14:30:00", 90 | "info": [ 91 | { 92 | "bucketname": "bucket1", 93 | "capacity_used": 6259635108, 94 | "obj_count": 4397333, 95 | "in_bandwidth": 6388855, 96 | "out_bandwidth": 15498830, 97 | "put_avg_time": { 98 | "total_time": 6160814, 99 | "reqs_count": 273, 100 | "avg_time": 22567.08 101 | }, 102 | "PUT": { 103 | "2xx": 199, 104 | "3xx": 0, 105 | "4xx": 0, 106 | "5xx": 0 107 | } 108 | }, 109 | { 110 | "bucketname": "bucket2", 111 | "capacity_used": 6259635108, 112 | "obj_count": 4397333, 113 | "in_bandwidth": 6388855, 114 | "out_bandwidth": 15498830, 115 | "put_avg_time": { 116 | "total_time": 6160814, 117 | "reqs_count": 273, 118 | "avg_time": 22567.08 119 | }, 120 | "PUT": { 121 | "2xx": 199, 122 | "3xx": 0, 123 | "4xx": 0, 124 | "5xx": 0 125 | } 126 | } 127 | ] 128 | }, 129 | "RequestId": "4ddbd437-97cc-44a7-8d5a-b94902ccb977" 130 | } 131 | ``` 132 | 133 | 134 | 135 | **python调用示例:(需替换自己的ak,sk,endpoint,bucket名称)** 136 | 137 | ``` 138 | # coding: utf-8 139 | import base64 140 | import hmac 141 | import time 142 | import urllib.parse as parse 143 | import uuid 144 | import json 145 | from hashlib import sha1 146 | 147 | import requests 148 | import xmltodict as xmlparse 149 | 150 | OSSPREBASEURL = 'https://gic-ossapi.capitalonline.net/ossapi' 151 | 152 | 153 | endpoint = "oss-cnsq02.cdsgss.com" 154 | a_key = 'XXXXXXXXXXXXXXXXXXXXXXXX' 155 | s_key = 'XXXXXXXXXXXXXXXXXXXXXXXX' 156 | 157 | def percent_encode(string): 158 | """将特殊转义字符替换""" 159 | res = parse.quote(string, '') 160 | res = res.replace('+', '%20') 161 | res = res.replace('*', '%2A') 162 | res = res.replace('%7E', '~') 163 | return res 164 | 165 | 166 | 167 | def signature(action, ak, access_key_secret, method, url, param={}): 168 | """ 169 | @params: action: 接口动作 170 | @params: ak: ak值 171 | @params: access_key_secret: ak秘钥 172 | @params: method: 接口调用方法(POST/GET) 173 | @params: param: 接口调用Query中参数(非POST方法Body中参数) 174 | @params: url: 接口调用路径 175 | @return: 请求的url可直接调用 176 | """ 177 | timestamp = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()) 178 | D = { 179 | 'Action': action, 180 | 'AccessKeyId': ak, 181 | 'SignatureMethod': 'HMAC-SHA1', 182 | 'SignatureNonce': str(uuid.uuid1()), 183 | 'SignatureVersion': "1.0", 184 | "Timestamp": timestamp, 185 | 'Version': '2019-08-08', 186 | } 187 | if param: 188 | D.update(param) 189 | sortedD = sorted(D.items(), key=lambda x: x[0]) 190 | canstring = '' 191 | for k, v in sortedD: 192 | canstring += '&' + percent_encode(k) + '=' + percent_encode(v) 193 | stringToSign = method + '&%2F&' + percent_encode(canstring[1:]) 194 | stringToSign = stringToSign.encode('utf-8') 195 | access_key_secret = access_key_secret.encode('utf-8') 196 | h = hmac.new(access_key_secret, stringToSign, sha1) 197 | signature = base64.encodebytes(h.digest()).strip() 198 | D['Signature'] = signature 199 | url = url + '/?' + parse.urlencode(D) 200 | return url 201 | 202 | class OpenAPI(object): 203 | centent_type = "application/json" 204 | 205 | def __init__(self, access_key, secret_key): 206 | self.access_key = access_key 207 | self.secret_key = secret_key 208 | 209 | self.headers = { 210 | 'content-type': 'application/json' 211 | } 212 | 213 | def GetAllBucketUsedCapacity(self): 214 | url = OSSPREBASEURL + "/GetAllBucketUsedCapacity" 215 | action = "GetAllBucketUsedCapacity" 216 | method = "POST" 217 | param = {} 218 | self.headers.update({"host":'%s' %(endpoint)}) 219 | url = signature(action, self.access_key, self.secret_key, method, url, param) 220 | resp = requests.post(url, headers=self.headers) 221 | if resp.status_code == 200: 222 | return json.loads(resp.text) 223 | else: 224 | return None 225 | 226 | def bucketinfo(data): 227 | for info in data["info"]: 228 | 229 | print("桶名:",info.get("bucketname")) 230 | print("桶使用量capacity_used: %s T" % round(info.get("capacity_used") / 1024 / 1024 / 1024 , 2)) 231 | print("桶对象个数obj_count:",info.get("obj_count")) 232 | print("上传带宽in_bandwidth: %s Mbps" % (info.get("in_bandwidth")/1024/1024)) 233 | print("下载带宽out_bandwidth: %s Mbps" % (info.get("out_bandwidth")/1024/1024)) 234 | 235 | print("GET平均延时: total_time:"+str(info.get("get_avg_time").get("total_time")) + " reqs_count:"+str(info.get("get_avg_time").get("reqs_count")) + " avg:" + str(round(info.get("get_avg_time").get("avg_time") / 1000, 2))) 236 | print("PUT平均延时: total_time:"+str(info.get("put_avg_time").get("total_time")) + " reqs_count:"+str(info.get("put_avg_time").get("reqs_count")) + " avg:" + str(round(info.get("put_avg_time").get("avg_time") / 1000, 2))) 237 | print("HEAD平均延时: total_time:"+str(info.get("head_avg_time").get("total_time")) + " reqs_count:"+str(info.get("head_avg_time").get("reqs_count")) + " avg:" + str(round(info.get("head_avg_time").get("avg_time") / 1000, 2))) 238 | print("DELETE平均延时: total_time:"+str(info.get("del_avg_time").get("total_time")) + " reqs_count:"+str(info.get("del_avg_time").get("reqs_count")) + " avg:" + str(round(info.get("del_avg_time").get("avg_time") / 1000, 2))) 239 | 240 | print("GET状态码: 2xx:"+str(info.get("GET").get("2xx")) + " 3xx:"+str(info.get("GET").get("3xx")) + " 4xx:" + str(info.get("GET").get("4xx"))+ " 5xx:" + str(info.get("GET").get("5xx"))) 241 | print("PUT状态码: 2xx:"+str(info.get("PUT").get("2xx")) + " 3xx:"+str(info.get("PUT").get("3xx")) + " 4xx:" + str(info.get("PUT").get("4xx"))+ " 5xx:" + str(info.get("GET").get("5xx"))) 242 | print("HEAD状态码: 2xx:"+str(info.get("HEAD").get("2xx")) + " 3xx:"+str(info.get("HEAD").get("3xx")) + " 4xx:" + str(info.get("HEAD").get("4xx"))+ " 5xx:" + str(info.get("GET").get("5xx"))) 243 | print("DELETE状态码: 2xx:"+str(info.get("DELETE").get("2xx")) + " 3xx:"+str(info.get("DELETE").get("3xx")) + " 4xx:" + str(info.get("DELETE").get("4xx"))+ " 5xx:" + str(info.get("GET").get("5xx"))) 244 | 245 | print() 246 | 247 | 248 | 249 | 250 | 251 | if __name__ == '__main__': 252 | api = OpenAPI(a_key, s_key) 253 | #获取最近一次查询的所有桶的数据 254 | res_data = api.GetAllBucketUsedCapacity() 255 | #print(json.dumps(res_data)) 256 | print("开始时间:", res_data.get("Data").get("start_time")) 257 | print() 258 | bucketinfo(res_data.get("Data")) 259 | 260 | ``` 261 | 262 | **python调用返回示例*(假设只有两个桶,数据时效性:监控开始时间——监控开始时间+5min,该五分钟内的数据):** 263 | 264 | ``` 265 | 开始时间: 2024-05-08T10:20:00 266 | 267 | 桶名: bucket1 268 | 桶使用量capacity_used: 12.12 T 269 | 桶对象个数obj_count: 54878 270 | 上传带宽in_bandwidth: 50.35516357421875 Mbps 271 | 下载带宽out_bandwidth: 213.71126651763916 Mbps 272 | GET平均延时: total_time:25562277 reqs_count:24 avg:1065.09 273 | PUT平均延时: total_time:74123014 reqs_count:241 avg:307.56 274 | HEAD平均延时: total_time:0 reqs_count:0 avg:0.0 275 | DELETE平均延时: total_time:0 reqs_count:0 avg:0.0 276 | GET状态码: 2xx:24 3xx:0 4xx:0 5xx:0 277 | PUT状态码: 2xx:241 3xx:0 4xx:0 5xx:0 278 | HEAD状态码: 2xx:0 3xx:0 4xx:0 5xx:0 279 | DELETE状态码: 2xx:0 3xx:0 4xx:0 5xx:0 280 | 281 | 桶名: bucket2 282 | 桶使用量capacity_used: 1.03 T 283 | 桶对象个数obj_count: 15430 284 | 上传带宽in_bandwidth: 0.0 Mbps 285 | 下载带宽out_bandwidth: 0.0 Mbps 286 | GET平均延时: total_time:0 reqs_count:0 avg:0.0 287 | PUT平均延时: total_time:0 reqs_count:0 avg:0.0 288 | HEAD平均延时: total_time:0 reqs_count:0 avg:0.0 289 | DELETE平均延时: total_time:0 reqs_count:0 avg:0.0 290 | GET状态码: 2xx:0 3xx:0 4xx:0 5xx:0 291 | PUT状态码: 2xx:0 3xx:0 4xx:0 5xx:0 292 | HEAD状态码: 2xx:0 3xx:0 4xx:0 5xx:0 293 | DELETE状态码: 2xx:0 3xx:0 4xx:0 5xx:0 294 | ``` 295 | 296 | -------------------------------------------------------------------------------- /对象存储OSS OpenAPI文档(v1.2).md: -------------------------------------------------------------------------------- 1 | # 对象存储公开API目录 2 | 3 | ## API概览 4 | 5 | OSS产品提供以下相关API接口 6 | 7 | | API | 描述 | 8 | | ------------------------ | ------------------------------------------------------------ | 9 | | DescribeBucketMetrics | 统计单个存储桶(Bucket)最近一个10min时间的用量(具体时间按照调用结果为准),流入流量、流出流量、请求的总耗时、请求次数 和 HTTP 状态码个数等监控信息,时间颗粒度为 10min。 | 10 | 11 | - 认证方式 12 | - [1.公共请求参数](https://github.com/capitalonline/openapi/blob/master/首云OpenAPI(v1.2).md#1公共请求参数) 13 | - 2.签名机制 14 | - [步骤一:构造规范化请求字符串](https://github.com/capitalonline/openapi/blob/master/首云OpenAPI(v1.2).md#步骤一构造规范化请求字符串) 15 | - [步骤二:构造签名字符串](https://github.com/capitalonline/openapi/blob/master/首云OpenAPI(v1.2).md#步骤二构造签名字符串) 16 | - [3.获取签名代码](https://github.com/capitalonline/openapi/blob/master/首云OpenAPI(v1.2).md#2获取签名代码) 17 | - [访问地址](https://github.com/capitalonline/openapi/blob/master/对象存储概览(v1.1).md#访问地址) 18 | 19 | ### 访问地址 20 | 21 | 访问地址:gic-ossapi.capitalonline.net 22 | 23 | API 支持的站点 Endpoint 地址: 24 | 25 | | 地区 | 访问地址 | 26 | | ---- | ---------------------------- | 27 | | 宿迁 | oss-high-sq01.cdsgss.com | 28 | | 庆阳 | oss-high-qy01.cdsgss.com | 29 | | 达拉斯 | oss-high-dal01.cdsgss.com | 30 | 31 | 32 | ## 实例 33 | 34 | ### DescribeBucketMetrics 35 | 36 | **Action:** DescribeBucketMetrics 37 | 38 | **数据时效:** 每次请求都会返回一个监控开始时间(StartTime)和结束时间(EndTime)之间的汇总数据,时间颗粒度均为 10min 39 | 40 | 例如:当前时间 18:42,调用接口后,会返回 StartTime <= RequestTime 的监控数据。例如 18:40 - 18:49 时段之间有数据,则返回该时段的数据;如果没有数据,则向前查询最近一个有数据的时段数据,并返回。 41 | 42 | **描述:** 获取单个(指定)存储桶(Bucket)的各项监控数据 43 | 44 | **请求方法:** POST 45 | 46 | **参数:** 无 47 | 48 | | **名称** | **类型** | **是否必需** | **描述** | 49 | | ----------- | ------ | -------- | ------------------------------------------------------------ | 50 | | BucketName | 字符串 | 是 | 存储桶名称 | 51 | | RequestTime | 时间字符串 | 否 | 请求该时间最近一次的监控数据。如果没有设置该参数,服务端会采用当前时间作为默认值。时间格式:2024-07-06 18:42:00 | 52 | 53 | **headers参数:** 54 | 55 | | 名称 | 类型 | 是否必需 | 描述 | 56 | | ---- | ------ | -------- | ------------------------------------------------------------ | 57 | | endpoint | 字符串 | 是 | 存储空间所在站点 endpoint 地址,各站点 endpoint 地址见上文列表 | 58 | 59 | **响应参数:** 60 | 61 | | **名称** | **单位** | **含义** | 62 | | ------------- | ------------ | ---------------------------------------- | 63 | | BucketName | / | 存储桶名称 | 64 | | StartTime | / | 监控数据的开始时间 | 65 | | EndTime | / | 监控数据的结束时间 | 66 | | CapacityUsed | 字节(byte) | 存储桶已使用的容量 | 67 | | ObjectCount | 个 | 存储桶中对象数量 | 68 | | InBandwidth | 字节(byte) | 上传总流量 | 69 | | OutBandwidth | 字节(byte) | 下载总流量 | 70 | | Network | 流量类型 | 内网流量:inner,外网流量:flow,CDN回源流量:cdn | 71 | | TotalCount | 个 | GET/PUT/POST/DELETE/HEADER 请求次数 | 72 | | TotalTime | 微秒(μs) | GET/PUT/POST/DELETE/HEADER 累计请求耗时 | 73 | | 2xx | 个 | http 2xx 响应码个数 | 74 | | 3xx | 个 | http 3xx 响应码个数 | 75 | | 4xx | 个 | http 4xx 响应码个数 | 76 | | 5xx | 个 | http 5xx 响应码个数 | 77 | 78 | 79 | 80 | **注意事项:** 81 | 82 | DescribeBucketMetrics API 仅支持部分站点,支持的站点列表见上文 endpoint 地址。 83 | 84 | **Python 请求示例:** 85 | 86 | ``` 87 | def request_describe_bucket_metrics(): 88 | base_url = 'http://gic-ossapi.capitalonline.net/ossapi/v2/DescribeBucketMetrics' 89 | bucket = "xxx" 90 | endpoint = "xxxx" 91 | access_key = 'xxx' 92 | secret_key = 'xxx' 93 | request_time = "2024-07-10 15:21:00" 94 | action = "DescribeBucketMetrics" 95 | method = "POST" 96 | body = { 97 | "BucketName": bucket, 98 | "RequestTime": request_time, # 非必填项 99 | } 100 | 101 | headers = { 102 | 'content-type': 'application/json', 103 | "endpoint": '%s.%s' % (bucket, endpoint) 104 | } 105 | 106 | data = json.dumps(body) 107 | url = base_url + "/?" + signature(action, access_key, secret_key, method) 108 | resp = requests.post(url, headers=headers, data=data) 109 | print(f'request url: {url} body: {data} resp: {resp}') 110 | ``` 111 | 112 | **返回示例:** 113 | 114 | ``` 115 | { 116 | "Code": "Success", 117 | "Msg": "Success", 118 | "Data": { 119 | "RequestTime": "2024-07-07T11:17:42", 120 | "BucketName": "xxx", 121 | "Usage": { 122 | "StartTime": "2024-07-07T11:00:00", 123 | "EndTime": "2024-07-07T11:09:59", 124 | "CapacityUsed": 1153478656, 125 | "ObjectCount": 11 126 | }, 127 | "NetworkTraffic": [ 128 | { 129 | "StartTime": "2024-07-07T11:00:00", 130 | "EndTime": "2024-07-07T11:09:59", 131 | "Network": "inner", 132 | "InBandwidth": 0, 133 | "OutBandwidth": 710, 134 | "Put": { 135 | "TotalCount": 0, 136 | "TotalTime": 0, 137 | "CountDetail": { 138 | "2xx": 0, 139 | "3xx": 0, 140 | "4xx": 0, 141 | "5xx": 0 142 | } 143 | }, 144 | "Get": { 145 | "TotalCount": 2, 146 | "TotalTime": 153873, 147 | "CountDetail": { 148 | "2xx": 2, 149 | "3xx": 0, 150 | "4xx": 0, 151 | "5xx": 0 152 | } 153 | }, 154 | "Delete": { 155 | "TotalCount": 0, 156 | "TotalTime": 0, 157 | "CountDetail": { 158 | "2xx": 0, 159 | "3xx": 0, 160 | "4xx": 0, 161 | "5xx": 0 162 | } 163 | }, 164 | "Post": { 165 | "TotalCount": 0, 166 | "TotalTime": 0, 167 | "CountDetail": { 168 | "2xx": 0, 169 | "3xx": 0, 170 | "4xx": 0, 171 | "5xx": 0 172 | } 173 | }, 174 | "Head": { 175 | "TotalCount": 0, 176 | "TotalTime": 0, 177 | "CountDetail": { 178 | "2xx": 0, 179 | "3xx": 0, 180 | "4xx": 0, 181 | "5xx": 0 182 | } 183 | } 184 | }, 185 | { 186 | "StartTime": "2024-07-05T20:30:00", 187 | "EndTime": "2024-07-05T20:39:59", 188 | "Network": "flow", 189 | "InBandwidth": 1153440717, 190 | "OutBandwidth": 8470, 191 | "Put": { 192 | "TotalCount": 77, 193 | "TotalTime": 9902016, 194 | "CountDetail": { 195 | "2xx": 77, 196 | "3xx": 0, 197 | "4xx": 0, 198 | "5xx": 0 199 | } 200 | }, 201 | "Get": { 202 | "TotalCount": 11, 203 | "TotalTime": 198003, 204 | "CountDetail": { 205 | "2xx": 11, 206 | "3xx": 0, 207 | "4xx": 0, 208 | "5xx": 0 209 | } 210 | }, 211 | "Delete": { 212 | "TotalCount": 0, 213 | "TotalTime": 0, 214 | "CountDetail": { 215 | "2xx": 0, 216 | "3xx": 0, 217 | "4xx": 0, 218 | "5xx": 0 219 | } 220 | }, 221 | "Post": { 222 | "TotalCount": 22, 223 | "TotalTime": 772349, 224 | "CountDetail": { 225 | "2xx": 22, 226 | "3xx": 0, 227 | "4xx": 0, 228 | "5xx": 0 229 | } 230 | }, 231 | "Head": { 232 | "TotalCount": 0, 233 | "TotalTime": 0, 234 | "CountDetail": { 235 | "2xx": 0, 236 | "3xx": 0, 237 | "4xx": 0, 238 | "5xx": 0 239 | } 240 | } 241 | } 242 | ] 243 | }, 244 | "RequestId": "094fee75447d4439aa3c27766a0cd8a6" 245 | } 246 | ``` 247 | 248 | 249 | -------------------------------------------------------------------------------- /新版MongoDB概览.md: -------------------------------------------------------------------------------- 1 | MongoDB 公开API目录 2 | ================= 3 | * [API概览](#api概览) 4 | * [认证方式](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#认证方式) 5 | * [1.公共请求参数](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#1公共请求参数) 6 | * [2.签名机制](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2签名机制) 7 | * [步骤一:构造规范化请求字符串](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#步骤一构造规范化请求字符串) 8 | * [步骤二:构造签名字符串](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#步骤二构造签名字符串) 9 | * [3.获取签名代码](https://github.com/capitalonline/openapi/blob/master/%E9%A6%96%E4%BA%91OpenAPI(v1.2).md#2获取签名代码) 10 | * [错误码](#错误码) 11 | * [访问地址](#访问地址) 12 | * [实例](#实例) 13 | * [1.DescribeZones](#1describezones) 14 | * [2.DescribeSpecInfo](#2describespecinfo) 15 | * [3.CreateDBInstance](#3createdbinstance) 16 | * [4.DescribeDBInstances](#4describedbinstances) 17 | * [5.DeleteDBInstance](#5deletedbinstance) 18 | * [6.ModifyDBInstanceSpec](#6modifydbinstancespec) 19 | 20 | ### API概览 21 | 22 | MongoDB产品提供以下相关API接口。 23 | 24 | #### 实例 25 | 26 | | API | 描述 | 27 | | -------------------- | ----------------------------------------- | 28 | | DescribeZones | 获取云数据库MongoDB支持的站点区域 | 29 | | DescribeSpecInfo | 获取某个站点支持的MongoDB产品类型以及规格 | 30 | | CreateDBInstance | 创建MongoDB云数据库实例 | 31 | | DescribeDBInstances | 获取MongoDB实例列表 | 32 | | DeleteDBInstance | 删除MongoDB实例 | 33 | | ModifyDBInstanceSpec | 修改MongoDB规格 | 34 | 35 | #### 错误码 36 | 37 | | **HttpCode** | **错误码** | **描述** | 38 | | ------------ | -------------------- | -------------------------------- | 39 | | 400 | ArgMissing | 缺少参数错误 | 40 | | 400 | InvalidParameter | 参数错误 | 41 | | 400 | BadArgs | 参数错误 | 42 | | 400 | UnsupportedOperation | 操作不支持 | 43 | | 404 | ResourceNotFound | 资源不存在 | 44 | | 409 | ResourceInUse | 资源正在被其他任务占用,操作冲突 | 45 | | 500 | InternalError | 内部错误 | 46 | | 500 | CreateOrderExcept | 创建订单异常 | 47 | 48 | ### 访问地址 49 | 50 | 51 | | 地区 | 访问地址 | 52 | | -------- | ----------------------------- | 53 | | 中国大陆 | cdsapi.capitalonline.net | 54 | | 亚太地区 | cdsapi-asia.capitalonline.net | 55 | | 欧美地区 | cdsapi-us.capitalonline.net | 56 | 57 | ### 1.DescribeZones 58 | 59 | **Action:** DescribeZones 60 | 61 | **描述:** 获取云数据库MongoDB支持的站点区域 62 | 63 | **请求地址:** cdsapi.capitalonline.net/mongodb/v1 64 | 65 | **请求方法:** GET 66 | 67 | **请求参数:** 68 | 69 | 无 70 | 71 | **请求示例:** 72 | 73 | ```python 74 | def get_mongodb_Zones(): 75 | """ 76 | 获取云数据库Mongodb支持的站点区域 77 | """ 78 | action = "DescribeZones" 79 | method = "GET" 80 | param = { 81 | } 82 | url = get_signature(action, AK, AccessKeySecret, method, MONGODB_URL, param) 83 | res = requests.get(url) 84 | result = json.loads(res.content) 85 | result = json.dumps(result) # json格式化 86 | print(result) 87 | ``` 88 | 89 | **返回示例:** 90 | 91 | ```json 92 | { 93 | "Code": "Success", 94 | "Data": [{ 95 | "CityId": "3082f45e-306e-11e7-9796-0050569b4d9c", 96 | "CityName": "洛杉矶", 97 | "IsSaling": 1, 98 | "RegionId": "US_LosAngeles_A", 99 | "RegionName": "北美地区", 100 | "SiteName": "洛杉矶1" 101 | }, { 102 | "CityId": "7b98a5d1-306e-11e7-9796-0050569b4d9c", 103 | "CityName": "法兰克福", 104 | "IsSaling": 1, 105 | "RegionId": "EUR_Germany_A", 106 | "RegionName": "欧洲地区", 107 | "SiteName": "德国1" 108 | }, { 109 | "CityId": "8737606f-306d-11e7-9796-0050569b4d9c", 110 | "CityName": "东京", 111 | "IsSaling": 1, 112 | "RegionId": "APAC_Tokyo_A", 113 | "RegionName": "亚太地区", 114 | "SiteName": "东京1" 115 | }, { 116 | "CityId": "27b57297-306d-11e7-9796-0050569b4d9c", 117 | "CityName": "香港", 118 | "IsSaling": 1, 119 | "RegionId": "CN_Hongkong_A", 120 | "RegionName": "亚太地区", 121 | "SiteName": "香港1" 122 | }, { 123 | "CityId": "a8937b00-306d-11e7-9796-0050569b4d9c", 124 | "CityName": "新加坡", 125 | "IsSaling": 1, 126 | "RegionId": "APAC_Singapore_A", 127 | "RegionName": "亚太地区", 128 | "SiteName": "新加坡1" 129 | }, { 130 | "CityId": "154ed19e-306e-11e7-9796-0050569b4d9c", 131 | "CityName": "纽约", 132 | "IsSaling": 1, 133 | "RegionId": "US_NewYork_A", 134 | "RegionName": "北美地区", 135 | "SiteName": "纽约1" 136 | }, { 137 | "CityId": "ea3ca775-306c-11e7-9796-0050569b4d9c", 138 | "CityName": "北京", 139 | "IsSaling": 1, 140 | "RegionId": "CN_Beijing_E", 141 | "RegionName": "中国大陆", 142 | "SiteName": "北京5" 143 | }, { 144 | "CityId": "e48e2312-306d-11e7-9796-0050569b4d9c", 145 | "CityName": "达拉斯", 146 | "IsSaling": 1, 147 | "RegionId": "US_Dallas_A", 148 | "RegionName": "北美地区", 149 | "SiteName": "达拉斯1" 150 | }, { 151 | "CityId": "713d3745-306d-11e7-9796-0050569b4d9c", 152 | "CityName": "台北", 153 | "IsSaling": 1, 154 | "RegionId": "CN_Taipei_A", 155 | "RegionName": "亚太地区", 156 | "SiteName": "台北1" 157 | }, { 158 | "CityId": "c11a5abe-3f7e-11e7-86b1-0242ac11000e", 159 | "CityName": "广州", 160 | "IsSaling": 1, 161 | "RegionId": "CN_Guangzhou_A", 162 | "RegionName": "中国大陆", 163 | "SiteName": "广州1" 164 | }], 165 | "Message": "Success." 166 | } 167 | ``` 168 | 169 | **返回参数说明:** 170 | 171 | | 参数名 | 类型 | 说明 | 172 | | :--------- | :----- | ------------------------------------------------------ | 173 | | Code | string | 状态码 | 174 | | Data | dict | 数据 | 175 | | CityId | string | 城市编号 | 176 | | CityName | string | 城市名称 | 177 | | IsSaling | int | 站点是否能购买服务,1:站点支持购买;0:资源不足以下线 | 178 | | RegionId | string | 区域编号 | 179 | | RegionName | string | 区域名称 | 180 | | SiteName | string | 站点名称 | 181 | | Message | string | 信息描述 | 182 | 183 | 184 | 185 | ### 2.DescribeSpecInfo 186 | 187 | **Action:** DescribeSpecInfo 188 | 189 | **描述:** 获取某个站点支持的MongoDB产品类型以及规格 190 | 191 | **请求地址:** cdsapi.capitalonline.net/mongodb/v1 192 | 193 | **请求方法:** GET 194 | 195 | **请求参数:** 196 | 197 | | 参数名 | 必选 | 类型 | 说明 | 198 | | :------- | :--- | :----- | -------- | 199 | | RegionId | 是 | string | 站点编号 | 200 | 201 | **请求示例:** 202 | 203 | ```python 204 | def get_mongodb_spec_info(RegionId): 205 | """ 206 | 获取某个站点支持的Mongodb产品类型以及规格 207 | :param RegionId: 208 | """ 209 | action = "DescribeSpecInfo" 210 | method = "GET" 211 | param = { 212 | "RegionId": RegionId 213 | } 214 | url = get_signature(action, AK, AccessKeySecret, method, MONGODB_URL, param) 215 | res = requests.get(url) 216 | result = json.loads(res.content) 217 | result = json.dumps(result) # json格式化 218 | print(result) 219 | ``` 220 | 221 | **返回示例:** 222 | 223 | ```json 224 | { 225 | "Code": "Success", 226 | "Data": { 227 | "ProductName": "mongodb", 228 | "Products": [{ 229 | "Architectures": [{ 230 | "ArchitectureName": "副本集", 231 | "ComputeRoles": [{ 232 | "ComputeName": "高性能型", 233 | "Standards": { 234 | "AttachDisk": [{ 235 | "BasicIops": "3000", 236 | "DiskMax": 2000, 237 | "DiskMaxExpand": 2000, 238 | "DiskMin": 100, 239 | "DiskName": "性能型", 240 | "DiskStep": 100, 241 | "DiskUnit": "G", 242 | "DiskValue": "high_disk" 243 | }], 244 | "CpuRam": [{ 245 | "CPU": 1, 246 | "Name": "1C2G", 247 | "PaasGoodsId": 7292, 248 | "RAM": 2 249 | }, { 250 | "CPU": 2, 251 | "Name": "2C4G", 252 | "PaasGoodsId": 7295, 253 | "RAM": 4 254 | }, { 255 | "CPU": 4, 256 | "Name": "4C8G", 257 | "PaasGoodsId": 7298, 258 | "RAM": 8 259 | }, { 260 | "CPU": 8, 261 | "Name": "8C16G", 262 | "PaasGoodsId": 7301, 263 | "RAM": 16 264 | }, { 265 | "CPU": 8, 266 | "Name": "8C32G", 267 | "PaasGoodsId": 7307, 268 | "RAM": 32 269 | }, { 270 | "CPU": 8, 271 | "Name": "8C24G", 272 | "PaasGoodsId": 7304, 273 | "RAM": 24 274 | }] 275 | } 276 | }], 277 | "EnginesType": ["WiredTiger"], 278 | "NetworkLinks": [{ 279 | "DescDetail": "默认链路:服务实例占用VDC私有网络IP地址,适用于对延迟敏感类型的应用。", 280 | "LinkType": "default_link", 281 | "Name": "默认链路", 282 | "SplitRwSwitch": 1 283 | }], 284 | "SubProductName": "MongoDB 副本集版" 285 | }], 286 | "Version": "3.4.21" 287 | }], 288 | "RegionId": "CN_Hongkong_A" 289 | }, 290 | "Message": "Success.", 291 | "TaskId": "" 292 | } 293 | ``` 294 | 295 | **返回参数说明:** 296 | 297 | | 参数名 | 类型 | 说明 | 298 | | :--------------- | :----- | ------------------------------------------------------------ | 299 | | Message | string | 信息描述 | 300 | | Code | string | 状态码 | 301 | | TaskId | string | 任务Id | 302 | | Data | dict | 数据 | 303 | | Products | list | 该类产品支持的产品列表 | 304 | | ProductName | string | 产品名称 | 305 | | SubProductName | string | 子产品名称 | 306 | | Version | string | 产品支持的版本 | 307 | | Architectures | string | 产品支持的架构 | 308 | | ArchitectureName | string | 架构名称 | 309 | | NetworkLinks | list | 此架构支持的链路类型 | 310 | | DescDetail | string | 链路类型描述 | 311 | | LinkType | string | 链路类型“英文” | 312 | | Name | string | 链路类型“中文” | 313 | | ComputeRoles | list | 支持的计算类型,不同的计算类型支持不同规格,并支持添加不同类型的硬盘 | 314 | | Standards | dict | 该类型支持的规格 | 315 | | CpuRam | list | 支持的规格列表 | 316 | | CPU | int | 规格CPU大小 | 317 | | RAM | int | 规格RAM大小 | 318 | | Name | string | 规格名称 | 319 | | PaasGoodsId | int | 具体的产品编号,根据产品编号确定购买哪一种规格 | 320 | | AttachDisk | list | 该类型规格能够添加的磁盘类型列表 | 321 | | DiskMax | int | 单次支持最大规格的磁盘 | 322 | | DiskValue | string | 磁盘类型,用于创建服务实例指定磁盘类型 (创建服务时候使用) | 323 | | BasicIops | string | 基础的磁盘的iops | 324 | | DiskUnit | string | 磁盘规格单位 | 325 | | DiskName | string | 磁盘类型名称 | 326 | | DiskMaxExpand | string | 磁盘最大可扩容大小 | 327 | | DiskMin | string | 磁盘最小大小 | 328 | | DiskStep | string | 磁盘扩容大小 | 329 | | EnginesType | string | 引擎类型 | 330 | 331 | 332 | 333 | ### 3.CreateDBInstance 334 | 335 | **Action:** CreateDBInstance 336 | 337 | **描述:** 创建MongoDB云数据库实例 338 | 339 | **请求地址:** cdsapi.capitalonline.net/mongodb/v1 340 | 341 | **请求方法:** POST 342 | 343 | **请求参数:** 344 | 345 | | 参数名 | 必选 | 类型 | 说明 | 346 | | :----------- | :--- | :----- | --------------------------------------------------------- | 347 | | RegionId | 是 | string | 站点编号 | 348 | | VdcId | 是 | string | 数据中心的编号 | 349 | | BasePipeId | 是 | string | 数据中心的私网编号,创建服务将按这个私网分配id | 350 | | InstanceName | 是 | string | 实例名称 | 351 | | PaasGoodsId | 是 | int | 产品的规格编号,注意:对比旧版使用Integer类型 | 352 | | DiskType | 是 | string | 磁盘类型 | 353 | | DiskValue | 是 | int | 磁盘大小 | 354 | | Password | 是 | string | Mongodb 最高权限数据库密码 | 355 | | Version | 否 | string | 实例的版本,默认4.0.3,参数范围["4.0.3","3.6.7","3.2.21"] | 356 | 357 | **请求示例:** 358 | 359 | ```python 360 | def create_mongodb(): 361 | """ 362 | 创建MongoDB实例 363 | """ 364 | action = "CreateDBInstance" 365 | method = "POST" 366 | param = {} 367 | url = get_signature(action, AK, AccessKeySecret, method, MONGODB_URL, param=param) 368 | body = { 369 | "RegionId": "******", 370 | "VdcId": "*******", 371 | "BasePipeId": "******", 372 | "InstanceName": "******", 373 | "PaasGoodsId": "******", 374 | "DiskType": "high_disk", 375 | "DiskValue": 100, 376 | "Version":"4.0.3", 377 | "Password": "******", 378 | } 379 | 380 | res = requests.post(url, json=body) 381 | result = json.loads(res.content) 382 | print(result) 383 | ``` 384 | 385 | **返回示例:** 386 | 387 | ```json 388 | { 389 | "Code": "Success", 390 | "Data": { 391 | "InstanceUuid":"****************" 392 | }, 393 | "Message": "Success.", 394 | "TaskId": "" 395 | } 396 | ``` 397 | 398 | **返回参数说明:** 399 | 400 | | 参数名 | 类型 | 说明 | 401 | | :------ | :----- | -------- | 402 | | Code | string | 状态码 | 403 | | Data | dict | 数据 | 404 | | InstanceUuid | string | 实例的编码 | 405 | | Message | string | 信息描述 | 406 | | TaskId | string | 任务id | 407 | 408 | 409 | 410 | ### 4.DescribeDBInstances 411 | 412 | **Action:** DescribeDBInstances 413 | 414 | **描述:** 获取MongoDB实例列表(支持常见字段过滤:实例编号、实例名称、实例IP) 415 | 416 | **请求地址:** cdsapi.capitalonline.net/mongodb/v1 417 | 418 | **请求方法:** GET 419 | 420 | **请求参数:** 421 | 422 | | 参数名 | 必选 | 类型 | 说明 | 423 | | :----------- | :--- | :----- | ---------------- | 424 | | InstanceUuid | 否 | string | 要过滤的实例编号 | 425 | | InstanceName | 否 | string | 要过滤的实例名称 | 426 | | IP | 否 | string | 要过滤的实例ip | 427 | 428 | **请求示例:** 429 | 430 | ```python 431 | def get_mongodb_instances_list(): 432 | """ 433 | 获取Mongodb实例列表(可根据ip、instance_uuid、instance_name过滤) 434 | """ 435 | action = "DescribeDBInstances" 436 | method = "GET" 437 | param = { 438 | "IP": "66.66" 439 | } 440 | url = get_signature(action, AK, AccessKeySecret, method, MONGODB_URL, param) 441 | res = requests.get(url) 442 | result = json.loads(res.content) 443 | print(result) 444 | ``` 445 | 446 | **返回示例:** 447 | 448 | ```json 449 | { 450 | "Code": "Success", 451 | "Data": [{ 452 | "CloneServices": null, 453 | "DisplayName": "亚太地区-香港-可用区A", 454 | "IP": "66.66.0.44", 455 | "InstanceName": "test-mongodb", 456 | "InstanceUuid": "9a5a796c-78ab-4b1c-88a4-ba9d9e8c996b", 457 | "LinkType": "default_link", 458 | "LinkTypeStr": "默认链路", 459 | "MasterInfo": "", 460 | "Port": 27017, 461 | "Ram": 2048, 462 | "RegionId": "CN_Hongkong_A", 463 | "RelationService": null, 464 | "ResourceId": "71bf731e-7cc8-4307-8408-4952e4dcd470", 465 | "Status": "RUNNING", 466 | "StatusStr": "运行中", 467 | "SubProductName": "MongoDB 副本集版", 468 | "VdcId": "d459c74b-d60e-4f28-adbb-67be402f76f3", 469 | "VdcName": "香港PaaS", 470 | "Version": "4.0.3" 471 | }], 472 | "Message": "Success." 473 | } 474 | ``` 475 | 476 | **返回参数说明:** 477 | 478 | | 参数名 | 类型 | 说明 | 479 | | :-------------- | :----- | ------------------------ | 480 | | Code | string | 状态码 | 481 | | Data | dict | 数据 | 482 | | CloneServices | list | 克隆的临时实例列表 | 483 | | DisplayName | string | 可用区 | 484 | | IP | string | 数据库的连接的IP | 485 | | InstanceName | string | 实例名称 | 486 | | InstanceUuid | string | 实例编号 | 487 | | LinkType | string | 链路类型名称 | 488 | | LinkTypeStr | string | 链路类型名称对应中文 | 489 | | MasterInfo | dict | 从属集群,只读服务会有值 | 490 | | Port | int | 连接的端口 | 491 | | Ram | int | 内存 单位M | 492 | | RegionId | string | 站点编号 | 493 | | RelationService | dict | 相关联的服务实例 | 494 | | Status | string | 实例状态 | 495 | | StatusStr | string | 状态对应的中文 | 496 | | SubProductName | string | 子产品的名字 | 497 | | VdcId | string | 数据中心的编号 | 498 | | VdcName | string | 数据中心名称 | 499 | | Version | string | 服务版本 | 500 | | Message | string | 信息描述 | 501 | 502 | 503 | 504 | ### 5.DeleteDBInstance 505 | 506 | **Action:** DeleteDBInstance 507 | 508 | **描述:** 删除MongoDB实例 509 | 510 | **请求地址:** cdsapi.capitalonline.net/mongodb/v1 511 | 512 | **请求方法:** POST 513 | 514 | **请求参数:** 515 | 516 | | 参数名 | 必选 | 类型 | 说明 | 517 | | :----------- | :--- | :----- | -------- | 518 | | InstanceUuid | 否 | string | 实例编号 | 519 | 520 | **请求示例:** 521 | 522 | ```python 523 | def delete_mongodb(instance_uuid, ): 524 | """ 525 | 删除MongoDB实例 526 | :param instance_uuid: 527 | """ 528 | action = "DeleteDBInstance" 529 | method = "POST" 530 | param = {} 531 | url = get_signature(action, AK, AccessKeySecret, method, MONGODB_URL, param=param) 532 | body = { 533 | "InstanceUuid": instance_uuid, 534 | } 535 | 536 | res = requests.post(url, json=body) 537 | result = json.loads(res.content) 538 | print(result) 539 | ``` 540 | 541 | **返回示例:** 542 | 543 | ```json 544 | { 545 | "Code": "Success", 546 | "Data": {}, 547 | "Message": "Success.", 548 | "TaskId": "***************" 549 | } 550 | ``` 551 | 552 | **返回参数说明:** 553 | 554 | | 参数名 | 类型 | 说明 | 555 | | :------ | :----- | -------- | 556 | | Code | string | 状态码 | 557 | | Data | dict | 数据 | 558 | | Message | string | 信息描述 | 559 | | TaskId | string | 任务编号 | 560 | 561 | ### 6.ModifyDBInstanceSpec 562 | 563 | **Action:** ModifyDBInstanceSpec 564 | 565 | **描述:** 修改MongoDB规格或存储空间 566 | 567 | **请求地址:** cdsapi.capitalonline.net/mongodb/v1 568 | 569 | **请求方法:** POST 570 | 571 | **请求参数:** 572 | 573 | | 参数名 | 必选 | 类型 | 说明 | 574 | | :----------- | :--- | :----- | ------------------------------------------------------------ | 575 | | InstanceUuid | 是 | string | 实例编号 | 576 | | PaasGoodsId | 否 | string | 产品的规格编号 | 577 | | DiskType | 否 | string | 磁盘类型,只能跟最开始购买时候类型一致。不能一个实例加多种类型磁盘,比如最开始添加高性能磁盘,后面也只能选择添加高性能磁盘 | 578 | | DiskValue | 否 | int | 磁盘大小 | 579 | 580 | **请求示例:** 581 | 582 | ```python 583 | def update_mongodb(self, instanceuuid, paasgoodsid, diskvalue): 584 | action = "ModifyDBInstanceSpec" 585 | method = "POST" 586 | param = {} 587 | url = get_signature(action, self.AK, self.AccessKeySecret, method, self.MongoDBUrl, param) 588 | body = { 589 | "InstanceUuid": instanceuuid, 590 | "PaasGoodsId": paasgoodsid, 591 | "DiskType": "ssd_disk", 592 | "DiskValue": diskvalue 593 | } 594 | print(body) 595 | res = requests.post(url, json=body) 596 | result = json.loads(res.content) 597 | print(result) 598 | return result 599 | ``` 600 | 601 | **返回示例:** 602 | 603 | ```json 604 | { 605 | "Code":"Success", 606 | "Data":{ 607 | "InstanceUuid":"****************" 608 | }, 609 | "Message":"success" 610 | } 611 | ``` 612 | 613 | **返回参数说明:** 614 | 615 | | 参数名 | 类型 | 说明 | 616 | | :------ | :------------------------- | -------- | 617 | | Code | string | 状态码 | 618 | | Data | object of [Data](#dataobj) | 数据 | 619 | | Message | string | 信息描述 | 620 | 621 | #### DataOBJ 622 | 623 | | 参数名 | 类型 | 说明 | 624 | | :----------- | :----- | -------- | 625 | | InstanceUuid | string | 实例编号 | 626 | --------------------------------------------------------------------------------