7. Launch instances

Instances are virtual machines that run inside the cloud.

Before you can launch an instance, gather the following parameters:

  • The instance source can be an image, snapshot, or block storage volume that contains an image or snapshot.

  • A name for your instance.

  • The flavor for your instance, which defines the compute, memory, and storage capacity of nova computing instances. A flavor is an available hardware configuration for a server. It defines the size of a virtual server that can be launched.

  • Any user data files. A user data file is a special key in the metadata service that holds a file that cloud-aware applications in the guest instance can access.

  • Access and security credentials, which include one or both of the following credentials:

    • A key pair for your instance, which are SSH credentials that are injected into images when they are launched. For the key pair to be successfully injected, the image must contain the cloud-init package. Create at least one key pair for each project. If you already have generated a key pair with an external tool, you can import it into OpenStack. You can use the key pair for multiple instances that belong to that project.

    • A security group that defines which incoming network traffic is forwarded to instances. Security groups hold a set of firewall policies, known as security group rules.

  • If needed, you can assign a floating (public) IP address to a running instance.

  • You can also attach a block storage device, or volume, for persistent storage.

Note

Instances that use the default security group cannot, by default, be accessed from any IP address outside of the cloud. If you want those IP addresses to access the instances, you must modify the rules for the default security group.

You can also assign a floating IP address to a running instance to make it accessible from outside the cloud. See Section 8.1, “Manage IP addresses”.

After you gather the parameters that you need to launch an instance, you can launch it from an image or a volume. You can launch an instance directly from one of the available OpenStack images or from an image that you have copied to a persistent volume. The OpenStack Image Service provides a pool of images that are accessible to members of different projects.

7.1. Gather parameters to launch an instance

Before you begin, source the OpenStack RC file.

  1. List the available flavors:

    $ nova flavor-list

    Note the ID of the flavor that you want to use for your instance:

    +----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
    | ID | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
    +----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
    | 1  | m1.tiny   | 512       | 0    | 0         |      | 1     | 1.0         | True      |
    | 2  | m1.small  | 2048      | 20   | 0         |      | 1     | 1.0         | True      |
    | 3  | m1.medium | 4096      | 40   | 0         |      | 2     | 1.0         | True      |
    | 4  | m1.large  | 8192      | 80   | 0         |      | 4     | 1.0         | True      |
    | 5  | m1.xlarge | 16384     | 160  | 0         |      | 8     | 1.0         | True      |
    +----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
  2. List the available images:

    $ nova image-list

    Note the ID of the image from which you want to boot your instance:

    +--------------------------------------+---------------------------------+--------+--------+
    | ID                                   | Name                            | Status | Server |
    +--------------------------------------+---------------------------------+--------+--------+
    | 397e713c-b95b-4186-ad46-6126863ea0a9 | cirros-0.3.2-x86_64-uec         | ACTIVE |        |
    | df430cc2-3406-4061-b635-a51c16e488ac | cirros-0.3.2-x86_64-uec-kernel  | ACTIVE |        |
    | 3cf852bd-2332-48f4-9ae4-7d926d50945e | cirros-0.3.2-x86_64-uec-ramdisk | ACTIVE |        |
    +--------------------------------------+---------------------------------+--------+--------+

    You can also filter the image list by using grep to find a specific image, as follows:

    $ nova image-list | grep 'kernel'
    | df430cc2-3406-4061-b635-a51c16e488ac | cirros-0.3.2-x86_64-uec-kernel  | ACTIVE |        |
  3. List the available security groups:

    Note

    If you are an admin user, specify the --all-tenants parameter to list groups for all tenants.

    $ nova secgroup-list --all-tenants

    Note the ID of the security group that you want to use for your instance:

    +----+---------+-------------+----------------------------------+
    | Id | Name    | Description | Tenant_ID                        |
    +----+---------+-------------+----------------------------------+
    | 2  | default | default     | 66265572db174a7aa66eba661f58eb9e |
    | 1  | default | default     | b70d90d65e464582b6b2161cf3603ced |
    +----+---------+-------------+----------------------------------+

    If you have not created any security groups, you can assign the instance to only the default security group.

    You can view rules for a specified security group:

    $ nova secgroup-list-rules default
  4. List the available key pairs and note the name of the key pair that you use for SSH access.

    $ nova keypair-list

7.2. Launch an instance from an image

  1. After you gather required parameters, run the following command to launch an instance. Specify the server name, flavor ID, and image ID. Additionally:

    • If more than one network is deployed, you must specify the network ID using --nic net-id=networkID.

    • Optionally, you can provide a key name for access control and a security group for security. You can also include metadata key and value pairs. For example, you can add a description for your server by providing the --meta description="My Server" parameter.

    • You can pass user data in a local file at instance launch by using the --user-data USER-DATA-FILE parameter.

    $ nova boot --flavor FLAVOR_ID --image IMAGE_ID \
    --nic net-id=NETWORK_ID --key-name KEY_NAME \
    --user-data USER_DATA_FILE --security-groups SEC_GROUP --meta KEY=VALUE \
    INSTANCE_NAME

    For example:

    $ nova boot --flavor 1 --image 397e713c-b95b-4186-ad46-6126863ea0a9 \
    --nic net-id=3d706957-7696-4aa8-973f-b80892ff9a95 \
     --key-name KeyPair01 --user-data cloudinit.file --security-groups default\
    myCirrosServer

    Depending on the parameters that you provide, the command returns a list of server properties.

    • A status of BUILD indicates that the instance has started, but is not yet online.

    • A status of ACTIVE indicates that the instance is active.

    +-------------------------------------+--------------------------------------+
    | Property                            | Value                                |
    +-------------------------------------+--------------------------------------+
    | OS-EXT-STS:task_state               | scheduling                           |
    | image                               | cirros-0.3.2-x86_64-uec              |
    | OS-EXT-STS:vm_state                 | building                             |
    | OS-EXT-SRV-ATTR:instance_name       | instance-00000002                    |
    | flavor                              | m1.small                             |
    | id                                  | b3cdc6c0-85a7-4904-ae85-71918f734048 |
    | security_groups                     | [{u'name': u'default'}]              |
    | user_id                             | 376744b5910b4b4da7d8e6cb483b06a8     |
    | OS-DCF:diskConfig                   | MANUAL                               |
    | accessIPv4                          |                                      |
    | accessIPv6                          |                                      |
    | progress                            | 0                                    |
    | OS-EXT-STS:power_state              | 0                                    |
    | OS-EXT-AZ:availability_zone         | nova                                 |
    | config_drive                        |                                      |
    | status                              | BUILD                                |
    | updated                             | 2013-07-16T16:25:34Z                 |
    | hostId                              |                                      |
    | OS-EXT-SRV-ATTR:host                | None                                 |
    | key_name                            | None                                 |
    | OS-EXT-SRV-ATTR:hypervisor_hostname | None                                 |
    | name                                | myCirrosServer                       |
    | adminPass                           | tVs5pL8HcPGw                         |
    | tenant_id                           | 66265572db174a7aa66eba661f58eb9e     |
    | created                             | 2013-07-16T16:25:34Z                 |
    | metadata                            | {u'KEY': u'VALUE'}                   |
    +-------------------------------------+--------------------------------------+

    Copy the server ID value from the id field in the output. You use this ID to get details for or delete your server.

    Copy the administrative password value from the adminPass field. You use this value to log in to your server.

    Note

    You can also place arbitrary local files into the instance file system at creation time by using the --file <dst-path=src-path> option. You can store up to five files. For example, if you have a special authorized keys file named special_authorized_keysfile that you want to put on the instance rather than using the regular SSH key injection, you can use the --file option as shown in the following example:

    $ nova boot --image rhel-cloudimage --flavor 1 \
    --nic net-id=3d706957-7696-4aa8-973f-b80892ff9a95 \
    --file /root/.ssh/authorized_keys=special_authorized_keysfile VM-name
  2. Check if the instance is online:

    $ nova list

    The list shows the ID, name, status, and private (and if assigned, public) IP addresses for all instances in the project to which you belong:

    +------------------------------------+--------------------+------+----------+-----------+----------------+
    |ID                                  |Name                |Status|Task State|Power State|Networks        |
    +------------------------------------+--------------------+------+----------+-----------+----------------+
    |84c6e57d-a6b1-44b6-81eb-fcb36afd31b5|myCirrosServer      |ACTIVE|None      |Running    |private=10.0.0.3|
    |8a99547e-7385-4ad1-ae50-4ecfaaad5f42|myInstanceFromVolume|ACTIVE|None      |Running    |private=10.0.0.4|
    +------------------------------------+--------------------+------+----------+-----------+----------------+

    If the status for the instance is ACTIVE, the instance is online.

    To view the available options for the nova list command, run the following command:

    $ nova help list
Note

If you did not provide a key pair, security groups, or rules, you can access the instance only from inside the cloud through VNC. Even pinging the instance is not possible.

7.3. Launch an instance from a volume

You can boot instances from a volume instead of an image.

To complete these tasks, use these parameters on the nova boot command:

Task nova boot parameter See
Boot an instance from an image and attach a non-bootable volume. --block-device Section 7.3.1, “Boot instance from image and attach non-bootable volume”
Create a volume from an image and boot an instance from that volume. --block-device Section 7.3.2, “Create volume from image and boot instance”
Boot from an existing source image, volume, or snapshot. --block-device Section 7.3.2, “Create volume from image and boot instance”
Attach a swap disk to an instance. --swap Section 7.3.3, “Attach swap or ephemeral disk to an instance”
Attach an ephemeral disk to an instance. --ephemeral Section 7.3.3, “Attach swap or ephemeral disk to an instance”
Note

To attach a volume to a running instance, see Section 16.3, “Attach a volume to an instance”.

7.3.1. Boot instance from image and attach non-bootable volume

Create a non-bootable volume and attach that volume to an instance that you boot from an image.

To create a non-bootable volume, do not create it from an image. The volume must be entirely empty with no partition table and no file system.

  1. Create a non-bootable volume:

    $ cinder create --display-name my-volume 8
    +---------------------+--------------------------------------+
    |       Property      |                Value                 |
    +---------------------+--------------------------------------+
    |     attachments     |                  []                  |
    |  availability_zone  |                 nova                 |
    |       bootable      |                false                 |
    |      created_at     |      2014-10-22T03:45:15.262732      |
    | display_description |                 None                 |
    |     display_name    |              my-volume               |
    |      encrypted      |                False                 |
    |          id         | 0306f8fa-4324-4a56-95c1-be2fa44954bc |
    |       metadata      |                  {}                  |
    |         size        |                  8                   |
    |     snapshot_id     |                 None                 |
    |     source_volid    |                 None                 |
    |        status       |               creating               |
    |     volume_type     |                 None                 |
    +---------------------+--------------------------------------+
  2. List volumes:

    $ cinder list
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    |                  ID                  |   Status  | Display Name | Size | Volume Type | Bootable | Attached to |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
    | 0306f8fa-4324-4a56-95c1-be2fa44954bc | available |  my-volume   |  8   |     None    |  false   |             |
    +--------------------------------------+-----------+--------------+------+-------------+----------+-------------+
  3. Boot an instance from an image and attach the empty volume to the instance:

    $ nova boot --flavor 2 --image 901d3823-2be1-4ce3-b9b4-56330d56fd45 \
    --nic net-id=3d706957-7696-4aa8-973f-b80892ff9a95          
    --block-device source=volume,id=0306f8fa-4324-4a56-95c1-be2fa44954bc,dest=volume,shutdown=preserve \
    myInstanceWithVolume
    +--------------------------------------+--------------------------------------------------+
    | Property                             | Value                                            |
    +--------------------------------------+--------------------------------------------------+
    | OS-DCF:diskConfig                    | MANUAL                                           |
    | OS-EXT-AZ:availability_zone          | nova                                             |
    | OS-EXT-STS:power_state               | 0                                                |
    | OS-EXT-STS:task_state                | scheduling                                       |
    | OS-EXT-STS:vm_state                  | building                                         |
    | OS-SRV-USG:launched_at               | -                                                |
    | OS-SRV-USG:terminated_at             | -                                                |
    | accessIPv4                           |                                                  |
    | accessIPv6                           |                                                  |
    | adminPass                            | 2yodoJ4tSR5N                                     |
    | config_drive                         |                                                  |
    | created                              | 2014-10-22T03:54:55Z                             |
    | flavor                               | m1.small (2)                                     |
    | hostId                               |                                                  |
    | id                                   | 41f0e45c-c6da-44fd-80f3-871a8bf9c9b4             |
    | image                                | cirros (901d3823-2be1-4ce3-b9b4-56330d56fd45)    |
    | key_name                             | -                                                |
    | metadata                             | {}                                               |
    | name                                 | myInstanceWithVolume                             |
    | os-extended-volumes:volumes_attached | [{"id": "0306f8fa-4324-4a56-95c1-be2fa44954bc"}] |
    | progress                             | 0                                                |
    | security_groups                      | default                                          |
    | status                               | BUILD                                            |
    | tenant_id                            | 2b70dffaf18a400fb37d6126677c1a35                 |
    | updated                              | 2014-10-22T03:54:56Z                             |
    | user_id                              | 4db8be9d66e7446c9293999ab6c4fdac                 |
    +--------------------------------------+--------------------------------------------------+

7.3.2. Create volume from image and boot instance

You can create a volume from an existing image, volume, or snapshot. This procedure shows you how to create a volume from an image, and use the volume to boot an instance.

  1. List the available images:

    $ nova image-list
    +--------------------------------------+---------------------------------+--------+--------+
    | ID                                   | Name                            | Status | Server |
    +--------------------------------------+---------------------------------+--------+--------+
    | 484e05af-a14d-4567-812b-28122d1c2260 | rhel-x86_64-20-20131211.1-sda   | ACTIVE |        |
    | 98901246-af91-43d8-b5e6-a4506aa8f369 | cirros-0.3.1-x86_64-uec         | ACTIVE |        |
    | b6e95589-7eb2-4171-8bab-d225d9262c73 | cirros-0.3.1-x86_64-uec-kernel  | ACTIVE |        |
    | c90893ea-e732-40ac-a23d-4e36b2082c35 | cirros-0.3.1-x86_64-uec-ramdisk | ACTIVE |        |
    +--------------------------------------+---------------------------------+--------+--------+

    Note the ID of the image that you want to use to create a volume.

  2. List the available flavors:

    $ nova flavor-list
    +-----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
    | ID  | Name      | Memory_MB | Disk | Ephemeral | Swap | VCPUs | RXTX_Factor | Is_Public |
    +-----+-----------+-----------+------+-----------+------+-------+-------------+-----------+
    | 1   | m1.tiny   | 512       | 1    | 0         |      | 1     | 1.0         | True      |
    | 2   | m1.small  | 2048      | 20   | 0         |      | 1     | 1.0         | True      |
    | 3   | m1.medium | 4096      | 40   | 0         |      | 2     | 1.0         | True      |
    | 4   | m1.large  | 8192      | 80   | 0         |      | 4     | 1.0         | True      |
    | 42  | m1.nano   | 64        | 0    | 0         |      | 1     | 1.0         | True      |
    | 451 | m1.heat   | 1024      | 0    | 0         |      | 2     | 1.0         | True      |
    | 5   | m1.xlarge | 16384     | 160  | 0         |      | 8     | 1.0         | True      |
    | 84  | m1.micro  | 128       | 0    | 0         |      | 1     | 1.0         | True      |
    +-----+-----------+-----------+------+-----------+------+-------+-------------+-----------+

    Note the ID of the flavor that you want to use to create a volume.

  3. To create a bootable volume from an image and launch an instance from this volume, use the --block-device parameter.

    For example:

    $ nova boot --flavor FLAVOR --nic net-id=NETWORK_ID --block-device source=SOURCE,id=ID,dest=DEST,size=SIZE,shutdown=PRESERVE,bootindex=INDEX NAME

    The parameters are:

    • --flavor FLAVOR. The flavor ID or name.

    • --nic net-id=NETWORK_ID. The network to which the new instance is attached. If only one network is available to the user, this option can be omitted.

    • --block-device source=SOURCE,id=ID,dest=DEST,size=SIZE,shutdown=PRESERVE,bootindex=INDEX

      source=SOURCE

      The type of object used to create the block device. Valid values are volume, snapshot, image, and blank.

      id=ID

      The ID of the source object.

      dest=DEST

      The type of the target virtual device. Valid values are volume and local.

      size=SIZE

      The size of the volume that is created.

      shutdown={preserve|remove}

      What to do with the volume when the instance is deleted. preserve does not delete the volume. remove deletes the volume.

      bootindex=INDEX

      Orders the boot disks. Use 0 to boot from this volume.

    • NAME. The name for the server.

  4. Create a bootable volume from an image, before the instance boots. The volume is not deleted when the instance is terminated:

    $ nova boot --flavor 2 --nic net-id=3d706957-7696-4aa8-973f-b80892ff9a95 \
    --block-device source=image,id=e0b7734d-2331-42a3-b19e-067adc0da17d,dest=volume,size=10,shutdown=preserve,bootindex=0 \
    myInstanceFromVolume
    +--------------------------------------+-------------------------------------------------+
    | Property                             | Value                                           |
    +--------------------------------------+-------------------------------------------------+
    | OS-EXT-STS:task_state                | scheduling                                      |
    | image                                | Attempt to boot from volume - no image supplied |
    | OS-EXT-STS:vm_state                  | building                                        |
    | OS-EXT-SRV-ATTR:instance_name        | instance-00000003                               |
    | OS-SRV-USG:launched_at               | None                                            |
    | flavor                               | m1.small                                        |
    | id                                   | 2e65c854-dba9-4f68-8f08-fe332e546ecc            |
    | security_groups                      | [{u'name': u'default'}]                         |
    | user_id                              | 352b37f5c89144d4ad0534139266d51f                |
    | OS-DCF:diskConfig                    | MANUAL                                          |
    | accessIPv4                           |                                                 |
    | accessIPv6                           |                                                 |
    | progress                             | 0                                               |
    | OS-EXT-STS:power_state               | 0                                               |
    | OS-EXT-AZ:availability_zone          | nova                                            |
    | config_drive                         |                                                 |
    | status                               | BUILD                                           |
    | updated                              | 2014-02-02T13:29:54Z                            |
    | hostId                               |                                                 |
    | OS-EXT-SRV-ATTR:host                 | None                                            |
    | OS-SRV-USG:terminated_at             | None                                            |
    | key_name                             | None                                            |
    | OS-EXT-SRV-ATTR:hypervisor_hostname  | None                                            |
    | name                                 | myInstanceFromVolume                            |
    | adminPass                            | TzjqyGsRcJo9                                    |
    | tenant_id                            | f7ac731cc11f40efbc03a9f9e1d1d21f                |
    | created                              | 2014-02-02T13:29:53Z                            |
    | os-extended-volumes:volumes_attached | []                                              |
    | metadata                             | {}                                              |
    +--------------------------------------+-------------------------------------------------+
  5. List volumes to see the bootable volume and its attached myInstanceFromVolume instance:

    $ cinder list
    +------------------------------------+------+------------+----+-----------+--------+------------------------------------+
    |                 ID                 |Status|Display Name|Size|Volume Type|Bootable|            Attached to             |
    +------------------------------------+------+------------+----+-----------+--------+------------------------------------+
    |2fff50ab-1a9c-4d45-ae60-1d054d6bc868|in-use|            | 10 |    None   |  true  |2e65c854-dba9-4f68-8f08-fe332e546ecc|
    +------------------------------------+------+------------+----+-----------+--------+------------------------------------+

7.3.3. Attach swap or ephemeral disk to an instance

Use the nova boot --swap parameter to attach a swap disk on boot or the nova boot --ephemeral parameter to attach an ephemeral disk on boot. When you terminate the instance, both disks are deleted.

Boot an instance with a 512 MB swap disk and 2 GB ephemeral disk:

$ nova boot --flavor FLAVOR --nic net-id=NETWORK_ID \
--image IMAGE_ID --swap 512 --ephemeral size=2 NAME
Note

The flavor defines the maximum swap and ephemeral disk size. You cannot exceed these maximum values.