starcluster.plugins.ipcluster

Package starcluster :: Package plugins :: Module ipcluster |
[hide private]
[frames] | no frames]

# Source Code for Module starcluster.plugins.ipcluster

     1  #!/usr/bin/env python
     2  import posixpath
     3
     4  from starcluster.clustersetup import ClusterSetup
     5  from starcluster.logger import log
     6
     7
     8 -class IPCluster(ClusterSetup):
     9      """
    10      Starts an IPCluster on StarCluster
    11      """
    12
    13      cluster_file = '/etc/clusterfile.py'
    14      log_file = '/var/log/ipcluster.log'
    15
    16 -    def _create_cluster_file(self, master, nodes):
    17          engines = {}
    18          for node in nodes:
    19              engines[node.alias] = node.num_processors
    20          cfile = 'send_furl = True\n'
    21          cfile += 'engines = %s\n' % engines
    22          f = master.ssh.remote_file(self.cluster_file, 'w')
    23          f.write(cfile)
    24          f.close()
    25
    26 -    def run(self, nodes, master, user, user_shell, volumes):
    27          self._create_cluster_file(master, nodes)
    28          log.info("Starting ipcluster...")
    29          master.ssh.execute(
    30              "su - %s -c 'screen -d -m ipcluster ssh --clusterfile %s'" % \
    31              (user, self.cluster_file))
    32
    33 -    def on_add_node(self, node, nodes, master, user, user_shell, volumes):
    34          log.info("Adding %s to ipcluster" % node.alias)
    35          self._create_cluster_file(master, nodes)
    36          user_home = node.getpwnam(user).pw_dir
    37          furl_file = posixpath.join(user_home, '.ipython', 'security',
    38                                     'ipcontroller-engine.furl')
    39          node.ssh.execute(
    40              "su - %s -c 'screen -d -m ipengine --furl-file %s'" % \
    41              (user, furl_file))
    42
    43 -    def on_remove_node(self, node, nodes, master, user, user_shell, volumes):
    44          log.info("Removing %s from ipcluster" % node.alias)
    45          less_nodes = filter(lambda x: x.id != node.id, nodes)
    46          self._create_cluster_file(master, less_nodes)
    47          node.ssh.execute('pkill ipengine')
    48