class Account:
def __init__(self, rec):
+ logger.verbose('Initing account %s'%rec['name'])
self.name = rec['name']
self.keys = ''
self.initscriptchanged = False
def configure(self, rec):
"""Write <rec['keys']> to my authorized_keys file."""
+ logger.verbose('in accounts:configure')
new_keys = rec['keys']
if new_keys != self.keys:
self.keys = new_keys
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)
+ logger.verbose('%s: installing ssh keys' % self.name)
tools.fork_as(self.name, do_installation)
def start(self, delay=0): pass
def ensure_created(self, rec):
"""Cause the account specified by <rec> to exist if it doesn't already."""
+ if rec.has_key('name'):
+ logger.verbose('Worker.ensure_created with name=%s'%rec['name'])
self._q.put((self._ensure_created, rec.copy(), Startingup))
+ logger.verbose('Worker queue has %d item(s)'%self._q.qsize())
def _ensure_created(self, rec, startingup):
curr_class = self._get_class()
"""Repeatedly pull commands off the queue and execute. If memory usage becomes an issue, it might be wise to terminate after a while."""
while True:
try:
+ logger.verbose('Worker:_run : getting - size is %d'%self._q.qsize())
cmd = self._q.get()
cmd[0](*cmd[1:])
except:
self._compute_effective_rspecs()
# create and destroy accounts as needed
+ logger.verbose("database:sync : fetching accounts")
existing_acct_names = accounts.all()
for name in existing_acct_names:
+ logger.verbose("database:sync : loop on %s"%name)
if name not in self: accounts.get(name).ensure_destroyed()
for name, rec in self.iteritems():
if rec['instantiation'] == 'plc-instantiated': accounts.get(name).ensure_created(rec)
LOG_FILE = '/var/log/nm'
+LOG_SLIVERS = '/var/log/getslivers.txt'
-def log(msg):
- """Write <msg> to the log file."""
+# Thierry - trying to debug this for 4.2
+# basically define 3 levels
+LOG_NONE=0
+LOG_NODE=1
+LOG_VERBOSE=2
+# default is to log a reasonable amount of stuff for when running on operational nodes
+LOG_LEVEL=1
+
+def set_level(level):
+ assert level in [LOG_NONE,LOG_NODE,LOG_VERBOSE]
+ LOG_LEVEL=level
+
+def verbose(msg):
+ log(msg,LOG_VERBOSE)
+
+def log(msg,level=LOG_NODE):
+ """Write <msg> to the log file if level >= current log level (default LOG_NODE)."""
+ if (level > LOG_LEVEL):
+ return
try:
fd = os.open(LOG_FILE, os.O_WRONLY | os.O_CREAT | os.O_APPEND, 0600)
if not msg.endswith('\n'): msg += '\n'
log("operation on %s failed. \n %s" %(self.name, traceback.format_exc()))
else:
log(traceback.format_exc())
+
+def log_slivers (data):
+ import pprint, time
+ try:
+ f=open(LOG_SLIVERS,'w')
+ now=time.strftime("GetSlivers stored at %H:%M:%S", time.localtime())
+ f.write(now+'\n')
+ pp=pprint.PrettyPrinter(stream=f,indent=2)
+ pp.pprint(data)
+ f.close()
+ except:
+ log_verbose('Cannot save GetSlivers in %s'%LOG_SLIVERS)
do_start()
{
- options=$1
echo -n $"Starting $prog: "
- daemon --check=nm $nm $options
+ daemon --check=nm $nm "$@"
RETVAL=$?
echo
[ $RETVAL -eq 0 ] && touch ${lockfile}
parser.add_option('-f', '--config', action='store', dest='config', default='/etc/planetlab/plc_config', help='PLC configuration file')
parser.add_option('-k', '--session', action='store', dest='session', default='/etc/planetlab/session', help='API session key (or file)')
parser.add_option('-p', '--period', action='store', dest='period', default=600, help='Polling interval (sec)')
+parser.add_option('-r', '--random', action='store', dest='random', default=301, help='Range for additional random polling interval (sec)')
+parser.add_option('-v', '--verbose', action='store_true', dest='verbose', default=False, help='more verbose log')
(options, args) = parser.parse_args()
modules = []
def GetSlivers(plc):
try: data = plc.GetSlivers()
except: logger.log_exc()
+ if (options.verbose):
+ logger.log_slivers(data)
# Set i2 ip list for nodes in I2 nodegroup.
try: net.GetSlivers(plc, data)
except: logger.log_exc()
try:
if options.daemon: tools.daemon()
+ # set log level
+ if (options.verbose):
+ logger.set_level(logger.LOG_VERBOSE)
+
# Load /etc/planetlab/plc_config
config = Config(options.config)
session = options.session
# Initialize XML-RPC client
- plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=options.period/2)
+ iperiod=int(options.period)
+ irandom=int(options.random)
+ plc = PLCAPI(config.plc_api_uri, config.cacert, session, timeout=iperiod/2)
while True:
# Main NM Loop
+ logger.verbose('mainloop - nm:getSlivers - period=%d random=%d'%(iperiod,irandom))
GetSlivers(plc)
- time.sleep(options.period + random.randrange(0,301))
+ delay=iperiod + random.randrange(0,irandom)
+ logger.verbose('mainloop - sleeping for %d s'%delay)
+ time.sleep(delay)
except: logger.log_exc()
if __name__ == '__main__':
+ logger.verbose("Entering nm.py")
stacklim = 512*1024 # 0.5 MiB
curlim = resource.getrlimit(resource.RLIMIT_STACK)[0] # soft limit
if curlim > stacklim:
_init_disk_info_sem = tools.NMLock("/var/run/nm-disk-info.lock")
def __init__(self, rec):
+ logger.verbose ('initing Sliver_VS with name=%s'%rec['name'])
try:
vserver.VServer.__init__(self, rec['name'])
except Exception, err:
@staticmethod
def create(name, vref = None):
+ logger.verbose('Sliver_VS:create - name=%s'%name)
if vref is not None:
logger.log_call('/usr/sbin/vuseradd', '-t', vref, name)
else:
in, use the GetSlivers() heartbeat as a cue to scan for expired
slivers."""
+ logger.verbose("Entering sm:GetSlivers with fullupdate=%r"%fullupdate)
+ for key in data.keys():
+ logger.verbose('GetSlivers key : ' + key)
+
node_id = None
try:
f = open('/etc/planetlab/node_id')
### Emulab-specific hack ends here
+ logger.verbose ('dealing with initscripts')
initscripts_by_id = {}
for is_rec in data['initscripts']:
initscripts_by_id[str(is_rec['initscript_id'])] = is_rec['script']
for sliver in data['slivers']:
+ logger.verbose("sm:GetSlivers in slivers loop")
rec = sliver.copy()
rec.setdefault('timestamp', data['timestamp'])