Commit e3ac208c authored by Guido Trotter's avatar Guido Trotter
Browse files

Update client os lists to name+variant format



List of OSes are displayed by gnt-os list, rapi, and gnt-instance
reinstall --select-os, and checked by burnin. In all of these show the
list with name+variant, if the os has variants.
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarOlivier Tharan <olive@google.com>
parent e16dfb5b
......@@ -105,7 +105,8 @@ class R_2_os(baserlib.R_Generic):
"""
cl = baserlib.GetClient()
op = opcodes.OpDiagnoseOS(output_fields=["name", "valid"], names=[])
op = opcodes.OpDiagnoseOS(output_fields=["name", "valid", "variants"],
names=[])
job_id = baserlib.SubmitJob([op], cl)
# we use custom feedback function, instead of print we log the status
result = cli.PollJob(job_id, cl, feedback_fn=baserlib.FeedbackFn)
......@@ -114,7 +115,12 @@ class R_2_os(baserlib.R_Generic):
if not isinstance(diagnose_data, list):
raise http.HttpBadGateway(message="Can't get OS list")
return [row[0] for row in diagnose_data if row[1]]
os_names = []
for (name, valid, variants) in diagnose_data:
if valid:
os_names.extend(cli.CalculateOSNames(name, variants))
return os_names
class R_2_redist_config(baserlib.R_Generic):
......
......@@ -481,7 +481,8 @@ def ReinstallInstance(opts, args):
# second, if requested, ask for an OS
if opts.select_os is True:
op = opcodes.OpDiagnoseOS(output_fields=["name", "valid"], names=[])
op = opcodes.OpDiagnoseOS(output_fields=["name", "valid", "variants"],
names=[])
result = SubmitOpCode(op)
if not result:
......@@ -491,10 +492,12 @@ def ReinstallInstance(opts, args):
ToStdout("Available OS templates:")
number = 0
choices = []
for entry in result:
ToStdout("%3s: %s", number, entry[0])
choices.append(("%s" % number, entry[0], entry[0]))
number = number + 1
for (name, valid, variants) in result:
if valid:
for entry in CalculateOSNames(name, variants):
ToStdout("%3s: %s", number, entry)
choices.append(("%s" % number, entry, entry))
number += 1
choices.append(('x', 'exit', 'Exit gnt-instance reinstall'))
selected = AskUser("Enter OS template number (or x to abort):",
......
......@@ -41,7 +41,8 @@ def ListOS(opts, args):
@return: the desired exit code
"""
op = opcodes.OpDiagnoseOS(output_fields=["name", "valid"], names=[])
op = opcodes.OpDiagnoseOS(output_fields=["name", "valid", "variants"],
names=[])
result = SubmitOpCode(op)
if not result:
......@@ -53,9 +54,13 @@ def ListOS(opts, args):
else:
headers = None
os_names = []
for (name, valid, variants) in result:
if valid:
os_names.extend([[n] for n in CalculateOSNames(name, variants)])
data = GenerateTable(separator=None, headers=headers, fields=["name"],
data=[[row[0]] for row in result if row[1]],
units=None)
data=os_names, units=None)
for line in data:
ToStdout(line)
......
......@@ -447,16 +447,20 @@ class Burner(object):
Err(msg, exit_code=err_code)
self.nodes = [data[0] for data in result if not (data[1] or data[2])]
op_diagos = opcodes.OpDiagnoseOS(output_fields=["name", "valid"], names=[])
result = self.ExecOp(True, op_diagos)
op_diagnose = opcodes.OpDiagnoseOS(output_fields=["name", "valid",
"variants"], names=[])
result = self.ExecOp(True, op_diagnose)
if not result:
Err("Can't get the OS list")
# filter non-valid OS-es
os_set = [val[0] for val in result if val[1]]
found = False
for (name, valid, variants) in result:
if valid and self.opts.os in cli.CalculateOSNames(name, variants):
found = True
break
if self.opts.os not in os_set:
if not found:
Err("OS '%s' not found" % self.opts.os)
@_DoCheckInstances
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment