git://git.onelab.eu
/
nodemanager.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Tagging module NodeManager - NodeManager-1.7-13
[nodemanager.git]
/
accounts.py
diff --git
a/accounts.py
b/accounts.py
index
b0ec4c2
..
3711a0d
100644
(file)
--- a/
accounts.py
+++ b/
accounts.py
@@
-30,7
+30,10
@@
import tools
# When this variable is true, start after any ensure_created
# When this variable is true, start after any ensure_created
-startingup = False
+Startingup = False
+# Cumulative delay for starts when Startingup is true
+csd_lock = threading.Lock()
+cumstartdelay = 0
# shell path -> account class association
shell_acct_class = {}
# shell path -> account class association
shell_acct_class = {}
@@
-65,8
+68,10
@@
def get(name):
class Account:
def __init__(self, rec):
class Account:
def __init__(self, rec):
+ logger.verbose('Initing account %s'%rec['name'])
self.name = rec['name']
self.keys = ''
self.name = rec['name']
self.keys = ''
+ self.initscriptchanged = False
self.configure(rec)
@staticmethod
self.configure(rec)
@staticmethod
@@
-76,6
+81,7
@@
class Account:
def configure(self, rec):
"""Write <rec['keys']> to my authorized_keys file."""
def configure(self, rec):
"""Write <rec['keys']> to my authorized_keys file."""
+ logger.verbose('in accounts:configure for %s'%self.name)
new_keys = rec['keys']
if new_keys != self.keys:
self.keys = new_keys
new_keys = rec['keys']
if new_keys != self.keys:
self.keys = new_keys
@@
-84,7
+90,7
@@
class Account:
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))
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
tools.fork_as(self.name, do_installation)
def start(self, delay=0): pass
@@
-107,9
+113,12
@@
class Worker:
def ensure_created(self, rec):
"""Cause the account specified by <rec> to exist if it doesn't already."""
def ensure_created(self, rec):
"""Cause the account specified by <rec> to exist if it doesn't already."""
- self._q.put((self._ensure_created, rec.copy()))
+ 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):
+ def _ensure_created(self, rec
, startingup
):
curr_class = self._get_class()
next_class = type_acct_class[rec['type']]
if next_class != curr_class:
curr_class = self._get_class()
next_class = type_acct_class[rec['type']]
if next_class != curr_class:
@@
-119,7
+128,14
@@
class Worker:
finally: self._create_sem.release()
if not isinstance(self._acct, next_class): self._acct = next_class(rec)
else: self._acct.configure(rec)
finally: self._create_sem.release()
if not isinstance(self._acct, next_class): self._acct = next_class(rec)
else: self._acct.configure(rec)
- if next_class != curr_class || startingup:
+ if startingup:
+ csd_lock.acquire()
+ global cumstartdelay
+ delay = cumstartdelay
+ cumstartdelay += 2
+ csd_lock.release()
+ self._acct.start(delay=delay)
+ elif next_class != curr_class or self._acct.initscriptchanged:
self._acct.start()
def ensure_destroyed(self): self._q.put((self._ensure_destroyed,))
self._acct.start()
def ensure_destroyed(self): self._q.put((self._ensure_destroyed,))
@@
-147,6
+163,8
@@
class Worker:
"""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:
"""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:])
cmd = self._q.get()
cmd[0](*cmd[1:])
- except: logger.log_exc()
+ except:
+ logger.log_exc(self.name)