Creating custom images

On this page, you can find an explanation of how to create and delete custom images in the Cloud Console.

Table of contents

  1. Prerequisites
  2. Get a list of all available images
  3. Create/upload an image
  4. Delete an image

Prerequisites

In this article, we will assume that we have already created the following resources, that refer to the Project named TestPr, that was created in the Organization named Test1:
  • SSH Key, that will be specified during creating the Virtual Machine for further connection to them via SSH- it was created with the next parameters:
    • Name: testV;
    • Public key is placed on the Linux VM during its creation;
    • Private Key was copied to the clipboard and saved on the local system in the next text file (for example: ~/.ssh/id_rsa);
  • Firewall (Name: for-ssh), that will be specified during creating the Virtual Machine for further connection to it via SSH - it was created with the rule allowing incoming traffic on port 22; this rule was created with the next parameters:
    • Description: for connection via ssh;
    • Direction: ingress;
    • Port range min: 22;
    • Port range max: 22;
    • Protocol: tcp;
    • Remote IP prefix: 0.0.0.0/0
  • Ubuntu Virtual Machine (IP: 185.226.42.40), from which we will create custom image - it was created with the next parameters and with additional Firewall named for-ssh, configured to allow incoming traffic on port 22,  so we can connect to this Virtual Machine remotely from our local server via SSH:
    • Name: testImages;
    • Flavor: VC-2;
    • Image: ubuntu-server-18.04-LTS-20201111;
    • Key pair: testV;
    • Networks: public;
    • Firewalls: default, for-ssh;
    • Volume size: 10.  
    • API User, created with the following parameters and its RC file has already been loaded:
      • Name: testCLIuser;
      • Password: P@sword.

    For more information on creating and configuring these resources, see the following articles:

    Get a list of all available images

    To get the list of all available images follow the next steps:

    • Loggin to your Ubuntu Virtual Machine - for this we use SSH protocol - to find additional information about, it see the article: Connect to Linux VM via SSH:
      ssh -i ~/.ssh/id_rsa ubuntu@185.226.42.40
    • Update Ubuntu package sources by running the following command:
      sudo apt update
    • Install Kubernetes Python Client by running the next command:
      sudo apt install python3-pip
    • Install openstack cli tool by running next command one by one: 
      sudo pip3 install python-openstackclient
      Place RC File of the created CLI User to your Virtual Machine:
      vi openrc

      Сheck that there were indicated the correct OS_USERNAME and  OS_PROJECT_ID and press  Esc:wq, then Enter to save the changes:

      #!/usr/bin/env bash

          # To use an OpenStack cloud you need to authenticate against the Identity

          # service named keystone, which returns a **Token** and **Service Catalog**.

          # The catalog contains the endpoints for all services the user/tenant has

          # access to - such as Compute, Image Service, Identity, Object Storage, Block

          # Storage, and Networking (code-named nova, glance, keystone, swift,

          # cinder, and neutron).

          #

          # *NOTE*: Using the 3 *Identity API* does not necessarily mean any other

          # OpenStack API is version 3. For example, your cloud provider may implement

          # Image API v1.1, Block Storage API v2, and Compute API v2.0. OS_AUTH_URL is

          # only for the Identity API served through keystone.

          export OS_AUTH_URL=https://upper-austria.ventuscloud.eu:443/v3

          # With the addition of Keystone we have standardized on the term **project**

          # as the entity that owns the resources.

          export OS_PROJECT_ID=681b1b8861fb45e899953da558f22f37

          export OS_PROJECT_NAME="Test1:TestPr"

          export OS_USER_DOMAIN_NAME="ventus"

          if [ -z "$OS_USER_DOMAIN_NAME" ]; then unset OS_USER_DOMAIN_NAME; fi

          export OS_PROJECT_DOMAIN_ID="e1780e7170674d5684076a726f683cfd"

          if [ -z "$OS_PROJECT_DOMAIN_ID" ]; then unset OS_PROJECT_DOMAIN_ID; fi

          # unset v2.0 items in case set

          unset OS_TENANT_ID

          unset OS_TENANT_NAME

          # In addition to the owning entity (tenant), OpenStack stores the entity

          # performing the action as the **user**.

          export OS_USERNAME="Test1:testCLIuser"

          # With Keystone you pass the keystone password.

          echo "Please enter your OpenStack Password for project $OS_PROJECT_NAME as user $OS_USERNAME: "

          read -sr OS_PASSWORD_INPUT

          export OS_PASSWORD=$OS_PASSWORD_INPUT

          # If your configuration has multiple regions, we set that information here.

          # OS_REGION_NAME is optional and only valid in certain environments.

          export OS_REGION_NAME="Upper-Austria"

          # Don't leave a blank variable, unset it if it was empty

          if [ -z "$OS_REGION_NAME" ]; then unset OS_REGION_NAME; fi

          export OS_INTERFACE=public

          export OS_IDENTITY_API_VERSION=3
    • Execute openrc starting with dot:
      . openrc
    • Provide the password of the created CLI User and hit Enter - this password will be used to authenticate you in the Cloud Console.
    • Run the next command to get a list of all available images:
      openstack image list

    In our case the output will be next:

    custimag1

    Also all this images you can find in the Cloud Console on the step of creating VMs when you need to an image:

    custimag2

    Create/upload an image

    To create/upload an image follow the next steps:

    • Prepare your own image that you want to upload to the Cloud Console.
      In our case, we use just one of the Ubuntu images, but you can upload your own unique image that should be located locally:
    wget https://cloud-images.ubuntu.com/focal/current/focal-server-cloudimg-amd64.img
    •  Upload your own unique image, which is already located locally - for this, use the following command:
    openstack image create \ 
    --disk-format=qcow2 \
    --container-format=bare \
    --file=focal-server-cloudimg-amd64.img \
    --property os_distro='ubuntu' \
    ubuntu-server-Ventus-Test
    If the creation was successful, the output will be as follows:
    custimag4
    • Make sure that our new image appeared among the available  - for this, use the "openstack image list" command:
    openstack image list

    In our case the output should be the next:

    custimag3

    Also you can find this new image in the Cloud Console on the step of creating VMs when you need to select an image:

    custimag5

    Let’s take a closer look to the command, that was used for image creating:

    openstack image create \ 
    --disk-format=qcow2 \
    --container-format=bare \
    --file=focal-server-cloudimg-amd64.img \
    --property os_distro='ubuntu' \
    ubuntu-server-Ventus-Test
    • –disk-format - The supported options are: ami, ari, aki, vhd, vmdk, raw, qcow2, vhdx, vdi, iso, and ploop. The default format is: raw.
    • –container-format - The supported options are: ami, ari, aki, bare, docker, ova, ovf. The default format is: bare.
    • –file - Upload image from a local file.
    • –property - Set a property on this image (repeat for multiple values).
    • ubuntu-server-Ventus-Test - New image name.

    Also here you can use some other required arguments, for example:

    • –location - Download image from an existing URL.
    • –copy-from - Copy image from the data store (similar to *--location*).
    • –volume - Create an image from a volume.

    To find more required arguments use the next command:

    openstack image create --help

    Delete an image

    To delete an image use the next command:

    openstack image delete <IMAGE-ID>

    If the image, that you want to delete is protected, the first step for deleting is to unprotect it, for this use the next command:

    openstack image set --unprotected <IMAGE-ID>