Migration ToolArcfra CloudMoveVM Initialization ToolArcfra VMTools

Step 5: Creating a virtual machine with cloudbase-init from the template

After creating a cloudbase-init template, you can use it to create new virtual machines. During the creation process, in addition to the usual parameters, you can also configure the initialization data for the newly created virtual machines.

You can create new virtual machines with cloudbase-init on Arcfra Operation Center (AOC) , or via the Web console, AOC RESTful API or SDK. This section covers the initialization data configuration only. See the Management > Managing virtual machines > Creating and configuring virtual machines > Creating a virtual machine > Creating a VM from a template section for full details on creating a virtual machine from a cloud-init template.

Creating a virtual machine on AOC or Web console

The process of creating a virtual machine on both the Web console and AOC is essentially the same. The following procedure uses AOC as an example.

Procedure

  1. Log in to AOC to access its homepage. On the upper-right corner of the homepage, click Create, and then select Create VM from template to open the Create VM from template dialog box.

  2. In the Create VM from template dialog box, select the cloudbase-init template you created. Refer to Management > Managing virtual machines > Creating and configuring virtual machines > Virtual machine configuration options section for details on the configurations of basic information, compute resources, and storage resources.

  3. When configuring Network device, go to cloud-init configuration and choose the IP address configuration mode for the virtual machine.

    • Configure static IP address: Once selected, you need to configure the static IP address and static routing for the virtual machine.

    • Enable network card DHCP: Once selected, you need to enable DHCP on the virtual machine to get a dynamic IP address.

    • Not configured: Not using cloud-init to configure the IP address.

    Note:

    When the network type of the virtual machine’s NIC is VPC network with the IP address left blank, the Configure static IP address mode cannot to be selected; if an IP address has been filled in and the Configure static IP address mode is selected, the system will automatically assign the filled IP address to the virtual machine's NIC as its static IP.

  4. In the Initialization configuration section, configure the initialization data for the virtual machine.

    1. Enter the hostname, default username and password, SSH public key, and DNS server configurations.

    2. Configure the user data. ELF supports up to 32 KB of user data. See User data examples for examples.

  5. Click Create to complete the virtual machine creation process.

User data examples

Refer to the official cloud-init document Userdata for supported user data.

This section provides examples using user data script and cloud config runcmd to configure the user data. Refer to the official documents for other configurations needed.

User data script

Configure the following Shell Script to ensure that the virtual machine with cloudbase-init runs the echo "Hello World. The time is now $(date -R)!" >> /root/arcfra.txt command on its first boot:

#!/bin/sh
echo "Hello World.  The time is now $(date -R)!" >> /root/arcfra.txt

Cloud config runcmd

Configure the following cloud config runcmd to ensure that the virtual machine with cloudbase-init runs the curl https://www.arcfra.com/ -o /root/arcfra.html command on its first boot:

#cloud-config
runcmd:
 - [ curl, "https://www.arcfra.com/", -o, /root/arcfra.html ]

Creating a virtual machine with cloudbase-init via AOC RESTful API or SDK

You can also create a virtual machine from a cloudbase-init template via the AOC RESTful API or SDK and configure the initialization data for the virtual machine.