CreateInstances

1. 接口描述

调用本接口用于创建一个或多个指定配置的虚拟机实例。

准备工作

注意事项

  • 实例创建成功后将自动开机启动,实例状态变为RUNNING(运行中)。

  • 预付费实例的购买会预先扣除本次实例购买所需金额,如果余额不足,请求将会失败。后付费实例购买时需要确保账户账号状态正常。

  • 调用本接口创建实例,支持代金券自动抵扣,详情请参考代金券选用规则。

  • 本接口为异步接口,当创建实例请求下发成功后会返回一个实例ID列表,此时创建实例操作并未立即完成。在此期间实例的状态将会处于PENDINGDEPLOYING,实例创建结果可以通过调用DescribeInstances 接口查询,如果实例状态(instanceStatus)由CREATING(创建中)或PENDING(等待创建)变为RUNNING(运行中),则代表实例创建成功,如果未查询到任何实例,则代表创建失败,创建过程中不可对实例进行任何操作。

  • 单次最多能创建100台实例。

2. 请求参数

以下请求参数列表仅列出了接口中需要的请求参数

3. 响应结果

4. 代码示例

1. 用最简单的参数创建一台后付费的实例 在首尔A创建一台后付费实例,规格为1c2g,其带宽计费为固定带宽,密码随机生成,不安装任何镜像,带宽大小为默认的1Mbps。

POST /api/v2/vm HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateInstances
<Common Request Params>

Request:
{
    "zoneId":"SEL-A",
    "instanceType":"c.1c2g",
    "imageId":"img-yKK4q6XybymPgfx7ynUUqC3N8",
    "instanceChargeType":"POSTPAID",
    "internetChargeType":"ByBandwidth"
}

Response:
{
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "response": {
        "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
        "instanceIdSet": ["instanceId1"],
        "orderNumber" : "the id of order number",
        "instances":[{"instanceId":"instanceId1","diskIdSet":[]}]
    }
}

2. 在1的基础上附带一块大小为40GB的标准数据盘 在首尔A创建一台后付费实例,规格为1c2g,其带宽计费为固定带宽,密码随机生成,不安装任何镜像,带宽大小为默认的1Mbps,附带一块40GB的标准类型的数据盘。

POST /api/v2/vm HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateInstances
<Common Request Params>

Request:
{
    "zoneId": "SEL-A",
    "instanceType": "c.1c2g",
    "imageId": "img-yKK4q6XybymPgfx7ynUUqC3N8",
    "instanceChargeType": "POSTPAID",
    "internetChargeType": "ByBandwidth",
    "dataDisks": [
        {
            "diskSize": 40,
            "diskCategory": "STANDARD"
        }
    ]
}

Response:
{
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
    "response": {
        "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D3",
        "instanceIdSet": ["instanceId1"],
        "orderNumber" : "the id of order number",
        "instances":[{"instanceId":"instanceId1","diskIdSet":["diskId1"]}]
    }
}

3. 创建2台预付费的实例 在首尔A 创建2台预付费付费实例,周期为2个月,规格为1c2g,两台实例的名称分别为:SEL-1C2G-01, SEL-1C2G-02, 密码Password-12345~,镜像ID: image-xxxxx,带宽计费为固定带宽,带宽大小为10Mbps。

POST /api/v2/vm HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateInstances
<Common Request Params>

Request:
{
    "instanceChargeType": "PREPAID",
    "instanceCount": 2, 
    "instanceChargePrepaid":{
        "period": 2
    },
    "instanceName": "SEL-1C2G-[1,2]",
    "internetMaxBandwidthOut": 10,
    "password": "Password-12345~",
    "instanceType": "c.1c2g",
    "internetChargeType": "ByBandwidth",
    "zoneId": "SEL-A", 
    "imageId": "image-xxxxx"
}

Response:
{
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D4",
    "response": {
        "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D4",
        "instanceIdSet": [
            "instanceId3",
            "instanceId4"
        ],
        "orderNumber": "the id of order number",
        "instances": [
            {
                "instanceId": "instanceId3",
                "diskIdSet": []
            },
            {
                "instanceId": "instanceId4",
                "diskIdSet": []
            }
        ]
    }
}

4. 创建2台预付费的实例,其网络计费方式为流量包 和2类似, 不同的是本次创建的网络计费方式是流量包, 其流量包大小为 10TB。带宽大小为100Mbps。

POST /api/v2/vm HTTP/1.1
Host: console.zenlayer.com
Content-Type: application/json
X-ZC-Action: CreateInstances
<Common Request Params>

Request:
{
    "instanceChargeType": "PREPAID",
    "instanceCount": 2, 
    "instanceChargePrepaid":{
        "period": 2
    },
    "instanceName": "SEL-1C2G-[1,2]",
    "internetMaxBandwidthOut": 100,
    "password": "Password-12345~",
    "instanceType": "c.1c2g",
    "internetChargeType": "ByTrafficPackage",
    "trafficPackageSize": 10,
    "zoneId": "SEL-A", 
    "imageId": "image-xxxxx"
}

Response:
{
    "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D4",
    "response": {
        "requestId": "T05992D0C-7E8B-4047-B0C0-780F2CD549D4",
        "instanceIdSet": ["instanceId5", "instanceId6"],
        "orderNumber" : "the id of order number",
        "instances": [
            {
                "instanceId": "instanceId5",
                "diskIdSet": []
            },
            {
                "instanceId": "instanceId6",
                "diskIdSet": []
            }
        ]
    }
}

5. 开发者工具

Zenlayer Cloud API 2.0 提供了配套的开发工具集(SDK),未来会陆续支持更多开发语言,方便快速接入和使用Zenlayer的产品和服务。

6. 错误码

下面包含业务逻辑中遇到的错误码,其他错误码见公共错误码

最后更新于