223 |
223 |
nicparams=None, hvparams=None, enabled_hypervisors=None,
|
224 |
224 |
modify_etc_hosts=True, modify_ssh_setup=True,
|
225 |
225 |
maintain_node_health=False, drbd_helper=None,
|
226 |
|
uid_pool=None, default_iallocator=None):
|
|
226 |
uid_pool=None, default_iallocator=None,
|
|
227 |
primary_ip_version=None):
|
227 |
228 |
"""Initialise the cluster.
|
228 |
229 |
|
229 |
230 |
@type candidate_pool_size: int
|
... | ... | |
244 |
245 |
" entries: %s" % invalid_hvs,
|
245 |
246 |
errors.ECODE_INVAL)
|
246 |
247 |
|
247 |
|
hostname = netutils.GetHostname()
|
248 |
248 |
|
249 |
|
if netutils.IP4Address.IsLoopback(hostname.ip):
|
|
249 |
ipcls = None
|
|
250 |
if primary_ip_version == constants.IP4_VERSION:
|
|
251 |
ipcls = netutils.IP4Address
|
|
252 |
elif primary_ip_version == constants.IP6_VERSION:
|
|
253 |
ipcls = netutils.IP6Address
|
|
254 |
else:
|
|
255 |
raise errors.OpPrereqError("Invalid primary ip version: %d." %
|
|
256 |
primary_ip_version)
|
|
257 |
|
|
258 |
hostname = netutils.GetHostname(family=ipcls.family)
|
|
259 |
if not ipcls.IsValid(hostname.ip):
|
|
260 |
raise errors.OpPrereqError("This host's IP (%s) is not a valid IPv%d"
|
|
261 |
" address." % (hostname.ip, primary_ip_version))
|
|
262 |
|
|
263 |
if ipcls.IsLoopback(hostname.ip):
|
250 |
264 |
raise errors.OpPrereqError("This host's IP (%s) resolves to a loopback"
|
251 |
265 |
" address. Please fix DNS or %s." %
|
252 |
266 |
(hostname.ip, constants.ETC_HOSTS),
|
253 |
267 |
errors.ECODE_ENVIRON)
|
254 |
268 |
|
255 |
|
if not netutils.IPAddress.Own(hostname.ip):
|
|
269 |
if not ipcls.Own(hostname.ip):
|
256 |
270 |
raise errors.OpPrereqError("Inconsistency: this host's name resolves"
|
257 |
271 |
" to %s,\nbut this ip address does not"
|
258 |
272 |
" belong to this host. Aborting." %
|
259 |
273 |
hostname.ip, errors.ECODE_ENVIRON)
|
260 |
274 |
|
261 |
|
clustername = netutils.GetHostname(name=cluster_name)
|
|
275 |
clustername = netutils.GetHostname(name=cluster_name, family=ipcls.family)
|
262 |
276 |
|
263 |
|
if netutils.TcpPing(clustername.ip, constants.DEFAULT_NODED_PORT,
|
264 |
|
timeout=5):
|
|
277 |
if netutils.TcpPing(clustername.ip, constants.DEFAULT_NODED_PORT, timeout=5):
|
265 |
278 |
raise errors.OpPrereqError("Cluster IP already active. Aborting.",
|
266 |
279 |
errors.ECODE_NOTUNIQUE)
|
267 |
280 |
|
268 |
|
if secondary_ip:
|
269 |
|
if not netutils.IP4Address.IsValid(secondary_ip):
|
270 |
|
raise errors.OpPrereqError("Invalid secondary ip given",
|
271 |
|
errors.ECODE_INVAL)
|
272 |
|
if (secondary_ip != hostname.ip and
|
273 |
|
not netutils.IPAddress.Own(secondary_ip)):
|
274 |
|
raise errors.OpPrereqError("You gave %s as secondary IP,"
|
275 |
|
" but it does not belong to this host." %
|
276 |
|
secondary_ip, errors.ECODE_ENVIRON)
|
277 |
|
else:
|
|
281 |
if not secondary_ip:
|
|
282 |
if primary_ip_version == constants.IP6_VERSION:
|
|
283 |
raise errors.OpPrereqError("When using a IPv6 primary address, a valid"
|
|
284 |
" IPv4 address must be given as secondary."
|
|
285 |
" Aborting.", errors.ECODE_INVAL)
|
278 |
286 |
secondary_ip = hostname.ip
|
279 |
287 |
|
|
288 |
if not netutils.IP4Address.IsValid(secondary_ip):
|
|
289 |
raise errors.OpPrereqError("Secondary IP address (%s) has to be a valid"
|
|
290 |
" IPv4 address." % secondary_ip,
|
|
291 |
errors.ECODE_INVAL)
|
|
292 |
|
|
293 |
if not netutils.IP4Address.Own(secondary_ip):
|
|
294 |
raise errors.OpPrereqError("You gave %s as secondary IP,"
|
|
295 |
" but it does not belong to this host." %
|
|
296 |
secondary_ip, errors.ECODE_ENVIRON)
|
|
297 |
|
280 |
298 |
if vg_name is not None:
|
281 |
299 |
# Check if volume group is valid
|
282 |
300 |
vgstatus = utils.CheckVolumeGroupSize(utils.ListVolumeGroups(), vg_name,
|
... | ... | |
373 |
391 |
maintain_node_health=maintain_node_health,
|
374 |
392 |
drbd_usermode_helper=drbd_helper,
|
375 |
393 |
default_iallocator=default_iallocator,
|
|
394 |
primary_ip_family=ipcls.family,
|
376 |
395 |
)
|
377 |
396 |
master_node_config = objects.Node(name=hostname.name,
|
378 |
397 |
primary_ip=hostname.ip,
|