예제 #1
0
def NodeList():
    logging.info("This is NodeList")
    contents = io.ReadFile(pathutils.CLUSTER_CONFIG_FILE)
    if cluster_help.GetLocalIP() == cluster_help.GetMasterIP(contents):
        print "IP Address\tHostname FQDN\t\tHostname\n", contents.strip()
    else:
        netutils.SendMasterCMD(contents, constants.CMD_GET_NODE_LIST)
예제 #2
0
def GetmasterNode():
    logging.info("This is GetmasterNode")
    # TODO: run on slave node
    MasterName = ""
    MasterIP = ""
    contents = io.ReadFile(pathutils.CLUSTER_CONFIG_FILE)
    logging.debug("contents are %s", contents)
    logging.debug("LocalIP is %s", cluster_help.GetLocalIP())
    if cluster_help.GetLocalIP() == cluster_help.GetMasterIP(contents):
        logging.debug("contents are %s", contents)
        MasterName = cluster_help.GetClusterName(contents)
        MasterIP = cluster_help.GetMasterIP(contents)
        print "Master node name: %s\nMaster node IP: %s" % (MasterName,
                                                            MasterIP)
    else:
        contents = io.ReadFile(pathutils.CLUSTER_CONFIG_FILE)
        netutils.SendMasterCMD(contents, constants.CMD_GET_MASTER_NODE)
예제 #3
0
def InfoCluster():
    logging.info("This is InfoCluster")
    # TODO: run on slave node
    contents = io.ReadFile(pathutils.CLUSTER_CONFIG_FILE)
    ClusterName = cluster_help.GetClusterName(contents)
    ClusterCreateTime = cluster_help.GetClusterCreateTime()
    print "Cluster name: %s\nCreation time: %s\nMaster node: %s" % (
        ClusterName, ClusterCreateTime, ClusterName)
예제 #4
0
파일: masterd.py 프로젝트: Xgreedy/homework
def masterd():
    logging.info("This is masterd")
    sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    sock.bind((constants.HOST, constants.FILE_PORT))
    sock.listen(constants.MAX_CONNECTION)
    while True:
        NewSock, Address = sock.accept()
        logging.info("Accept a new connection, address: %s", Address[0])
        FormatSize = struct.calcsize(constants.SOCK_SEND_FILE_FMT)
        DataFrame = NewSock.recv(FormatSize)
        CMD_Format, FileSize, FileName, IP = struct.unpack(
            constants.SOCK_SEND_FILE_FMT, DataFrame)
        logging.info("999 CMD Format is %d", CMD_Format)
        if CMD_Format == constants.CMD_GET_MASTER_NODE:
            logging.info("999 masterd get master node")
            contents = io.ReadFile(pathutils.CLUSTER_CONFIG_FILE)
            NewSock.send(contents)
        if CMD_Format == constants.CMD_SEND_FILE:
            logging.info("999 slave send file, filesize %d, filename %s" %
                         (FileSize, FileName))
            _FileName = pathutils.FILE_STORAGE_DIR + FileName.strip("\0\0")
            logging.info("999 FileName is %s", _FileName)
            RemoteIP = IP.strip("\0\0")
            logging.info("999 RemoteIP is %s", IP.strip("\0\0"))
            io.MakeDir(pathutils.FILE_STORAGE_DIR)
            contents = NewSock.recv(FileSize)
            logging.info("999 contents are %s", contents)
            io.WriteFile(_FileName, contents)
            if RemoteIP != cluster_help.GetLocalIP():
                netutils._SendNodeCMD(constants.CMD_SEND_FILE, RemoteIP,
                                      constants.FILE_PORT, _FileName)
                io.RemoveFile(_FileName)
        elif CMD_Format == constants.CMD_GET_NODE_LIST:
            logging.info("999 masterd get node list")
            contents = io.ReadFile(pathutils.CLUSTER_CONFIG_FILE)
            NewSock.send(contents)
        elif CMD_Format == constants.CMD_DESTROY:
            NewSock.close()
            break
        else:
            continue
    sock.close()
예제 #5
0
def DestroyCluster():
    logging.info("This is DestroyCluster")
    # TODO: Remove dirs on all nodes
    # Remove these dirs directly? shutil.rmtree()?
    contents = io.ReadFile(pathutils.CLUSTER_CONFIG_FILE)
    netutils.SendMasterCMD(contents, constants.CMD_DESTROY)
    netutils.SendDestroyNodesCMD(contents)
    io.RemoveFile(pathutils.CLUSTER_CONFIG_FILE)
    io.RemoveDir(pathutils.CLUSTER_ETC_DIR)
    io.RemoveFile(pathutils.CLUSTER_LOGGING_FILE)
    io.RemoveFile(pathutils.NODE_LOGGING_FILE)
    io.RemoveDir(pathutils.CLUSTER_LOGGING_DIR)
예제 #6
0
def _GetMasterIP():
    # FIXME: handle Master IP normal
    contents = io.ReadFile(pathutils.CLUSTER_CONFIG_FILE)
    _contents = contents.split()
    return _contents[0]
예제 #7
0
      FormatSize = struct.calcsize(constants.SOCK_SEND_FILE_FMT)
      DataFrame = struct.pack(constants.SOCK_SEND_FILE_FMT,
                              CMDType, 0, "None", "None")
      sock.send(DataFrame)
    elif CMDType == constants.CMD_DESTROY:
      FormatSize = struct.calcsize(constants.SOCK_SEND_FILE_FMT)
      DataFrame = struct.pack(constants.SOCK_SEND_FILE_FMT,
                              CMDType, 0, "None", "None")
      sock.send(DataFrame)
    elif CMDType == constants.CMD_SEND_FILE:
      filename = os.path.basename(filepath)
      filesize = os.stat(filepath).st_size
      DataFrame = struct.pack(constants.SOCK_SEND_FILE_FMT,
                              CMDType, filesize, filename, IP)
      sock.send(DataFrame)
      contents = io.ReadFile(filepath)
      sock.send(contents)
    else:
      logging.error("Error: Unknown command!")
      raise
  sock.close()

def SendMasterCMD(contents, CMDType):
  MasterIP = cluster_help.GetMasterIP(contents)
  _SendNodeCMD(CMDType, MasterIP, constants.FILE_PORT, None)

def SendDestroyNodesCMD(contents):
  MasterIP = cluster_help.GetMasterIP(contents)
  for line in contents.splitlines():
    fileds = line.split()
    if MasterIP not in line:
예제 #8
0
def ReadNcsConfig():
    _contents = io.ReadFile(pathutils.CLUSTER_CONFIG_FILE)
    logging.debug("Read contents are: %s", _contents)