reguire gnupg1 on f>=31; sense the system to use gpg1 when installed
[nodemanager.git] / controller.py
1 #
2 """Delegate accounts are used to provide secure access to the XMLRPC API.
3 They are normal Unix accounts with a shell that tunnels XMLRPC requests to the API server."""
4
5 from pwd import getpwnam
6 from grp import getgrnam
7
8 import logger
9 import tools
10 import account
11
12 class Controller(account.Account):
13     SHELL = '/usr/bin/forward_api_calls'  # tunneling shell
14     TYPE = 'controller.Controller'
15
16     @staticmethod
17     def create(name, vref = None):
18         add_shell(Controller.SHELL)
19         group = getgrnam("slices")[2]
20         logger.log_call(['/usr/sbin/useradd', '-p', '*', '-g', str(group), '-s', Controller.SHELL, name, ])
21
22     @staticmethod
23     def destroy(name): logger.log_call(['/usr/sbin/userdel', '-r', name, ])
24
25     def is_running(self):
26         logger.verbose("controller: is_running:  %s" % self.name)
27         return getpwnam(self.name)[6] == self.SHELL
28
29
30 def add_shell(shell):
31     """Add <shell> to /etc/shells if it's not already there."""
32     etc_shells = open('/etc/shells')
33     valid_shells = etc_shells.read().split()
34     etc_shells.close()
35     if shell not in valid_shells:
36         etc_shells = open('/etc/shells', 'a')
37         print(shell, file=etc_shells)
38         etc_shells.close()