Revision 137161c9 scripts/gnt-node

b/scripts/gnt-node
48 48
  op = opcodes.OpQueryNodes(output_fields=selected_fields)
49 49
  output = SubmitOpCode(op)
50 50

  
51
  mlens = [0 for name in selected_fields]
52
  format_fields = []
53
  unitformat_fields = ("dtotal", "dfree", "mtotal", "mnode", "mfree")
54
  for field in selected_fields:
55
    if field in ("dtotal", "dfree", "mtotal", "mnode",
56
                 "mfree", "pinst", "sinst"):
57
      format_fields.append("%*s")
58
    else:
59
      format_fields.append("%-*s")
60

  
61
  separator = opts.separator
62
  if "%" in separator:
63
    separator = separator.replace("%", "%%")
64
  format = separator.join(format_fields)
65

  
66
  for row in output:
67
    for idx, val in enumerate(row):
68
      if opts.human_readable and selected_fields[idx] in unitformat_fields:
69
        try:
70
          val = int(val)
71
        except ValueError:
72
          pass
73
        else:
74
          val = row[idx] = utils.FormatUnit(val)
75
      mlens[idx] = max(mlens[idx], len(val))
76

  
77 51
  if not opts.no_headers:
78
    header_list = {"name": "Node", "pinst": "Pinst", "sinst": "Sinst",
79
                   "pip": "PrimaryIP", "sip": "SecondaryIP",
80
                   "dtotal": "DTotal", "dfree": "DFree",
81
                   "mtotal": "MTotal", "mnode": "MNode", "mfree": "MFree"}
82
    args = []
83
    for idx, name in enumerate(selected_fields):
84
      hdr = header_list[name]
85
      mlens[idx] = max(mlens[idx], len(hdr))
86
      args.append(mlens[idx])
87
      args.append(hdr)
88
    logger.ToStdout(format % tuple(args))
89

  
90
  for row in output:
91
    args = []
92
    for idx, val in enumerate(row):
93
      args.append(mlens[idx])
94
      args.append(val)
95
    logger.ToStdout(format % tuple(args))
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"}
56
  else:
57
    headers = None
58

  
59
  if opts.human_readable:
60
    unitfields = ["dtotal", "dfree", "mtotal", "mnode", "mfree"]
61
  else:
62
    unitfields = None
63

  
64
  numfields = ["dtotal", "dfree", "mtotal", "mnode", "mfree", "pinst", "sinst"]
65

  
66
  OutputTable(separator=opts.separator, headers=headers,
67
      fields=selected_fields, unitfields=unitfields,
68
      numfields=numfields, data=output)
96 69

  
97 70
  return 0
98 71

  
......
143 116
  op = opcodes.OpQueryNodeVolumes(nodes=args, output_fields=selected_fields)
144 117
  output = SubmitOpCode(op)
145 118

  
146
  mlens = [0 for name in selected_fields]
147
  format_fields = []
148
  unitformat_fields = ("size",)
149
  for field in selected_fields:
150
    if field in unitformat_fields:
151
      format_fields.append("%*s")
152
    else:
153
      format_fields.append("%-*s")
154

  
155
  separator = opts.separator
156
  if "%" in separator:
157
    separator = separator.replace("%", "%%")
158
  format = separator.join(format_fields)
159

  
160
  for row in output:
161
    for idx, val in enumerate(row):
162
      if opts.human_readable and selected_fields[idx] in unitformat_fields:
163
        try:
164
          val = int(val)
165
        except ValueError:
166
          pass
167
        else:
168
          val = row[idx] = utils.FormatUnit(val)
169
      mlens[idx] = max(mlens[idx], len(val))
170

  
171 119
  if not opts.no_headers:
172
    header_list = {"node": "Node", "phys": "PhysDev",
173
                   "vg": "VG", "name": "Name",
174
                   "size": "Size", "instance": "Instance"}
175
    args = []
176
    for idx, name in enumerate(selected_fields):
177
      hdr = header_list[name]
178
      mlens[idx] = max(mlens[idx], len(hdr))
179
      args.append(mlens[idx])
180
      args.append(hdr)
181
    logger.ToStdout(format % tuple(args))
182

  
183
  for row in output:
184
    args = []
185
    for idx, val in enumerate(row):
186
      args.append(mlens[idx])
187
      args.append(val)
188
    logger.ToStdout(format % tuple(args))
120
    headers = {"node": "Node", "phys": "PhysDev",
121
               "vg": "VG", "name": "Name",
122
               "size": "Size", "instance": "Instance"}
123
  else:
124
    headers = None
125

  
126
  if opts.human_readable:
127
    unitfields = ["size"]
128
  else:
129
    unitfields = None
130

  
131
  numfields = ["size"]
132

  
133
  OutputTable(separator=opts.separator, headers=headers,
134
      fields=selected_fields, unitfields=unitfields,
135
      numfields=numfields, data=output)
189 136

  
190 137
  return 0
191 138

  

Also available in: Unified diff