前提条件 安装 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 Demo示例 创建一个Eci实例 #!/usr/bin/env python #coding=utf-8 from aliyunsdkcore.client import AcsClient from aliyunsdkeci.request.v20180808.CreateContainerGroupRequest import CreateContainerGroupRequest client = AcsClient(' ', ' ', 'cn-hangzhou') request = CreateContainerGroupRequest() request.set_accept_format('json') request.set_SecurityGroupId("sg-bp13xej624v0pfqnf6dr") request.set_VSwitchId("vsw-bp1dmqtg608k99wmb90fk") request.set_ContainerGroupName("test") request.set_Containers([ { "Image": "nginx", "Name": "nginx", "Cpu": 2, "Memory": 4, "VolumeMount": [ "emptyVolume" ] } ]) request.set_Tags([ { "Key": "env", "Value": "test" } ]) request.set_Volumes([ { "Name": "emptyVolume", "Type": "EmptyDirVolume" } ]) response = client.do_action_with_exception(request)
print(str(response)) 成功返回数据 {"ContainerGroupId":"eci-bp1brvmc6xtpz2exk5zd","RequestId":"ED7ED3FA-AA2F-47CE-B45A-122B446751D8"} 删除指定Eci实例 #!/usr/bin/env python #coding=utf-8 from aliyunsdkcore.client import AcsClient from aliyunsdkeci.request.v20180808.DeleteContainerGroupRequest import DeleteContainerGroupRequest client = AcsClient(' ', ' ', 'cn-hangzhou') request = DeleteContainerGroupRequest() request.set_accept_format('json') request.set_ContainerGroupId("eci-bp1brvmc6xtpz2exk5zd") response = client.do_action_with_exception(request)
print(str(response)) 成功返回数据 {"RequestId":"81F15B16-B5AD-4081-924A-F91D9FF8E402"}
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。