Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Situation Awareness
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive

Creating an ECS

Updated on 2024-12-19 GMT+08:00

Scenarios

This section describes how to create an ECS by calling APIs. For details, see Calling APIs.

An ECS can be created using a disk or image. This section uses an image as an example to describe how to create an ECS.

Constraints

The ECS created using this API is in pay-per-use billing mode.

Involved APIs

Creating an ECS involves viewing flavors and AZs as well as creating EVS disks. The following APIs are required:

Procedure

  1. Determine the AZ where the ECS is located.

    1. View AZs.
      • API

        URI format: GET /v2.1/{project_id}/os-availability-zone

        For details, see Querying the AZ List.

      • Example request

        GET https://{endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/os-availability-zone

        Obtain {endpoint} from Regions and Endpoints.

      • Example response
         {
          "availabilityZoneInfo": [
            {
              "hosts": null,
              "zoneState": {
                "available": true
              },
              "zoneName":"zone_01" 
            },
            {
              "hosts": null,
              "zoneState": {
                "available": true
              },
              "zoneName": "zone_01" 
            }
          ]
        }
    2. Select an AZ based on site requirements and record the AZ (zoneName).

  2. Determine the ECS flavor.

    1. View ECS flavors.
      • API

        URI format: GET /v1/{project_id}/cloudservers/flavors?availability_zone={availability_zone}

        The fields following the question mark (?) are optional, which are used for querying ECS flavors. For details, see Querying Details About Flavors and Extended Flavor Information.

      • Example request

        GET https://{endpoint}/v1/74610f3a5ad941998e91f076297ecf27/cloudservers/flavors?availability_zone=zone_01

        Obtain {endpoint} from Regions and Endpoints.

        The value of availability_zone is zone_01, which can be obtained from 1.

      • Example response
        {
            "flavors": [
                {
                    "attachableQuantity": {
                        "free_scsi": 60,
                        "free_blk": 24,
                        "free_disk": 60,
                        "free_nic": 12
                    },
                    "id": "c3.2xlarge.2",
                    "name": "c3.2xlarge.2",
                    "vcpus": "8",
                    "ram": 8192,
                    "disk": "0",
                    "swap": "",
                    "links": [
                        {
                            "rel": "self",
                            "href": "https://xxx/v1.0/74610f3a5ad941998e91f076297ecf27/flavors/c3.2xlarge.2",
                            "type": null
                        },
                        {
                            "rel": "bookmark",
                            "href": "https://xxx/74610f3a5ad941998e91f076297ecf27/flavors/c3.2xlarge.2",
                            "type": null
                        }
                    ],
                    "OS-FLV-EXT-DATA:ephemeral": 0,
                    "rxtx_factor": 1,
                    "OS-FLV-DISABLED:disabled": false,
                    "rxtx_quota": null,
                    "rxtx_cap": null,
                    "os-flavor-access:is_public": true,
                    "os_extra_specs": {
                        "ecs:virtualization_env_types": "CloudCompute",
                        "ecs:generation": "c3",
                        "ecs:instance_architecture":"arm64" ,
                        "ecs:performancetype": "computingv3",
                        "resource_type": "IOoptimizedC3_2"
                    }
                }
            ]                              
        }
    2. Select a flavor based on site requirements and record the flavor ID.

  3. Determine the image.

    1. Query images.
      • API

        URI format: GET /v2.1/{project_id}/images/detail

        For details, see Querying Image Details (Discarded).

      • Example request

        GET https://{endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/images/detail

        Obtain {endpoint} from Regions and Endpoints.

      • Example response
        {
          "images": [
            {
              "OS-EXT-IMG-SIZE:size": 0,
              "metadata": {
                "__os_type": "Linux",
                "hw_vif_multiqueue_enabled": "true",
                "__imagetype": "gold",
                "__quick_start": "true",
                "virtual_env_type": "FusionCompute",
                "__support_xen": "true",
                "__support_kvm": "true",
                "__image_source_type": "uds",
                "__platform": "EulerOS",
                "__os_version": "EulerOS 2.2 64bit",
                "__os_bit": "64",
                "__isregistered": "false"
              },
              "created": "2018-05-14T06:13:50Z",
              "minRam": 0,
              "name": "DBS-MySQL-Image_2.1.3.3",
              "progress": 100,
              "links": [
                {
                  "rel": "self",
                  "href": "https://None/v2.1/74610f3a5ad941998e91f076297ecf27/images/11e8f727-d439-4ed1-b3b8-33f46c0379c4"
                },
                {
                  "rel": "bookmark",
                  "href": "https://None/74610f3a5ad941998e91f076297ecf27/images/11e8f727-d439-4ed1-b3b8-33f46c0379c4"
                },
                {
                  "rel": "alternate",
                  "href": "https://None/images/11e8f727-d439-4ed1-b3b8-33f46c0379c4",
                  "type": "application/vnd.openstack.image"
                }
              ],
              "id": "11e8f727-d439-4ed1-b3b8-33f46c0379c4",
              "updated": "2018-05-14T06:13:52Z",
              "minDisk": 40,
              "status": "ACTIVE"
            }
          ]
        }
    2. Select an image based on site requirements and record the image ID.

  4. Determine the network configuration.

    1. Query networks.
      • API

        URI format: GET /v2.1/{project_id}/os-networks

        For details, see Querying Networks (Discarded).

      • Example request

        GET https://{endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/os-networks

        Obtain {endpoint} from Regions and Endpoints.

      • Example response
        {
          "networks": [
            {
              "id": "07a9557d-4256-48ae-847c-415a9c8f7ff6",
              "label": "b_tt3_td1b",
              "broadcast": null,
              "cidr": null,
              "dns1": null,
              "dns2": null,
              "gateway": null,
              "netmask": null,
              "cidr_v6": null,
              "gateway_v6": null,
              "netmask_v6": null
            }
          ]
        }
    2. Select a network based on site requirements and record the network ID.

  5. Set the login mode to Key pair.

    1. Create a key pair.
      • API

        URI format: POST /v2.1/{project_id}/os-keypairs

        For details, see Creating and Importing an SSH Key Pair (Discarded).

      • Example request

        POST https://{endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/os-keypairs

        Obtain {endpoint} from Regions and Endpoints.

        Body:

        {
            "keypair": {
                "type": "ssh",
                "name": "demo1",
                "user_id": "fake"
            }
        }
      • Example response
        {
          "keypair": {
            "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCrR5Gcwlh5ih7JOvzIUuQxS5qzWWPMYHeDXkDKSQ9W5pumOV05SiO3WCswnaQ5xMdOl31mNiHtwlwq9dJi7X6jJBB2shT******************************************************************************************************************************************************************************************************************************************************************************************************* Generated-by-Nova\n",
            "private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEogIBAAKCAQEAq0eRnMJYeYoeyTr8yFLkMUuas1ljzGB3g15AykkPVuabpjld\nOUojt1grMJ2kOcTHTpd9ZjYh7cJcKvXSYu1+oyQQdrIUw/tNBuVrsJAWxVOAi77d\nQeOLtDVImkyd+TQL1tv+F76V5vTsIkNweYHumWOxLIt/FJ4fqZG4T5GMTQQivMqD\npaI0IVrO+Wm3cWQYvNdf/EcC3DYhYqHANkRsbUYwXaREnI/tU1PjnH2XUJ69ABWz\ntdc+8sXyMoMMM1U4FLiTWzGyh0rUKkW5JXzJR2OEQT0IG+0Tf2Glyk0El0/OJPg/\ncZQzaO1o+H8DiUzs/7Pz72yDqo0R7fQ+mOCCn***********************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************************\n-----END RSA PRIVATE KEY-----\n",
            "user_id": "f79791beca3c48159ac2553fff22e166",
            "name": "demo1",
            "fingerprint": "57:a7:a2:ed:5f:aa:e7:**:**:**:**:**:**:**:**:**"
          }
        }
    2. Import the key pair.
      • API

        URI format: POST /v2.1/{project_id}/os-keypairs

        For details, see Creating and Importing an SSH Key Pair (Discarded).

      • Example request

        POST https://{endpoint}/v2.1/74610f3a5ad941998e91f076297ecf27/os-keypairs

        Obtain {endpoint} from Regions and Endpoints.

        Body:

        {
            "keypair": {
                "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDY8wMTdBYiJgi62o6eShoOlSKx3CZ3cE6PHisDblfK3Y0Bg7EHV7iV9c74pqsrIhK0xuGUuO1NxDQWbkwLTPN4F9Iy5CI********************************************************************************************************************************************************************************************************************************************************* Generated-by-Nova\n",
                "type": "ssh",
                "name": "demo2",
                "user_id": "fake"
            }
        }
      • Example response
        {
          "keypair": {
            "public_key": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDY8wMTdBYiJgi62o6eShoOlSKx3CZ3cE6PHisDblfK3Y0Bg7EHV7iV9c74pqsrIhK0xuGUuO1NxDQWbkwLTPN4F9Iy5CI********************************************************************************************************************************************************************************************************************************************************* Generated-by-Nova\n",
            "user_id": "f79791beca3c48159ac2553fff22e166",
            "name": "demo2",
            "fingerprint": "dd:44:45:49:d9:f6:4f:**:**:**:**:**:**:**:**:**"
          }
        }
    3. Record the name in the response body, for example, demo2.

  6. Create an ECS authenticated using the key pair.

    • API

      URI format: POST /v1/{project_id}/cloudservers

      For details about API constraints and request parameters, see Creating an ECS (Pay-per-Use).

    • Example request

      POST https://{endpoint}/v1/74610f3a5ad941998e91f076297ecf27/cloudservers

      Obtain {endpoint} from Regions and Endpoints.

      Body:

      {
          "server": {
              "availability_zone":"zone_01",
              "name": "newserver", 
              "imageRef": "67f433d8-ed0e-4321-a8a2-a71838539e09", 
              "root_volume": {
                  "volumetype": "SSD"
              }, 
              "data_volumes": [ 
                  {
                      "volumetype": "SSD", 
                      "size": 100,
                      "multiattach": true,
                      "hw:passthrough": true
                  }
              ], 
              "flavorRef": "s3.xlarge.2", 
              "vpcid": "0dae26c9-9a70-4392-93f3-87d53115d171", 
              "security_groups": [
                  {
                      "id": "507ca48f-814c-4293-8706-300564d54620"
                  }
              ], 
              "nics": [
                  {
                      "subnet_id": "157ee789-03ea-45b1-a698-76c92660dd83"
                  }
              ], 
              "publicip": {
                  "eip": {
                      "iptype": "5_bgp",
                      "bandwidth": {
                          "size": 10, 
                          "sharetype": "PER"
                      }
                  }
              }, 
              "key_name": "sshkey-123", 
              "count": 1, 
              "server_tags": [
                  {
                      "key": "key1",
                      "value": "value1"
                  }
              ],
              "metadata": {
                     "op_svc_userid": "8ea65f4099ba412883e2a0da72b96873",
                     "agency_name": "test"
              }
          }
      }
    • Example response
      {
          "job_id": "ff808082739334d80173941567f21d4f",
          "serverIds": [
              "6d311127-bce1-48db-bf0f-cac9f8f7f077"
          ]
      }
      

  7. Verify the ECS creation.

    • API

      URI format: GET /v1/{project_id}/cloudservers/{server_id}

      For details, see Querying Details About an ECS.

    • Example request

      GET https://{endpoint}/v1/74610f3a5ad941998e91f076297ecf27/cloudservers/0c71c0da-8852-4c56-a1d1-3a9b9bcb6da6

      where,

      0c71c0da-8852-4c56-a1d1-3a9b9bcb6da6 is the UUID of the created ECS.

      Obtain {endpoint} from Regions and Endpoints.

    • Example response
      {
          "server":{
              "id":"0c71c0da-8852-4c56-a1d1-3a9b9bcb6da6",
              "name":"ecs-2ecf",
              "addresses":{
                  "2a6f4aa6-d93e-45f5-a8cb-b030dbf8cd68":[
                      {
                          "version":"4",
                          "addr":"192.168.1.99",
                          "OS-EXT-IPS-MAC:mac_addr":"fa:16:3e:df:18:6d",
                          "OS-EXT-IPS:port_id":"23037c18-027a-44e5-b6b9-f8d8f113fe02",
                          "OS-EXT-IPS:type":"fixed"
                      }
                  ]
              },
              "flavor":{
                  "disk":"0",
                  "vcpus":"2",
                  "ram":"1024",
                  "id":"s3.large.1",
                  "name":"s3.large.1",
                  "gpus": [],
                  "asic_accelerators": [] 
              },
              "accessIPv4":"",
              "accessIPv6":"",
              "status":"ACTIVE",
              "progress":0,
              "hostId":"c7145889b2e3202cd295ceddb1742ff8941b827b586861fd0acedf64",
              "updated":"2018-09-13T07:06:51Z",
              "created":"2018-09-13T07:03:44Z",
              "image":{
                  "id":"1ce5800a-e487-4c1b-b264-3353a39e2b4b"
              },
              "metadata":{
                  "metering.order_id":"CS1809131459IGC24",
                  "metering.image_id":"c71b64e7-4767-4406-afde-2c7c7ac2242c",
                  "metering.imagetype":"gold",
                  "metering.resourcespeccode":"s3.small.1.linux",
                  "image_name":"HEC_Public_Cloudinit_Oracle_Linux_7.4_64bit_40G",
                  "metering.resourcetype":"1",
                  "metering.product_id":"00301-117024-0--0",
                  "cascaded.instance_extrainfo":"pcibridge:2",
                  "os_bit":"64",
                  "vpc_id":"0431c5e5-bc94-4a44-8263-15da2a642435",
                  "os_type":"Linux",
                  "charging_mode":"1"
              },
              "tags":[
              ],
              "description":"",
              "locked":false,
              "config_drive":"",
              "tenant_id":"74610f3a5ad941998e91f076297ecf27",
              "user_id":"f79791beca3c48159ac2553fff22e166",
              "key_name":"KeyPair-d750",
              "os-extended-volumes:volumes_attached":[
                  {
                      "device":"/dev/vda",
                      "bootIndex":"0",
                      "id":"80c15cff-2473-4982-a816-d760cad6c42c",
                      "delete_on_termination":"false"
                  }
              ],
              "OS-EXT-STS:task_state":null,
              "OS-EXT-STS:power_state":1,
              "OS-EXT-STS:vm_state":"active",
              "OS-EXT-SRV-ATTR:host":"az21.dc1",
              "OS-EXT-SRV-ATTR:instance_name":"instance-0015147f",
              "OS-EXT-SRV-ATTR:hypervisor_hostname":"nova003@74",
              "OS-EXT-SRV-ATTR:user_data":null,
              "OS-DCF:diskConfig":"MANUAL",
              "OS-EXT-AZ:availability_zone":"zone_01",
              "os:scheduler_hints":{
              },
              "OS-EXT-SRV-ATTR:root_device_name":"/dev/vda",
              "OS-EXT-SRV-ATTR:ramdisk_id":"",
              "OS-SRV-USG:launched_at":"2018-09-13T07:04:09.197749",
              "OS-EXT-SRV-ATTR:kernel_id":"",
              "OS-EXT-SRV-ATTR:launch_index":0,
              "host_status":"UP",
              "OS-EXT-SRV-ATTR:reservation_id":"r-nrd8b5c4",
              "OS-EXT-SRV-ATTR:hostname":"ecs-2ecf",
              "sys_tags":[
                  {
                      "key":"_sys_enterprise_project_id",
                      "value":"0"
                  }
              ],
              "security_groups":[
                  {
                      "name":"sg-95ec",
                      "id":"6505b5d1-7837-41eb-8a1c-869d4355baa3"
                  }
              ]
          }
      }

We use cookies to improve our site and your experience. By continuing to browse our site you accept our cookie policy. Find out more

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback