IBM Cloud: Power Systems Virtual Serverのsnapshot機能をCLI(ibmcloudコマンド)から実行する


1. はじめに

Power Systems Virtual Serverのsnapshotを取得するためには、いまだにAPIを利用する必要がある。その実際の手順は、以下などで紹介されている。

https://cloud.ibm.com/docs/power-iaas?topic=power-iaas-volume-snapshot-clone
https://qiita.com/khayama/items/f0bf62dc04677a321e0c

一方で、これらの処理はCLI(ibmcloudコマンド)経由でも実施可能なため、本項でその手順を確認する。

$ ibmcloud pi | grep -i snapshot
  snapshot, snap                       Get the detail of a snapshot.
  snapshot-create, snapc               Create a PVM instance snapshot
  snapshot-delete, snapd               Delete a snapshot.
  snapshot-restore, snapr              Restore a PVM instance snapshot
  snapshots, snaps                     List all snapshots
$ ibmcloud pi | grep -i clone
  volume-clone, volcl                  Get the status of a clone request for the specified clone task ID.
  volume-create-clone, volcc           Create a volume clone for specific volumes.

2. 実施方法

2.1 ibmcloudコマンドによるログイン

API Keyを使えばInteractiveな認証なしでログインできる。
詳細はIBM Cloud: ibmcloudコマンドでAPI Keyを使ってログインする方法を参照。

$ ibmcloud login -a cloud.ibm.com --apikey @ibmcloud_apikey -r jp-tok

2.2 対象のPower Systems Virtual Serverのインスタンスを指定

$ ibmcloud pi service-list
Listing services under account IBM as user [email protected]...
ID                                                                                                                    Name
crn:v1:bluemix:public:power-iaas:lon06:a/039dbe6794084c7cb514a276dd2345da:a8c306d4-cc1c-45d2-ae73-97a77fea3316::      Power Systems Virtual Server-LON06
crn:v1:bluemix:public:power-iaas:us-east:a/039dbe6794084c7cb514a276dd2345da:0d9ef0ef-2744-4307-85a6-20b5eedd8f6a::    Power Systems Virtual Server-WDC
crn:v1:bluemix:public:power-iaas:us-south:a/039dbe6794084c7cb514a276dd2345da:01595fe7-55ac-42b9-ad3e-44a58a846a8e::   Power Systems Virtual Server-DAL
crn:v1:bluemix:public:power-iaas:syd04:a/039dbe6794084c7cb514a276dd2345da:9454e06f-00c7-4a97-b89a-419492a994ce::      Power Systems Virtual Server-SYD04
crn:v1:bluemix:public:power-iaas:eu-de-1:a/039dbe6794084c7cb514a276dd2345da:a1fa522e-6b9a-4ad2-b511-38f6b5067372::    Power Systems Virtual Server-FRA01
crn:v1:bluemix:public:power-iaas:tok04:a/039dbe6794084c7cb514a276dd2345da:7bcf8f28-869c-4c3c-8955-a989a8d4406b::      Power Systems Virtual Server-TOK04

$ ibmcloud pi service-target crn:v1:bluemix:public:power-iaas:tok04:a/039dbe6794084c7cb514a276dd2345da:7bcf8f28-869c-4c3c-8955-a989a8d4406b::

2.3 対象のVSIを特定

$ ibmcloud pi instances
Listing instances under account IBM as user [email protected]...
ID                                     Name       Path
d9c9cdb3-5b16-43d5-8fbe-0692c1dbac6d   powervs1   /pcloud/v1/cloud-instances/bd4124205da84b46b6c61e580f912b25/pvm-instances/d9c9cdb3-5b16-43d5-8fbe-0692c1dbac6d

2.4 Snapshotの取得と確認

$ ibmcloud pi snapshot-create  d9c9cdb3-5b16-43d5-8fbe-0692c1dbac6d --name powervs1-$(date '+%Y%m%d-%H%M%S')
Creating snapshot for instance d9c9cdb3-5b16-43d5-8fbe-0692c1dbac6d under account IBM as user [email protected]...
OK
Snapshot powervs120210407-172905 with ID of a355ce98-d3e8-478b-a887-489bd2abac7f has started.

$ ibmcloud pi snapshots
Listing all Snapshots under account IBM as user [email protected]...
Snapshot ID                            Snapshot Name             Instance ID                            Status      Action     Creation Date
a355ce98-d3e8-478b-a887-489bd2abac7f   powervs1-20210407-172905   d9c9cdb3-5b16-43d5-8fbe-0692c1dbac6d   available   snapshot   2021-04-07T08:29:20.000Z

参考: Power Systems Virtual Serverからの実行方法

Power Systems Virtual Serverにはibmcloudコマンドは導入できない。curlなどを使ってAPIを直接呼び出すにしても、その手順はそこそこ複雑だし、Power Systems Virtual ServerのAPI endpointはpublic側にしかないため、Internet accessを要する。

さて困った、、、と思ったが簡単な対処方法がある。IBM Cloud(x86)側にインターネット通信が可能なサーバーを用意し、例えば以下のようなスクリプトを配置しておく。Power Systems Virtual ServerからはDirect Link経由でsshでそのスクリプトを実行すれば良い。

IBMCloud(x86)に配置するpowervs1-snapshot.sh
ibmcloud login -a cloud.ibm.com --apikey @ibmcloud_apikey -r jp-tok
ibmcloud pi service-target crn:v1:bluemix:public:power-iaas:tok04:a/039dbe6794084c7cb514a276dd2345da:7bcf8f28-869c-4c3c-8955-a989a8d4406b::
ibmcloud pi snapshot-create  d9c9cdb3-5b16-43d5-8fbe-0692c1dbac6d --name powervs1-$(date '+%Y%m%d-%H%M%S')
AIXからの実行例(10.0.0.4はIBMCloud(x86)上のサーバー)
$ ssh 10.0.0.4 sh powervs1-snapshot.sh