Revision ea3a925f

b/lib/bootstrap.py
108 108
def InitCluster(cluster_name, hypervisor_type, mac_prefix, def_bridge,
109 109
                master_netdev, file_storage_dir,
110 110
                secondary_ip=None,
111
                vg_name=None):
111
                vg_name=None, beparams=None, hvparams=None,
112
                enabled_hypervisors=None):
112 113
  """Initialise the cluster.
113 114

  
114 115
  """
......
224 225
    master_netdev=master_netdev,
225 226
    cluster_name=clustername.name,
226 227
    file_storage_dir=file_storage_dir,
228
    enabled_hypervisors=enabled_hypervisors,
229
    beparams={constants.BEGR_DEFAULT: beparams},
230
    hvparams=hvparams,
227 231
    )
228 232
  master_node_config = objects.Node(name=hostname.name,
229 233
                                    primary_ip=hostname.ip,
b/scripts/gnt-cluster
50 50
  if opts.lvm_storage and not opts.vg_name:
51 51
    vg_name = constants.DEFAULT_VG
52 52

  
53
  hvlist = opts.enabled_hypervisors
54
  if hvlist is not None:
55
    hvlist = hvlist.split(",")
56
  else:
57
    hvlist = constants.DEFAULT_ENABLED_HYPERVISOR
58

  
59
  hvparams = opts.hvparams
60
  if hvparams:
61
    # a list of (name, dict) we can pass directly to dict()
62
    hvparams = dict(opts.hvparams)
63
  else:
64
    # otherwise init as empty dict
65
    hvparams = {}
66

  
67
  beparams = opts.beparams
68
  # check for invalid parameters
69
  for parameter in beparams:
70
    if parameter not in constants.BES_PARAMETERS:
71
      print "Invalid backend parameter: %s" % parameter
72
      return 1
73

  
74
  # prepare beparams dict
75
  for parameter in constants.BES_PARAMETERS:
76
    if parameter not in beparams:
77
      beparams[parameter] = constants.BEC_DEFAULTS[parameter]
78

  
79
  # type wrangling
80
  try:
81
    beparams[constants.BE_VCPUS] = int(beparams[constants.BE_VCPUS])
82
  except ValueError:
83
    print "%s must be an integer" % constants.BE_VCPUS
84
    return 1
85

  
86
  beparams[constants.BE_MEMORY] = utils.ParseUnit(beparams[constants.BE_MEMORY])
87

  
88
  # prepare hvparams dict
89
  for hv in constants.HYPER_TYPES:
90
    if hv not in hvparams:
91
      hvparams[hv] = {}
92
    for parameter in constants.HVC_DEFAULTS[hv]:
93
      if parameter not in hvparams[hv]:
94
        hvparams[hv][parameter] = constants.HVC_DEFAULTS[hv][parameter]
95

  
96
  for hv in hvlist:
97
    if hv not in constants.HYPER_TYPES:
98
      print "invalid hypervisor: %s" % hv
99
      return 1
100

  
53 101
  bootstrap.InitCluster(cluster_name=args[0],
54 102
                        secondary_ip=opts.secondary_ip,
55 103
                        hypervisor_type=opts.hypervisor_type,
......
57 105
                        mac_prefix=opts.mac_prefix,
58 106
                        def_bridge=opts.def_bridge,
59 107
                        master_netdev=opts.master_netdev,
60
                        file_storage_dir=opts.file_storage_dir)
108
                        file_storage_dir=opts.file_storage_dir,
109
                        enabled_hypervisors=hvlist,
110
                        hvparams=hvparams,
111
                        beparams=beparams)
61 112
  return 0
62 113

  
63 114

  
......
445 496
                        help="No support for lvm based instances"
446 497
                             " (cluster-wide)",
447 498
                        action="store_false", default=True,),
499
            make_option("--enabled-hypervisors", dest="enabled_hypervisors",
500
                        help="Comma-separated list of hypervisors",
501
                        type="string", default=None),
502
            ikv_option("-H", "--hypervisor-parameters", dest="hvparams",
503
                       help="Hypervisor and hypervisor options, in the"
504
                         " format"
505
                       " hypervisor:option=value,option=value,...",
506
                       default=[],
507
                       action="append",
508
                       type="identkeyval"),
509
            keyval_option("-B", "--backend-parameters", dest="beparams",
510
                          type="keyval", default={},
511
                          help="Backend parameters"),
448 512
            ],
449 513
           "[opts...] <cluster_name>",
450 514
           "Initialises a new cluster configuration"),

Also available in: Unified diff