Launch an instance using an ISO image file with the OpenStack CLI

Creating an OpenStack image from an ISO image file

DreamCompute allows ISO image files to be used in the creation of instances. The first step is to import the .iso file into the Glance image service. This can be done using the openstack image create command with the following parameters.

[[email protected]]$ openstack image create \
    --private \
    --container-format bare \
    --disk-format iso \
    --file ubuntu-17.04-server-amd64.iso \
    ubuntu-17.04-server-amd64-iso
+------------------+------------------------------------------------------+
| Field            | Value                                                |
+------------------+------------------------------------------------------+
| checksum         | 4672ce371fb3c1170a9e71bc4b2810b9                     |
| container_format | bare                                                 |
| created_at       | 2017-05-27T13:22:49Z                                 |
| disk_format      | iso                                                  |
| file             | /v2/images/b840f7f6-7fd8-47f9-848a-...               |
| id               | b840f7f6-7fd8-47f9-848a-9e9422925cb2                 |
| min_disk         | 0                                                    |
| min_ram          | 0                                                    |
| name             | ubuntu-17.04-server-amd64-iso                        |
| owner            | USER_ID                                              |
| protected        | False                                                |
| schema           | /v2/schemas/image                                    |
| size             | 718274560                                            |
| status           | active                                               |
| tags             |                                                      |
| updated_at       | 2017-05-27T13:23:17Z                                 |
| virtual_size     | None                                                 |
| visibility       | private                                              |
+------------------+------------------------------------------------------+

In this command, ubuntu-17.04-server-amd64.iso is the ISO image file, and ubuntu-17.04-server-amd64-iso is the name of the new image.

Boot an instance from the ISO-based, OpenStack image

The next step is to launch a temporary instance that will be used to install/configure the operating system. Do this with the openstack server create command using the following parameters.

[[email protected]]$ openstack server create \
    --image ubuntu-17.04-server-amd64-iso \
    --nic net-id = NETWORK_UUID \
    --flavor 100 ubuntu-17.04-server-amd64-installer
+--------------------------------------+----------------------------------+
| Field                                | Value                            |
+--------------------------------------+----------------------------------+
| OS-DCF:diskConfig                    | MANUAL                           |
| OS-EXT-AZ:availability_zone          | iad-2                            |
| OS-EXT-STS:power_state               | 0                                |
| OS-EXT-STS:task_state                | scheduling                       |
| OS-EXT-STS:vm_state                  | building                         |
| OS-SRV-USG:launched_at               | None                             |
| OS-SRV-USG:terminated_at             | None                             |
| accessIPv4                           |                                  |
| accessIPv6                           |                                  |
| addresses                            |                                  |
| adminPass                            | SLZV7QgA7ick                     |
| config_drive                         |                                  |
| created                              | 2017-05-27T13:27:42Z             |
| flavor                               | gp1.semisonic (50)               |
| hostId                               |                                  |
| id                                   | INSTANCE_ID                      |
| image                                | ubuntu-17.04-server-amd64-iso    |
| key_name                             |                                  |
| name                                 | INSTANCE_NAME                    |
| os-extended-volumes:volumes_attached | []                               |
| progress                             | 0                                |
| project_id                           | PROJECT_ID                       |
| properties                           |                                  |
| security_groups                      | [{u'name': u'default'}]          |
| status                               | BUILD                            |
| updated                              | 2017-05-27T13:27:42Z             |
| user_id                              | USER_ID                          |
+--------------------------------------+----------------------------------+

ubuntu-17.04-server-amd64-iso is the OpenStack image created from the ISO file in the previous step and NETWORK_UUID is a valid network id.

After the instance is successfully launched, create a blank volume to temporarily store the configured operating system.

[[email protected]]$ openstack volume create --size 20 VOLUME_NAME
+---------------------+--------------------------------------+
| Field               | Value                                |
+---------------------+--------------------------------------+
| attachments         | []                                   |
| availability_zone   | iad-2                                |
| bootable            | false                                |
| consistencygroup_id | None                                 |
| created_at          | 2017-05-27T13:48:05.568204           |
| description         | None                                 |
| encrypted           | False                                |
| id                  | VOLUME_ID                            |
| multiattach         | False                                |
| name                | VOLUME_NAME                          |
| properties          |                                      |
| replication_status  | disabled                             |
| size                | 20                                   |
| snapshot_id         | None                                 |
| source_volid        | None                                 |
| status              | creating                             |
| type                | None                                 |
| updated_at          | None                                 |
| user_id             | USER_ID                              |
+---------------------+--------------------------------------+

Connect the volume to the instance as the root device using the following command:

[[email protected]]$ openstack server add volume INSTANCE_ID VOLUME_ID --device /dev/vda

Connect to the instance using the console and install the operating system (just as if you were using an ISO image on a regular computer). When the installation is finished and the system is rebooted, the instance will try to install the operating system again. This is expected as that's what the instance was instructed to do (remember, this instance is just being used to prepare the image).

If problems with image creation are encountered, please check OpenStack's Virtual Machine Image Guide for reference.

The next step is to isolate the volume attached to the temporary instance so that it can be uploaded to the Glance image service. To do this, delete the server with the following command:

[[email protected]]$ openstack server delete INSTANCE_ID

With the volume isolated, its contents can now be uploaded to the Glance image service using the following:

[[email protected]]$ openstack image create --volume VOLUME_ID ubuntu-17.04-server-amd64

ubuntu-17.04-server-amd64 can now be used to launch functional instances based on the operating system that was just installed/configured! Example:

[[email protected]]$ openstack server create \
    --image ubuntu-17.04-server-amd64 \
    --nic net-id=NETWORK_UUID \
    --flavor 50 ubuntu17test
+--------------------------------------+--------------------------------------+
| Field                                | Value                                |
+--------------------------------------+--------------------------------------+
| OS-DCF:diskConfig                    | MANUAL                               |
| OS-EXT-AZ:availability_zone          | iad-2                                |
| OS-EXT-STS:power_state               | 0                                    |
| OS-EXT-STS:task_state                | scheduling                           |
| OS-EXT-STS:vm_state                  | building                             |
| OS-SRV-USG:launched_at               | None                                 |
| OS-SRV-USG:terminated_at             | None                                 |
| accessIPv4                           |                                      |
| accessIPv6                           |                                      |
| addresses                            |                                      |
| adminPass                            | DALBYZhdk8f4                         |
| config_drive                         |                                      |
| created                              | 2017-05-27T14:26:09Z                 |
| flavor                               | gp1.semisonic (50)                   |
| hostId                               |                                      |
| id                                   | INSTANCE_ID                          |
| image                                | ubuntu-17.04-server-amd64 (...)      |
| key_name                             |                                      |
| name                                 | ubuntu17test                         |
| os-extended-volumes:volumes_attached | []                                   |
| progress                             | 0                                    |
| project_id                           | PROJECT_ID                           |
| properties                           |                                      |
| security_groups                      | [{u'name': u'default'}]              |
| status                               | BUILD                                |
| updated                              | 2017-05-27T14:26:10Z                 |
| user_id                              | USER_ID                              |
+--------------------------------------+--------------------------------------+

Alternatively the volume can simply be used as the boot source for a new instance. The "upload to Glance" concept is just in case using the same operating system/configuration on multiple instances is desired. 

If you choose not to upload the volume, make sure to run the openstack volume set --bootable VOLUME_ID command so the volume can be used as the source of a new instance.

Did this article answer your questions?

Article last updated PST.