Commit f96d588c authored by Marc Vef's avatar Marc Vef
Browse files

Start/shutdown script automatically creates a pssh compatible hostfile

parent e38b7f1d
Loading
Loading
Loading
Loading
+6 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ global PRETEND
global PSSH_PATH
global WAITTIME

CONST_PSSH_HOSTFILE_PATH = '/tmp/hostfile_pssh'


def check_dependencies():
    global PSSH_PATH
@@ -49,8 +51,11 @@ def shutdown_system(daemon_path, nodelist, sigkill):
        print '[ERR] Daemon executable not found or not a file'
        exit(1)
    nodefile = False
    if os.path.exists(nodelist):  # XXX Currently, we assume that the nodefile syntax is sane.
    if os.path.exists(nodelist):
        nodefile = True
        if not util.create_pssh_hostfile(nodelist, CONST_PSSH_HOSTFILE_PATH):
            exit(1)
        nodelist = CONST_PSSH_HOSTFILE_PATH
    if PSSH_PATH is '':
        check_dependencies()
    # set pssh arguments
+6 −1
Original line number Diff line number Diff line
@@ -15,6 +15,8 @@ global PRETEND
global PSSH_PATH
global WAITTIME

CONST_PSSH_HOSTFILE_PATH = '/tmp/hostfile_pssh'


def check_dependencies():
    global PSSH_PATH
@@ -51,8 +53,11 @@ def init_system(daemon_path, rootdir, mountdir, nodelist, cleanroot):
        print '[ERR] Daemon executable not found or not a file'
        exit(1)
    nodefile = False
    if os.path.exists(nodelist):  # XXX Currently, we assume that the nodefile syntax is sane.
    if os.path.exists(nodelist):
        nodefile = True
        if not util.create_pssh_hostfile(nodelist, CONST_PSSH_HOSTFILE_PATH):
            exit(1)
        nodelist = CONST_PSSH_HOSTFILE_PATH
    if PSSH_PATH is '':
        check_dependencies()
    # set pssh arguments
+28 −0
Original line number Diff line number Diff line
@@ -111,3 +111,31 @@ def check_shell_out(msg):
    if msg.err != '':
        raise OSError('Shell command failed with\n\t%s' % msg.err)
    return msg.output


def create_pssh_hostfile(hostfile, hostfile_pssh):
    """Function creates a pssh compatible hostfile

    Args:
        hostfile(str): Path to source hostfile
        hostfile_pssh(str): Path to pssh compatible hostfile (contents will be created first)

    Returns:
        (bool): Returns true if successful
    """
    # truncate pssh hostfile
    try:
        open(hostfile_pssh, 'w').close()
        # make nodefile pssh compatible
        with open(hostfile, 'r') as rf:
            for line in rf.readlines():
                # skip commented lines
                if line.startswith('#'):
                    continue
                with open(hostfile_pssh, 'a') as wf:
                    wf.write(line.strip().split(' ')[0] + '\n')
    except IOError as e:
        print 'ERR while creating pssh compatible hostfile'
        print e.strerror
        return False
    return True