c3c4c1bc7739a6a202d04f7ae29d823bdab46474
[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',
18                         '-p', '*', '-s', Delegate.SHELL, name)
19
20     @staticmethod
21     def destroy(name): logger.log_call('/usr/sbin/userdel', '-r', name)
22
23     def configure(self, rec): accounts.install_ssh_keys(rec)
24     def start(self): pass
25     def stop(self): pass
26
27
28 def add_shell(shell):
29     """Add <shell> to /etc/shells if it's not already there."""
30     etc_shells = open('/etc/shells')
31     valid_shells = etc_shells.read().split()
32     etc_shells.close()
33     if shell not in valid_shells:
34         etc_shells = open('/etc/shells', 'a')
35         print >>etc_shells, shell
36         etc_shells.close()