Creating OVA images using a CentOS instance in IBM Power Systems Virtual Servers – IBM Developer

Join the Digital Developer Conference: AIOps & Integration to propel your AI-powered automation skills Register for free

Creating OVA images using a CentOS instance in IBM Power Systems Virtual Servers

This tutorial is part of the Learning path: Deploying Red Hat OpenShift Container Platform 4.x on IBM Power Systems Virtual Servers.

Introduction

This tutorial is an enhancement of the previous tutorial for creating and uploading OVA images to IBM Power Systems Virtual Server. It provides a completely automated way by using a script for creating and uploading Red Hat Enterprise Linux (RHEL) and Red Hat Enterprise Linux CoreOS (RHCOS) OVA images. This script creates its own CentOS virtual machine (VM) in Power Systems Virtual Server to perform all the conversion tasks. This script uses the pvsadm tool to manage the image conversion and upload tasks.

Workflow

The workflow of the script for creating and uploading images includes:

  • Creating a CentOS instance using the default CentOS image present in Power Virtual Server with terraform code.
  • Converting the given RHEL and RHCOS images from the created CentOS instance using the pvsadm tool.
  • Uploading and importing the RHEL and RHCOS OVA images from the CentOS instance using the pvsadm tool.

The automation script can run in the following environments:

  • Mac OS X
  • Microsoft Windows10 with Windows Subsystem for Linux (WSL), or Cygwin
  • Any Linux x86_64 system

Prerequisites

The prerequisites for running the automation script includes:

  • Access to any of the environments supported (mentioned in previous section) with internet connectivity.
  • IBM cloud API key to login to the service instance
  • A valid Red Hat subscription (for RHEL image)

Estimated time

It requires approximately 2.5 to 3 hours for creating OVA images and uploading them to an IBM Power Virtual Server service using the automated script.

Steps

This section provides the steps for using the script to convert and upload an OVA image into the IBM Cloud Virtual Server instance.

  1. Download the script.

    curl -O -fsSL https://raw.githubusercontent.com/ppc64le-cloud/pvsadm/master/samples/convert-upload-images-powervs/convert-upload-images-powervs

  2. Provide execute permission to run script.

    chmod +x ./convert-upload-images-powervs

  3. Export the required keys and RHEL credentials for creating and uploading the OVA images.

    
     export IBMCLOUD_API_KEY="<ibm cloud api key>"
     export RHEL_SUBSCRIPTION_USERNAME="<redhat subscription username>" (only if you are creating rhel image)
     export RHEL_SUBSCRIPTION_PASSWORD="<redhat subscription password>" (only if you are creating rhel image)
     export RHEL_ROOT_PASSWORD="<rhel root password>" (if the user doesn’t set this variable, the script will generate a password )
    
  4. Use the following command to run the script.

    
      ./convert-upload-images-powervs [ --rhel-url <url> | --rhcos-url <url> ] --service-name  <service name> --region <bucket region> --cos-bucket <bucket name> --cos-resource-group <resource group>  --cos-instance-name <cos instance name>
    

    If prompted for the following information, make sure that you provide the required input.

    • Enter RHEL subscription username for bastion nodes
    • Enter the password for above username

    Use the following URLs for RHEL, and RHCOS Qcow2 images.

    Note: You need a valid Red Hat subscription to access the RHEL images.

    Example usage

    
     ./convert-upload-images-powervs  --service-name  my-powervs-service  --region us-south --cos-bucket my-cos-bucket --cos-resource-group my-resource-group --cos-instance-name my-cos-instance --rhel-url  https://access.cdn.redhat.com/content/origin/files/sha256/4e/xxxxxx/rhel-8.3-ppc64le-kvm.qcow2\?user\=xxxxxxxxxxx\&_auth_\=xxxxxxx  --rhcos-url  https://mirror.openshift.com/pub/openshift-v4/ppc64le/dependencies/rhcos/4.7/4.7.0/rhcos-4.7.0-ppc64le-openstack.ppc64le.qcow2.gz
    

    Where:

    Parameter Description
    --service-name A list of Power Virtual Server service instances with comma separated (mandatory)
    --region Object store bucket region (mandatory)
    --cos-bucket Object store bucket name (mandatory)
    --cos-resource-group Cloud Object Storage resource group (mandatory)
    --cos-instance-name Cloud Object Storage instance name (mandatory)
    --rhel-url An URL pointing to the RHEL Qcow2 image (optional)
    --rhcos-url An URL pointing to the RHCOS Qcow2 image (optional)

    For more options run the following command:

    ./convert-upload-images-powervs --help

Sample run of the script on a Mac system

 ./convert-upload-images-powervs  --service-name  my-powervs-service  --region us-south --cos-bucket my-test-bucket-2001 --cos-resource-group my-resource-group --rhcos-url  https://mirror.openshift.com/pub/openshift-v4/ppc64le/dependencies/rhcos/4.7/4.7.0/rhcos-4.7.0-ppc64le-openstack.ppc64le.qcow2.gz  --rhel-url https://access.cdn.redhat.com/content/origin/files/sha256/4e/xxxxxx/rhel-8.3-ppc64le-kvm.qcow2\?user\=xxxxxxxxxxx\&_auth_\=xxxxxxx  
[setup] Installing dependency packages and tools
[setup_tools] Verifying the latest packages and tools
[setup_ibmcloudcli] Installing the latest version of IBM-Cloud CLI...
Attempt: 1/5
./ibmcloud version 1.4.0+4705d79-2021-02-24T21:58:03+00:00
[setup_terraform] Installing the latest version of Terraform...
Attempt: 1/5
Terraform v0.13.5
[setup_pvsadm] Identifying operating system and setting up pvsadm
Attempt: 1/5
I0304 12:45:35.399209   60664 root.go:43] Using an API key from IBMCLOUD_API_KEY environment variable
Version: v0.1.1-alpha.2, GoVersion: go1.15.8
[setup_artifacts] Downloading code artifacts master in ./automation
Attempt: 1/5
[setup] SUCCESS: setup command completed!
[setup_tools] Verifying the latest packages and tools
[setup_pvsadm] Identifying operating system and settingup pvsadm
Attempt: 1/5
I0304 12:45:52.073872   60858 root.go:43] Using an API key from IBMCLOUD_API_KEY environment variable
Version: v0.1.1-alpha.2, GoVersion: go1.15.8
[variables] Trying to login with the provided IBMCLOUD_API_KEY...
Targeting service crn:v1:bluemix:public:power-iaas:tok04:a/65b64c1f1c29460e:e4bb3d9d-a37c-xxxx-yyyy-4537c0c8beb3::...
[variables] Gathering information from the selected Service Instance... Please wait
[create_cos_bucket] Creating a new cos instance and bucket my-test-bucket-2001(if not present)
Attempt: 1/5
I0304 12:46:05.270869   60901 root.go:43] Using an API key from IBMCLOUD_API_KEY environment variable
I0304 12:46:13.556166   60901 s3client.go:145] uploading the file tmp.8QxCyunJ81K/demo.6jfQ5xfoZK
I0304 12:46:14.020771   60901 s3client.go:171] Upload completed successfully in 0.464415 seconds to location https://s3.us-south.cloud-object-storage.appdomain.cloud/my-test-bucket-2001/demo.6jfQ5xfoZK
[create_cos_bucket] SUCCESS: Creating new bucket successful
[variables] SUCCESS: variables command completed!
[download_image] downloading rhel image
Attempt: 1/5
[main] Downloading rhel qcow2 image completed in: 0hrs 1min 52sec
[import_image] Creating centos-02232021-250 in service my-powervs-service (will take time based on the object size)
Attempt: 1/5
[import_image] SUCCESS: Importing centos-02232021-250.ova.gz to my-powervs-service completed
[import_image] Importing default CentOS OVA image to my-powervs-service completed in: 0hrs 46min 16sec
[setup_tools] Verifying the latest packages and tools
[setup_pvsadm] Identifying operating system and setting up pvsadm
Attempt: 1/5
I0304 13:34:53.288177   70315 root.go:43] Using an API key from IBMCLOUD_API_KEY environment variable
Version: v0.1.1-alpha.2, GoVersion: go1.15.8
[verify_data] WARN: Creating new SSH key-pair...
[powervs_login] Trying to login with the provided IBMCLOUD_API_KEY...
Targeting service crn:v1:bluemix:public:power-iaas:mycosinstance04:a/65b64c1f1c29460e8c:e4bb3d9d-xxxx-yyyy-a923-4537c0c8beb3::...
[init_terraform] Initializing Terraform plugins...
[init_terraform] Validating Terraform code...
[apply] Running terraform apply... please wait
Attempt: 1/5
[retry_terraform] WARN: Issues were seen while running the terraform command. Attempting to run again...
Attempt: 2/5
[retry_terraform] Completed running the terraform command.
Login to bastion: 'ssh -i data/id_rsa root@128.168.101.126' and start using the 'oc' command.
[apply] SUCCESS: Congratulations! create command completed
[apply] Create CentOS VM instance completed in: 0hrs 40min 44sec
[setup_pvsadm_remote] Identifying operating system and setting up pvsadm
Attempt: 1/5
pvsadm
Version: v0.1.1-alpha.2, GoVersion: go1.15.8
[setup_pvsadm_remote] SUCCESS: pvsadm setup in the remote infra machine
[prepare_remote] Preparing the remote machine for image management
Attempt: 1/5
[prepare_remote] SUCCESS: Remote machine preparation completed
[copy_image_to_remote] Copying downloaded rhel and rhcos images to infra node
Attempt: 1/5
rhel-8.3-update-2-ppc64le-kvm.qcow2?user=e35f87692fc38ef0f0eb5404dc81a448&_auth_=1614843861_31ab6059bd4269bb59963ab2 100% 1175MB   8.7MB/s   02:14
[copy_image_to_remote] SUCCESS: Copied ./rhel-8.3-update-2-ppc64le-kvm.qcow2?user=xxxxxx&_auth_=xxxxxx to remote machine completed
[copy_image_to_remote] Copying rhel image to target centos VM completed in: 0hrs 2min 16sec
[convert_image_remote] Converting rhel/rhcos/centos images from qcow2 to ova
Attempt: 1/5
[convert_image_remote] SUCCESS: Converting rhel-83-03042021 completed
[convert_image_remote] Converting rhel-83-03042021 image to OVA completed in: 0hrs 8min 46sec
[upload_image_remote] Uploading image /tmp/tmp.0Pvluq3RKo/rhel-83-03042021.ova.gz to the cos bucket my-test-bucket-2001
Attempt: 1/5
[upload_image_remote] WARN: /tmp/tmp.0Pvluq3RKo/rhel-83-03042021.ova.gz object already exists in the my-test-bucket-2001 bucket. Skipping upload
[upload_image_remote] Uploading /tmp/tmp.0Pvluq3RKo/rhel-83-03042021.ova.gz image to my-test-bucket-2001 completed in: 0hrs 0min 13sec
[import_image_remote] Importing rhel-83-03042021.ova.gz to my-powervs-service
Attempt: 1/5
[import_image_remote] SUCCESS: Importing rhel-83-03042021.ova.gz to my-powervs-service completed
[import_image_remote] Importing rhel-83-03042021.ova.gz image to my-powervs-service completed in: 0hrs 26min 18sec
[convert_image_remote] Converting rhel/rhcos/centos images from qcow2 to ova
Attempt: 1/5
[convert_image_remote] SUCCESS: Converting rhcos-47-03042021 completed
[convert_image_remote] Converting rhcos-47-03042021 image to OVA completed in: 0hrs 6min 46sec
[upload_image_remote] Uploading image /tmp/tmp.0Pvluq3RKo/rhcos-47-03042021.ova.gz to the cos bucket my-test-bucket-2001
Attempt: 1/5
[upload_image_remote] WARN: /tmp/tmp.0Pvluq3RKo/rhcos-47-03042021.ova.gz object already exists in the my-test-bucket-2001 bucket. Skipping upload
[upload_image_remote] Uploading /tmp/tmp.0Pvluq3RKo/rhcos-47-03042021.ova.gz image to my-test-bucket-2001 completed in: 0hrs 0min 8sec
[import_image_remote] Importing rhcos-47-03042021.ova.gz to my-powervs-service
Attempt: 1/5
[import_image_remote] SUCCESS: Importing rhcos-47-03042021.ova.gz to my-powervs-service completed
[import_image_remote] Importing rhcos-47-03042021.ova.gz image to my-powervs-service completed in: 0hrs 24min 14sec
[destroy] Running terraform destroy... please wait
[is_terraform_running] WARN: Last run was less than a min ago... please wait
Attempt: 1/5
[retry_terraform] Completed running the terraform command.
[destroy] SUCCESS: Done! destroy command completed
Thursday March 04 2021 03:27:34 PM 
╭─pvsadm/samples/convert-upload-images-powervs

Note: You need to provide any or combination of --rhel-url, --rhcos-url URLs for image conversion and uploading to the Power Virtual Server service. If the RHEL URL pointing to access.cdn.redhat.com expires, just refresh the page to get the new URL.

Summary

In this tutorial, we have used an automated script for creating and uploading images in Power Virtual Server from a Centos VM. You are now all set for deploying an OpenShift cluster.