Fun with CMSH

    

Those of you who are familiar with Bright probably know that CMSH is the Cluster Management Shell. The CMSH is one of the two administrative interfaces provided by Bright Cluster Manager, the other being Bright View. Most people start off using Bright View, because it’s easy to use. But in time, most admins learn how to use the CMSH because of its power; it allows them to operate on many nodes simultaneously. Here are a couple of tips that will make your use of CMSH more enjoyable.

Aliases

Let’s say that you’re configuring Bright Auto Scaler so you’re deep into the CMSH device mode hierarchy. But you need to list all the nodes in the cluster, which means that the ‘list’ command needs to be run from the top level of device mode. Here’s an example.

You are here:

[headnode->device[headnode]->roles[scaleserver]->engines[k8s-default]]%

You can list the cluster nodes without moving to the top level of device mode by using the fully qualified command: ‘device list’.

[headnode->device[headnode]->roles[scaleserver]->engines[k8s-default]]%  device list
hostname (key)       category             ip                   status
-------------------- -------------------- -------------------- --------------------
cnode001             gpu                  10.0.144.216         [  UP   ]
cnode002             gpu                  10.0.231.32          [  UP   ]
cnode003             gpu                  10.0.190.83          [  UP   ]
headnode                                  10.0.104.82          [  UP   ]

Note: Some columns omitted for clarity

That’s pretty easy right? But an alias can make it even easier.

[headnode->device[headnode]->roles[scaleserver]->engines[k8s-default]]% alias dl device list

Now you can list the cluster nodes from wherever you happen to be by typing just two characters!

[headnode->device[headnode]->roles[scaleserver]->engines[k8s-default]]% dl
hostname (key)       category             ip                   status
-------------------- -------------------- -------------------- --------------------
cnode001             gpu                  10.0.144.216         [  UP   ]
cnode002             gpu                  10.0.231.32          [  UP   ]
cnode003             gpu                  10.0.190.83          [  UP   ]
headnode                                  10.0.104.82          [  UP   ]

You can make the alias persistent by adding this line to your $HOME/.cmshrc file, which gets read when you start CMSH.

alias dl device list

Bookmarks

What? Bookmarks don’t sound like your idea of fun? How about less typing? Well maybe you’ll settle for less work. Let me explain. A CMSH bookmark allows you to go to any mode in the CMSH hierarchy with a single command.

Let’s assume that you want to be able to configure Bright Auto Scaler quickly and easily. To do that you need to be in scaleserver mode, as shown below.

[headnode->device[headnode]->roles[scaleserver]]%

You can create a bookmark that will allow you to get there with minimal typing. I’ll name this bookmark “ss” (short for scale server).

[headnode->device[headnode]->roles[scaleserver]]% bookmark ss

Next time you want to look at the Auto Scaler configuration, you can use the ‘goto’ command to go to the bookmarked mode.

[headnode->network[kube-default-pod]]% goto ss

[headnode->device[headnode]->roles[scaleserver]]%

And you can return to the previous mode using “goto -”. The hyphen is a special bookmark that always contains the last mode you were in. To make it even easier you can just type “-” (a hyphen), because “-” is an alias for “goto -”.

[headnode->device[headnode]->roles[scaleserver]]% -

[headnode->network[kube-default-pod]]%

If you want your bookmarks to be persistent you can save them to a file.

[headnode->device[headnode]->roles[scaleserver]]% bookmark -s /root/.bookmarks-cmsh

And you can automatically load them every time you start CMSH by adding this line to your $HOME/.cmshrc file.

bookmark -x /root/.bookmarks-cmsh

You might also want to add these convenient aliases while you’re at it. What do you think the ss alias does?

alias bm bookmark

alias ss goto ss

Scripts

Have you ever wished that you could pass arguments to CMSH commands? Here’s how to do it. As an example, I’ll create a simple script that shows an IP interface on a node. The node is passed as the first argument and the interface is passed as the second argument.

# cat /root/.cm/cmsh/si.cmsh

device interfaces $1

show $2

The script can be run from anywhere in the CMSH hierarchy.

[headnode->device[headnode]->roles[scaleserver]]% run /root/.cm/cmsh/si.cmsh cnode001 eth0

Parameter                        Value
-------------------------------- ------------------------------------------------
Additional Hostnames
BringUpDuringInstall             NO
Card Type                        Ethernet
DHCP                             yes
IP                               10.0.144.216
MAC                              00:00:00:00:00:00
Network                          vpc-0-private
Network device name              eth0 [prov,dhcp]
On network priority              60
Revision
Speed
Start if                         ALWAYS
Type                             physical

Viola! Now you pass arguments to your CMSH commands using scripts. But it’s still too much typing. To make it even easier, you can create an alias.

alias si run /root/.cm/cmsh/si.cmsh

Now you can call the si.cmsh script using the si alias.

[headnode->device[headnode]->roles[scaleserver]]% si cnode001 eth0
Parameter                        Value
-------------------------------- ------------------------------------------------
Additional Hostnames
BringUpDuringInstall             NO
Card Type                        Ethernet
DHCP                             yes
IP                               10.0.144.216
MAC                              00:00:00:00:00:00
Network                          vpc-0-private
Network device name              eth0 [prov,dhcp]
On network priority              60
Revision
Speed
Start if                         ALWAYS
Type                             physical

Summary

I hope that this blog post makes your job as a Bright administrator easier and maybe even a little more fun. To wrap everything up, here are the completed bookmark and .cmshrc files.

# .bookmarks-cmsh
-=home;network;use "kube-default-pod";
ss=home;device;use "headnode";roles;use scaleserver;

# .cmshrc
alias dl device list
alias bm bookmark
alias ss goto ss
alias si run /root/.cm/cmsh/si.cmsh
bookmark -x /root/.bookmarks-cmsh