全部产品
云市场

Python SDK 使用示例

更新时间:2019-01-09 11:20:11

前提条件

安装 ECI SDK

ECI Python SDK 的 PyPI 地址:

https://pypi.org/project/aliyun-python-sdk-eci/

安装:

pip install aliyun-python-sdk-eci==1.0.3

如果提示超时,则添加超时选项:

pip --default-timeout=100 install aliyun-python-sdk-eci==1.0.3

如果需要升级到最新版本,则使用以下命令:

pip install --upgrade aliyun-python-sdk-eci

创建 Client

接口参数

名称 类型 是否必须 描述
region string 实例所属的地域 ID
accessKey string 用户 AccessKey
secretKey string 用户 SecretKey
返回参数
名称 类型 描述
eciClient aliyunsdkcore.client.AcsClient 用户调用 ECI 接口的对象
示例代码
  1. from aliyunsdkcore.client import AcsClient
  2. eciClient = AcsClient(accessKey, secretKey, region)

创建容器组

接口参数 CreateContainerGroupRequest

名称 类型 是否必须 描述
SecurityGroupId string 安全组 ID
VSwitchId string 虚机交换机 ID
ContainerGroupName string 实例名称,不要求唯一。长度为[2, 128]个英文小写字母、数字或者连字符(-)。不能以连接字符开始或结尾
InitContainers Container[] 初始化容器列表
Containers Container[] 容器列表
ZoneId string 实例所属的可用区编号,空表示由系统选择,默认值:空
RestartPolicy string 实例重启策略,默认:Always
Tags Tag[] 容器标签
ImageRegistryCredentials ImageRegistryCredential[] 镜像仓库登录信息
Volumes Volume[] 数据卷列表
EipInstanceId string 弹性IP ID

返回参数 CreateContainerGroupResponse

名称 类型 描述
ContainerGroupId string 容器组 ID
RequestId string 请求 ID
示例代码
  1. from aliyunsdkeci.request.v20180808.CreateContainerGroupRequest import CreateContainerGroupRequest
  2. request = CreateContainerGroupRequest()
  3. request.set_SecurityGroupId(secureGroup-xxx)
  4. request.set_VSwitchId(vSwitch-xxx)
  5. request.set_ContainerGroupName(name-xxx)
  6. request.set_EipInstanceId(eip-xxx)
  7. request.set_RestartPolicy('Always')
  8. #volumes,第一个为EmptyDirVolume,用于容器间的数据共享;第二个为NFSVolume, 加载阿里云的NAS
  9. volume1 = {
  10. 'Name': 'default-volume1-empty',
  11. 'Type': 'EmptyDirVolume',
  12. }
  13. #NFS volume需要配置您的NFS Server
  14. volume2 = {
  15. 'Name': 'default-volume2-nfs',
  16. 'Type': 'NFSVolume',
  17. 'NFSVolume.Path': '/',
  18. 'NFSVolume.Server': 'yourserver.cn-hangzhou.nas.aliyuncs.com',
  19. 'NFSVolume.ReadOnly': False,
  20. }
  21. #Content需要BASE64编码
  22. configFileToPath1 = {
  23. 'Path': 'nginx-proxy.conf',
  24. 'Content': 'aGVsbG8gd29ybGQ=',
  25. }
  26. configFileToPath2 = {
  27. 'Path': 'access.lua',
  28. 'Content': 'aGVsbG8gd29ybGQ=',
  29. }
  30. volume3 = {
  31. 'Name': 'default-volume3-config',
  32. 'Type': 'ConfigFileVolume',
  33. 'ConfigFileVolume.ConfigFileToPaths': [configFileToPath1, configFileToPath2],
  34. }
  35. #安装volume到containerGroup
  36. request.set_Volumes([volume1, volume2, volume3])
  37. #tags
  38. tag1 = {
  39. 'Key': 'test',
  40. 'Value': 'sdk-python',
  41. }
  42. tag2 = {
  43. 'Key': 'app',
  44. 'Value': 'nginx',
  45. }
  46. #为containerGroup添加tag
  47. request.set_Tags([tag1, tag2])
  48. #dns options
  49. option1 = {
  50. 'Name': 'name1',
  51. 'Value': 'value1',
  52. }
  53. option2 = {
  54. 'Name': 'name2',
  55. 'Value': 'value2',
  56. }
  57. #DNS config
  58. request.set_DnsConfigOptions([option1, option2])
  59. #request.set_DnsConfigNameServers(['8.8.8.8', '127.0.0.1'])
  60. #request.set_DnsConfigSearchs(['ns.svc.cluster.local'])
  61. #volumeMounts,挂载containerGroup安装的数据卷到容器的目录
  62. volume_mount1 = {
  63. 'Name': 'default-volume1-empty',
  64. 'MountPath': '/usr/share',
  65. 'ReadOnly': False,
  66. }
  67. volume_mount2 = {
  68. 'Name': 'default-volume2-nfs',
  69. 'MountPath': '/pod-data',
  70. 'ReadOnly': False,
  71. }
  72. volume_mount3 = {
  73. 'Name': 'default-volume1-empty',
  74. 'MountPath': '/usr/share/nginx/html',
  75. 'ReadOnly': False,
  76. }
  77. volume_mount4 = {
  78. 'Name': 'default-volume3-config',
  79. 'MountPath': '/etc/liumi/',
  80. 'ReadOnly': False,
  81. }
  82. #environment variable
  83. env ={
  84. 'Key': 'MESSAGE',
  85. 'Value': 'hello world',
  86. }
  87. #container ports
  88. port = {
  89. 'Protocol':'TCP',
  90. 'Port': 8080,
  91. }
  92. #initContainers
  93. initContainer = {
  94. 'Image': 'registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0',
  95. 'Name': 'init-liu',
  96. # cpu 和 memory 规格按照文档规范按需设置
  97. 'Cpu': 1.0,
  98. 'Memory': 2.0,
  99. 'VolumeMounts': [volume_mount1, volume_mount2],
  100. 'Commands': ['/bin/sh'],
  101. 'Args': ['-c', 'cp -r /pod-data/ /usr/share/'],
  102. 'EnvironmentVars': [env],
  103. 'Ports': [port],
  104. }
  105. # containers
  106. container1 = {
  107. 'Image': 'registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0',
  108. 'Name': 'busy-liu',
  109. 'Cpu': 0.5,
  110. 'Memory': 1.0,
  111. 'ImagePullPolicy': 'Always',
  112. 'Commands':['/bin/sh'],
  113. 'Args': ['-c', 'cp -r /pod-data/ /usr/share/'],
  114. 'VolumeMounts': [volume_mount1, volume_mount2],
  115. }
  116. container2 = {
  117. 'Image': 'registry-vpc.cn-hangzhou.aliyuncs.com/jovi/nginx:alpine',
  118. 'Name': 'nginx-liu',
  119. 'Cpu': 0.5,
  120. 'Memory': 1.0,
  121. 'ImagePullPolicy': 'Always',
  122. 'VolumeMounts': [volume_mount3, volume_mount4],
  123. 'EnvironmentVars': [env],
  124. 'Ports': [port],
  125. ##'ReadinessProbe.HttpGet.Path':'/heath',
  126. ##'ReadinessProbe.HttpGet.Port': 80,
  127. #'ReadinessProbe.Exec.Commands': ['/bin/sh', '-c', 'cat /etc/nginx/nginx.conf'],
  128. ##'ReadinessProbe.TcpSocket.Port': 80,
  129. #'ReadinessProbe.InitialDelaySeconds': 10,
  130. #'ReadinessProbe.PeriodSeconds': 10,
  131. #'ReadinessProbe.FailureThreshold': 3,
  132. #'ReadinessProbe.SuccessThreshold': 3,
  133. #'ReadinessProbe.TimeoutSeconds': 5,
  134. #'LivenessProbe.Exec.Commands': ['/bin/sh', '-c', 'cat /etc/nginx/nginx.conf'],
  135. ##'LivenessProbe.TcpSocket.Port': 80,
  136. #'LivenessProbe.InitialDelaySeconds': 10,
  137. #'LivenessProbe.PeriodSeconds': 10,
  138. #'LivenessProbe.FailureThreshold': 3,
  139. #'LivenessProbe.SuccessThreshold': 1,
  140. #'LivenessProbe.TimeoutSeconds': 5,
  141. #'SecurityContext.Capability.Adds': ['NET_ADMIN'],
  142. #'SecurityContext.ReadOnlyRootFilesystem': True,
  143. #'SecurityContext.RunAsUser': 1337,
  144. }
  145. request.set_InitContainers([initContainer])
  146. request.set_Containers([container1,container2])
  147. response = eciClient.do_action_with_exception(request)
  148. print response

输出结果

  1. {"ContainerGroupId":"eci-bp1jfs45an09sg8k9cnf","RequestId":"C8BE6D53-2297-4EB8-8C7F-9B71A07B4545"}

删除容器组

接口参数 DeleteContainerGroupRequest

名称 类型 是否必须 描述
ContainerGroupId string 容器组 ID

返回参数 DeleteContainerGroupResponse

名称 类型 描述
RequestId string 请求 ID
示例代码
  1. from aliyunsdkeci.request.v20180808.DeleteContainerGroupRequest import DeleteContainerGroupRequest
  2. request = DeleteContainerGroupRequest()
  3. request.set_ContainerGroupId('eci-xxx')
  4. response = eciClient.do_action_with_exception(request)
  5. print response

输出结果

  1. {"RequestId":"8050300F-3D96-46FC-8AC1-6485080B7992"}

批量查询已创建容器组

接口参数 DescribeContainerGroupsRequest

名称 类型 是否必须 描述
ZoneId string 实例所属的可用区编号,空表示由系统选择,默认值:空
VSwitchId string 虚机交换机 ID
NextToken string 用来返回更多结果。第一次查询不需要提供这个参数,后续查询的token从返回结果中获取
Limit int 限定此次返回资源的数量。如果不设定,默认返回20,最大不能超过20。返回结果可能小于指定的数量,但不会多于指定的数量
Tags Tag[] 容器标签,最多10
ContainerGroupId string[] 容器组 ID,最多20
ContainerGroupName string 容器组名

返回参数 DescribeContainerGroupsResponse

名称 类型 描述
RequestId string 请求 ID
NextToken string 用来返回更多结果。后续查询的token从返回结果中获取
TotalCount int 容器组数量
ContainerGroups ContainerGroup[] 容器组详细内容
示例代码
  1. from aliyunsdkeci.request.v20180808.DescribeContainerGroupsRequest import DescribeContainerGroupsRequest
  2. request = DescribeContainerGroupsRequest()
  3. #注意:containerGroupIds数组需要编码为json格式传入
  4. request.set_ContainerGroupIds(json.dumps(ContainerGroupIds))
  5. #支持带tag过滤的查询
  6. tag = {
  7. 'Key': 'test',
  8. 'Value': 'sdk-python',
  9. }
  10. request.set_Tags([tag])
  11. response = eciClient.do_action_with_exception(request)
  12. print response

输出结果

  1. {
  2. "ContainerGroups": [
  3. {
  4. "ContainerGroupId": "eci-bp1ddjhfcjtrwvpcpxem",
  5. "ContainerGroupName": "test-python-sdk",
  6. "Containers": [
  7. {
  8. "Args": [
  9. "-c",
  10. "cp -r /pod-data/ /usr/share/ && sleep 3600"
  11. ],
  12. "Commands": [
  13. "/bin/sh"
  14. ],
  15. "Cpu": 0.5,
  16. "CurrentState": {
  17. "FinishTime": "",
  18. "StartTime": "2019-01-03T09:28:00Z",
  19. "State": "Running"
  20. },
  21. "EnvironmentVars": [],
  22. "Image": "registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0",
  23. "ImagePullPolicy": "Always",
  24. "LivenessProbe": {
  25. "HttpGet": {},
  26. "TcpSocket": {}
  27. },
  28. "Memory": 1.0,
  29. "Name": "busy-liu",
  30. "Ports": [],
  31. "PreviousState": {
  32. "FinishTime": "",
  33. "StartTime": "",
  34. "State": ""
  35. },
  36. "ReadinessProbe": {
  37. "HttpGet": {},
  38. "TcpSocket": {}
  39. },
  40. "RestartCount": 0,
  41. "SecurityContext": {
  42. "Capability": {}
  43. },
  44. "VolumeMounts": [
  45. {
  46. "MountPath": "/usr/share",
  47. "Name": "default-volume1-empty",
  48. "ReadOnly": false
  49. },
  50. {
  51. "MountPath": "/pod-data",
  52. "Name": "default-volume2-nfs",
  53. "ReadOnly": false
  54. }
  55. ],
  56. "WorkingDir": ""
  57. },
  58. {
  59. "Cpu": 0.5,
  60. "CurrentState": {
  61. "FinishTime": "",
  62. "StartTime": "2019-01-03T09:28:02Z",
  63. "State": "Running"
  64. },
  65. "EnvironmentVars": [
  66. {
  67. "Key": "MESSAGE",
  68. "Value": "hello world"
  69. }
  70. ],
  71. "Image": "registry-vpc.cn-hangzhou.aliyuncs.com/jovi/nginx:alpine",
  72. "ImagePullPolicy": "Always",
  73. "LivenessProbe": {
  74. "HttpGet": {},
  75. "TcpSocket": {}
  76. },
  77. "Memory": 1.0,
  78. "Name": "nginx-liu",
  79. "Ports": [
  80. {
  81. "Port": 8080,
  82. "Protocol": "TCP"
  83. }
  84. ],
  85. "PreviousState": {
  86. "FinishTime": "",
  87. "StartTime": "",
  88. "State": ""
  89. },
  90. "ReadinessProbe": {
  91. "HttpGet": {},
  92. "TcpSocket": {}
  93. },
  94. "RestartCount": 0,
  95. "SecurityContext": {
  96. "Capability": {}
  97. },
  98. "VolumeMounts": [
  99. {
  100. "MountPath": "/usr/share/nginx/html",
  101. "Name": "default-volume1-empty",
  102. "ReadOnly": false
  103. },
  104. {
  105. "MountPath": "/etc/liumi/",
  106. "Name": "default-volume3-config",
  107. "ReadOnly": false
  108. }
  109. ],
  110. "WorkingDir": ""
  111. }
  112. ],
  113. "Cpu": 1.0,
  114. "CreationTime": "2019-01-03T09:27:49Z",
  115. "DnsConfig": {
  116. "Options": [
  117. {
  118. "Name": "name1",
  119. "Value": "value1"
  120. },
  121. {
  122. "Name": "name2",
  123. "Value": "value2"
  124. }
  125. ]
  126. },
  127. "EniInstanceId": "eni-bp1hyp5oips8yau23dyk",
  128. "Events": [
  129. {
  130. "Count": 1,
  131. "FirstTimestamp": "2019-01-03T09:27:56Z",
  132. "LastTimestamp": "2019-01-03T09:27:56Z",
  133. "Message": "MountVolume.SetUp succeeded for volume \"default-volume3-config\" ",
  134. "Name": "test-python-sdk.15764c89a2da411f",
  135. "Reason": "SuccessfulMountVolume",
  136. "Type": "Normal"
  137. },
  138. {
  139. "Count": 1,
  140. "FirstTimestamp": "2019-01-03T09:27:56Z",
  141. "LastTimestamp": "2019-01-03T09:27:56Z",
  142. "Message": "MountVolume.SetUp succeeded for volume \"default-volume1-empty\" ",
  143. "Name": "test-python-sdk.15764c89a31002e6",
  144. "Reason": "SuccessfulMountVolume",
  145. "Type": "Normal"
  146. },
  147. {
  148. "Count": 1,
  149. "FirstTimestamp": "2019-01-03T09:27:57Z",
  150. "LastTimestamp": "2019-01-03T09:27:57Z",
  151. "Message": "MountVolume.SetUp succeeded for volume \"default-volume2-nfs\" ",
  152. "Name": "test-python-sdk.15764c89e21f9ab6",
  153. "Reason": "SuccessfulMountVolume",
  154. "Type": "Normal"
  155. },
  156. {
  157. "Count": 1,
  158. "FirstTimestamp": "2019-01-03T09:27:57Z",
  159. "LastTimestamp": "2019-01-03T09:27:57Z",
  160. "Message": "pulling image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\"",
  161. "Name": "test-python-sdk.15764c89e7f364de",
  162. "Reason": "Pulling",
  163. "Type": "Normal"
  164. },
  165. {
  166. "Count": 1,
  167. "FirstTimestamp": "2019-01-03T09:27:58Z",
  168. "LastTimestamp": "2019-01-03T09:27:58Z",
  169. "Message": "Successfully pulled image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\"",
  170. "Name": "test-python-sdk.15764c8a30f0c918",
  171. "Reason": "Pulled",
  172. "Type": "Normal"
  173. },
  174. {
  175. "Count": 1,
  176. "FirstTimestamp": "2019-01-03T09:27:58Z",
  177. "LastTimestamp": "2019-01-03T09:27:58Z",
  178. "Message": "Created container",
  179. "Name": "test-python-sdk.15764c8a340debbf",
  180. "Reason": "Created",
  181. "Type": "Normal"
  182. },
  183. {
  184. "Count": 1,
  185. "FirstTimestamp": "2019-01-03T09:27:58Z",
  186. "LastTimestamp": "2019-01-03T09:27:58Z",
  187. "Message": "Started container",
  188. "Name": "test-python-sdk.15764c8a37a0c791",
  189. "Reason": "Started",
  190. "Type": "Normal"
  191. },
  192. {
  193. "Count": 1,
  194. "FirstTimestamp": "2019-01-03T09:27:59Z",
  195. "LastTimestamp": "2019-01-03T09:27:59Z",
  196. "Message": "pulling image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\"",
  197. "Name": "test-python-sdk.15764c8a77ad5645",
  198. "Reason": "Pulling",
  199. "Type": "Normal"
  200. },
  201. {
  202. "Count": 1,
  203. "FirstTimestamp": "2019-01-03T09:28:00Z",
  204. "LastTimestamp": "2019-01-03T09:28:00Z",
  205. "Message": "Successfully pulled image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\"",
  206. "Name": "test-python-sdk.15764c8aa1a02fb9",
  207. "Reason": "Pulled",
  208. "Type": "Normal"
  209. },
  210. {
  211. "Count": 1,
  212. "FirstTimestamp": "2019-01-03T09:28:00Z",
  213. "LastTimestamp": "2019-01-03T09:28:00Z",
  214. "Message": "Created container",
  215. "Name": "test-python-sdk.15764c8aa3d4183c",
  216. "Reason": "Created",
  217. "Type": "Normal"
  218. },
  219. {
  220. "Count": 1,
  221. "FirstTimestamp": "2019-01-03T09:28:00Z",
  222. "LastTimestamp": "2019-01-03T09:28:00Z",
  223. "Message": "Started container",
  224. "Name": "test-python-sdk.15764c8aa710b3f9",
  225. "Reason": "Started",
  226. "Type": "Normal"
  227. },
  228. {
  229. "Count": 1,
  230. "FirstTimestamp": "2019-01-03T09:28:00Z",
  231. "LastTimestamp": "2019-01-03T09:28:00Z",
  232. "Message": "pulling image \"registry-vpc.cn-hangzhou.aliyuncs.com/jovi/nginx:alpine\"",
  233. "Name": "test-python-sdk.15764c8aa71a2a14",
  234. "Reason": "Pulling",
  235. "Type": "Normal"
  236. },
  237. {
  238. "Count": 1,
  239. "FirstTimestamp": "2019-01-03T09:28:02Z",
  240. "LastTimestamp": "2019-01-03T09:28:02Z",
  241. "Message": "Successfully pulled image \"registry-vpc.cn-hangzhou.aliyuncs.com/jovi/nginx:alpine\"",
  242. "Name": "test-python-sdk.15764c8b15c28c74",
  243. "Reason": "Pulled",
  244. "Type": "Normal"
  245. },
  246. {
  247. "Count": 1,
  248. "FirstTimestamp": "2019-01-03T09:28:02Z",
  249. "LastTimestamp": "2019-01-03T09:28:02Z",
  250. "Message": "Created container",
  251. "Name": "test-python-sdk.15764c8b185298b7",
  252. "Reason": "Created",
  253. "Type": "Normal"
  254. },
  255. {
  256. "Count": 1,
  257. "FirstTimestamp": "2019-01-03T09:28:02Z",
  258. "LastTimestamp": "2019-01-03T09:28:02Z",
  259. "Message": "Started container",
  260. "Name": "test-python-sdk.15764c8b1b9aee37",
  261. "Reason": "Started",
  262. "Type": "Normal"
  263. },
  264. {
  265. "Count": 1,
  266. "FirstTimestamp": "2019-01-03T09:33:37Z",
  267. "LastTimestamp": "2019-01-03T09:33:37Z",
  268. "Message": "Container image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\" already present on machine",
  269. "Name": "test-python-sdk.15764cd91ea636aa",
  270. "Reason": "Pulled",
  271. "Type": "Normal"
  272. },
  273. {
  274. "Count": 1,
  275. "FirstTimestamp": "2019-01-03T09:33:37Z",
  276. "LastTimestamp": "2019-01-03T09:33:37Z",
  277. "Message": "Created container",
  278. "Name": "test-python-sdk.15764cd92092af49",
  279. "Reason": "Created",
  280. "Type": "Normal"
  281. },
  282. {
  283. "Count": 1,
  284. "FirstTimestamp": "2019-01-03T09:33:37Z",
  285. "LastTimestamp": "2019-01-03T09:33:37Z",
  286. "Message": "Started container",
  287. "Name": "test-python-sdk.15764cd923f53212",
  288. "Reason": "Started",
  289. "Type": "Normal"
  290. },
  291. {
  292. "Count": 1,
  293. "FirstTimestamp": "2019-01-03T09:40:03Z",
  294. "LastTimestamp": "2019-01-03T09:40:03Z",
  295. "Message": "Container image \"registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0\" already present on machine",
  296. "Name": "test-python-sdk.15764d32fdfe8609",
  297. "Reason": "Pulled",
  298. "Type": "Normal"
  299. },
  300. {
  301. "Count": 1,
  302. "FirstTimestamp": "2019-01-03T09:40:03Z",
  303. "LastTimestamp": "2019-01-03T09:40:03Z",
  304. "Message": "Created container",
  305. "Name": "test-python-sdk.15764d33007fa5e5",
  306. "Reason": "Created",
  307. "Type": "Normal"
  308. },
  309. {
  310. "Count": 1,
  311. "FirstTimestamp": "2019-01-03T09:40:03Z",
  312. "LastTimestamp": "2019-01-03T09:40:03Z",
  313. "Message": "Started container",
  314. "Name": "test-python-sdk.15764d33042e3e93",
  315. "Reason": "Started",
  316. "Type": "Normal"
  317. }
  318. ],
  319. "InitContainers": [
  320. {
  321. "Args": [
  322. "-c",
  323. "cp -r /pod-data/ /usr/share/"
  324. ],
  325. "Command": [
  326. "/bin/sh"
  327. ],
  328. "Cpu": 1.0,
  329. "CurrentState": {
  330. "ExitCode": 0,
  331. "FinishTime": "2019-01-03T09:40:03Z",
  332. "Reason": "Completed",
  333. "StartTime": "2019-01-03T09:40:03Z",
  334. "State": "Terminated"
  335. },
  336. "EnvironmentVars": [
  337. {
  338. "Key": "MESSAGE",
  339. "Value": "hello world"
  340. }
  341. ],
  342. "Image": "registry-vpc.cn-hangzhou.aliyuncs.com/baz/busybox:1.0",
  343. "ImagePullPolicy": "IfNotPresent",
  344. "Memory": 2.0,
  345. "Name": "init-liu",
  346. "Ports": [
  347. {
  348. "Port": 8080,
  349. "Protocol": "TCP"
  350. }
  351. ],
  352. "PreviousState": {
  353. "FinishTime": "",
  354. "StartTime": "",
  355. "State": ""
  356. },
  357. "RestartCount": 0,
  358. "SecurityContext": {
  359. "Capability": {
  360. "Adds": [
  361. "NET_ADMIN"
  362. ]
  363. },
  364. "ReadOnlyRootFilesystem": true,
  365. "RunAsUser": 1337
  366. },
  367. "VolumeMounts": [
  368. {
  369. "MountPath": "/usr/share",
  370. "Name": "default-volume1-empty",
  371. "ReadOnly": false
  372. },
  373. {
  374. "MountPath": "/pod-data",
  375. "Name": "default-volume2-nfs",
  376. "ReadOnly": false
  377. }
  378. ],
  379. "WorkingDir": ""
  380. }
  381. ],
  382. "InternetIp": "",
  383. "IntranetIp": "192.168.1.218",
  384. "Memory": 2.0,
  385. "RegionId": "cn-hangzhou",
  386. "RestartPolicy": "Always",
  387. "SecurityGroupId": "sg-bp11zjwu3eumpw32memr",
  388. "Status": "Running",
  389. "SucceededTime": "",
  390. "Tags": [
  391. {
  392. "Key": "test",
  393. "Value": "sdk-python"
  394. },
  395. {
  396. "Key": "app",
  397. "Value": "nginx"
  398. }
  399. ],
  400. "VSwitchId": "vsw-bp1a6dake404nwul5yoec",
  401. "Volumes": [
  402. {
  403. "Name": "default-volume1-empty",
  404. "Type": "EmptyDirVolume"
  405. },
  406. {
  407. "NFSVolumePath": "/",
  408. "NFSVolumeReadOnly": false,
  409. "NFSVolumeServer": "0551049961-eqr13.cn-hangzhou.nas.aliyuncs.com",
  410. "Name": "default-volume2-nfs",
  411. "Type": "NFSVolume"
  412. },
  413. {
  414. "ConfigFileVolumeConfigFileToPaths": [
  415. {
  416. "Path": "nginx-proxy.conf"
  417. },
  418. {
  419. "Path": "access.lua"
  420. }
  421. ],
  422. "Name": "default-volume3-config",
  423. "Type": "ConfigFileVolume"
  424. }
  425. ],
  426. "ZoneId": "cn-hangzhou-g"
  427. }
  428. ],
  429. "NextToken": "",
  430. "RequestId": "3213275D-E2F9-4903-BE52-D0625A3C9F03",
  431. "TotalCount": 1
  432. }

查询容器日志

接口参数 DescribeContainerLogRequest

名称 类型 是否必须 描述
ContainerGroupId string 容器组 ID
ContainerName string 容器名
StartTime string UTC时间,RFC3339标准,例如:2018-08-02T15:00:00Z
Tail int 默认500行,最大2000行

返回参数 DescribeContainerLogResponse

名称 类型 描述
RequestId string 请求 ID
ContainerName string 容器名
Content string 日志内容
示例代码
  1. from aliyunsdkeci.request.v20180808.DescribeContainerLogRequest import DescribeContainerLogRequest
  2. request = DescribeContainerLogRequest()
  3. request.set_ContainerGroupId('eci-xxx')
  4. request.set_ContainerName(ContainerName)
  5. response = eciClient.do_action_with_exception(request)
  6. print response

输出结果

  1. {"RequestId":"0F333D18-51A0-43D3-A804-120921446EB8","ContainerName":"nginx","Content":"106.11.34.14 - - [27/Nov/2018:07:25:37 +0000] \"GET / HTTP/1.1\" 403 555 \"-\" \"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36\" \"-\"\n2018/11/27 07:25:37 [error] 6#6: *1 directory index of \"/usr/share/nginx/html/\" is forbidden, client: 106.11.34.14, server: localhost, request: \"GET / HTTP/1.1\", host: \"47.99.145.99\"\n2018/11/27 07:27:49 [error] 6#6: *3 directory index of \"/usr/share/nginx/html/\" is forbidden, client: 24.0.70.174, server: localhost, request: \"GET / HTTP/1.0\", host: \"1.2.3.4\"\n24.0.70.174 - - [27/Nov/2018:07:27:49 +0000] \"GET / HTTP/1.0\" 403 153 \"-\" \"-\" \"-\"\n50.29.137.33 - - [27/Nov/2018:07:34:00 +0000] \"GET / HTTP/1.0\" 403 153 \"-\" \"-\" \"-\"\n2018/11/27 07:34:00 [error] 6#6: *4 directory index of \"/usr/share/nginx/html/\" is forbidden, client: 50.29.137.33, server: localhost, request: \"GET / HTTP/1.0\", host: \"1.2.3.4\"\n"}