Revision b43dcc5a

b/lib/bootstrap.py
348 348
  sshkey = sshline.split(" ")[1]
349 349

  
350 350
  if modify_etc_hosts:
351
    utils.AddHostToEtcHosts(hostname.name)
351
    utils.AddHostToEtcHosts(hostname)
352 352

  
353 353
  if modify_ssh_setup:
354 354
    _InitSSHSetup()
......
480 480
  @param ssh_key_check: whether to do a strict key check
481 481

  
482 482
  """
483
  sshrunner = ssh.SshRunner(cluster_name)
483
  family = ssconf.SimpleStore().GetPrimaryIPFamily()
484
  sshrunner = ssh.SshRunner(cluster_name,
485
                            ipv6=family==netutils.IP6Address.family)
484 486

  
485 487
  noded_cert = utils.ReadFile(constants.NODED_CERT_FILE)
486 488
  rapi_cert = utils.ReadFile(constants.RAPI_CERT_FILE)
......
502 504
  if not confd_hmac_key.endswith("\n"):
503 505
    confd_hmac_key += "\n"
504 506

  
507
  bind_address = constants.IP4_ADDRESS_ANY
508
  if family == netutils.IP6Address.family:
509
    bind_address = constants.IP6_ADDRESS_ANY
510

  
505 511
  # set up inter-node password and certificate and restarts the node daemon
506 512
  # and then connect with ssh to set password and start ganeti-noded
507 513
  # note that all the below variables are sanitized at this point,
......
515 521
               "cat > '%s' << '!EOF.' && \n"
516 522
               "%s!EOF.\n"
517 523
               "chmod 0400 %s %s %s && "
518
               "%s start %s" %
524
               "%s start %s -b '%s'" %
519 525
               (constants.NODED_CERT_FILE, noded_cert,
520 526
                constants.RAPI_CERT_FILE, rapi_cert,
521 527
                constants.CONFD_HMAC_KEY, confd_hmac_key,
522 528
                constants.NODED_CERT_FILE, constants.RAPI_CERT_FILE,
523 529
                constants.CONFD_HMAC_KEY,
524
                constants.DAEMON_UTIL, constants.NODED))
530
                constants.DAEMON_UTIL, constants.NODED, bind_address))
525 531

  
526 532
  result = sshrunner.Run(node, 'root', mycommand, batch=False,
527 533
                         ask_key=ssh_key_check,
b/lib/cmdlib.py
3675 3675

  
3676 3676
  def CheckArguments(self):
3677 3677
    # validate/normalize the node name
3678
    self.op.node_name = netutils.Hostname.GetNormalizedName(self.op.node_name)
3678
    self.hostname = netutils.GetHostname(name=self.op.node_name,
3679
                                         family=self.cfg.GetPrimaryIPFamily())
3680
    self.op.node_name = self.hostname.name
3679 3681

  
3680 3682
  def BuildHooksEnv(self):
3681 3683
    """Build hooks env.
......
3704 3706
    Any errors are signaled by raising errors.OpPrereqError.
3705 3707

  
3706 3708
    """
3707
    hostname = netutils.GetHostname(name=self.op.node_name)
3708
    node = hostname.name
3709 3709
    cfg = self.cfg
3710

  
3710
    hostname = self.hostname
3711
    node = hostname.name
3711 3712
    primary_ip = self.op.primary_ip = hostname.ip
3712 3713
    if self.op.secondary_ip is None:
3713 3714
      self.op.secondary_ip = primary_ip
3714
    if not netutils.IP4Address.IsValid(self.op.secondary_ip):
3715
      raise errors.OpPrereqError("Invalid secondary IP given",
3716
                                 errors.ECODE_INVAL)
3715

  
3717 3716
    secondary_ip = self.op.secondary_ip
3717
    if not netutils.IP4Address.IsValid(secondary_ip):
3718
      raise errors.OpPrereqError("Secondary IP (%s) needs to be a valid IPv4"
3719
                                 " address" % secondary_ip, errors.ECODE_INVAL)
3718 3720

  
3719 3721
    node_list = cfg.GetNodeList()
3720 3722
    if not self.op.readd and node in node_list:
......
3846 3848
    # Add node to our /etc/hosts, and add key to known_hosts
3847 3849
    if self.cfg.GetClusterInfo().modify_etc_hosts:
3848 3850
      # FIXME: this should be done via an rpc call to node daemon
3849
      utils.AddHostToEtcHosts(new_node.name)
3851
      utils.AddHostToEtcHosts(self.hostname)
3850 3852

  
3851 3853
    if new_node.secondary_ip != new_node.primary_ip:
3852 3854
      result = self.rpc.call_node_has_ip_address(new_node.name,
b/lib/netutils.py
132 132
      if family in (socket.AF_INET, socket.AF_INET6):
133 133
        result = socket.getaddrinfo(hostname, None, family)
134 134
      else:
135
        result = socket.getaddrinfo(hostname, None, socket.AF_INET)
135
        result = socket.getaddrinfo(hostname, None)
136 136
    except (socket.gaierror, socket.herror, socket.error), err:
137 137
      # hostname not found in DNS, or other socket exception in the
138 138
      # (code, description format)
b/lib/rpc.py
272 272
  @returns: List of corresponding addresses, if found
273 273

  
274 274
  """
275
  iplist = ssc().GetNodePrimaryIPList()
275
  ss = ssc()
276
  iplist = ss.GetNodePrimaryIPList()
277
  family = ss.GetPrimaryIPFamily()
276 278
  addresses = []
277 279
  ipmap = dict(entry.split() for entry in iplist)
278 280
  for node in node_list:
279 281
    address = ipmap.get(node)
280 282
    if address is None:
281
      address = nslookup_fn(node)
283
      address = nslookup_fn(node, family=family)
282 284
    addresses.append(address)
283 285

  
284 286
  return addresses
b/lib/ssh.py
1 1
#
2 2
#
3 3

  
4
# Copyright (C) 2006, 2007 Google Inc.
4
# Copyright (C) 2006, 2007, 2010 Google Inc.
5 5
#
6 6
# This program is free software; you can redistribute it and/or modify
7 7
# it under the terms of the GNU General Public License as published by
......
66 66
  """Wrapper for SSH commands.
67 67

  
68 68
  """
69
  def __init__(self, cluster_name):
69
  def __init__(self, cluster_name, ipv6=False):
70
    """Initializes this class.
71

  
72
    @type cluster_name: str
73
    @param cluster_name: name of the cluster
74
    @type ipv6: bool
75
    @param ipv6: If true, force ssh to use IPv6 addresses only
76

  
77
    """
70 78
    self.cluster_name = cluster_name
79
    self.ipv6 = ipv6
71 80

  
72 81
  def _BuildSshOptions(self, batch, ask_key, use_cluster_key,
73 82
                       strict_host_check, private_key=None, quiet=True):
......
128 137
      else:
129 138
        options.append("-oStrictHostKeyChecking=no")
130 139

  
140
    if self.ipv6:
141
      options.append("-6")
142

  
131 143
    return options
132 144

  
133 145
  def BuildCmd(self, hostname, user, command, batch=True, ask_key=False,
b/lib/utils.py
61 61
from ganeti import errors
62 62
from ganeti import constants
63 63
from ganeti import compat
64
from ganeti import netutils
65 64

  
66 65

  
67 66
_locksheld = []
......
1461 1460
      L{constants.ETC_HOSTS}
1462 1461

  
1463 1462
  """
1464
  SetEtcHostsEntry(constants.ETC_HOSTS, netutils.Hostname.GetIP(hostname),
1465
                   hostname, [hostname.split(".")[0]])
1463
  SetEtcHostsEntry(constants.ETC_HOSTS, hostname.ip, hostname.name,
1464
                   [hostname.name.split(".")[0]])
1466 1465

  
1467 1466

  
1468 1467
def RemoveEtcHostsEntry(file_name, hostname):
b/test/ganeti.rpc_unittest.py
59 59
def GetFakeSimpleStoreClass(fn):
60 60
  class FakeSimpleStore:
61 61
    GetNodePrimaryIPList = fn
62
    GetPrimaryIPFamily = lambda _: None
62 63

  
63 64
  return FakeSimpleStore
64 65

  
......
239 240
    addr_list = ["192.0.2.%d" % n for n in range(0, 255, 13)]
240 241
    node_list = ["node%d.example.com" % n for n in range(0, 255, 13)]
241 242
    node_addr_list = [ " ".join(t) for t in zip(node_list, addr_list)]
242
    ssc = GetFakeSimpleStoreClass(lambda s: node_addr_list)
243
    ssc = GetFakeSimpleStoreClass(lambda _: node_addr_list)
243 244
    result = rpc._AddressLookup(node_list, ssc=ssc)
244 245
    self.assertEqual(result, addr_list)
245 246

  
246 247
  def testAddressLookupNSLookup(self):
247 248
    addr_list = ["192.0.2.%d" % n for n in range(0, 255, 13)]
248 249
    node_list = ["node%d.example.com" % n for n in range(0, 255, 13)]
249
    ssc = GetFakeSimpleStoreClass(lambda s: [])
250
    ssc = GetFakeSimpleStoreClass(lambda _: [])
250 251
    node_addr_map = dict(zip(node_list, addr_list))
251
    nslookup_fn = lambda name: node_addr_map.get(name)
252
    nslookup_fn = lambda name, family=None: node_addr_map.get(name)
252 253
    result = rpc._AddressLookup(node_list, ssc=ssc, nslookup_fn=nslookup_fn)
253 254
    self.assertEqual(result, addr_list)
254 255

  
......
257 258
    node_list = ["node%d.example.com" % n for n in range(0, 255, 13)]
258 259
    n = len(addr_list) / 2
259 260
    node_addr_list = [ " ".join(t) for t in zip(node_list[n:], addr_list[n:])]
260
    ssc = GetFakeSimpleStoreClass(lambda s: node_addr_list)
261
    ssc = GetFakeSimpleStoreClass(lambda _: node_addr_list)
261 262
    node_addr_map = dict(zip(node_list[:n], addr_list[:n]))
262
    nslookup_fn = lambda name: node_addr_map.get(name)
263
    nslookup_fn = lambda name, family=None: node_addr_map.get(name)
263 264
    result = rpc._AddressLookup(node_list, ssc=ssc, nslookup_fn=nslookup_fn)
264 265
    self.assertEqual(result, addr_list)
265 266

  
267
  def testAddressLookupIPv6(self):
268
    addr_list = ["2001:db8::%d" % n for n in range(0, 255, 13)]
269
    node_list = ["node%d.example.com" % n for n in range(0, 255, 13)]
270
    node_addr_list = [ " ".join(t) for t in zip(node_list, addr_list)]
271
    ssc = GetFakeSimpleStoreClass(lambda _: node_addr_list)
272
    result = rpc._AddressLookup(node_list, ssc=ssc)
273
    self.assertEqual(result, addr_list)
274

  
266 275

  
267 276
if __name__ == "__main__":
268 277
  testutils.GanetiTestProgram()

Also available in: Unified diff