#chiroito ’s blog

Java を中心とした趣味の技術について

Oracle Cloud の PaaS Service Manager CLI ツールを使う

Oracle Cloud は他のクラウドサービス同様にコマンドラインインターフェース(CLI)として PaaS Service Manager Command Line Interface (以下PSM CLI) を用意しています。

使用するまでのステップは次の 3 ステップです。

  1. ダウンロード
  2. インストール
  3. セットアップ

参考: Oracle Cloud PaaS Service Manager Command Line Interface Reference, Release 17.1

事前準備

PSM CLI を使うには Python 3.3 以降と Python に含まれている pip が必要です。また、今回の例では PSM CLI のダウンロードに curl を使用してます。pythonコマンド、pipコマンド、curlコマンドが環境変数 PATH に通っているものとします。

ダウンロード

PSM CLI のダウンロードはブラウザを使用してダウンロードする方法と REST API を使用してダウンロードする方法があります。今回は REST API を使用してダウンロードします。 ダウンロードには以下の情報が必要です。

  • 通信先となる REST API サーバ
  • アイデンティティドメイン名
  • ユーザ名
  • パスワード

REST API サーバは、リージョンに us1 と us2 を使用している場合は psm.us.oraclecloud.com、それ以外のリージョンを使用している場合は psm.europe.oraclecloud.com を指定します。それぞれの違いは地域を表す useurope の部分だけです。

次の例では REST API サーバの地域を europe、アイデンティティドメインをMyIdentityDomain54321、ユーザ名をmyuser321、パスワードをmypassword321指定して、ダウンロードしたファイルをpsmcli.zipとして保存します。

export AREA=europe
export IDENTITYDOMAIN=MyIdentityDomain54321
export USER=myuser321
export PASSWD=mypassword321

curl -v -X GET -u ${USER}:${PASSWD} -H X-ID-TENANT-NAME:${IDENTITYDOMAIN} https://psm.${AREA}.oraclecloud.com/paas/core/api/v1.1/cli/${IDENTITYDOMAIN}/client -o psmcli.zip

プロキシを利用している場合は curl を実行する前にプロキシを設定しましょう。

export PROXY_SERVER=<プロキシのホスト>
export PROXY_PORT=<ポート名>

export http_proxy=http://${PROXY_SERVER}:${PROXY_PORT}/
export https_proxy=http://${PROXY_SERVER}:${PROXY_PORT}/

インストール

pip を使用して PSM CLI をインストールします。pip コマンドに先ほどダウンロードしたpsmcli.zipを指定します。

>pip install -U psmcli.zip
Processing c:\users\user1\desktop\psmcli.zip
Collecting requests<=2.8.1,>=2.7.0 (from psmcli==1.1.12)
  Downloading requests-2.8.1-py2.py3-none-any.whl (497kB)
    100% |████████████████████████████████| 501kB 1.1MB/s
Collecting keyring<=5.6,>=5.4 (from psmcli==1.1.12)
  Downloading keyring-5.6.tar.gz (69kB)
    100% |████████████████████████████████| 71kB 930kB/s
Collecting colorama==0.3.3 (from psmcli==1.1.12)
  Downloading colorama-0.3.3.tar.gz
Collecting PyYAML==3.11 (from psmcli==1.1.12)
  Downloading PyYAML-3.11.zip (371kB)
    100% |████████████████████████████████| 378kB 1.4MB/s
Installing collected packages: requests, keyring, colorama, PyYAML, psmcli
  Running setup.py install for keyring ... done
  Running setup.py install for colorama ... done
  Running setup.py install for PyYAML ... done
  Running setup.py install for psmcli ... done
Successfully installed PyYAML-3.11 colorama-0.3.3 keyring-5.6 psmcli-1.1.12 requests-2.8.1

Successfully~が出力されればインストールは完了です。

3. セットアップ

セットアップでは、PSM CLI が Oracle Cloud に接続する情報を指定します。

  • ユーザ名
  • パスワード
  • アイデンティティドメイン名
  • リージョン
  • 出力フォーマット

次の例では リージョンを emea、アイデンティティドメインをMyIdentityDomain54321、ユーザ名をmyuser321、パスワードをmypassword321、デフォルトの出力形式を JSON に設定します。※パスワードは表示されません。

>psm setup
Username: myuser321
Password: mypassword321 #表示されません
Retype Password: mypassword321 #表示されません
Identity domain: MyIdentityDomain54321
Region [us]: emea
Output format [json]:
----------------------------------------------------
'psm setup' was successful. Available services are:

  o ANALYTICS : Oracle Analytics Cloud
  o BDCSCE : Oracle Big Data Cloud Service - Compute Edition
  o CONTAINER : Oracle Container Cloud Service
  o IDCS : Oracle Identity Cloud Service
  o IDCSControlPlane : Oracle Identity Cloud Service
  o IOTAssetMon : Oracle IoT Asset Monitoring Cloud Service
  o IOTEnterpriseApps : Oracle Internet of Things Cloud - Enterprise
  o IOTFleetMon : Oracle IoT Fleet Monitoring Cloud Service
  o IOTProdMonitoring : Oracle IoT Production Monitoring Cloud Service
  o MySQLCS : Oracle MySQL Cloud Service
  o OEHCS : Oracle Event Hub Cloud Service
  o OEHPCS : Oracle Event Hub Cloud Service - Platform
  o accs : Oracle Application Container Cloud Service
  o caching : Oracle Application Cache
  o dbcs : Oracle Database Cloud Service
  o ggcs : Oracle GoldenGate Cloud Service
  o jcs : Oracle Java Cloud Service
  o stack : Oracle Cloud Stack Manager
----------------------------------------------------

ヘルプ

PSM CLI の引数にhelpを指定すると、使用可能なクラウドサービスの一覧が表示されます。

>psm help

DESCRIPTION
  A command line tool to interact with Oracle Cloud Platform Services (PaaS)

SYNOPSIS
  psm <service> <command> [parameters]

AVAILABLE SERVICES
  o ANALYTICS
       Oracle Analytics Cloud
  o BDCSCE
       Oracle Big Data Cloud Service - Compute Edition
  o CONTAINER
       Oracle Container Cloud Service
  o IDCS
       Oracle Identity Cloud Service
  o IDCSControlPlane
       Oracle Identity Cloud Service
  o IOTAssetMon
       Oracle IoT Asset Monitoring Cloud Service
  o IOTEnterpriseApps
       Oracle Internet of Things Cloud - Enterprise
  o IOTFleetMon
       Oracle IoT Fleet Monitoring Cloud Service
  o IOTProdMonitoring
       Oracle IoT Production Monitoring Cloud Service
  o MySQLCS
       Oracle MySQL Cloud Service
  o OEHCS
       Oracle Event Hub Cloud Service
  o OEHPCS
       Oracle Event Hub Cloud Service - Platform
  o accs
       Oracle Application Container Cloud Service
  o caching
       Oracle Application Cache
  o dbcs
       Oracle Database Cloud Service
  o ggcs
       Oracle GoldenGate Cloud Service
  o jcs
       Oracle Java Cloud Service
  o stack
       Oracle Cloud Stack Manager
  o setup
       Configure psm client options
  o update
       Update psm client to latest version
  o log
       View or update psm client log level
  o help
       Show help

AVAILABLE PARAMETERS
  -v, --version
       Show current version of psm client

各クラウドサービスのヘルプ

各クラウドサービスのヘルプは PSM CLI にクラウドサービス名とhelpを引数として指定します。
psm <クラウドサービス名> help
Application Container Cloud Service (accs) のヘルプは次のようになります。

>psm accs help

DESCRIPTION
  Oracle Application Container Cloud Service

SYNOPSIS
  psm accs <command> [parameters]

AVAILABLE COMMANDS
  o apps
       List all Oracle Application Container Cloud applications
  o app
       List an Oracle Application Container Cloud application
  o push
       Create or Update an Oracle Application Container Cloud application
  o scale
       Scale an Oracle Application Container Cloud Service instance for a...
  o delete
       Delete an Oracle Application Container Cloud application
  o stop
       Stop an Oracle Application Container Cloud application
  o start
       Start an Oracle Application Container Cloud application
  o restart
       Restart an Oracle Application Container Cloud application
  o logs
       List log details of all the instances of an Oracle Application Container...
  o log
       View log details of an instance of an Oracle Application Container Cloud...
  o get-logs
       Request for log details of an instance of an Oracle Application Container...
  o recordings
       View recording details of all the instances of an Oracle Application...
  o recording
       List recording details of an instance of an Oracle Application Container...
  o get-recordings
       Request for recording details of an instance of an Oracle Application...
  o operation-status
       View status of an Oracle Application Container Cloud application operation
  o help
       Show help