Export Image

วิธี export image qcow2 ออกจาก NCS เพื่อเอาไปใช้ภายนอก

Prerequisite

  • ต้องมี image อยู่ใน project

Instructions

สามารถ export image ได้จากบน Windows OS และ Linux OS โดยดำเนินการตามขั้นตอนด้านล่าง

หากต้องการ export ด้วย Windows OS สามารถดำเนินการได้ตามด้านล่าง

  1. Download & Install Python

    สามารถ Download Python ได้จาก link https://www.python.org/ftp/python/3.13.3/python-3.13.3-amd64.exe เลือก Add python.exe to PATH และ กด Install Now

  2. ทดสอบ python ใช้งานได้ปกติหรือไม่ โดยเปิด cmd และใช้ command ดังนี้

C:\Users\OhmzPC>python --version
Python 3.13.3
  1. สร้าง venv เพื่อใช้งานสำหรับ openstack client

C:\Users\OhmzPC>cd Documents

C:\Users\OhmzPC\Documents>mkdir Export_Image

C:\Users\OhmzPC\Documents>cd Export_Image

C:\Users\OhmzPC\Documents\Export_Image>python -m venv osclient

C:\Users\OhmzPC\Documents\Export_Image>osclient\Scripts\activate

(osclient) C:\Users\OhmzPC\Documents\Export_Image>pip install --upgrade pip
Requirement already satisfied: pip in c:\users\ohmzpc\documents\export_image\osclient\lib\site-packages (25.0.1)

(osclient) C:\Users\OhmzPC\Documents\Export_Image>pip install python-openstackclient

(osclient) C:\Users\OhmzPC\Documents\Export_Image>openstack --version
openstack 8.0.0
  1. Setting Public API RC File

  1. แก้ไข test_project_RC_file.sh เป็น test_project_RC_file.bat ดังนี้

แก้จาก #!/usr/bin/env bash เป็น @echo off

แก้จาก # เป็น rem

แก้จาก export เป็น set

แก้จาก if [ -z "$<Variable>" ]; then unset <Variable>; fi เป็น if "%<Variable>%"=="" set <Variable>=

ตัวอย่าง

if [ -z "$OS_USER_DOMAIN_NAME" ]; then unset OS_USER_DOMAIN_NAME; fi เป็น

if "%OS_USER_DOMAIN_NAME%"=="" set OS_USER_DOMAIN_NAME=

แก้จาก read -sr OS_PASSWORD_INPUT เป็น set /p OS_PASSWORD_INPUT=

(osclient) C:\Users\OhmzPC\Documents\Export_Image>notepad test_project_RC_file.sh

#!/usr/bin/env bash
# To use NIPA Cloud Space public API 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/project has
# access to - such as Compute Instance, Compute Image, Block Storage, Networking.

export OS_AUTH_URL=https://identity-api.nipa.cloud/
# Co-working project identity
export OS_PROJECT_ID=834995e704b44fa888b7xxxxxxxxxxxx
export OS_PROJECT_NAME="test_project"
export OS_USER_DOMAIN_NAME="nipacloud"
if [ -z "$OS_USER_DOMAIN_NAME" ]; then unset OS_USER_DOMAIN_NAME; fi
export OS_PROJECT_DOMAIN_ID="c6b00adf4ed04fc5a958121fadb0e401"
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
# performing the action as the **user**.
export OS_USERNAME="test_user@nipa.cloud"
echo "Please enter your NIPA Cloud Space user's password for project $OS_PROJECT_NAME as user $OS_USERNAME: "
read -sr OS_PASSWORD_INPUT
export OS_PASSWORD=$OS_PASSWORD_INPUT
# NIPA Cloud Space only have 1 region "NCP-TH"
export OS_REGION_NAME="NCP-TH"
# 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

แก้เป็น (osclient) C:\Users\OhmzPC\Documents\Export_Image>notepad test_project_RC_file.batฃ

@echo off
rem To use NIPA Cloud Space public API you need to authenticate against the Identity
rem service named keystone, which returns a **Token** and **Service Catalog**.
rem The catalog contains the endpoints for all services the user/project has
rem access to - such as Compute Instance, Compute Image, Block Storage, Networking.

set OS_AUTH_URL=https://identity-api.nipa.cloud/
rem Co-working project identity
set OS_PROJECT_ID=834995e704b44fa888b7xxxxxxxxxxxx
set OS_PROJECT_NAME=test_project
set OS_USER_DOMAIN_NAME=nipacloud
if "%OS_USER_DOMAIN_NAME%"=="" set OS_USER_DOMAIN_NAME=
set OS_PROJECT_DOMAIN_ID=c6b00adf4ed04fc5a958121fadb0e401
if "%OS_PROJECT_DOMAIN_ID%"=="" set OS_PROJECT_DOMAIN_ID=
rem unset v2.0 items in case set
set OS_TENANT_ID=
set OS_TENANT_NAME=
rem performing the action as the **user**.
set OS_USERNAME=test_user@nipa.cloud
echo Please enter your NIPA Cloud Space user's password for project %OS_PROJECT_NAME% as user %OS_USERNAME%:
set /p OS_PASSWORD_INPUT= 
set OS_PASSWORD=%OS_PASSWORD_INPUT%
rem NIPA Cloud Space only have 1 region "NCP-TH"
set OS_REGION_NAME=NCP-TH
rem Don't leave a blank variable, unset it if it was empty
if "%OS_REGION_NAME%"=="" set OS_REGION_NAME=
set OS_INTERFACE=public
set OS_IDENTITY_API_VERSION=3
  1. รันไฟล์ test_project_RC_file.bat และ check ว่า สามารถใช้ openstack client ใน project ได้หรือไม่

(osclient) C:\Users\OhmzPC\Documents\Export_Image>test_project_RC_file.bat
Please enter your NIPA Cloud Space user's password for project test_project as user test_user@nipa.cloud: <ใส่ password>
(osclient) C:\Users\OhmzPC\Documents\Export_Image>openstack token issue
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field      | Value                                                                                                                                                                                   |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| expires    | 2025-04-26T03:59:41+0000                                                                                                                                                                |
| id         | gAAAAABoCwithNSV3tPsaDzi54VvrSxIz6V9rreRJBurlVV2e4Ii5aolilEBRWtUnargn4iKPu8ru-Rt0XqXJl3HHs1x5ZzmH-oM-XQoFRRi7ov_ofiuhryudjdbvSmKHX7d0ZsrEOIvrbCkAqH4gnPNlpsbNc6dnnY5P1s5vmqDrXsOAOB9ywY |
| project_id | 834995e704b44fa888b7xxxxxxxxxxxx                                                                                                                                                     |
| user_id    | e6275119d15648bfb7c2xxxxxxxxxxxx                                                                                                                                                        |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
  1. list image ใน project ด้วย command

(osclient) C:\Users\OhmzPC\Documents\Export_Image>openstack image list
+--------------------------------------+--------------------------------------+--------+
| ID                                   | Name                                 | Status |
+--------------------------------------+--------------------------------------+--------+
| d00037bf-85f6-4bc3-b271-xxxxxxxxxxxx | ubuntu-24-v250307                    | active |
+--------------------------------------+--------------------------------------+--------+
  1. download image ใน project ด้วย command

(osclient) C:\Users\OhmzPC\Documents\Export_Image>openstack image save --file <ชื่อ file image>.qcow2 <image_ID>

ตัวอย่าง
(osclient) C:\Users\OhmzPC\Documents\Export_Image>openstack image save --file ubuntu-24-v250307.qcow2 d00037bf-85f6-4bc3-b271-xxxxxxxxxxxx
  1. ถ้า download เรียบร้อยแล้วจะได้ไฟล์ image

(osclient) C:\Users\OhmzPC\Documents\Export_Image>dir
 Volume in drive C is Windows
 Volume Serial Number is XXXX-XXXX

 Directory of C:\Users\OhmzPC\Documents\Export_Image

04/25/2025  11:08 AM    <DIR>          .
04/25/2025  10:43 AM    <DIR>          ..
04/25/2025  10:57 AM             1,270 test_project_RC_file.bat
04/25/2025  10:49 AM             1,343 test_project_RC_file.sh
04/25/2025  10:51 AM    <DIR>          osclient
04/25/2025  11:09 AM     1,243,992,064 ubuntu-24-v250307.qcow2
               3 File(s)  1,243,994,677 bytes
               3 Dir(s)  326,236,172,288 bytes free

หากต้องการ export ด้วย Linux สามารถดำเนินการได้ตามด้านล่าง

สำหรับ Mac OS ให้เตรียม environment ตามด้านล่าง

  1. Download & Install Python

1.1 ติดตั้ง Homebrew (หากยังไม่ได้ติดตั้ง)

$ /bin/bash -c "$(curl -fsSL <https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh>)"

1.2 ติดตั้ง Python ผ่าน Homebrew

$ brew update
$ brew install python3

1.3 ทดสอบ python ใช้งานได้ปกติหรือไม่ ใช้ command ดังนี้

$ python3 --version
Python 3.12.3
  1. สร้าง venv เพื่อใช้งานสำหรับ openstack client

$ cd ~/
$ python3 -m venv osclient
$ source osclient/bin/activate
(osclient) $ pip install --upgrade pip
(osclient) $ pip install python-openstackclient
(osclient) $ openstack --version
openstack 8.0.0

สำหรับ Ubuntu/Debian ให้เตรียม environment ตามด้านล่าง

  1. Download & Install Python

root@test-export-image:~# apt update -y
root@test-export-image:~# apt install -y python3 python3-pip python3-venv
  1. ทดสอบ python ใช้งานได้ปกติหรือไม่ ใช้ command ดังนี้

root@test-export-image:~# python3 --version
Python 3.12.3
  1. สร้าง venv เพื่อใช้งานสำหรับ openstack client

root@test-export-image:~# mkdir /opt/osclient
root@test-export-image:~# cd /opt/osclient/
root@test-export-image:/opt/osclient# python3 -m venv osclient
root@test-export-image:/opt/osclient# source /opt/osclient/osclient/bin/activate
(osclient) root@test-export-image:/opt/osclient# pip install --upgrade pip
(osclient) root@test-export-image:/opt/osclient# pip install python-openstackclient
(osclient) root@test-export-image:/opt/osclient# openstack --version
openstack 8.0.0

สำหรับ Rocky/AlmaLinux ให้เตรียม environment ตามด้านล่าง

  1. Download & Install Python

[root@test-export-image ~]# yum update -y
[root@test-export-image ~]# yum install -y python3 python3-pip python3-virtualenv
  1. ทดสอบ python ใช้งานได้ปกติหรือไม่ ใช้ command ดังนี้

[root@test-export-image ~]# python3 --version
Python 3.12.3
  1. สร้าง venv เพื่อใช้งานสำหรับ openstack client

[root@test-export-image ~]# mkdir /opt/osclient
[root@test-export-image ~]# cd /opt/osclient/
[root@test-export-image osclient]# python3 -m venv osclient
[root@test-export-image osclient]# source /opt/osclient/osclient/bin/activate
(osclient) [root@test-export-image osclient]# pip install --upgrade pip
(osclient) [root@test-export-image osclient]# pip install python-openstackclient
(osclient) [root@test-export-image osclient]# openstack --version
openstack 8.0.0

หลังจากเตรียม environment สำหรับแต่ละ OS เรียบร้อยแล้ว ให้ดำเนินการตามขั้นตอนด้านล่างต่อไป

  1. Download Public API RC File โดย download จากหน้า project บน Nipa Cloud Space

  1. ตรวจสอบ RC_file.sh

(osclient) root@test-export-image:/opt/osclient# vim test_project_RC_file.sh
#!/usr/bin/env bash
# To use NIPA Cloud Space public API 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/project has
# access to - such as Compute Instance, Compute Image, Block Storage, Networking.

export OS_AUTH_URL=https://identity-api.nipa.cloud/
# Co-working project identity
export OS_PROJECT_ID=834995e704b44fa888b7xxxxxxxxxxxx
export OS_PROJECT_NAME="test_project"
export OS_USER_DOMAIN_NAME="nipacloud"
if [ -z "$OS_USER_DOMAIN_NAME" ]; then unset OS_USER_DOMAIN_NAME; fi
export OS_PROJECT_DOMAIN_ID="c6b00adf4ed04fc5a958121fadb0e401"
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
# performing the action as the **user**.
export OS_USERNAME="test_user@nipa.cloud"
echo "Please enter your NIPA Cloud Space user's password for project $OS_PROJECT_NAME as user $OS_USERNAME: "
read -sr OS_PASSWORD_INPUT
export OS_PASSWORD=$OS_PASSWORD_INPUT
# NIPA Cloud Space only have 1 region "NCP-TH"
export OS_REGION_NAME="NCP-TH"
# 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
  1. source ไฟล์ test_project_RC_file.sh และ check ว่า สามารถใช้ openstack client ใน project ได้หรือไม่

(osclient) root@test-export-image:/opt/osclient# source test_project_RC_file.sh
Please enter your NIPA Cloud Space user's password for project test_project as user test_user@nipa.cloud:<ใส่ password>
(osclient) root@test-export-image:/opt/osclient# openstack token issue
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Field      | Value                                                                                                                                                                                   |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| expires    | 2025-04-26T04:36:06+0000                                                                                                                                                                |
| id         | gAAAAABoCxE24s4f-T2MOyOFsLcfGWvbf1zwQBZfwC3KcqiKSpod1OuDJa3xdWaBvtMui7w9Hr3B0OHkQYx8u1aQYKodxhyKSLIcazwG1JbwAbt-Vgx8KAcU5zWQGAkPoOUmWuyNFW0ZkzONKU0HOmISAr8DM1bErVjWL7Il595Xmzmjr_889Uo |
| project_id | 834995e704b44fa888b7xxxxxxxxxxxx                                                                                                                                                        |
| user_id    | e6275119d15648bfb7c2xxxxxxxxxxxx                                                                                                                                                        |
+------------+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
(osclient) root@test-export-image:/opt/osclient#
  1. list image ใน project ด้วย command

(osclient) root@test-export-image:/opt/osclient# openstack image list
+--------------------------------------+--------------------------------------+--------+
| ID                                   | Name                                 | Status |
+--------------------------------------+--------------------------------------+--------+
| d00037bf-85f6-4bc3-b271-xxxxxxxxxxxx | ubuntu-24-v250307                    | active |
+--------------------------------------+--------------------------------------+--------+
  1. download image ที่ต้องการใน project ด้วย command

(osclient) root@test-export-image:/opt/osclient# openstack image save --file <ชื่อ file image> <image_ID>

ตัวอย่าง
(osclient) root@test-export-image:/opt/osclient# openstack image save --file ubuntu-24-v250307.qcow2 d00037bf-85f6-4bc3-b271-xxxxxxxxxxxx
  1. ถ้า download เรียบร้อยแล้วจะได้ไฟล์ image

(osclient) root@test-export-image:/opt/osclient# ls -lh
total 1.2G
-rw-r--r-- 1 root root 1.4K Apr 25 11:31 test_project_RC_file.sh
drwxr-xr-x 5 root root 4.0K Apr 25 11:26 osclient
-rw-r--r-- 1 root root 1.2G Apr 25 11:38 ubuntu-24-v250307.qcow2
(osclient) root@test-export-image:/opt/osclient#

Last updated

Was this helpful?