Added ReCreate. Also added try catch to api eval of rpc method.
[nodemanager.git] / delegate.py
1 """Delegate accounts are used to provide secure access to the XMLRPC API.  They are normal Unix accounts with a shell that tunnels XMLRPC requests to the API server."""
2
3 import accounts
4 import logger
5 import tools
6
7
8 class Delegate(accounts.Account):
9     SHELL = '/usr/bin/forward_api_calls'  # tunneling shell
10     TYPE = 'delegate'
11
12     @staticmethod
13     def create(name, vref = None):
14         add_shell(Delegate.SHELL)
15         logger.log_call('/usr/sbin/useradd', '-p', '*', '-s', Delegate.SHELL, name)
16
17     @staticmethod
18     def destroy(name): logger.log_call('/usr/sbin/userdel', '-r', name)
19
20 def add_shell(shell):
21     """Add <shell> to /etc/shells if it's not already there."""
22     etc_shells = open('/etc/shells')
23     valid_shells = etc_shells.read().split()
24     etc_shells.close()
25     if shell not in valid_shells:
26         etc_shells = open('/etc/shells', 'a')
27         print >>etc_shells, shell
28         etc_shells.close()