Create multiple cloud servers through the OpenStack CLI
Use the --debug flag in OpenStack CLI commands to enable the display of debugging information when commands are executed. The flag displays complete OpenStack API requests, server responses, and internal command execution steps. This helps diagnose problems with authentication, configuration, or communication with OpenStack services.
-
Optional: configure the OpenStack CLI.
-
Optional: add an SSH key to the service user.
1. Optional: customize the OpenStack CLI
Use the Configure OpenStack CLI subsection with OS tools or Configure OpenStack CLI in the Docker container of the OpenStack CLI instructions.
If you have already configured the OpenStack CLI, run it.
2. Optional: add a public SSH key to the service user
If the service user through which you logged into the OpenStack API already has an SSH key added, skip the step.
-
In the control panel, on the top menu, click Account.
-
Go to the Service Users section.
-
Open the service user page → Access tab.
-
In the SSH keys row, click Add Key.
-
Enter the name of the key.
-
In the Public Key field, insert the public key that you created in step 1.
-
Click Add.
3. Create a private network and subnet
-
Open the CLI.
-
Create a private network:
openstack network create <network_name>Specify
<network_name>is the name of the private network. -
Create a subnet on the private network:
openstack subnet create \
--subnet-range <cidr> \
<dhcp> \
--gateway <gateway> \
--network <network> \
<subnet_name>Specify:
<cidr>- CIDR of a private subnet, e.g.192.168.0.0/24;<dhcp>- DHCP option setting. Specify one of the values:--dhcp- enable DHCP;--no-dhcp- disable DHCP;
<gateway>- IP address default gateway for example192.168.0.1;<network>- The ID or name of the private network you created in step 2;<subnet_name>- name of the private subnet.
4. Create a cloud router connected to an external network
-
Create a cloud router:
openstack router create <router_name>Specify
<router_name>- the name of the cloud router.. -
Optional: connect the cloud router to an external network - an external IP address will be assigned to the router:
openstack router set --external-gateway external-network <router>Specify
<router>- The ID or name of the cloud router you created in step 1.
5. Connect the subnet to the cloud router
-
Connect the subnet to the cloud router:
openstack router add subnet <router> <subnet>Specify:
<router>- The ID or name of the cloud router you created in step 5;<subnet>- The ID or name of the private subnet that you created in step 4.
6. Add ports for servers on the subnet
-
Create a port on the subnet:
openstack port create \
--network <network> \
--fixed-ip subnet=<subnet>,ip-address=<port_ip_address> \
<port_name>Specify:
<network>- The ID or name of the private network, the global router network, that you you created in step 4.. You can view the list of networks using the commandopenstack network list;<subnet>- The ID or name of the subnet you you created in step 4.. You can view the list of subnets using the commandopenstack subnet list;<port_ip_address>- The IP address of the port;<port_name>- port name.
-
Repeat step 1 to create ports for each new cloud server.
7. Create cloud servers
-
Create a cloud server:
openstack server create \
[--image <image> | --volume <volume> | --snapshot <snapshot>] \
--flavor <flavor> \
--availability-zone <pool_segment> \
--nic port-id=<port_uuid> \
--security-group <security_group> \
--key-name <key_name> \
<server_name>Specify:
- source type:
--image <image>- to create a server from off-the-shelf or custom image. Parameter<image>- The ID or name of the image. The image must be in the same pool as the server. The list of images can be viewed with the commandopenstack image list;--volume <volume>- to create a server from network disk. Parameter<volume>- ID or name of the disk. The disk must be in the same pool segment as the server. The list of network disks can be viewed with the commandopenstack volume list;--snapshot <snapshot>- to create a server from snapshot. Parameter<snapshot>- The ID or name of the snapshot. The snapshot must be in the same pool segment as the server. The list of snapshots can be viewed with the commandopenstack snapshot list;
<flavor>- The ID or name of the flavor. The flavors correspond to cloud server configurations and determine the number of vCPUs, RAM, and local disk size (optional) of the server. You can use fixed configuration flavors or create a flavor. For example,4011- ID to create a Memory Line fixed configuration server with 2 vCPUs, 16 GB RAM in a ru-9 pool. You can view the list of flavors using the commandopenstack flavor listor in the table List of fixed configuration flavors in all pools;<pool_segment>- pool segment in which the cloud server will be created, e.g.ru-9a. The list of available pool segments can be found in the instructions. Availability matrices;<port_uuid>- The port ID you created in step 7.. You can view the list of ports using the commandopenstack port list;<security_group>- The ID or name of the security group that will be assigned to all ports on the server. To create a server with a security group, the network must have port security enabled. port security. The list of groups can be viewed with the commandopenstack security group list;<key_name>- name of the public SSH key for the service user that you added in step 2.. You can view the list of keys using the commandopenstack keypair list;- optional:
--block-device-mapping vdb=<extra_volume>- ID or name of the extra disk. The list of disks can be viewed using theopenstack volume listcommand; - optional:
--tag <tag_name> --os-compute-api-version 2.52- tag to add more information about the server; - optional:
--tag preemptible --os-compute-api-version 2.72- tag to create an interruptible server; - optional:
--user-data <user_data.file>- path to the script with Base64 encoded data. Scripts and tasks from the script will be executed at the first boot of the operating system. Examples of scripts can be found in the User data instruction; <server_name>- server name.
- source type:
-
Repeat step 1 to create the desired number of servers.
8. Create public IP addresses
-
Create a public IP address:
openstack floating ip create external-network -
Repeat step 1 to create public IP addresses for all cloud servers.
9. Connect public IP addresses to cloud servers
-
Connect the public IP address to the cloud server port:
openstack floating ip set --port <port> <public_ip_address>Specify:
<port>- The port ID of the cloud server you added in step 7;<public_ip_address>- The ID or public IP address you created in step 9. You can view the list of public IP addresses using the commandopenstack floating ip list.
-
Repeat step 1 to connect public IP addresses to all cloud servers.