Added NodeManager API calls for inspecting the slicename -> XID mapping and slice...
authorDavid E. Eisenstat <deisenst@cs.princeton.edu>
Sat, 3 Feb 2007 20:39:54 +0000 (20:39 +0000)
committerDavid E. Eisenstat <deisenst@cs.princeton.edu>
Sat, 3 Feb 2007 20:39:54 +0000 (20:39 +0000)
accounts.py
api.py
database.py

index b330033..fe0af53 100644 (file)
@@ -44,9 +44,12 @@ def register_class(acct_class):
 name_worker_lock = threading.Lock()
 name_worker = {}
 
+def allpwents():
+    return [pw_ent for pw_ent in pwd.getpwall() if pw_ent[6] in shell_acct_class]
+
 def all():
     """Return the names of all accounts on the system with recognized shells."""
-    return [pw_ent[0] for pw_ent in pwd.getpwall() if pw_ent[6] in shell_acct_class]
+    return [pw_ent[0] for pw_ent in allpwents()]
 
 def get(name):
     """Return the worker object for a particular username.  If no such object exists, create it first."""
@@ -76,6 +79,7 @@ class Account:
             dot_ssh = '/home/%s/.ssh' % self.name
             def do_installation():
                 if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh)
+                os.chmod(dot_ssh, 0700)
                 tools.write_file(dot_ssh + '/authorized_keys', lambda f: f.write(new_keys))
             logger.log('%s: installing ssh keys' % self.name)
             tools.fork_as(self.name, do_installation)
diff --git a/api.py b/api.py
index 825539f..8e8794a 100644 (file)
--- a/api.py
+++ b/api.py
@@ -21,6 +21,7 @@ import xmlrpclib
 import accounts
 import database
 import logger
+import sliver_vs
 import ticket
 import tools
 
@@ -56,6 +57,20 @@ def Ticket(tkt):
     except Exception, err:
         raise xmlrpclib.Fault(102, 'Ticket error: ' + str(err))
 
+@export_to_api(0)
+def GetXIDs():
+    """GetXIDs(): return an dictionary mapping slice names to XIDs"""
+    return dict([(pwent[0], pwent[2]) for pwent in pwd.getpwall() if pwent[6] == sliver_vs.Sliver_VS.SHELL])
+
+@export_to_api(0)
+def GetSSHKeys():
+    """GetSSHKeys(): return an dictionary mapping slice names to SSH keys"""
+    keydict = {}
+    for rec in database.db.itervalues():
+        if 'keys' in rec:
+            keydict[rec['name']] = rec['keys']
+    return keydict
+
 @export_to_api(1)
 def Create(rec):
     """Create(sliver_name): create a non-PLC-instantiated sliver"""
@@ -128,7 +143,7 @@ class APIRequestHandler(SimpleXMLRPCServer.SimpleXMLRPCRequestHandler):
             ucred = self.request.getsockopt(socket.SOL_SOCKET, SO_PEERCRED, sizeof_struct_ucred)
             xid = struct.unpack('3i', ucred)[2]
             caller_name = pwd.getpwuid(xid)[0]
-            if method_name not in ('Help', 'Ticket'):
+            if method_name not in ('Help', 'Ticket', 'GetXIDs', 'GetSSHKeys'):
                 target_name = args[0]
                 target_rec = database.db.get(target_name)
                 if not (target_rec and target_rec['type'].startswith('sliver.')): raise xmlrpclib.Fault(102, 'Invalid argument: the first argument must be a sliver name.')
index 890e9c2..58dffbe 100644 (file)
@@ -23,7 +23,7 @@ import tools
 
 # We enforce minimum allocations to keep the clueless from hosing their slivers.
 # Disallow disk loans because there's currently no way to punish slivers over quota.
-MINIMUM_ALLOCATION = {'cpu_min': 0, 'cpu_share': 16, 'net_min_rate': 0, 'net_max_rate': 8, 'net_i2_min_rate': 0, 'net_i2_max_rate': 8, 'net_share': 1}
+MINIMUM_ALLOCATION = {'cpu_min': 0, 'cpu_share': 32, 'net_min_rate': 0, 'net_max_rate': 8, 'net_i2_min_rate': 0, 'net_i2_max_rate': 8, 'net_share': 1}
 LOANABLE_RESOURCES = MINIMUM_ALLOCATION.keys()
 
 DB_FILE = '/root/sliver_mgr_db.pickle'