Refactoring in progress...
[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:
9     SHELL = '/bin/forward_api_calls'  # tunneling shell
10     TYPE = 'delegate'
11
12     def __init__(self, name): self.name = name
13
14     @staticmethod
15     def create(name):
16         add_shell(Delegate.SHELL)
17         logger.log_call('/usr/sbin/useradd', '-p', '*', '-s', Delegate.SHELL, name)
18
19     @staticmethod
20     def destroy(name): logger.log_call('/usr/sbin/userdel', '-r', name)
21
22     def configure(self, rec): accounts.install_keys(rec)
23     def start(self): pass
24     def stop(self): pass
25
26
27 def add_shell(shell):
28     """Add <shell> to /etc/shells if it's not already there."""
29     etc_shells = open('/etc/shells')
30     valid_shells = etc_shells.read().split()
31     etc_shells.close()
32     if shell not in valid_shells:
33         etc_shells = open('/etc/shells', 'a')
34         print >>etc_shells, shell
35         etc_shells.close()