开发者社区> 问答> 正文

如何使用Python SDK?

如何使用Python SDK?

展开
收起
小天使爱美 2020-03-20 19:32:48 1174 0
1 条回答
写回答
取消 提交回答
  • 前提条件 安装 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)

    python2: print(response)

    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)

    python2: print(response)

    print(str(response)) 成功返回数据 {"RequestId":"81F15B16-B5AD-4081-924A-F91D9FF8E402"}

    2020-03-20 19:33:06
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
From Python Scikit-Learn to Sc 立即下载
Data Pre-Processing in Python: 立即下载
双剑合璧-Python和大数据计算平台的结合 立即下载