LoginSignup
16
15

More than 5 years have passed since last update.

CLIプラグインでもっと快適にBluemixを操る

Last updated at Posted at 2015-08-19

1. はじめに

皆さん コマンドライン、使ってますか?

Bluemixと言うとフラットデザインなWeb UIのイメージがあるかもしれませんが、Cloud FoundryのCLI(Command Line Interface)の黒い画面もいいものです。コマンドヒストリーを呼び出したりスクリプトでバッチ処理をさせたり、コマンドラインなら何かと作業も捗ります。
そんなコマンドラインをもっと快適に使うためのプラグインについてご紹介します。

※Cloud FoundryのCLIはこちらからダウンロードできます。

2. CLIプラグインの導入方法

Cloud FoundryのCLIは、標準のcfコマンドでは対応できない様々な機能をプラグインによって拡張することが可能です。CLIプラグインはスクラッチで一から作ることも可能です。また、コミュニティで作成され公開されているプラグインもあります。

Cloud Foundryが公開しているコミュニティプラグインの一覧はこちらにあります。
2015-08-19_16485540p.jpg

ここからプラグインを導入する手順は以下の通りです。

-Cloud Foundryのサイトに任意の名前を付け、リポジトリとして登録する
cf add-plugin-repo [リポジトリ名] http://plugins.cloudfoundry.org/

-リポジトリに存在するプラグインをリスト表示する
cf repo-plugins

-リストから名前を指定してプラグインをインストールする
cf install-plugin [プラグイン名] -r [リポジトリ名]

-導入済みのプラグインをリスト表示する
cf plugins

導入したプラグインがリストに表示されれば完了です!

3. Openプラグインの導入例

実行例として、ひとつプラグインをインストールしてみましょう。

コマンドラインでファイル操作をしたりアプリをpushしたりした後に、実際にアプリを動かして確認する場合を考えてみましょう。
ここでマウスに手を伸ばしてWebブラウザを起動してアプリのURLを打ち込んで、というのが普通の操作でしょうか。もしくはWebブラウザでBluemixにアクセスした状態であれば、ダッシュボードからアプリのリンクをクリックしてアクセスするかもしれません。

しかしコマンドラインで作業しているのであれば、こういう操作もすべてコマンドラインから出来るといいですよね。そんなときはOpenプラグインの出番です。

実際に2.の手順で導入を行った例は以下の通りです。
任意のリポジトリ名としてCF-community、導入するプラグイン名としてOpenを指定しています。

c:\Bluemix>cf add-plugin-repo CF-community http://plugins.cloudfoundry.org/

OK
http://plugins.cloudfoundry.org/list added as 'CF-community'


c:\Bluemix>cf repo-plugins
Getting plugins from all repositories ...

Repository: CF-community
name                   version   description
Targets                1.1.0     Easily manage multiple CF targets
Usage Report           1.1.0     Report on memory usage and application instances for orgs and space
s
Statistics             1.0.0     Display live metrics/statistics about an app
wildcard_plugin        1.0.0     Allows user to search and delete apps using wildcard(*)
Diego-SSH              0.1.2     Access Diego containers with SSH
Scaleover              1.0.1     Roll traffic from one app to another by scaling over time
CF App Stack Changer   1.1.0     Allows admins to list and update applications with outdated lucid64
 stacks.
cf-download            1.0.0     Plugin for downloading your application contents after staging.
Copy Env               1.0.0     Expose remote VCAP_SERVICES on the client environment
Diego-Beta             1.3.0     Enables Diego-specific commands and functionality
Buildpack Usage        1.0.0     View all buildpacks used in the current CLI target context.
Test User              0.0.1     Create a user and assign all possible permissions, organisation and
 space are created if they do not already exist as well. If no organisation or space name are specif
ied then the default value of 'development' is used
kibana-me-logs         0.3.0     Launches the Kibana UI (from kibana-me-logs) for an application.

Brooklyn               0.1.1     Interact with Service Broker for Apache Brooklyn
autopilot              0.0.1     zero downtime deploy plugin for cf applications
Open                   1.1.0     Open app url in browser
Live Stats             1.0.0     Monitor CPU and Memory usage on an app via the browser.
Console                1.0.0     Start a tmate session on an application container
CLI-Recorder           1.0.1     Records and playbacks CLI commands.


c:\Bluemix>cf install-plugin Open -r CF-community
Looking up 'Open' from repository 'CF-community'
8133632 bytes downloaded...
Installing plugin C:\Users\IBM_AD~1\AppData\Local\Temp\ filename=cf-plugin-open_windows_amd64.exe...

OK
Plugin open successfully installed.

c:\Bluemix>cf plugins
Listing Installed Plugins...
OK

Plugin name         Version   Command name        Command Help
open                1.1.0     open                open app url in browser
open                1.1.0     service-open        open service instance dashboard in browser

c:\Bluemix>

これで導入が完了しました。

それでは導入したOpenプラグインの動作を確認してみましょう。cf open [アプリケーション名]を実行します。
pushしたアプリケーション名を忘れてしまった? そんなときは標準のcfコマンドでアプリ名を確認できます。cf appsです。

c:\Bluemix>cf apps
Getting apps in org xxxxx_org / space dev as xxxxx@xxx.xxx...
OK

name              requested state   instances   memory   disk   urls
autovehicle01     started           3/3         128M     1G     autovehicle01.eu-gb.mybluemix.net

c:\Bluemix>cf open autovehicle01

c:\Bluemix>

Webブラウザが起動し、アプリケーションのURL(エンドポイント)にアクセスできます。
ちょっとしたことですがこれは嬉しいかも :blush:

2015-08-19_16541540p.jpg

4. その他のCLIプラグイン

Cloud Foundryのサイトでは他にもプラグインが公開されています。Bluemixではユーザーに付与する権限を制限していることもあり、一部仕様通りに動かないものもありますが、役立ちそうなものがありましたらぜひ試してみてください。

Usage Report

リソース使用状況を表示する。

c:\Bluemix>cf usage-report
Gathering usage information
Org xxxxx_org is consuming 1408 MB of 2048 MB.
        Space dev is consuming 1408 MB memory (68%) of org quota.
                3 apps: 3 running 0 stopped
                5 instances: 5 running, 0 stopped
You are running 3 apps in all orgs, with a total of 5 instances.

c:\Bluemix>

Buildpack Usage

使用しているビルドパックの情報を表示する。

c:\Bluemix>cf buildpack-usage

Buildpacks in use across all organizations...
2 buildpacks found across 3 app deployments

Buildpacks Used
----------------
SDK for Node.js(TM) (ibm-node.js-0.10.38)
SDK for Node.js(TM) (ibm-node.js-0.10.40)

c:\Bluemix>

CLI-Recorder

コマンドラインの一連の操作を記録してスクリプト化する。後から再実行可能。

Statistics

リソース使用状況をリアルタイムにグラフ化する。
2015-08-19_17191040p.jpg

16
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
16
15