expects the 'interfaces' key in GetSlivers - review logs to always mention module
[nodemanager.git] / controller.py
1 # $Id$
2 # $URL$
3
4 """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."""
5
6 import accounts
7 import logger
8 import tools
9 from pwd import getpwnam
10 from grp import getgrnam
11
12 class Controller(accounts.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 >>etc_shells, shell
38         etc_shells.close()