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
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

Writing a Template to Create an ECS

Updated on 2022-02-22 GMT+08:00

This section describes how to create an Elastic Cloud Server (ECS), including a Virtual Private Cloud (VPC) and subnet by writing a template. An ECS is a computing server equipped with CPUs, memory, images, and Elastic Volume Service (EVS) disks. ECSs can be created on demand and supports auto scaling. A VPC provides logically isolated, configurable, and manageable virtual networks for your ECSs. One or more subnets are automatically created when you create a VPC.

At the end of this walkthrough, you will see the newly created ECS on the Cloud Server Console.

NOTE:

In this walkthrough, you will write a template in the YAML language. For more information about templates, see Template Reference.

In this section, you will complete the following steps:

  1. Step 1: Write a Template: Use the YAML language to write a template for creating an ECS, VPC, and subnet.
  2. Step 2: Create an ECS: Use the template to create an ECS, VPC, and subnet.
  3. Step 3: Delete Unnecessary Resources: Delete unnecessary stack to avoid unwanted charges.

Step 1: Write a Template

  1. Write a simple template to create a VPC.

    tosca_definitions_version: cloud_tosca_version_1_0   #Template version information
    node_templates:                 #Element object definition
      myvpc:                        #VPC
        type: Cloud.VPC.VPC   
        properties:                 
          name: my-vpc              #Name of the VPC
          cidr: '192.168.0.0/16'    #VPC CIDR

    This template includes:

    1. tosca_definitions_version: specifies the version of a template. Currently, only cloud_tosca_version_1_0 is supported by AOS.
    2. node_templates: defines the set of objects to be orchestrated in a template. In AOS, objects are used interchangeably with elements. An object can be an application or cloud service resource. In the preceding template, node_templates defines the myvpc VPC.
    3. type: specifies the type of an orchestration object. The value comes from the element type list and can be set to Cloud.*** (*** indicates the element name in the Resource Indexes). In the preceding template, the myvpc VPC type is Cloud.VPC.VPC.
    4. properties: defines element properties, which vary with element types. In the preceding template, the myvpc VPC has the names and cidr properties, which indicate the name and network segment of the VPC, respectively. For more information, see VPC.VPC.

  2. Define a subnet in the VPC. A VPC is a large network segment and is usually divided into several subnets. Define a subnet in the created VPC based on the preceding template.

    tosca_definitions_version: cloud_tosca_version_1_0   #Template version information
    node_templates:                 #Element object definition
      myvpc:                        #VPC
        type: Cloud.VPC.VPC   
        properties:                 
          name: my-vpc              #Name of the VPC
          cidr: '192.168.0.0/16'    #VPC CIDR
      mysubnet:                     #Subnet
        type: Cloud.VPC.Subnet
        properties:
          name: my-subnet           #Name of the subnet
          cidr: '192.168.1.0/24'    #Subnet CIDR
          gateway: 192.168.1.1      #Gateway of the subnet
          vpcId:                    #ID of the VPC to which the subnet belongs
            get_reference: myvpc
          dhcpEnable: true          #Determines whether to enable the DHCP function for the subnet in the VPC.
        requirements:               #Dependency between the subnet and VPC.
          - vpcId:
              node: myvpc

    The requirements section specifies the elements that have dependencies with the current element. For example, define myvpc as a dependent node in the requirements section of the subnet because a subnet depends on a VPC.

  3. Define an ECS in the template.

    tosca_definitions_version: cloud_tosca_version_1_0   #Template version information
    node_templates:                 #Element object definition
      myvpc:                        #VPC
        type: Cloud.VPC.VPC   
        properties:                 
          name: my-vpc              #Name of the VPC
          cidr: '192.168.0.0/16'    #VPC CIDR
      mysubnet:                     #Subnet
        type: Cloud.VPC.Subnet
        properties:
          name: my-subnet           #Name of the subnet
          cidr: '192.168.1.0/24'    #Subnet CIDR
          gateway: 192.168.1.1      #Gateway of the subnet
          vpcId:                    #ID of the VPC to which the subnet belongs
            get_reference: myvpc
          dhcpEnable: true          #Determines whether to enable the DHCP function for the subnet in the VPC.
        requirements:               #Dependency between the subnet and VPC.
          - vpcId:
              node: myvpc
      myecs:                        #ECS
        type: Cloud.ECS.CloudServer    
        properties:       
          name: my-ecs              #Name of the ECS
          instances: 1              #Number of created ECSs
          imageId: 60e757e9-1924-413e-b71f-b7b49bacd2ca    #Image ID used by the ECS. In this template, the image ID is the ID of the system disk based on 64-bit CentOS 7.2.
          flavor: c2.large         #Specifications of the ECS
          vpcId:                    #ID of the VPC to which the ECS belongs. Either a new or an existing VPC ID can be used.
            get_reference: myvpc    #Obtains the dynamic attribute value of the associated element.
          availabilityZone: ae-ad-1a      #AZ to which the ECS belongs
          nics:                              #NIC of the ECS
            - subnetId: 
                get_reference: mysubnet      
          rootVolume:              #System disk configuration of the ECS
            volumeType: SATA       #Common I/O disk type
            size: 40               #System disk size (unit: GB)
        requirements:              #Dependency among the ECS, VPC, and subnet.
          - vpcId:         
              node: myvpc      
          - nics.subnetId:          
              node: mysubnet

  4. Save the template as a local file myecs.yaml.
  5. Log in to the AOS console.
  6. In the navigation pane, choose My Templates, and then click Create Template.
  7. On the Upload File tab page, specify the following parameters, upload a local YAML file, and then click Create. The template details page is then displayed, showing the template information.

    • Template: Enter a template name. Each template name must be globally unique. For example, set this parameter to myecs.
    • Version: Set this parameter to 1.0.
    • Select File: Upload the myecs.yaml file.

Step 2: Create an ECS

  1. Log in to the AOS console.
  2. In the navigation pane, choose My Templates. The myecs template is displayed in the template list.
  3. Click Create Stack in the Operation column of the myecs template.
  4. Set the stack information.

    • Stack Name: Enter a unique stack name, for example, aos-ecs.
    • Description: The description can be left blank.

  5. Click Next and check the stack information. If the stack information is correct, click Create Stack.

    The stack details page is displayed, showing that the stack is being created. The stack includes a VPC, a subnet, and an ECS. It will take about 6 minutes to create the stack.

  6. Wait until the stack status becomes Normal. The VPC, subnet, and ECS are created and displayed in the stack element list.

    Figure 1 Stack successfully created

  7. View the created cloud services.

    1. Log in to the management console.
    2. Choose Service List > Computing > Elastic Cloud Server. You will see the newly created ECS on the ECS list.
    3. Choose Service List > Network > Virtual Private Cloud. You will see the newly created VPC on the VPC list.
    4. Click the VPC name to show more details about the VPC. On the VPC details page, you will see that the subnet has been created in the VPC.

Step 3: Delete Unnecessary Resources

Delete unnecessary stack resources to avoid unwanted charges.

  1. Log in to the AOS console.
  2. In the navigation pane, click My Stacks.
  3. Select the stack that will no longer be used, and click Delete to delete the stack.

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