November 11, 2016 | Written by: Henrik Loeser
Categorized: Compute Services | How-tos
Share this post:
As much as I like nice graphical user interfaces (UIs) and working with the browser, for most tasks I prefer using the command line. I’ve done so—and still do. For working with DB2 and dashDB, I also use the Cloud Foundry (CF) Command Line Interface (CLI) to manage my Bluemix environments. The “cf” tool is quite handy—it allows me to perform what I need to accomplish.
A great feature is its support of plugins, which allow users to extend its functionality. There are IBM-provided plugins and several coming from the Cloud Foundry ecosystem. Below are some brief instructions on how to get started.
Once you’ve installed a recent version of the cf tool, invoking it without any parameters should display some help text on available commands and features. In the lower part of that text should be two sections related to plugins:
Quick overview of CF commands
Below is a quick reference of plug-in repository commands:
add-plugin-repo adds a new plugin repository
remove-plugin-repo removes a plugin repository
list-plugin-repos lists all the added plugin repositories
repo-plugins lists all available plugins in specified repository or in all added repositories
And a quick reference of general plug-in commands:
plugins lists all available plugin commands
install-plugin installs CLI plugin
uninstall-plugin uninstalls the plugin defined in command argument
Adding new CF commands via plug-ins
add-plugin-repo allows to add new repositories from which plugins can be installed,
list-plugin-repos lists those repositories already available in your environment. Try the following two commands to add the plugin repositories from Bluemix Public and from the Cloud Foundry community collection:
cf add-plugin-repo BluemixPublic http://plugins.ng.bluemix.net/
cf add-plugin-repo CF-Community http://plugins.cloudfoundry.org/
When done, try the following command to list the repositories. It should return something like this:
henrik>> cf list-plugin-repos
Repo Name Url
With the command
it’s possible to list all the available plugins ready to be installed. You can read more about them at the repository descriptions linked above. For switching quickly between my different Bluemix environments I installed the “targets” plugin from the Cloud Foundry community repository:
henrik>> cf install-plugin targets -r CF-Community
Plugins are binaries written by potentially untrusted authors. Install and use plugins at your own risk.
Do you want to install the plugin targets? (y or n)> y
Looking up 'targets' from repository 'CF-Community'
8230816 bytes downloaded...
Installing plugin /tmp/cf-targets-plugin...
Plugin cf-targets v1.1.0 successfully installed.
After I’m done, when calling just “cf” again, there’s a new section in the help text available:
INSTALLED PLUGIN COMMANDS:
targets List available targets
set-target Set current target
save-target Save current target
delete-target Delete a saved target
If you have more plugins installed, there will be more commands displayed. Using the “targets” plugin I can save the current environment, i.e., the Bluemix or Cloud Foundry instance I’m logged into, and quickly switch between the Bluemix Dallas (NG) and Bluemix London (EU-GB) platforms using the
set-target command. The
cf set-target eu command would replace several
cf api and
cf login commands, and a lot of typing, great for scripting and more efficient work.
Sign up for Bluemix. It’s free!