First version. Most definitely a work in progress.
[nodemanager.git] / delegate.py
1 import accounts
2 import logger
3 import tools
4
5
6 class Delegate:
7     SHELL = '/bin/forward_api_calls'
8     TYPE = 'delegate'
9
10     def __init__(self, name): self.name = name
11
12     @staticmethod
13     def create(name):
14         add_shell(Delegate.SHELL)
15         logger.log_call('/usr/sbin/useradd',
16                         '-p', '*', '-s', Delegate.SHELL, name)
17
18     @staticmethod
19     def destroy(name): logger.log_call('/usr/sbin/userdel', '-r', name)
20
21     def configure(self, rec): accounts.install_ssh_keys(rec)
22     def start(self): pass
23     def stop(self): pass
24
25
26 def add_shell(shell):
27     """Add <shell> to /etc/shells if it's not already there."""
28     etc_shells = open('/etc/shells')
29     valid_shells = etc_shells.read().split()
30     etc_shells.close()
31     if shell not in valid_shells:
32         etc_shells = open('/etc/shells', 'a')
33         print >>etc_shells, shell
34         etc_shells.close()