StarCluster - Mailing List Archive

development shell, plugin, AttributeError: 'str' object has no attribute 'get'

From: Walker Haddock <no email>
Date: Thu, 05 May 2011 14:01:09 -0500

(I tried the suggestion in http://mailman.mit.edu/pipermail/starcluster/2011-March/000629.html but 0.91.2 does not have Cluster.ClusterManager())

I am developing a plugin to push a user provided rsa public key to the authorized_keys of the cluster user. I studied the default cluster setup module to understand the extensions that are provided by the starcluster language to Python and I have implemented the plugin configuration section of the config file for starcluster.

While running `starcluster shell`, I have experienced two problems.

1) In [25]: cluster.run_plugin('installpublickey','small',cfg)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)

/usr/lib/python2.6/site-packages/StarCluster-0.91.2-py2.6.egg/starcluster/cli.pyc in <module>()
----> 1
      2
      3
      4
      5

/usr/lib/python2.6/site-packages/StarCluster-0.91.2-py2.6.egg/starcluster/cluster.pyc in run_plugin(plugin_name, cluster_tag, cfg)
    170 def run_plugin(plugin_name, cluster_tag, cfg):
    171 ec2 = cfg.get_easy_ec2()
--> 172 cl = get_cluster(cluster_tag)
    173 cl.load_receipt()
    174 plug = cfg.get_plugin(plugin_name)

TypeError: get_cluster() takes exactly 2 arguments (1 given)

Solution: modified line 172 in cluster.py to add cfg to the parameter list.

2) In [4]: cluster.run_plugin('installpublickey', 'small', cfg)
ssh.py:77 - WARNING - specified key does not end in either rsa or dsa, trying both
>>> Using private key /home/admin/.ssh/sfwmd2011_keypair2.pem (rsa)
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)

/usr/lib/python2.6/site-packages/StarCluster-0.91.2-py2.6.egg/starcluster/cli.pyc in <module>()
----> 1
      2
      3
      4
      5

/usr/lib/python2.6/site-packages/StarCluster-0.91.2-py2.6.egg/starcluster/cluster.py in run_plugin(plugin_name, cluster_tag, cfg)
    175 plugins = {}
    176 plugins[plugin_name] = plug
--> 177 plugins = cl.load_plugins(plugins)
    178 master = cl.master_node
    179 for p in plugins:

/usr/lib/python2.6/site-packages/StarCluster-0.91.2-py2.6.egg/starcluster/cluster.py in load_plugins(self, plugins)
    314 plugs = []
    315 for plugin in plugins:
--> 316 setup_class = plugin.get('setup_class')
    317 plugin_name = plugin.get('__name__')
    318 mod_name = '.'.join(setup_class.split('.')[:-1])

AttributeError: 'str' object has no attribute 'get'

But, I have configured the config file per the documentation:
[plugin installpublickey]
setup_class = rtcsplugin.KeyInstaller
key_to_install = ~/.starcluster/keys/sfwmd_test_rsa.pub

And, the plugin is located in ~/.starcluster/plugins/rtcsplugin.py
[admin_at_ip-10-202-155-135 .starcluster]$ cat plugins/rtcsplugin.py
#!/usr/bin/env python
  """
  Plugin modules for StarCluster to configure
  specialized featers for users.

  rtcsplugin.py
  """

from starcluster.clustersetup import ClusterSetup
from starcluster.logger import log

class KeyInstaller(ClusterSetup):
     """ Install user's public key in %user/.ssh/authorized_keys
         path to key is in config as value for key: key_to_install """
     def __init__(self, key_to_install):
          self.the_key = None
          self.key_to_install = key_to_install
          log.debug('key_to_install = %s' % key_to_install)

    def _load_rsa_key(self, public_key):
        public_key_file = os.path.expanduser(public_key)
        try:
             f = file(public_key_file, 'r')
            rsa_public_key = f.read()
            log.info("Using public key %s (rsa)" % public_key)
            return rsa_public_key
        except:
            log.error("%s not found, user public key." % public_key)

     def run(self, nodes, master, user, user_shell, volumes):
          mconn = self._master.ssh
          self.the_key = _load_rsa_key(key_to_install)
          if not the_key is None
          log.info("Installing %s on Head Node" % (self.key_to_install))
          mconn.execute('echo -n {pk} >> /home/{user}/.ssh/authorized_keys'.format(pk=self.the_key, user=self._user))

I am sure that the plugin code is not being executed as the stack trace does not indicate that the load_plugins(self, plugins) function on line 313 has not executed beyond line 316
Received on Thu May 05 2011 - 15:02:11 EDT
This archive was generated by hypermail 2.3.0.

Search:

Sort all by:

Date

Month

Thread

Author

Subject