Revision a744b676 lib/cmdlib.py

b/lib/cmdlib.py
49 49
from ganeti import uidpool
50 50
from ganeti import compat
51 51
from ganeti import masterd
52
from ganeti import netutils
52 53

  
53 54
import ganeti.masterd.instance # pylint: disable-msg=W0611
54 55

  
......
2513 2514
    """Verify that the passed name is a valid one.
2514 2515

  
2515 2516
    """
2516
    hostname = utils.GetHostInfo(self.op.name)
2517
    hostname = netutils.GetHostInfo(self.op.name)
2517 2518

  
2518 2519
    new_name = hostname.name
2519 2520
    self.ip = new_ip = hostname.ip
......
2524 2525
                                 " cluster has changed",
2525 2526
                                 errors.ECODE_INVAL)
2526 2527
    if new_ip != old_ip:
2527
      if utils.TcpPing(new_ip, constants.DEFAULT_NODED_PORT):
2528
      if netutils.TcpPing(new_ip, constants.DEFAULT_NODED_PORT):
2528 2529
        raise errors.OpPrereqError("The given cluster IP address (%s) is"
2529 2530
                                   " reachable on the network. Aborting." %
2530 2531
                                   new_ip, errors.ECODE_NOTUNIQUE)
......
3654 3655

  
3655 3656
  def CheckArguments(self):
3656 3657
    # validate/normalize the node name
3657
    self.op.node_name = utils.HostInfo.NormalizeName(self.op.node_name)
3658
    self.op.node_name = netutils.HostInfo.NormalizeName(self.op.node_name)
3658 3659

  
3659 3660
  def BuildHooksEnv(self):
3660 3661
    """Build hooks env.
......
3686 3687
    node_name = self.op.node_name
3687 3688
    cfg = self.cfg
3688 3689

  
3689
    dns_data = utils.GetHostInfo(node_name)
3690
    dns_data = netutils.GetHostInfo(node_name)
3690 3691

  
3691 3692
    node = dns_data.name
3692 3693
    primary_ip = self.op.primary_ip = dns_data.ip
3693 3694
    if self.op.secondary_ip is None:
3694 3695
      self.op.secondary_ip = primary_ip
3695
    if not utils.IsValidIP4(self.op.secondary_ip):
3696
    if not netutils.IsValidIP4(self.op.secondary_ip):
3696 3697
      raise errors.OpPrereqError("Invalid secondary IP given",
3697 3698
                                 errors.ECODE_INVAL)
3698 3699
    secondary_ip = self.op.secondary_ip
......
3744 3745
                                   errors.ECODE_INVAL)
3745 3746

  
3746 3747
    # checks reachability
3747
    if not utils.TcpPing(primary_ip, constants.DEFAULT_NODED_PORT):
3748
    if not netutils.TcpPing(primary_ip, constants.DEFAULT_NODED_PORT):
3748 3749
      raise errors.OpPrereqError("Node not reachable by ping",
3749 3750
                                 errors.ECODE_ENVIRON)
3750 3751

  
3751 3752
    if not newbie_singlehomed:
3752 3753
      # check reachability from my secondary ip to newbie's secondary ip
3753
      if not utils.TcpPing(secondary_ip, constants.DEFAULT_NODED_PORT,
3754
      if not netutils.TcpPing(secondary_ip, constants.DEFAULT_NODED_PORT,
3754 3755
                           source=myself.secondary_ip):
3755 3756
        raise errors.OpPrereqError("Node secondary ip not reachable by TCP"
3756 3757
                                   " based ping to noded port",
......
4885 4886

  
4886 4887
    # new name verification
4887 4888
    if self.op.check_name:
4888
      name_info = utils.GetHostInfo(self.op.new_name)
4889
      name_info = netutils.GetHostInfo(self.op.new_name)
4889 4890
      self.op.new_name = name_info.name
4890 4891

  
4891 4892
    new_name = self.op.new_name
......
4896 4897
                                 new_name, errors.ECODE_EXISTS)
4897 4898

  
4898 4899
    if not self.op.ignore_ip:
4899
      if utils.TcpPing(name_info.ip, constants.DEFAULT_NODED_PORT):
4900
      if netutils.TcpPing(name_info.ip, constants.DEFAULT_NODED_PORT):
4900 4901
        raise errors.OpPrereqError("IP %s of instance %s already in use" %
4901 4902
                                   (name_info.ip, new_name),
4902 4903
                                   errors.ECODE_NOTUNIQUE)
......
6492 6493
      self.LogInfo("No-installation mode selected, disabling startup")
6493 6494
      self.op.start = False
6494 6495
    # validate/normalize the instance name
6495
    self.op.instance_name = utils.HostInfo.NormalizeName(self.op.instance_name)
6496
    self.op.instance_name = \
6497
      netutils.HostInfo.NormalizeName(self.op.instance_name)
6498

  
6496 6499
    if self.op.ip_check and not self.op.name_check:
6497 6500
      # TODO: make the ip check more flexible and not depend on the name check
6498 6501
      raise errors.OpPrereqError("Cannot do ip checks without a name check",
......
6530 6533

  
6531 6534
    # instance name verification
6532 6535
    if self.op.name_check:
6533
      self.hostname1 = utils.GetHostInfo(self.op.instance_name)
6536
      self.hostname1 = netutils.GetHostInfo(self.op.instance_name)
6534 6537
      self.op.instance_name = self.hostname1.name
6535 6538
      # used in CheckPrereq for ip ping check
6536 6539
      self.check_ip = self.hostname1.ip
......
6610 6613
        raise errors.OpPrereqError("Missing source instance name",
6611 6614
                                   errors.ECODE_INVAL)
6612 6615

  
6613
      self.source_instance_name = \
6614
        utils.GetHostInfo(utils.HostInfo.NormalizeName(src_instance_name)).name
6616
      norm_name = netutils.HostInfo.NormalizeName(src_instance_name)
6617
      self.source_instance_name = netutils.GetHostInfo(norm_name).name
6615 6618

  
6616 6619
    else:
6617 6620
      raise errors.OpPrereqError("Invalid instance creation mode %r" %
......
6955 6958
                                     errors.ECODE_INVAL)
6956 6959
        nic_ip = self.hostname1.ip
6957 6960
      else:
6958
        if not utils.IsValidIP4(ip):
6961
        if not netutils.IsValidIP4(ip):
6959 6962
          raise errors.OpPrereqError("Given IP address '%s' doesn't look"
6960 6963
                                     " like a valid IP" % ip,
6961 6964
                                     errors.ECODE_INVAL)
......
7061 7064

  
7062 7065
    # ip ping checks (we use the same ip that was resolved in ExpandNames)
7063 7066
    if self.op.ip_check:
7064
      if utils.TcpPing(self.check_ip, constants.DEFAULT_NODED_PORT):
7067
      if netutils.TcpPing(self.check_ip, constants.DEFAULT_NODED_PORT):
7065 7068
        raise errors.OpPrereqError("IP %s of instance %s already in use" %
7066 7069
                                   (self.check_ip, self.op.instance_name),
7067 7070
                                   errors.ECODE_NOTUNIQUE)
......
8630 8633
        if nic_ip.lower() == constants.VALUE_NONE:
8631 8634
          nic_dict['ip'] = None
8632 8635
        else:
8633
          if not utils.IsValidIP4(nic_ip):
8636
          if not netutils.IsValidIP4(nic_ip):
8634 8637
            raise errors.OpPrereqError("Invalid IP address '%s'" % nic_ip,
8635 8638
                                       errors.ECODE_INVAL)
8636 8639

  

Also available in: Unified diff