Upload
takeshi-morikawa
View
821
Download
0
Embed Size (px)
Citation preview
About meTakeshi Morikawa
業務: Cloud Foundry関連
CF関連チェック範囲(業務外も含む)
◎ 少し前○ ccngとdeaまわり
◎ 最近○ rootfs(lucid64やcflinuxfs2)○ cli plugin(本日の内容)
cli plugin???
◎ 基本的な特長
○ cfコマンド(cli)のサブコマンドのように扱える◉ 例:cf hoge APP_NAME
○ go版のcfコマンド v6.7以降?から使用可能http://docs.cloudfoundry.org/devguide/installcf/use-cli-plugins.html
cli plugin???
◎ 基本的な特長
○ cli自体と同じようにGolangで実装
○ RPCでやりとり
https://github.com/cloudfoundry/cli/tree/master/plugin_examples#architecture-overview
Install plugin
『cf install-plugin』からgoのクロスコンパイルで生成されたbinファイルを指定
$ cf install-plugin hoge
githubのリリース等からバイナリを持ってきた場合
go get等でバイナリを持ってきた場合
$ export GOPATH=$HOME/tmp_gopath
$ go get github.com/hoge/cf-plugin-hoge
$ cf install-plugin $GOPATH/bin/hoge
Uninstall plugin
『cf plugins』でPlugin nameを確認し 『cf uninstall-plugin』する
$ cf pluginsListing Installed Plugins...OK
Plugin name Version Command name Command Helphoge 1.0.0 hoge cf hoge plugin
$ cf uninstall-plugin hogeUninstalling plugin hoge...OKPlugin name tree successfully uninstalled
plugin nameがhogeの場合
community pluginを使う その1
communityのplugin用urlをcfコマンドに登録する
https://blog.starkandwayne.com/2015/03/04/installing-cloud-foundry-cli-plugins/
$ cf add-plugin-repo community http://plugins.cfapps.io/
OKhttp://plugins.cfapps.io/list added as 'community'
$ cf list-plugin-reposOK
Repo Name Urlcommunity http://plugins.cfapps.io/
community pluginを使う その2
communityのplugin一覧から入れたいpluginを探す
https://blog.starkandwayne.com/2015/03/04/installing-cloud-foundry-cli-plugins/
$ cf repo-plugins communityGetting plugins from all repositories ...
Repository: communityname version descriptionCLI-Recorder 1.0.1 Records and playbacks CLI commands.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 containerDiego-Beta 1.3.0 Enables Diego-specific commands and functionality
etc…
community pluginを使う その3
communityの一覧経由でpluginを入れる
https://blog.starkandwayne.com/2015/03/04/installing-cloud-foundry-cli-plugins/
$ cf install-plugin Console -r communityLooking up 'Console' from repository 'community'7974312 bytes downloaded...Installing plugin /tmp/cf-plugin-console...OKPlugin Console successfully installed.
$ cf pluginsListing Installed Plugins...OK
Plugin name Version Command name Command Helphoge 1.0.0 hoge cf hoge pluginConsole N/A console Start a live console
入れたいplugin名がConsoleの場合
※ -rで取得元のnameを入れる
Community plugin一覧 その1 (2015/5/6調べ)
Version Description
CLI-Recorder v1.0.1 Records and playbacks CLI commands.
Live Stats v1.0.0Monitor CPU and Memory usage on an app via the browser.
Console v1.0.0 Start a tmate session on an application container
Live Stats
localhost:8080でHTTPserverを立ち上げ内部的にはstats相当を叩く(cf app APP_NAME)
https://github.com/danhigham/cf-live-stats
Console
cloudfoundry-tmate-buildpackやcf-sshと同じようにtmate経由でコンテナにアクセスするplugin
https://github.com/danhigham/cf-console
$ cf console cf-api-checker> Finding app guid for cf-api-checker ... 62de88da-8947-46fc-9877-52319c0a0bfb> Updating app to connect to tmate.> Updating app start command to 'curl -s https://raw.githubusercontent.com/danhigham/cf-console/master/install.sh > /tmp/install.sh && bash /tmp/install.sh && sleep 3600'.> Changing instance count to 2.> Checking app log datestamps.
Community plugin一覧 その2 (2015/5/6調べ)
Version Description
Diego-Beta v1.3.0Enables Diego-specific commands and functionality
Open v1.10 Open app url in browser
autopilot v0.0.1 zero downtime deploy plugin for cf applications
autopilot
appの旧バージョンmanifestと新バージョンmanifestを指定しダウンタイムゼロでアプリを新バージョンに移行するplugin
https://github.com/concourse/autopilot
$ cf zero-downtime-push application-to-replace \ -f path/to/new_manifest.yml \ -p path/to/new/path
pluginの配布元READMEの説明による動作原理
1. 旧バージョンのアプリ名を <APP-NAME>-venerableにリネームこの時アプリの routesは変更しない
2. 新バージョンのアプリを <APP-NAME>でpushこの時のroutesは旧バージョンと一緒になるのでロードバランシングされる
3. 旧バージョン側の routesとアプリそのものを削除し移行完了
Community plugin一覧 その3 (2015/5/6調べ)
Version Description
Brooklyn v0.1.1Interact with Service Broker for Apache Brooklyn
kinaba-me-logs v0.3.0 Launches the Kibana UI (from kibana-me-logs) for an application.
Buildpack Usage v1.0.0 Buildpack Usage
CF App Stack Changer v1.0.0
Allows admins to list and update applications with outdated lucid64 stacks.
cf-plugin-kinaba-me-logs(kibana-me-logs)Docker/Logstash Service Brokerを使ってapplicationのlogをkibana経由で確認する用のplugin
https://github.com/cloudfoundry-community/cf-plugin-kibana-me-logs
pluginの配布元READMEの説明による動作原理
1. https://github.com/cloudfoundry-community/kibana-me-logsを内部的には利用
2. cf-kinaba-me-logs <kibana-app-name> <log-target-app-name>3. 本来のkibana-me-logs単体の使い方
a. logをkibana UIで確認したいアプリに対して cf bind-service APP_NAMb. kibana-me-logs自体をpush&bind-serviceするとbindしたその他のアプリが見える
Buildpack Usage
特定のspaceやorgが利用しているbuildpackを確認するplugin
https://github.com/csterwa/cf_buildpacks_usage_cmd
$ cf buildpack-usage
13 buildpacks found across 110 app deployments
Buildpacks Used----------------
Node.jsPHPRubyhttps://github.com/cloudfoundry/java-buildpack.githttps://github.com/cloudfoundry/php-buildpack.git
CF App Stack Changer
lucid64のstacksをcflinuxfs2に移行する為のplugin◎ lucid64のアプリの確認◎ stacks変更+restartが行える
https://github.com/simonleung8/cli-stack-changer
$ cf stack-listGetting all apps with lucid64 stack...OK
Total 14 found ...name guid statehogehoge 09d03ad3-24ee-44a1-8969-4abb3268aab6 STARTED
$ cf stack-change APP_NAME
Community plugin一覧 その4 (2015/5/6調べ)
Version Description
Targets v1.0.0 Easily manage multiple CF targets
Test User v0.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 specified then the default value of 'development' is used
cf-download v1.0.0 Plugin for downloading your application contents after staging.
Targets
CF_HOMEを利用して複数環境のtarget情報を管理するplugin
https://github.com/csterwa/cf_buildpacks_usage_cmd
$ cf api https://api.ng.bluemix.net$ cf login$ cf save-target bluemix
$ cf api https://api.10.244.0.34.xip.io --skip-ssl-validation$ cf login$ cf save-target bosh-lite
$ cf set-target dev$ cf targetsbluemixbosh-lite (current)
cf-download
cf files APP_NAME app/hogehoge.logのように内部的にfiles相当のAPI経由でstaging後のアプリ上にあるファイルを取得するplugin
https://github.com/csterwa/cf_buildpacks_usage_cmd
$ cf download doraFiles completed: 1755 /
$ ls ~/dora-download/app logs run.pid staging_info.yml tmp
実装する上で参考になるコード解説 1
最初pluginを作る上で参考になるのはgithub/cloudfoundry/cliの中にあるplugin_examples/call_cli_cmdがオススメ
https://github.com/cloudfoundry/cli/tree/master/plugin_examples/call_cli_cmd/main
import ("fmt"
"github.com/cloudfoundry/cli/plugin")
import部分でgithub.com/cloudfoundry/cli/pluginをimportする
main部分でplugin.Startでstructをnewさせる
func main() {plugin.Start(new(CliCmd))
}
実装する上で参考になるコード解説 2
https://github.com/cloudfoundry/cli/tree/master/plugin_examples/call_cli_cmd/main
func (c *CliCmd) GetMetadata() plugin.PluginMetadata {return plugin.PluginMetadata{
Name: "CliCmd",Version: plugin.VersionType{
Major: 1,Minor: 1,Build: 0,
},Commands: []plugin.Command{
{Name: "cli-command",HelpText: "Command to call cli command. It passes all arguments
through to the command",UsageDetails: plugin.Usage{
Usage: "cli-command\n cf cli-command CORE-COMMAND",
},},
},}
}
GetMetadata()を定義しpluginの名前(uninstall時に利用するもの)やコマンド名、およびバージョン定義を行う
実装する上で参考になるコード解説 3
https://github.com/cloudfoundry/cli/tree/master/plugin_examples/call_cli_cmd/main
func (c *CliCmd) Run(cliConnection plugin.CliConnection, args []string) {output, err := cliConnection.CliCommand(args[1:]...)
if err != nil {fmt.Println("PLUGIN ERROR: Error from CliCommand: ", err)
}
fmt.Println("")fmt.Println("---------- Command output from the plugin ----------")for index, val := range output {
fmt.Println("#", index, " value: ", val)}fmt.Println("---------- FIN -----------")
}
Run()部分で実際に処理を行う ※以下は実際のソースのコメントアウト部分を除いたもの
cliConnection.CliCommand部分でpluginに渡ってきた引数を cliにそのまま渡す
実装する上で参考になるコード解説 4
https://github.com/cloudfoundry/cli/tree/master/plugin_examples/call_cli_cmd/main
$ cf cli-command appsGetting apps in org testOrg / space testSpace as admin...OK
name requested state instances memory disk urlsaaa started ?/1 256M 1G aaa.10.244.0.34.xip.iogo started 1/1 256M 1G go.10.244.0.34.xip.iodora started 1/1 256M 1G dora.10.244.0.34.xip.io
---------- Command output from the plugin ----------# 0 value: Getting apps in org testOrg / space testSpace as admin...# 1 value: OK# 2 value:# 3 value: name requested state instances memory disk urls# 4 value: aaa started ?/1 256M 1G aaa.10.244.0.34.xip.io# 5 value: go started 1/1 256M 1G go.10.244.0.34.xip.io# 6 value: dora started 1/1 256M 1G dora.10.244.0.34.xip.io---------- FIN -----------
cli-command pluginに値を渡した時の挙動
CliConnectionのinterface(旧)
https://github.com/cloudfoundry/cli/tree/master/plugin_examples/call_cli_cmd/main
v6.10.0の場合は基本的な以下の2つが用意されていた(最新はv6.11.2)
● CliCommand○ plugin_examplesで使われている○ plugin内部でコマンド発行した結果も標準出力に出す
● CliCommanWithoutTerminalOutput○ plugin内部でコマンドを発行し、発行コマンド自体の標準出力
は表示はしない ⇒ 通常はこちらを使う
CliConnectionのinterface(新)
https://github.com/cloudfoundry/cli/tree/master/plugin_examples/call_cli_cmd/main
v6.11.2の場合はpluginを作る際によく使われる値を取得するためのinterfaceが追加された
type CliConnection interface {CliCommandWithoutTerminalOutput(args ...string) ([]string, error)CliCommand(args ...string) ([]string, error)GetCurrentOrg() (plugin_models.Organization, error)GetCurrentSpace() (plugin_models.Space, error)Username() (string, error)UserGuid() (string, error)UserEmail() (string, error)IsLoggedIn() (bool, error)IsSSLDisabled() (bool, error)HasOrganization() (bool, error)HasSpace() (bool, error)ApiEndpoint() (string, error)ApiVersion() (string, error)HasAPIEndpoint() (bool, error)LoggregatorEndpoint() (string, error)DopplerEndpoint() (string, error)AccessToken() (string, error)
}
CliConnectionのinterface(次期)
https://groups.google.com/a/cloudfoundry.org/d/msg/vcap-dev/jF1h16IFEh4/I2s19nlemgAJ
更に良く使われる以下のような値が追加される?
Example:
apps = cliConnection.GetApps()println(apps[0].Name)println(apps[0].Guid)
- GetApps()- GetApp()- GetOrgs()- GetOrg()- GetSpaces()- GetSpace()- GetUsers()- GetUser()- GetServices()- GetService()
その他参考情報
pluginリリースの参考になる情報https://groups.google.com/a/cloudfoundry.org/forum/#!starred/vcap-dev/RDk9xbmp3gc
Credits
Special thanks to all the people who made and released these awesome resources for free:◎ Presentation template by SlidesCarnival◎ Photographs by Unsplash & Death to the Stock Photo
(license)