Revision 779c15bb

b/lib/cmdlib.py
1151 1151
    """
1152 1152
    # FIXME: This only works because there is only one parameter that can be
1153 1153
    # changed or removed.
1154
    if not self.op.vg_name:
1154
    if self.op.vg_name is not None and not self.op.vg_name:
1155 1155
      instances = self.cfg.GetAllInstancesInfo().values()
1156 1156
      for inst in instances:
1157 1157
        for disk in inst.disks:
......
1159 1159
            raise errors.OpPrereqError("Cannot disable lvm storage while"
1160 1160
                                       " lvm-based instances exist")
1161 1161

  
1162
    node_list = self.acquired_locks[locking.LEVEL_NODE]
1163

  
1162 1164
    # if vg_name not None, checks given volume group on all nodes
1163 1165
    if self.op.vg_name:
1164
      node_list = self.acquired_locks[locking.LEVEL_NODE]
1165 1166
      vglist = self.rpc.call_vg_list(node_list)
1166 1167
      for node in node_list:
1167 1168
        vgstatus = utils.CheckVolumeGroupSize(vglist[node], self.op.vg_name,
......
1170 1171
          raise errors.OpPrereqError("Error on node '%s': %s" %
1171 1172
                                     (node, vgstatus))
1172 1173

  
1174
    self.cluster = cluster = self.cfg.GetClusterInfo()
1175
    # beparams changes do not need validation (we can't validate?),
1176
    # but we still process here
1177
    if self.op.beparams:
1178
      self.new_beparams = cluster.FillDict(
1179
        cluster.beparams[constants.BEGR_DEFAULT], self.op.beparams)
1180

  
1181
    # hypervisor list/parameters
1182
    self.new_hvparams = cluster.FillDict(cluster.hvparams, {})
1183
    if self.op.hvparams:
1184
      if not isinstance(self.op.hvparams, dict):
1185
        raise errors.OpPrereqError("Invalid 'hvparams' parameter on input")
1186
      for hv_name, hv_dict in self.op.hvparams.items():
1187
        if hv_name not in self.new_hvparams:
1188
          self.new_hvparams[hv_name] = hv_dict
1189
        else:
1190
          self.new_hvparams[hv_name].update(hv_dict)
1191

  
1192
    if self.op.enabled_hypervisors is not None:
1193
      self.hv_list = self.op.enabled_hypervisors
1194
    else:
1195
      self.hv_list = cluster.enabled_hypervisors
1196

  
1197
    if self.op.hvparams or self.op.enabled_hypervisors is not None:
1198
      # either the enabled list has changed, or the parameters have, validate
1199
      for hv_name, hv_params in self.new_hvparams.items():
1200
        if ((self.op.hvparams and hv_name in self.op.hvparams) or
1201
            (self.op.enabled_hypervisors and
1202
             hv_name in self.op.enabled_hypervisors)):
1203
          # either this is a new hypervisor, or its parameters have changed
1204
          hv_class = hypervisor.GetHypervisor(hv_name)
1205
          hv_class.CheckParameterSyntax(hv_params)
1206
          _CheckHVParams(self, node_list, hv_name, hv_params)
1207

  
1173 1208
  def Exec(self, feedback_fn):
1174 1209
    """Change the parameters of the cluster.
1175 1210

  
1176 1211
    """
1177
    if self.op.vg_name != self.cfg.GetVGName():
1178
      self.cfg.SetVGName(self.op.vg_name)
1179
    else:
1180
      feedback_fn("Cluster LVM configuration already in desired"
1181
                  " state, not changing")
1212
    if self.op.vg_name is not None:
1213
      if self.op.vg_name != self.cfg.GetVGName():
1214
        self.cfg.SetVGName(self.op.vg_name)
1215
      else:
1216
        feedback_fn("Cluster LVM configuration already in desired"
1217
                    " state, not changing")
1218
    if self.op.hvparams:
1219
      self.cluster.hvparams = self.new_hvparams
1220
    if self.op.enabled_hypervisors is not None:
1221
      self.cluster.enabled_hypervisors = self.op.enabled_hypervisors
1222
    if self.op.beparams:
1223
      self.cluster.beparams[constants.BEGR_DEFAULT] = self.new_beparams
1224
    self.cfg.Update(self.cluster)
1182 1225

  
1183 1226

  
1184 1227
def _WaitForSync(lu, instance, oneshot=False, unlock=False):
b/lib/opcodes.py
255 255

  
256 256
  """
257 257
  OP_ID = "OP_CLUSTER_SET_PARAMS"
258
  __slots__ = ["vg_name"]
258
  __slots__ = ["vg_name", "enabled_hypervisors", "hvparams", "beparams"]
259 259

  
260 260

  
261 261
# node opcodes
b/scripts/gnt-cluster
342 342
    opts - class with options as members
343 343

  
344 344
  """
345
  if not (not opts.lvm_storage or opts.vg_name):
345
  if not (not opts.lvm_storage or opts.vg_name or
346
          opts.enabled_hypervisors or opts.hvparams or
347
          opts.beparams):
346 348
    print "Please give at least one of the parameters."
347 349
    return 1
348 350

  
......
351 353
    print ("Options --no-lvm-storage and --vg-name conflict.")
352 354
    return 1
353 355

  
354
  op = opcodes.OpSetClusterParams(vg_name=opts.vg_name)
356
  hvlist = opts.enabled_hypervisors
357
  if hvlist is not None:
358
    hvlist = hvlist.split(",")
359

  
360
  hvparams = opts.hvparams
361
  if hvparams:
362
    # a list of (name, dict) we can pass directly to dict()
363
    hvparams = dict(opts.hvparams)
364

  
365
  beparams = opts.beparams
366

  
367
  op = opcodes.OpSetClusterParams(vg_name=opts.vg_name,
368
                                  enabled_hypervisors=hvlist,
369
                                  hvparams=hvparams,
370
                                  beparams=beparams)
355 371
  SubmitOpCode(op)
356 372
  return 0
357 373

  
......
487 503
                          help="Disable support for lvm based instances"
488 504
                               " (cluster-wide)",
489 505
                          action="store_false", default=True,),
506
              make_option("--enabled-hypervisors", dest="enabled_hypervisors",
507
                          help="Comma-separated list of hypervisors",
508
                          type="string", default=None),
509
              ikv_option("-H", "--hypervisor-parameters", dest="hvparams",
510
                         help="Hypervisor and hypervisor options, in the"
511
                         " format"
512
                         " hypervisor:option=value,option=value,...",
513
                         default=[],
514
                         action="append",
515
                         type="identkeyval"),
516
              keyval_option("-B", "--backend-parameters", dest="beparams",
517
                            type="keyval", default={},
518
                            help="Backend parameters"),
490 519
              ],
491 520
             "[opts...]",
492 521
             "Alters the parameters of the cluster"),

Also available in: Unified diff