* Delegated slivers are refreshed on each epoc from info from PLC. Can be suspended...
authorFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Mon, 16 Feb 2009 20:32:53 +0000 (20:32 +0000)
committerFaiyaz Ahmed <faiyaza@cs.princeton.edu>
Mon, 16 Feb 2009 20:32:53 +0000 (20:32 +0000)
* Comments

LICENSE
bootauth.py
bwmon.py
controller.py [moved from delegate.py with 68% similarity]
net.py
setup.py
sm.py

diff --git a/LICENSE b/LICENSE
index 4a80642..8443213 100644 (file)
--- a/LICENSE
+++ b/LICENSE
@@ -1,4 +1,4 @@
-Copyright 2008 Princeton University
+Copyright 2009 Princeton University
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
 
 Redistribution and use in source and binary forms, with or without
 modification, are permitted provided that the following conditions are
index 930b9de..bf845d6 100755 (executable)
@@ -1,10 +1,7 @@
 #!/usr/bin/python
 #
 # Test script for obtaining a node session key. Usually, the Boot
 #!/usr/bin/python
 #
 # Test script for obtaining a node session key. Usually, the Boot
-# Manager obtains it, then writes it to /etc/planetlab/session. To
-# generate a node key for a node, execute:
-#
-# AdmGenerateNodeConfFile(node_id)
+# Manager obtains it, then writes it to /etc/planetlab/session. 
 #
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
 #
 # Mark Huang <mlhuang@cs.princeton.edu>
 # Copyright (C) 2006 The Trustees of Princeton University
index 8a9e96f..ce33e19 100644 (file)
--- a/bwmon.py
+++ b/bwmon.py
@@ -648,6 +648,7 @@ def sync(nmdbcopy):
     pickle.dump((version, slices, deaddb), f)
     f.close()
 
     pickle.dump((version, slices, deaddb), f)
     f.close()
 
+
 def getDefaults(nmdbcopy):
     '''
     Get defaults from default slice's slice attributes.
 def getDefaults(nmdbcopy):
     '''
     Get defaults from default slice's slice attributes.
@@ -661,6 +662,7 @@ def getDefaults(nmdbcopy):
             status = False
     return status
 
             status = False
     return status
 
+
 def allOff():
     """
     Turn off all slice HTBs
 def allOff():
     """
     Turn off all slice HTBs
@@ -676,7 +678,10 @@ def allOff():
 
 lock = threading.Event()
 def run():
 
 lock = threading.Event()
 def run():
-    """When run as a thread, wait for event, lock db, deep copy it, release it, run bwmon.GetSlivers(), then go back to waiting."""
+    """
+    When run as a thread, wait for event, lock db, deep copy it, release it, 
+    run bwmon.GetSlivers(), then go back to waiting.
+    """
     logger.log("bwmon:  Thread started", 2)
     while True:
         lock.wait()
     logger.log("bwmon:  Thread started", 2)
     while True:
         lock.wait()
similarity index 68%
rename from delegate.py
rename to controller.py
index 73a0743..17268d2 100644 (file)
@@ -3,20 +3,25 @@
 import accounts
 import logger
 import tools
 import accounts
 import logger
 import tools
+from pwd import getpwnam
 
 
-
-class Delegate(accounts.Account):
+class Controller(accounts.Account):
     SHELL = '/usr/bin/forward_api_calls'  # tunneling shell
     SHELL = '/usr/bin/forward_api_calls'  # tunneling shell
-    TYPE = 'delegate'
+    TYPE = 'controller.Controller'
 
     @staticmethod
     def create(name, vref = None):
 
     @staticmethod
     def create(name, vref = None):
-        add_shell(Delegate.SHELL)
-        logger.log_call('/usr/sbin/useradd', '-p', '*', '-s', Delegate.SHELL, name)
+        add_shell(Controller.SHELL)
+        logger.log_call('/usr/sbin/useradd', '-p', '*', '-s', Controller.SHELL, name)
 
     @staticmethod
     def destroy(name): logger.log_call('/usr/sbin/userdel', '-r', name)
 
 
     @staticmethod
     def destroy(name): logger.log_call('/usr/sbin/userdel', '-r', name)
 
+    def is_running(self):
+        logger.verbose("Delegate:  %s" % self.name)
+        return getpwnam(self.name)[6] == self.SHELL
+    
+
 def add_shell(shell):
     """Add <shell> to /etc/shells if it's not already there."""
     etc_shells = open('/etc/shells')
 def add_shell(shell):
     """Add <shell> to /etc/shells if it's not already there."""
     etc_shells = open('/etc/shells')
diff --git a/net.py b/net.py
index 1c34b2b..4bd7c71 100644 (file)
--- a/net.py
+++ b/net.py
@@ -28,9 +28,9 @@ def GetSlivers(plc, data, config):
     else:
         InitNodeLimit(data)
         InitI2(plc, data)
     else:
         InitNodeLimit(data)
         InitI2(plc, data)
-        
     InitNAT(plc, data)
 
     InitNAT(plc, data)
 
+
 def InitNodeLimit(data):
     if not 'networks' in data: return
 
 def InitNodeLimit(data):
     if not 'networks' in data: return
 
index d7e298b..4e06e3e 100644 (file)
--- a/setup.py
+++ b/setup.py
@@ -12,30 +12,30 @@ from distutils.core import setup, Extension
 
 setup(
     py_modules=[
 
 setup(
     py_modules=[
-    'accounts',
-    'api',
-    'api_calls',
-    'conf_files',
-    'config',
-    'curlwrapper',
-    'database',
-    'delegate',
-    'logger',
-    'net',
-    'nm',
-    'plcapi',
-    'safexmlrpc',
-    'sliver_vs',
-    'sm',
-    'ticket',
-    'tools',
-    'bwmon',
-    'iptables',
-    ],
+        'accounts',
+        'api',
+        'api_calls',
+        'bwmon',
+        'conf_files',
+        'config',
+        'controller',
+        'curlwrapper',
+        'database',
+        'iptables',
+        'logger',
+        'net',
+        'nm',
+        'plcapi',
+        'safexmlrpc',
+        'sliver_vs',
+        'sm',
+        'ticket',
+        'tools',
+        ],
     scripts = [
     scripts = [
-    'forward_api_calls',
-    ],
-    packages = [
-    'plugins',
-    ],
+        'forward_api_calls',
+        ],
+    packages =[
+        'plugins',
+        ],
     )
     )
diff --git a/sm.py b/sm.py
index 45644d8..c5384c3 100644 (file)
--- a/sm.py
+++ b/sm.py
@@ -15,7 +15,7 @@ import accounts
 import api
 import api_calls
 import database
 import api
 import api_calls
 import database
-import delegate
+import controller
 import logger
 import sliver_vs
 import string,re
 import logger
 import sliver_vs
 import string,re
@@ -97,12 +97,13 @@ def GetSlivers(data, fullupdate=True):
         keys = rec.pop('keys')
         rec.setdefault('keys', '\n'.join([key_struct['key'] for key_struct in keys]))
 
         keys = rec.pop('keys')
         rec.setdefault('keys', '\n'.join([key_struct['key'] for key_struct in keys]))
 
+        ## 'Type' isn't returned by GetSlivers() for whatever reason.  We're overloading
+        ## instantiation here, but i suppose its the ssame thing when you think about it. -FA
         # Handle nm controller here
         # Handle nm controller here
-        rec.setdefault('type', attr_dict.get('type', 'sliver.VServer'))
-        if rec['instantiation'] == 'nm-controller':
-        # type isn't returned by GetSlivers() for whatever reason.  We're overloading
-        # instantiation here, but i suppose its the ssame thing when you think about it. -FA
-            rec['type'] = 'delegate'
+        if rec['instantiation'].lower() == 'nm-controller':
+            rec.setdefault('type', attr_dict.get('type', 'controller.Controller'))
+        else:
+            rec.setdefault('type', attr_dict.get('type', 'sliver.VServer'))
 
         # set the vserver reference.  If none, set to default.
         rec.setdefault('vref', attr_dict.get('vref', 'default'))
 
         # set the vserver reference.  If none, set to default.
         rec.setdefault('vref', attr_dict.get('vref', 'default'))
@@ -134,6 +135,7 @@ def GetSlivers(data, fullupdate=True):
 
         database.db.deliver_record(rec)
     if fullupdate: database.db.set_min_timestamp(data['timestamp'])
 
         database.db.deliver_record(rec)
     if fullupdate: database.db.set_min_timestamp(data['timestamp'])
+    # slivers are created here.
     database.db.sync()
     accounts.Startingup = False
 
     database.db.sync()
     accounts.Startingup = False
 
@@ -145,7 +147,7 @@ def start(options, config):
         DEFAULT_ALLOCATION[resname]=default_amt
         
     accounts.register_class(sliver_vs.Sliver_VS)
         DEFAULT_ALLOCATION[resname]=default_amt
         
     accounts.register_class(sliver_vs.Sliver_VS)
-    accounts.register_class(delegate.Delegate)
+    accounts.register_class(controller.Controller)
     accounts.Startingup = options.startup
     database.start()
     api_calls.deliver_ticket = deliver_ticket
     accounts.Startingup = options.startup
     database.start()
     api_calls.deliver_ticket = deliver_ticket