4 # Copyright (C) 2006, 2007 Google Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
23 from optparse import make_option
25 from ganeti.cli import *
26 from ganeti import opcodes
27 from ganeti import logger
28 from ganeti import utils
31 def AddNode(opts, args):
32 """Add node cli-to-processor bridge."""
33 op = opcodes.OpAddNode(node_name=args[0], secondary_ip=opts.secondary_ip)
37 def ListNodes(opts, args):
38 """List nodes and their properties.
41 if opts.output is None:
42 selected_fields = ["name", "dtotal", "dfree",
43 "mtotal", "mnode", "mfree",
46 selected_fields = opts.output.split(",")
48 op = opcodes.OpQueryNodes(output_fields=selected_fields)
49 output = SubmitOpCode(op)
51 if not opts.no_headers:
52 headers = {"name": "Node", "pinst": "Pinst", "sinst": "Sinst",
53 "pip": "PrimaryIP", "sip": "SecondaryIP",
54 "dtotal": "DTotal", "dfree": "DFree",
55 "mtotal": "MTotal", "mnode": "MNode", "mfree": "MFree"}
59 if opts.human_readable:
60 unitfields = ["dtotal", "dfree", "mtotal", "mnode", "mfree"]
64 numfields = ["dtotal", "dfree", "mtotal", "mnode", "mfree", "pinst", "sinst"]
66 data = GenerateTable(separator=opts.separator, headers=headers,
67 fields=selected_fields, unitfields=unitfields,
68 numfields=numfields, data=output)
75 def ShowNodeConfig(opts, args):
76 """Show node information.
79 op = opcodes.OpQueryNodeData(nodes=args)
80 result = SubmitOpCode(op)
82 for name, primary_ip, secondary_ip, pinst, sinst in result:
83 logger.ToStdout("Node name: %s" % name)
84 logger.ToStdout(" primary ip: %s" % primary_ip)
85 logger.ToStdout(" secondary ip: %s" % secondary_ip)
87 logger.ToStdout(" primary for instances:")
89 logger.ToStdout(" - %s" % iname)
91 logger.ToStdout(" primary for no instances")
93 logger.ToStdout(" secondary for instances:")
95 logger.ToStdout(" - %s" % iname)
97 logger.ToStdout(" secondary for no instances")
102 def RemoveNode(opts, args):
103 """Remove node cli-to-processor bridge."""
104 op = opcodes.OpRemoveNode(node_name=args[0])
108 def ListVolumes(opts, args):
109 """List logical volumes on node(s).
112 if opts.output is None:
113 selected_fields = ["node", "phys", "vg",
114 "name", "size", "instance"]
116 selected_fields = opts.output.split(",")
118 op = opcodes.OpQueryNodeVolumes(nodes=args, output_fields=selected_fields)
119 output = SubmitOpCode(op)
121 if not opts.no_headers:
122 headers = {"node": "Node", "phys": "PhysDev",
123 "vg": "VG", "name": "Name",
124 "size": "Size", "instance": "Instance"}
128 if opts.human_readable:
129 unitfields = ["size"]
135 data = GenerateTable(separator=opts.separator, headers=headers,
136 fields=selected_fields, unitfields=unitfields,
137 numfields=numfields, data=output)
140 logger.ToStdout(line)
146 'add': (AddNode, ARGS_ONE,
148 make_option("-s", "--secondary-ip", dest="secondary_ip",
149 help="Specify the secondary ip for the node",
150 metavar="ADDRESS", default=None),],
151 "<node_name>", "Add a node to the cluster"),
152 'info': (ShowNodeConfig, ARGS_ANY, [DEBUG_OPT],
153 "[<node_name>...]", "Show information about the node(s)"),
154 'list': (ListNodes, ARGS_NONE,
155 [DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
156 "", "Lists the nodes in the cluster"),
157 'remove': (RemoveNode, ARGS_ONE, [DEBUG_OPT],
158 "<node_name>", "Removes a node from the cluster"),
159 'volumes': (ListVolumes, ARGS_ANY,
160 [DEBUG_OPT, NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
161 "[<node_name>...]", "List logical volumes on node(s)"),
165 if __name__ == '__main__':
166 sys.exit(GenericMain(commands))