Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use clustershell exec worker to run command #65

Open
rezib opened this issue Apr 5, 2016 · 0 comments
Open

Use clustershell exec worker to run command #65

rezib opened this issue Apr 5, 2016 · 0 comments

Comments

@rezib
Copy link
Contributor

rezib commented Apr 5, 2016

As explained in #63, I guess now that we're using clustershell 1.7 everywhere, we should better rely on it now to run commands such as ipmitool, using the exec worker, instead of using low-level subprocess python module directly.

Here is an example of usage of this worker:

#!/usr/bin/env python

import sys
import ConfigParser
from ClusterShell.Task import task_self
from ClusterShell.Worker.Exec import ExecWorker

conf = None

def read_conf():

    global conf

    conf = ConfigParser.ConfigParser()
    conf.read('/etc/slurm-llnl/pwmgt.conf')

def wake_nodes(hostlist):
    """Wake nodes through their BMC with IPMI"""

    ipmi_cmd = conf.get('ipmi', 'cmd')
    ipmi_prefix = conf.get('ipmi', 'prefix')
    ipmi_user = conf.get('ipmi', 'user')
    ipmi_user = conf.get('ipmi', 'password')

    cmd = "{cmd} -I lanplus -U {user} -H {prefix}%host chassis power s3wake" \
            .format(cmd=ipmi_cmd, user=ipmi_user, prefix=ipmi_prefix)
    task = task_self()
    worker = ExecWorker(hostlist,
                        handler=None,
                        command=cmd)
    task.schedule(worker)
    task.resume()

def main():
    """Main function"""
    read_conf()
    hostlist = sys.argv[1]
    wake_nodes(hostlist)

if __name__ == '__main__':
    main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant