X-Git-Url: https://code.grnet.gr/git/ganeti-local/blobdiff_plain/d9a51679a1248277d5cfc87631477f44834b136a..d80cb8c4a228b3f28b613064d931a62d0ddb435a:/lib/cli.py diff --git a/lib/cli.py b/lib/cli.py index e18ebb2..fba312e 100644 --- a/lib/cli.py +++ b/lib/cli.py @@ -82,6 +82,7 @@ __all__ = [ "NODE_PLACEMENT_OPT", "NOHDR_OPT", "NOIPCHECK_OPT", + "NONAMECHECK_OPT", "NOLVM_STORAGE_OPT", "NOMODIFY_ETCHOSTS_OPT", "NOMODIFY_SSH_SETUP_OPT", @@ -169,7 +170,7 @@ UN_PREFIX = "-" class _Argument: - def __init__(self, min=0, max=None): + def __init__(self, min=0, max=None): # pylint: disable-msg=W0622 self.min = min self.max = max @@ -184,6 +185,7 @@ class ArgSuggest(_Argument): Value can be any of the ones passed to the constructor. """ + # pylint: disable-msg=W0622 def __init__(self, min=0, max=None, choices=None): _Argument.__init__(self, min=min, max=max) self.choices = choices @@ -250,7 +252,6 @@ ARGS_ONE_INSTANCE = [ArgInstance(min=1, max=1)] ARGS_ONE_NODE = [ArgNode(min=1, max=1)] - def _ExtractTagsObject(opts, args): """Extract the tag type object. @@ -311,8 +312,8 @@ def ListTags(opts, args): """ kind, name = _ExtractTagsObject(opts, args) - op = opcodes.OpGetTags(kind=kind, name=name) - result = SubmitOpCode(op) + cl = GetClient() + result = cl.QueryTags(kind, name) result = list(result) result.sort() for tag in result: @@ -353,7 +354,7 @@ def RemoveTags(opts, args): SubmitOpCode(op) -def check_unit(option, opt, value): +def check_unit(option, opt, value): # pylint: disable-msg=W0613 """OptParsers custom converter for units. """ @@ -383,7 +384,7 @@ def _SplitKeyVal(opt, data): """ kv_dict = {} if data: - for elem in data.split(","): + for elem in utils.UnescapeAndSplit(data, sep=","): if "=" in elem: key, val = elem.split("=", 1) else: @@ -400,7 +401,7 @@ def _SplitKeyVal(opt, data): return kv_dict -def check_ident_key_val(option, opt, value): +def check_ident_key_val(option, opt, value): # pylint: disable-msg=W0613 """Custom parser for ident:key=val,key=val options. This will store the parsed values as a tuple (ident, {key: val}). As such, @@ -428,7 +429,7 @@ def check_ident_key_val(option, opt, value): return retval -def check_key_val(option, opt, value): +def check_key_val(option, opt, value): # pylint: disable-msg=W0613 """Custom parser class for key=val,key=val options. This will store the parsed values as a dict {key: val}. @@ -597,6 +598,11 @@ NOIPCHECK_OPT = cli_option("--no-ip-check", dest="ip_check", default=True, help="Don't check that the instance's IP" " is alive") +NONAMECHECK_OPT = cli_option("--no-name-check", dest="name_check", + default=True, action="store_false", + help="Don't check that the instance's name" + " is resolvable") + NET_OPT = cli_option("--net", help="NIC parameters", default=[], dest="nics", action="append", type="identkeyval") @@ -1396,7 +1402,7 @@ def GenericInstanceCreate(mode, opts, args): if opts.nics: try: - nic_max = max(int(nidx[0])+1 for nidx in opts.nics) + nic_max = max(int(nidx[0]) + 1 for nidx in opts.nics) except ValueError, err: raise errors.OpPrereqError("Invalid NIC index passed: %s" % str(err)) nics = [{}] * nic_max @@ -1427,7 +1433,7 @@ def GenericInstanceCreate(mode, opts, args): if opts.sd_size is not None: opts.disks = [(0, {"size": opts.sd_size})] try: - disk_max = max(int(didx[0])+1 for didx in opts.disks) + disk_max = max(int(didx[0]) + 1 for didx in opts.disks) except ValueError, err: raise errors.OpPrereqError("Invalid disk index passed: %s" % str(err)) disks = [{}] * disk_max @@ -1467,6 +1473,7 @@ def GenericInstanceCreate(mode, opts, args): nics=nics, pnode=pnode, snode=snode, ip_check=opts.ip_check, + name_check=opts.name_check, wait_for_sync=opts.wait_for_sync, file_storage_dir=opts.file_storage_dir, file_driver=opts.file_driver, @@ -1524,8 +1531,8 @@ def GenerateTable(headers, fields, separator, data, if unitfields is None: unitfields = [] - numfields = utils.FieldSet(*numfields) - unitfields = utils.FieldSet(*unitfields) + numfields = utils.FieldSet(*numfields) # pylint: disable-msg=W0142 + unitfields = utils.FieldSet(*unitfields) # pylint: disable-msg=W0142 format_fields = [] for field in fields: @@ -1573,6 +1580,12 @@ def GenerateTable(headers, fields, separator, data, args.append(hdr) result.append(format % tuple(args)) + if separator is None: + assert len(mlens) == len(fields) + + if fields and not numfields.Matches(fields[-1]): + mlens[-1] = 0 + for line in data: args = [] if line is None: @@ -1666,7 +1679,7 @@ def GetOnlineNodes(nodes, cl=None, nowarn=False): use_locking=False) offline = [row[0] for row in result if row[1]] if offline and not nowarn: - ToStderr("Note: skipping offline node(s): %s" % ", ".join(offline)) + ToStderr("Note: skipping offline node(s): %s" % utils.CommaJoin(offline)) return [row[0] for row in result if not row[1]] @@ -1758,7 +1771,7 @@ class JobExecutor(object): if self.verbose: ok_jobs = [row[1] for row in self.jobs if row[0]] if ok_jobs: - ToStdout("Submitted jobs %s", ", ".join(ok_jobs)) + ToStdout("Submitted jobs %s", utils.CommaJoin(ok_jobs)) for submit_status, jid, name in self.jobs: if not submit_status: ToStderr("Failed to submit job for %s: %s", name, jid)