If you use the Ganeti command line you probably have used
gnt-instance list and
gnt-node list. In fact, most of the
gnt-* commands have a
list subcommand. Here's some things you probably didn't know.
Part 1: Change what "list" outputs
Unhappy with how verbose
gnt-instance list is? The
-o option lets you pick which fields are output. Try this to just see the name:
gnt-instance list -o name
I used to use
tail and other Unix commands to extract just the name or just the status. Now I use
-o name,status to get exactly the information I need.
I'm quite partial to this set of fields:
gnt-instance list --no-headers -o name,pnode,snodes,admin_state,oper_state,oper_ram
--no-headers flag means just output the data, no column headings.
What if you like the default fields that are output but want to add others to them? Prepend a
+ to the option:
gnt-node list --no-headers -o +group,drained,offline,master_candidate
This will print the default fields plus the node group, and the three main status flags nodes havee: is it drained (no instances can move onto it), offline (the node is essentially removed from the cluster), and whether or not the node can be a master.
How does one find the list of all the fields one can output? Use the
list-fields subcommand. For each
gnt-* command it lists the fields that are available with that
list command. That is,
gnt-instance list-fields shows a different set of names than
Putting all this together I've come up with three bash aliases that make my life easier. They print a lot of information but (usually) fit it all on an 80-character wide terminal:
alias i='gnt-instance list --no-headers -o name,pnode,snodes,admin_state,oper_state,oper_ram | sed -e '\''s/.MY.DOMAIN.NAME//g'\''' alias n='gnt-node list --no-headers -o +group,drained,offline,master_candidate | sed -e '\''s/.MY.DOMAIN.NAME//g'\''' alias j='gnt-job list | tail -n 90 | egrep --color=always '\''^|waiting|running'\'''
MY.DOMAIN.NAME to the name of your domain.)
Part 2: Filter what's output
-F option has got to be the least-known about feature of the Ganeti command line tools. It lets you restrict what nodes or instances are listed.
List the instances that are using more than 3 virtual CPUs:
gnt-instance list -F 'oper_vcpus > 3'
List the instances that have more than 6G of RAM (otherwise known as "6144 megabytes"):
gnt-instance list -F 'be/memory > 6144'
The filtering language can handle complex expressions. It understands
> and all the operations you'd expect. The
ganeti(7) man page explains it all.
Which nodes have zero primary instances? Which have none at all?
gnt-node list --filter 'pinst_cnt 0' gnt-node list -F 'pinst_cnt 0 and sinst_cnt == 0'
Strings must be quoted with double-quotes. Since the entire formula is in single-quotes this looks a bit odd but you'll get used to it quickly.
Which instances have node "fred" as their primary?
gnt-instance list --no-header -o name -F 'pnode == "fred" '
(I included a space between
' to make it easier to read. It isn't needed otherwise.)
Which nodes are master candidates?
gnt-node list --no-headers -o name -F 'role == "C" '
Do you find typing
gnt-cluster getmaster too quick and easy? Try this command to find out who the master is:
gnt-node list --no-headers -o name -F 'role == "M" '
gnt-* commands it must be run on the master, so be sure to use
gnt-cluster getmaster to find out who the master is and run the command there.
If you use the "node group" feature of Ganeti (and you probably don't) you can find out which nodes are in node group foo:
gnt-node list -o name -F 'group == "foo" '
and which instances have primaries that are in group foo:
gnt-instance list --no-header -o name -F "pnode.group == "foo"'
It took me forever to realize that, since snodes is a list, one has to use
in instead of
==. Here's a list of all the instances whose secondary is in node group "bar":
gnt-instance list --no-header -o name -F '"bar" in snodes.group'
("snodes" is plural, "pnode" is singular")
- The following commands have a
-ocontrols which fields are output when using the
-Fspecifies a filter that controls which items are listed.
- The field names used with
-Fare different for each
- Use the
list-fieldssubcommand to find out what fields are available for a command.
- The filtering language is documented in
ganeti(7). i.e. view with:
man 7 ganeti
- The man pages for the individual
gnt-*commands give longer explanations of what each field means.
bash, filters have to be in single quotes so that the shell doesn't interpret
>, double-quotes, and other symbols as bash operators.