Refactoring almost complete, with a stubbed out version of GetSlivers().
authorDavid E. Eisenstat <deisenst@cs.princeton.edu>
Fri, 27 Oct 2006 20:30:18 +0000 (20:30 +0000)
committerDavid E. Eisenstat <deisenst@cs.princeton.edu>
Fri, 27 Oct 2006 20:30:18 +0000 (20:30 +0000)
accounts.py
database.py
nm.py
sliver_vs.py

index 5066b9e..8363e7f 100644 (file)
@@ -74,7 +74,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)
-                tools.write_file(dot_ssh + '/authorized_keys', lambda f: f.write(keys))
+                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)
 
@@ -108,7 +108,7 @@ class Worker:
             self._create_sem.acquire()
             try: next_class.create(self.name)
             finally: self._create_sem.release()
-        if not isinstance(self._acct, next_class): self._acct = next_class(self.name, rec)
+        if not isinstance(self._acct, next_class): self._acct = next_class(rec)
         else: self._acct.configure(rec)
         if next_class != curr_class: self._acct.start()
 
index ede28d9..782922a 100644 (file)
@@ -91,25 +91,6 @@ class Database(dict):
         db_cond.notify()
 
 
-@synchronized
-def GetSlivers_callback(data):
-    for d in data:
-        for sliver in d['slivers']:
-            rec = sliver.copy()
-            attr_dict = {}
-            for attr in rec.pop('attributes'): attr_dict[attr['name']] = attr_dict[attr['value']]
-            keys = rec.pop('keys')
-            rec['keys'] = '\n'.join([key_struct['key'] for key_struct in keys])
-            rspec = {}
-            rec['rspec'] = rspec
-            for resname, default_amt in DEFAULT_ALLOCATIONS.iteritems():
-                try: amt = int(attr_dict[resname])
-                except (KeyError, ValueError): amt = default_amt
-                rspec[resname] = amt
-        db.set_min_timestamp(d['timestamp'])
-    db.sync()
-
-
 def start():
     """The database dumper daemon.  When it starts up, it populates the database with the last dumped database.  It proceeds to handle dump requests forever."""
     def run():
@@ -131,3 +112,33 @@ def start():
         logger.log_exc()
         db = Database()
     tools.as_daemon_thread(run)
+
+@synchronized
+def GetSlivers_callback(data):
+    for d in data:
+        for sliver in d['slivers']:
+            rec = sliver.copy()
+            rec.setdefault('timestamp', d['timestamp'])
+            rec.setdefault('type', 'sliver.VServer')
+
+            # convert attributes field to a proper dict
+            attr_dict = {}
+            for attr in rec.pop('attributes'): attr_dict[attr['name']] = attr['value']
+
+            # squash keys
+            keys = rec.pop('keys')
+            rec.setdefault('keys', '\n'.join([key_struct['key'] for key_struct in keys])
+
+            rec.setdefault('initscript', attr_dict.get('initscript'))
+            rec.setdefault('delegations', [])  # XXX - delegation not yet supported
+
+            # extract the implied rspec
+            rspec = {}
+            rec['rspec'] = rspec
+            for resname, default_amt in DEFAULT_ALLOCATIONS.iteritems():
+                try: amt = int(attr_dict[resname])
+                except (KeyError, ValueError): amt = default_amt
+                rspec[resname] = amt
+            db.deliver_record(rec)
+        db.set_min_timestamp(d['timestamp'])
+    db.sync()
diff --git a/nm.py b/nm.py
index b1bce16..5d89e21 100644 (file)
--- a/nm.py
+++ b/nm.py
@@ -2,13 +2,13 @@
 
 import optparse
 import time
+import xmlrpclib
 
 import accounts
 import api
 import database
 import delegate
 import logger
-import plc
 import sliver_vs
 import tools
 
@@ -18,6 +18,18 @@ parser.add_option('-d', '--daemon', action='store_true', dest='daemon', default=
 parser.add_option('-s', '--startup', action='store_true', dest='startup', default=False, help='run all sliver startup scripts')
 (options, args) = parser.parse_args()
 
+# XXX - awaiting a real implementation
+data = []
+modules = []
+
+def GetSlivers():
+    for mod in modules: mod.GetSlivers_callback(data)
+
+def start_and_register_callback(mod):
+    mod.start()
+    modules.append(mod)
+
+
 def run():
     try:
         if options.daemon: tools.daemon()
@@ -27,10 +39,10 @@ def run():
 
         other_pid = tools.pid_file()
         if other_pid != None:
-            print """There might be another instance of the node manager running as pid %d.  If this is not the case, please remove the pid file %s""" % (other_pid, PID_FILE)
+            print """There might be another instance of the node manager running as pid %d.  If this is not the case, please remove the pid file %s""" % (other_pid, tools.PID_FILE)
             return
 
-        database.start()
+        start_and_register_callback(database)
         api.start()
         while True:
             try: plc.fetch_and_update()
index f6e9397..1ada697 100644 (file)
@@ -25,18 +25,6 @@ import logger
 import tools
 
 
-DEFAULTS = {'disk_max': 5000000,
-            'net_min':    bwmin,
-            'net_max':    bwmax,
-            'net2_min':   bwmin,
-            'net2_max':   bwmax,
-            'net_share':      1,
-            'enabled':        1,
-            'cpu_min':        0,
-            'cpu_share':     32,
-            'keys':          '',
-            'initscript':    ''}
-
 class Sliver_VS(accounts.Account, vserver.VServer):
     """This class wraps vserver.VServer to make its interface closer to what we need for the Node Manager."""
 
@@ -102,7 +90,7 @@ class Sliver_VS(accounts.Account, vserver.VServer):
                 logger.log('%s: computing disk usage' % self.name)
                 self.init_disk_info()
                 self.disk_usage_initialized = True
-            vserver.VServer.set_disklimit(self, disk_max_KiB)
+            vserver.VServer.set_disklimit(self, disk_max)
         except OSError: logger.log_exc()
 
         net_limits = (self.rspec['net_min'], self.rspec['net_max'], self.rspec['net2_min'], self.rspec['net2_max'], self.rspec['net_share'])