from ganeti import opcodes
from ganeti import utils
from ganeti import constants
-from ganeti import compat
from ganeti import errors
from ganeti import netutils
]
-#: headers (and full field list for L{ListNodes}
-_LIST_HEADERS = {
- "name": "Node", "pinst_cnt": "Pinst", "sinst_cnt": "Sinst",
- "pinst_list": "PriInstances", "sinst_list": "SecInstances",
- "pip": "PrimaryIP", "sip": "SecondaryIP",
- "dtotal": "DTotal", "dfree": "DFree",
- "mtotal": "MTotal", "mnode": "MNode", "mfree": "MFree",
- "bootid": "BootID",
- "ctotal": "CTotal", "cnodes": "CNodes", "csockets": "CSockets",
- "tags": "Tags",
- "serial_no": "SerialNo",
- "master_candidate": "MasterC",
- "master": "IsMaster",
- "offline": "Offline", "drained": "Drained",
- "role": "Role",
- "ctime": "CTime", "mtime": "MTime", "uuid": "UUID",
- "master_capable": "MasterCapable", "vm_capable": "VMCapable",
- }
-
-
-#: headers (and full field list for L{ListStorage}
+#: headers (and full field list) for L{ListStorage}
_LIST_STOR_HEADERS = {
constants.SF_NODE: "Node",
constants.SF_TYPE: "Type",
op = opcodes.OpAddNode(node_name=args[0], secondary_ip=sip,
readd=opts.readd, group=opts.nodegroup,
- vm_capable=opts.vm_capable,
+ vm_capable=opts.vm_capable, ndparams=opts.ndparams,
master_capable=opts.master_capable)
SubmitOpCode(op, opts=opts)
@param opts: the command line options selected by the user
@type args: list
- @param args: should be an empty list
+ @param args: nodes to list, or empty for all
@rtype: int
@return: the desired exit code
"""
selected_fields = ParseFields(opts.output, _LIST_DEF_FIELDS)
- output = GetClient().QueryNodes(args, selected_fields, opts.do_locking)
+ fmtoverride = dict.fromkeys(["pinst_list", "sinst_list", "tags"],
+ (lambda value: ",".join(value), False))
- if not opts.no_headers:
- headers = _LIST_HEADERS
- else:
- headers = None
+ return GenericList(constants.QR_NODE, selected_fields, args, opts.units,
+ opts.separator, not opts.no_headers,
+ format_override=fmtoverride)
- unitfields = ["dtotal", "dfree", "mtotal", "mnode", "mfree"]
- numfields = ["dtotal", "dfree",
- "mtotal", "mnode", "mfree",
- "pinst_cnt", "sinst_cnt",
- "ctotal", "serial_no"]
-
- list_type_fields = ("pinst_list", "sinst_list", "tags")
- # change raw values to nicer strings
- for row in output:
- for idx, field in enumerate(selected_fields):
- val = row[idx]
- if field in list_type_fields:
- val = ",".join(val)
- elif field in ('master', 'master_candidate', 'offline', 'drained',
- 'master_capable', 'vm_capable'):
- if val:
- val = 'Y'
- else:
- val = 'N'
- elif field == "ctime" or field == "mtime":
- val = utils.FormatTime(val)
- elif val is None:
- val = "?"
- elif opts.roman_integers and isinstance(val, int):
- val = compat.TryToRoman(val)
- row[idx] = str(val)
+def ListNodeFields(opts, args):
+ """List node fields.
- data = GenerateTable(separator=opts.separator, headers=headers,
- fields=selected_fields, unitfields=unitfields,
- numfields=numfields, data=output, units=opts.units)
- for line in data:
- ToStdout(line)
+ @param opts: the command line options selected by the user
+ @type args: list
+ @param args: fields to list, or empty for all
+ @rtype: int
+ @return: the desired exit code
- return 0
+ """
+ return GenericListFields(constants.QR_NODE, args, opts.separator,
+ not opts.no_headers)
def EvacuateNode(opts, args):
cl = GetClient()
result = cl.QueryNodes(fields=["name", "pip", "sip",
"pinst_list", "sinst_list",
- "master_candidate", "drained", "offline"],
+ "master_candidate", "drained", "offline",
+ "master_capable", "vm_capable"],
names=args, use_locking=False)
for (name, primary_ip, secondary_ip, pinst, sinst,
- is_mc, drained, offline) in result:
+ is_mc, drained, offline, master_capable, vm_capable) in result:
ToStdout("Node name: %s", name)
ToStdout(" primary ip: %s", primary_ip)
ToStdout(" secondary ip: %s", secondary_ip)
ToStdout(" master candidate: %s", is_mc)
ToStdout(" drained: %s", drained)
ToStdout(" offline: %s", offline)
- if pinst:
- ToStdout(" primary for instances:")
- for iname in utils.NiceSort(pinst):
- ToStdout(" - %s", iname)
- else:
- ToStdout(" primary for no instances")
- if sinst:
- ToStdout(" secondary for instances:")
- for iname in utils.NiceSort(sinst):
- ToStdout(" - %s", iname)
- else:
- ToStdout(" secondary for no instances")
+ ToStdout(" master_capable: %s", master_capable)
+ ToStdout(" vm_capable: %s", vm_capable)
+ if vm_capable:
+ if pinst:
+ ToStdout(" primary for instances:")
+ for iname in utils.NiceSort(pinst):
+ ToStdout(" - %s", iname)
+ else:
+ ToStdout(" primary for no instances")
+ if sinst:
+ ToStdout(" secondary for instances:")
+ for iname in utils.NiceSort(sinst):
+ ToStdout(" - %s", iname)
+ else:
+ ToStdout(" secondary for no instances")
return 0
"""
all_changes = [opts.master_candidate, opts.drained, opts.offline,
- opts.master_capable, opts.vm_capable]
+ opts.master_capable, opts.vm_capable, opts.secondary_ip,
+ opts.ndparams]
if all_changes.count(None) == len(all_changes):
ToStderr("Please give at least one of the parameters.")
return 1
drained=opts.drained,
master_capable=opts.master_capable,
vm_capable=opts.vm_capable,
+ secondary_ip=opts.secondary_ip,
force=opts.force,
+ ndparams=opts.ndparams,
auto_promote=opts.auto_promote)
# even if here we process the result, we allow submit only
AddNode, [ArgHost(min=1, max=1)],
[SECONDARY_IP_OPT, READD_OPT, NOSSH_KEYCHECK_OPT, NONODE_SETUP_OPT,
VERBOSE_OPT, NODEGROUP_OPT, PRIORITY_OPT, CAPAB_MASTER_OPT,
- CAPAB_VM_OPT],
+ CAPAB_VM_OPT, NODE_PARAMS_OPT],
"[-s ip] [--readd] [--no-ssh-key-check] [--no-node-setup] [--verbose] "
" <node_name>",
"Add a node to the cluster"),
"[<node_name>...]", "Show information about the node(s)"),
'list': (
ListNodes, ARGS_MANY_NODES,
- [NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT, SYNC_OPT, ROMAN_OPT],
+ [NOHDR_OPT, SEP_OPT, USEUNITS_OPT, FIELDS_OPT],
"[nodes...]",
- "Lists the nodes in the cluster. The available fields are (see the man"
- " page for details): %s. The default field list is (in order): %s." %
- (utils.CommaJoin(_LIST_HEADERS), utils.CommaJoin(_LIST_DEF_FIELDS))),
+ "Lists the nodes in the cluster. The available fields can be shown using"
+ " the \"list-fields\" command (see the man page for details)."
+ " The default field list is (in order): %s." %
+ utils.CommaJoin(_LIST_DEF_FIELDS)),
+ "list-fields": (
+ ListNodeFields, [ArgUnknown()],
+ [NOHDR_OPT, SEP_OPT],
+ "[fields...]",
+ "Lists all available fields for nodes"),
'modify': (
SetNodeParams, ARGS_ONE_NODE,
[FORCE_OPT, SUBMIT_OPT, MC_OPT, DRAINED_OPT, OFFLINE_OPT,
- CAPAB_MASTER_OPT, CAPAB_VM_OPT,
- AUTO_PROMOTE_OPT, DRY_RUN_OPT, PRIORITY_OPT],
+ CAPAB_MASTER_OPT, CAPAB_VM_OPT, SECONDARY_IP_OPT,
+ AUTO_PROMOTE_OPT, DRY_RUN_OPT, PRIORITY_OPT, NODE_PARAMS_OPT],
"<node_name>", "Alters the parameters of a node"),
'powercycle': (
PowercycleNode, ARGS_ONE_NODE,