Skip to main content

Create several cloud servers via OpenStack CLI

Используйте флаг --debug in командах OpenStack CLI, чтобы включить отображение отладочной информации при выполнении команд. Флаг выводит полные запросы к OpenStack API, ответы серверов, а также внутренние шаги выполнения команды. Это помогает диагностировать проблемы with аутентификацией, конфигурацией or взаимодействием with сервисами OpenStack.

  1. Optional: configure OpenStack CLI.

  2. Optional: add an SSH key to the service user.

  3. Create a private network and subnet.

  4. Create a cloud router connected to the internet.

  5. Connect the private network to the cloud router.

  6. Create ports for the cloud servers.

  7. Create cloud servers.

  8. Create public IP addresses.

  9. Connect public IP addresses to the cloud servers.

1. Optional: configure OpenStack CLI

Use the Configure OpenStack CLI in the OS or Configure OpenStack CLI in a Docker container section of the OpenStack CLI documentation.

If you have already configured the OpenStack CLI, run it.

2. Optional: add a public SSH key to the service user

If an SSH key has already been added to the service user you are using to authenticate with the OpenStack API, skip this step.

  1. Create an SSH key.

  2. In the control panel, on the top menu, click IAM.

  3. Перейдите in раздел Сервисные пользователи.

  4. Откройте страницу сервисного пользователя → вкладка Доступ.

  5. In the SSH keys row, click Add key.

  6. Enter the name of the key.

  7. In the Public key field, paste the public key that you created in step 1.

  8. Click Add.

3. Create a private network and subnet

  1. Open the CLI.

  2. Create a private network:

    openstack network create <network_name>

    Specify <network_name> — the private network name.

  3. Create a subnet in the private network:

    openstack subnet create \
    --subnet-range <cidr> \
    <dhcp> \
    --gateway <gateway> \
    --network <network> \
    <subnet_name>

    Specify:

    • <cidr> — CIDR приватной подсети, например 192.168.0.0/24;
    • <dhcp> — the DHCP option settings. Specify one of the following values:
      • --dhcp — enable DHCP; ;
      • --no-dhcp — disable DHCP; ;
    • <gateway> — IP-адрес шлюза по умолчанию, например 192.168.0.1;
    • <network> — the ID or name of the private network you created in step 2; ;
    • <subnet_name> — the private subnet name.

4. Create a cloud router connected to the internet

  1. Create a cloud router:

    openstack router create <router_name>

    Specify <router_name> — the cloud router name.

  2. Optional: connect the cloud router to the internet — 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

  1. Connect the subnet to the cloud router:

    openstack router add subnet <router> <subnet>

    Specify:

6. Add ports for servers to the subnet

  1. Create a port in 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 or global router network you created in step 4. You can view the list of networks with the command openstack network list;
    • <subnet> — the ID or name of the subnet you created in step 4. You can view the list of subnets with the command openstack subnet list;
    • <port_ip_address> — the port IP address; ;
    • <port_name> — the port name.
  2. Repeat step 1 to create ports for each new cloud server.

7. Create cloud servers

  1. 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 a pre-built or custom image. The <image> parameter is the image ID or name. The image must be in the same pool as the server. You can view the list of images with the command openstack image list;
      • --volume <volume> — to create a server from a network volume. The <volume> parameter is the disk ID or name. The disk must be in the same pool segment as the server. You can view the list of network volumes with the command openstack volume list;
      • --snapshot <snapshot> — to create a server from a snapshot. The <snapshot> parameter is the snapshot ID or name. The snapshot must be in the same pool segment as the server. You can view the list of snapshots with the command openstack snapshot list;
    • <flavor> — ID or имя флейвора. Флейворы соответствуют конфигурациям облачного сервера and определяют количество vCPU, RAM and размер локального диска (optional) сервера. Можно использовать флейворы фиксированных конфигураций or создать флейвор. Например, 1013 — ID для создания сервера with фиксированной конфигурацией линейки Standard with 2 vCPU, 4 ГБ RAM in пуле ru-3. Список флейворов можно посмотреть with помощью команды openstack flavor list or in таблице Список флейворов фиксированной конфигурации во всех пулах;
    • <pool_segment>сегмент пула, in котором будет создан облачный сервер, например ru-9a. Список доступных сегментов пула можно посмотреть in инструкции Матрицы доступности;
    • <port_uuid> — the ID of the port you created in step 7. You can view the list of ports with the command openstack port list;
    • <security_group> — the ID or name of the security group to be assigned to all server ports. To create a server with a security group, traffic filtering (port security) must be enabled in the network. You can view the list of groups with the command openstack security group list;
    • <key_name> — the name of the public SSH key for the service user that you added in step 2. You can view the list of keys with the command openstack keypair list;
    • optional: --block-device-mapping vdb=<extra_volume> — the ID or name of an additional disk. You can view the list of disks with the command openstack volume list;
    • optional: --property x_cloud_smt_enabled=false — выключение Hyper-Threading (SMT). Если параметр не указан — Hyper-Threading (SMT) будет включен по умолчанию. Можно использовать только with флейворами, которые поддерживают работу выделенных ядер. Список флейворов можно посмотреть in таблице Список флейворов фиксированной конфигурации во всех пулах;
    • optional: --property x_cloud_numa_nodes=1 — размещение ресурсов on одной NUMA-ноде. Можно использовать только with флейворами, которые поддерживают работу выделенных ядер. Список флейворов можно посмотреть in таблице Список флейворов фиксированной конфигурации во всех пулах;
    • optional: --tag <tag_name> --os-compute-api-version 2.52тег для добавления дополнительной информации о сервере;
    • optional: --tag preemptible --os-compute-api-version 2.72 — тег для создания прерываемого сервера;
    • optional: --user-data <user_data.file> — путь до скрипта with данными, закодированными in Base64. Сценарии and задачи из скрипта выполнятся при первой загрузке операционной системы. Примеры скриптов можно посмотреть in инструкции User data;
    • <server_name> — the server name.
  2. Repeat step 1 to create the required number of servers.

8. Create public IP addresses

  1. Create a public IP address:

    openstack floating ip create external-network
  2. Repeat step 1 to create public IP addresses for all cloud servers.

9. Connect public IP addresses to cloud servers

  1. Connect a public IP address to the cloud server port:

    openstack floating ip set --port <port> <public_ip_address>

    Specify:

    • <port> — the ID of the cloud server port that 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 with the command openstack floating ip list.
  2. Repeat step 1 to connect public IP addresses to all cloud servers.