def start(options, config): pass
-def GetSlivers(plc, data, config = None):
+def GetSlivers(data, config = None, plc = None):
logger.log("conf_files: Running.")
cf = conf_files()
cf.run_once(data)
def start(options, conf):
logger.log("net plugin starting up...")
-def GetSlivers(plc, data, config):
+def GetSlivers(data, config, plc):
logger.verbose("net:GetSlivers called.")
InitInterfaces(plc, data) # writes sysconfig files.
if 'OVERRIDES' in dir(config):
modules = []
-def GetSlivers(plc, config):
+def GetSlivers(config, plc):
'''Run call backs defined in modules'''
try:
logger.log("Syncing w/ PLC")
for module in modules:
try:
callback = getattr(module, 'GetSlivers')
- callback(plc, data, config)
+ callback(data, config, plc)
except: logger.log_exc()
irandom=int(options.random)
plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=iperiod/2)
+ #check auth
+ while plc.check_authentication() != True:
+ try:
+ plc.update_session()
+ logger.log("Authentication Failure. Retrying")
+ except:
+ logger.log("Retry Failed. Waiting")
+ time.sleep(iperiod)
+
+
while True:
# Main NM Loop
logger.verbose('mainloop - nm:getSlivers - period=%d random=%d'%(iperiod,irandom))
- GetSlivers(plc, config)
+ GetSlivers(config, plc)
delay=iperiod + random.randrange(0,irandom)
logger.verbose('mainloop - sleeping for %d s'%delay)
time.sleep(delay)
import safexmlrpc
import hmac, sha
+import logger
class PLCAPI:
"""
self.node_id = self.key = self.session = None
self.server = safexmlrpc.ServerProxy(self.uri, self.cacert, self.timeout, allow_none = 1, **kwds)
-
- self.__check_authentication()
- def __update_session(self, f="/usr/boot/plnode.txt"):
+ def update_session(self, f="/usr/boot/plnode.txt"):
# try authenticatipopulate /etc.planetlab/session
def plnode(key):
try:
plc = PLCAPI(self.uri, self.cacert, auth, self.timeout)
open("/etc/planetlab/session", 'w').write(plc.GetSession().strip())
self.session = open("/etc/planetlab/session").read().strip()
+
- def __check_authentication(self):
+ def check_authentication(self):
# just a simple call to check authentication
- def check():
- if (self.node_id and self.key) or self.session:
- try:
- if self.AuthCheck() == 1: return True
- except:
- return False
- return False
- if not check():
- if self.node_id and self.key:
- # if hmac fails, just make it fail
- raise Exception, "Unable to authenticate with hmac"
- else:
- self.__update_session()
- if not check():
- raise Exception, "Unable to authenticate with session"
-
+ return self.AuthCheck(self)
+
def add_auth(self, function):
"""
def start(options, conf):
logger.log("codemux plugin starting up...")
-def GetSlivers(plc, data, config):
+def GetSlivers(data, config, plc = None):
"""
For each sliver with the codemux attribute, parse out "host,port"
and make entry in conf. Restart service after.
partitions.close()
return devices
-def GetSlivers(plc, data, conf):
+def GetSlivers(data, config=None, plc=None):
if 'slivers' not in data:
logger.log("sliverauth: getslivers data lack's sliver information. IGNORING!")
return
slivertag_id=slivertags[0]['slice_tag_id']
plc.UpdateSliceTag(slivertag_id,value)
-def GetSlivers(plc, data, conf):
+def GetSlivers(data, config, plc):
# XXX REMOVE ME
logger.log("sliverauth: DISABLED!")
return
def start(options, conf):
logger.log("personkeys plugin starting up...")
-def GetSlivers(plc, data, conf):
- if 'accounts' not in data: return
+def GetSlivers(data, conf = None, plc = None):
+ if 'accounts' not in data:
+ logger.log("specialaccounts: No account information found. DISABLED!")
+ return
+
for account in data['accounts']:
name = account['name']
new_keys = account['keys']
dot_ssh = os.path.join(pw_dir,'.ssh')
if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh)
auth_keys = os.path.join(dot_ssh,'authorized_keys')
+
logger.log("new keys = %s" % auth_keys)
fd, fname = tempfile.mkstemp('','authorized_keys',dot_ssh)
- for key in new_keys:
+ for key in new_keys:
os.write(fd,key)
os.write(fd,'\n')
os.close(fd)
- if os.path.exists(auth_keys):
- os.unlink(auth_keys)
- os.rename(fname,auth_keys)
+ if os.path.exists(auth_keys): os.unlink(auth_keys)
+ os.rename(fname, auth_keys)
# set permissions properly
os.chmod(dot_ssh, 0700)
def start(options, conf):
logger.log("vsys plugin starting up...")
-def GetSlivers(plc, data, config=None):
+def GetSlivers(data, config=None, plc=None):
"""For each sliver with the vsys attribute, set the script ACL, create the vsys directory in the slice, and restart vsys."""
# Touch ACLs and create dict of available
scripts = {}
start_requested = False # set to True in order to request that all slivers be started
@database.synchronized
-def GetSlivers(plc, data, config = None, fullupdate=True):
+def GetSlivers(data, config = None, plc=None, fullupdate=True):
"""This function has two purposes. One, convert GetSlivers() data
into a more convenient format. Two, even if no updates are coming
in, use the GetSlivers() heartbeat as a cue to scan for expired