Skip to content

ucloud/ustack-sdk-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UCloudStack SDK Python

Python Version License

UCloudStack SDK Python 是 UCloudStack API 的 Python 客户端库。

安装

pip install ustack-sdk-python

或从源码安装:

pip install -r requirements.txt

快速开始

登陆控制台后获取公私钥,替换到代码中:

from ucloudstack.client import Client
from ucloudstack.services.apis.create_vm_instance_request import CreateVMInstanceRequest

client = Client({
    "base_url": "http://my_api_endpoint/api",  # 替换成平台的API端点
    # 替换成平台上获取的公/私钥
    "public_key": "my_public_key",
    "private_key": "my_private_key",
})

api = client.ucloudstack_client()

req = CreateVMInstanceRequest(
    Region="my_region",       # 替换成平台上的目标地域
    Name="sdk-example-vm",
    ImageID="image-xxx",      # 替换成平台上可用的镜像ID
    Password="my_vm_password",
    ChargeType="Dynamic",
    CPU=1,
    Memory=1024,
)

try:
    resp = api.create_vm_instance(req)
    print("resource id of the vm:", resp.VMID)
except Exception as e:
    print("error:", e)

Releases

Packages

Contributors

Languages