Booting an instance

The most fundamental tasks that can be performed with instances are life cycle tasks. In this recipe, we will show you how to start or boot an instance.

Getting ready

To start an instance, you will need the following:

  • The openstack command-line client
  • The openrc file containing appropriate credentials
  • The name of the instance
  • The image to use for the instance
  • The name of the flavor to create the instance with
  • The name of the network or networks to attach the instance to
  • The keypair name to allow access to an instance
  • The name of any security groups to associate with the instance

How to do it…

The instance we will boot will have the following attributes:

  • Instance name: cookbook.test
  • Flavor type: openstack.cookbook
  • Image name: Ubuntu 16.04 amd64 (UUID)
  • Network: public (UUID)
  • Keypair name: cookbook_key
  • Security groups: ssh

To start an instance, use the following steps:

  1. To list the instances that are currently running, we issue the following command:
    openstack server list
    

    Tip

    This command will produce no output if there are no instances.

  2. List the available images:
    openstack image list
    

    This will bring back a list of images available:

    How to do it…
  3. List the available networks:
    openstack network list
    

    This will list the networks that we can attach an instance to:

    How to do it…
  4. Create a keypair (if you do not have one already created and available for use):
    ssh-keygen -q -N ""
    

    Also, upload this with the following command:

    openstack keypair create --public-key ~/.ssh/id_rsa.pub cookbook_key
    

    This will bring back an output showing the fingerprint of your key:

    How to do it…
  5. Now we can boot the instance with the following command:
    openstack server create
        --flavor openstack.cookbook
        --image 08b822ba-be44-4639-b577-45e8dd37c06d
        --nic net-id=6cb5a4ce-1ea5-4817-9c34-a2212a66f394
        --security-group ssh 
        --key-name cookbook_key
        cookbook.test
    

    This produces a table of output showing that the instance is booting (not shown here for brevity).

  6. To view more information about the booted instance, issue the following command:
    openstack server show cookbook.test
    

    This gives an output like the following:

    How to do it…

How it works…

After noting a number of required values we will be supplying as input, such as the UUID of the image that we want to boot and the UUID of the network we want to attach the instance to, we then called a tool from OpenStack Client to launch our instance. Part of that command line refers to the keypair to use. We then connect to the instance using the private key as part of that keypair generated.

How does the cloud instance know what key to use? As part of the boot scripts for this image, it makes a call back to the metaserver, which is a function of the nova-api and nova-api-metadata services. The metaserver provides a go-between that bridges our instance and the real world, which the cloud-init boot process can call and in this case, it downloads a script to inject our private key into the Ubuntu user's .ssh/authorized_keys file.

When a cloud instance is launched, it generates a number of useful metrics and details about that instance. This is presented by the openstack server list and openstack server show commands. The openstack server list command shows a convenient short version listing the ID, name, status, and IP addresses of our instance.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.149.243.18