Revision 07bd8a51 lib/cmdlib.py

b/lib/cmdlib.py
944 944
    return int(bad)
945 945

  
946 946

  
947
class LURenameCluster(LogicalUnit):
948
  """Rename the cluster.
949

  
950
  """
951
  HPATH = "cluster-rename"
952
  HTYPE = constants.HTYPE_CLUSTER
953
  _OP_REQP = ["name"]
954

  
955
  def BuildHooksEnv(self):
956
    """Build hooks env.
957

  
958
    """
959
    env = {
960
      "NEW_NAME": self.op.name,
961
      }
962
    mn = self.sstore.GetMasterNode()
963
    return env, [mn], [mn]
964

  
965
  def CheckPrereq(self):
966
    """Verify that the passed name is a valid one.
967

  
968
    """
969
    hostname = utils.LookupHostname(self.op.name)
970
    if not hostname:
971
      raise errors.OpPrereqError("Cannot resolve the new cluster name ('%s')" %
972
                                 self.op.name)
973

  
974
    new_name = hostname["hostname"]
975
    self.ip = new_ip = hostname["ip"]
976
    old_name = self.sstore.GetClusterName()
977
    old_ip = self.sstore.GetMasterIP()
978
    if new_name == old_name and new_ip == old_ip:
979
      raise errors.OpPrereqError("Neither the name nor the IP address of the"
980
                                 " cluster has changed")
981
    if new_ip != old_ip:
982
      result = utils.RunCmd(["fping", "-q", new_ip])
983
      if not result.failed:
984
        raise errors.OpPrereqError("The given cluster IP address (%s) is"
985
                                   " reachable on the network. Aborting." %
986
                                   new_ip)
987

  
988
    self.op.name = new_name
989

  
990
  def Exec(self, feedback_fn):
991
    """Rename the cluster.
992

  
993
    """
994
    clustername = self.op.name
995
    ip = self.ip
996
    ss = self.sstore
997

  
998
    # shutdown the master IP
999
    master = ss.GetMasterNode()
1000
    if not rpc.call_node_stop_master(master):
1001
      raise errors.OpExecError("Could not disable the master role")
1002

  
1003
    try:
1004
      # modify the sstore
1005
      ss.SetKey(ss.SS_MASTER_IP, ip)
1006
      ss.SetKey(ss.SS_CLUSTER_NAME, clustername)
1007

  
1008
      # Distribute updated ss config to all nodes
1009
      myself = self.cfg.GetNodeInfo(master)
1010
      dist_nodes = self.cfg.GetNodeList()
1011
      if myself.name in dist_nodes:
1012
        dist_nodes.remove(myself.name)
1013

  
1014
      logger.Debug("Copying updated ssconf data to all nodes")
1015
      for keyname in [ss.SS_CLUSTER_NAME, ss.SS_MASTER_IP]:
1016
        fname = ss.KeyToFilename(keyname)
1017
        result = rpc.call_upload_file(dist_nodes, fname)
1018
        for to_node in dist_nodes:
1019
          if not result[to_node]:
1020
            logger.Error("copy of file %s to node %s failed" %
1021
                         (fname, to_node))
1022
    finally:
1023
      if not rpc.call_node_start_master(master):
1024
        logger.Error("Could not re-enable the master role on the master,\n"
1025
                     "please restart manually.")
1026

  
1027

  
947 1028
def _WaitForSync(cfgw, instance, oneshot=False, unlock=False):
948 1029
  """Sleep and poll for an instance's disk to sync.
949 1030

  

Also available in: Unified diff