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): ...@@ -105,7 +105,8 @@ class R_2_os(baserlib.R_Generic):
""" """
cl = baserlib.GetClient() 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) job_id = baserlib.SubmitJob([op], cl)
# we use custom feedback function, instead of print we log the status # we use custom feedback function, instead of print we log the status
result = cli.PollJob(job_id, cl, feedback_fn=baserlib.FeedbackFn) result = cli.PollJob(job_id, cl, feedback_fn=baserlib.FeedbackFn)
...@@ -114,7 +115,12 @@ class R_2_os(baserlib.R_Generic): ...@@ -114,7 +115,12 @@ class R_2_os(baserlib.R_Generic):
if not isinstance(diagnose_data, list): if not isinstance(diagnose_data, list):
raise http.HttpBadGateway(message="Can't get OS 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): class R_2_redist_config(baserlib.R_Generic):
......
...@@ -481,7 +481,8 @@ def ReinstallInstance(opts, args): ...@@ -481,7 +481,8 @@ def ReinstallInstance(opts, args):
# second, if requested, ask for an OS # second, if requested, ask for an OS
if opts.select_os is True: 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) result = SubmitOpCode(op)
if not result: if not result:
...@@ -491,10 +492,12 @@ def ReinstallInstance(opts, args): ...@@ -491,10 +492,12 @@ def ReinstallInstance(opts, args):
ToStdout("Available OS templates:") ToStdout("Available OS templates:")
number = 0 number = 0
choices = [] choices = []
for entry in result: for (name, valid, variants) in result:
ToStdout("%3s: %s", number, entry[0]) if valid:
choices.append(("%s" % number, entry[0], entry[0])) for entry in CalculateOSNames(name, variants):
number = number + 1 ToStdout("%3s: %s", number, entry)
choices.append(("%s" % number, entry, entry))
number += 1
choices.append(('x', 'exit', 'Exit gnt-instance reinstall')) choices.append(('x', 'exit', 'Exit gnt-instance reinstall'))
selected = AskUser("Enter OS template number (or x to abort):", selected = AskUser("Enter OS template number (or x to abort):",
......
...@@ -41,7 +41,8 @@ def ListOS(opts, args): ...@@ -41,7 +41,8 @@ def ListOS(opts, args):
@return: the desired exit code @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) result = SubmitOpCode(op)
if not result: if not result:
...@@ -53,9 +54,13 @@ def ListOS(opts, args): ...@@ -53,9 +54,13 @@ def ListOS(opts, args):
else: else:
headers = None 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 = GenerateTable(separator=None, headers=headers, fields=["name"],
data=[[row[0]] for row in result if row[1]], data=os_names, units=None)
units=None)
for line in data: for line in data:
ToStdout(line) ToStdout(line)
......
...@@ -447,16 +447,20 @@ class Burner(object): ...@@ -447,16 +447,20 @@ class Burner(object):
Err(msg, exit_code=err_code) Err(msg, exit_code=err_code)
self.nodes = [data[0] for data in result if not (data[1] or data[2])] self.nodes = [data[0] for data in result if not (data[1] or data[2])]
op_diagos = opcodes.OpDiagnoseOS(output_fields=["name", "valid"], names=[]) op_diagnose = opcodes.OpDiagnoseOS(output_fields=["name", "valid",
result = self.ExecOp(True, op_diagos) "variants"], names=[])
result = self.ExecOp(True, op_diagnose)
if not result: if not result:
Err("Can't get the OS list") Err("Can't get the OS list")
# filter non-valid OS-es found = False
os_set = [val[0] for val in result if val[1]] 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) Err("OS '%s' not found" % self.opts.os)
@_DoCheckInstances @_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