Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cloud Foundry Cli Plugin入門

Cloud Foundry Cli Plugin入門

Cloud Foundry / Lattice Deep Talks
PaaS勉強会番外編: Cloud FoundryやLatticeを深く知ろう!資料

morika-t

May 09, 2015
Tweet

Other Decks in Technology

Transcript

  1. About me Takeshi Morikawa 業務: Cloud Foundry関連 CF関連チェック範囲(業務外も含む) ◎ 少し前

    ◦ ccngとdeaまわり ◎ 最近 ◦ rootfs(lucid64やcflinuxfs2) ◦ cli plugin(本日の内容)
  2. cli plugin??? ◎ 基本的な特長 ◦ cfコマンド(cli)のサブコマンドのように扱える ◉ 例:cf hoge APP_NAME

    ◦ go版のcfコマンド v6.7以降?から使用可能 http://docs.cloudfoundry.org/devguide/installcf/use-cli-plugins.html
  3. 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
  4. Uninstall plugin 『cf plugins』でPlugin nameを確認し 『cf uninstall-plugin』する $ cf plugins

    Listing Installed Plugins... OK Plugin name Version Command name Command Help hoge 1.0.0 hoge cf hoge plugin $ cf uninstall-plugin hoge Uninstalling plugin hoge... OK Plugin name tree successfully uninstalled plugin nameがhogeの場合
  5. community pluginを使う その2 communityのplugin一覧から入れたいpluginを探す https://blog.starkandwayne.com/2015/03/04/installing-cloud-foundry-cli-plugins/ $ cf repo-plugins community Getting

    plugins from all repositories ... Repository: community name version description CLI-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 container Diego-Beta 1.3.0 Enables Diego-specific commands and functionality etc…
  6. community pluginを使う その3 communityの一覧経由でpluginを入れる https://blog.starkandwayne.com/2015/03/04/installing-cloud-foundry-cli-plugins/ $ cf install-plugin Console -r

    community Looking up 'Console' from repository 'community' 7974312 bytes downloaded... Installing plugin /tmp/cf-plugin-console... OK Plugin Console successfully installed. $ cf plugins Listing Installed Plugins... OK Plugin name Version Command name Command Help hoge 1.0.0 hoge cf hoge plugin Console N/A console Start a live console 入れたいplugin名がConsoleの場合 ※ -rで取得元のnameを入れる
  7. Community plugin一覧 その1 (2015/5/6調べ) Version Description CLI-Recorder v1.0.1 Records and

    playbacks CLI commands. Live Stats v1.0.0 Monitor CPU and Memory usage on an app via the browser. Console v1.0.0 Start a tmate session on an application container
  8. 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.
  9. Community plugin一覧 その2 (2015/5/6調べ) Version Description Diego-Beta v1.3.0 Enables Diego-specific

    commands and functionality Open v1.10 Open app url in browser autopilot v0.0.1 zero downtime deploy plugin for cf applications
  10. 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とアプリそのものを削除し移行完了
  11. Community plugin一覧 その3 (2015/5/6調べ) Version Description Brooklyn v0.1.1 Interact 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.
  12. 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_NAM b. kibana-me-logs自体をpush&bind-serviceするとbindしたその他のアプリが見える
  13. 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.js PHP Ruby https://github.com/cloudfoundry/java-buildpack.git https://github.com/cloudfoundry/php-buildpack.git
  14. CF App Stack Changer lucid64のstacksをcflinuxfs2に移行する為のplugin ◎ lucid64のアプリの確認 ◎ stacks変更+restartが行える https://github.com/simonleung8/cli-stack-changer

    $ cf stack-list Getting all apps with lucid64 stack... OK Total 14 found ... name guid state hogehoge 09d03ad3-24ee-44a1-8969-4abb3268aab6 STARTED $ cf stack-change APP_NAME
  15. 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.
  16. 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 targets bluemix bosh-lite (current)
  17. 実装する上で参考になるコード解説 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時に利用するもの)や コマンド名、およびバージョン定義を行う
  18. 実装する上で参考になるコード解説 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にそのまま渡す
  19. 実装する上で参考になるコード解説 4 https://github.com/cloudfoundry/cli/tree/master/plugin_examples/call_cli_cmd/main $ cf cli-command apps Getting apps in

    org testOrg / space testSpace as admin... OK name requested state instances memory disk urls aaa started ?/1 256M 1G aaa.10.244.0.34.xip.io go started 1/1 256M 1G go.10.244.0.34.xip.io dora 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に値を渡した時の挙動
  20. 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) }
  21. 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)