弹性云服务器 ECS-创建云服务器(废弃):请求示例

时间:2024-11-14 15:10:22

请求示例

  • 通过block_device_mapping_v2扩展属性使用镜像创建一台云服务器,采用密钥方式登录鉴权。
    POST https://{endpoint}/v2.1/9c53a566cb3443ab910cf0daebca90c4/servers
    
    { 
        "server": { 
            "flavorRef": "s3.xlarge.2", 
            "name": "wjvm48", 
            "metadata": { 
                "name": "name_xx1", 
                "id": "id_xxxx1" 
            }, 
            "block_device_mapping_v2": [{ 
                "source_type": "image", 
                "destination_type": "volume", 
                "uuid": "b023fe17-11db-4efb-b800-78882a0e394b", 
                "delete_on_termination": "False", 
                "boot_index": "0",
                "volume_type": "SAS",
                "volume_size": "40"
            }], 
            "security_groups": [{ 
                "name": "name_xx5_sg" 
            }], 
            "networks": [{ 
                "uuid": "fd40e6f8-942d-4b4e-a7ae-465287b02a2c", 
                "port": "e730a11c-1a19-49cc-8797-cee2ad67af6f", 
                "fixed_ip": "10.20.30.137" 
            }], 
            "key_name": "test", 
            "user_data": "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==", 
            "availability_zone":"az1-dc1"
        } 
    }
  • 通过block_device_mapping_v2扩展属性使用快照创建一台云服务器,其中,boot_index为0,且该快照对应的云硬盘必须为系统盘。
    POST https://{endpoint}/v2.1/9c53a566cb3443ab910cf0daebca90c4/servers
    
    {
        "server":{
            "name":"wjvm48",
            "availability_zone":"az1-dc1",
            "block_device_mapping_v2": [
                {
                    "source_type":"snapshot",
                    "boot_index":"0",
                    "uuid":"df51997d-ee35-4fb3-a372-e2ac933a6565", // snapshot id,创建snapshot接口会返回id
                    "destination_type":"volume"
                }
            ],
            "flavorRef":"s3.xlarge.2",
            "max_count":1,
            "min_count":1,
            "networks": [
                {
                    "uuid":"79a68cef-0936-4e21-b1f4-b800ecb70246"
                }
            ] 
        } 
    }
  • 通过block_device_mapping_v2使用卷创建一台弹性云服务器
    POST https://{endpoint}/v2.1/9c53a566cb3443ab910cf0daebca90c4/servers
    
    { 
        "server": { 
            "flavorRef": "s3.xlarge.2", 
            "name": "wjvm48", 
            "metadata": { 
                "name": "name_xx1", 
                "id": "id_xxxx1" 
            }, 
            "block_device_mapping_v2": [{ 
                "source_type": "volume", 
                "destination_type": "volume", 
                "uuid": "bd7e4f86-b004-4745-bea2-a55b1085f107", 
                "delete_on_termination": "False", 
                "boot_index": "0", 
                "volume_type": "dsware",
                "volume_size": "40"
            }], 
            "security_groups": [{ 
                "name": "name_xx5_sg" 
            }], 
            "networks": [{ 
                "uuid": "fd40e6f8-942d-4b4e-a7ae-465287b02a2c", 
                "port": "e730a11c-1a19-49cc-8797-cee2ad67af6f", 
                "fixed_ip": "10.20.30.137" 
            }], 
            "key_name": "test", 
            "user_data": "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==", 
            "availability_zone":"az1-dc1"
        } 
    }
  • 使用imageRef创建一台弹性云服务器,建议将密码在配置文件或者环境变量中密文存放,使用时解密,确保安全。
    POST https://{endpoint}/v2.1/9c53a566cb3443ab910cf0daebca90c4/servers
    
    { 
        "server": { 
            "flavorRef": "s3.xlarge.2", 
            "name": "wjvm48", 
            "metadata": { 
                "name": "name_xx1", 
                "id": "id_xxxx1" 
            }, 
            "adminPass": "$ADMIN_PASS",
            "imageRef": "6b344c54-d606-4e1a-a99e-a7d0250c3d14",
            "security_groups": [{ 
                "name": "name_xx5_sg" 
            }], 
            "networks": [{ 
                "uuid": "fd40e6f8-942d-4b4e-a7ae-465287b02a2c",
                "port": "e730a11c-1a19-49cc-8797-cee2ad67af6f",
                "fixed_ip": "10.20.30.137" 
            }], 
            "key_name": "test", 
            "user_data": "ICAgICAgDQoiQSBjbG91ZCBkb2VzIG5vdCBrbm93IHdoeSBpdCBtb3ZlcyBpbiBqdXN0IHN1Y2ggYSBkaXJlY3Rpb24gYW5kIGF0IHN1Y2ggYSBzcGVlZC4uLkl0IGZlZWxzIGFuIGltcHVsc2lvbi4uLnRoaXMgaXMgdGhlIHBsYWNlIHRvIGdvIG5vdy4gQnV0IHRoZSBza3kga25vd3MgdGhlIHJlYXNvbnMgYW5kIHRoZSBwYXR0ZXJucyBiZWhpbmQgYWxsIGNsb3VkcywgYW5kIHlvdSB3aWxsIGtub3csIHRvbywgd2hlbiB5b3UgbGlmdCB5b3Vyc2VsZiBoaWdoIGVub3VnaCB0byBzZWUgYmV5b25kIGhvcml6b25zLiINCg0KLVJpY2hhcmQgQmFjaA==", 
            "availability_zone":"az1-dc1"
        } 
    }
  • 批量创建弹性云服务器,最小数量为2,最大数量为3。
    POST https://{endpoint}/v2.1/9c53a566cb3443ab910cf0daebca90c4/servers
    
    {
        "server": {
            "availability_zone":"az1.dc1",
            "name": "test",
            "imageRef": "10ff4f01-35b6-4209-8397-359cb4475fa0",
            "flavorRef": "s3.xlarge.2",
            "return_reservation_id": "true",
            "networks": [
                {
                    "uuid": "51bead38-d1a3-4d08-be20-0970c24b7cab"
                }
            ],
            "min_count": "2",
            "max_count": "3"
        }
    }
support.huaweicloud.com/api-ecs/ecs_03_0201.html