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
cosmetic
[nodemanager.git]
/
account.py
diff --git
a/account.py
b/account.py
index
52ebb97
..
d45f533
100644
(file)
--- a/
account.py
+++ b/
account.py
@@
-71,9
+71,11
@@
def get(name):
"""
name_worker_lock.acquire()
try:
"""
name_worker_lock.acquire()
try:
- if name not in name_worker: name_worker[name] = Worker(name)
+ if name not in name_worker:
+ name_worker[name] = Worker(name)
return name_worker[name]
return name_worker[name]
- finally: name_worker_lock.release()
+ finally:
+ name_worker_lock.release()
class Account:
class Account:
@@
-99,7
+101,8
@@
class Account:
Write <rec['keys']> to my authorized_keys file.
"""
new_keys = rec['keys']
Write <rec['keys']> to my authorized_keys file.
"""
new_keys = rec['keys']
- logger.verbose('account: configuring {} with {} keys'.format(self.name, len(new_keys)))
+ nb_keys = len(new_keys) if isinstance(new_keys, list) else 1
+ logger.verbose('account: configuring {} with {} keys'.format(self.name, nb_keys))
if new_keys != self.keys:
# get the unix account info
gid = grp.getgrnam("slices")[2]
if new_keys != self.keys:
# get the unix account info
gid = grp.getgrnam("slices")[2]
@@
-122,9
+125,9
@@
class Account:
tools.write_file(auth_keys, lambda f: f.write(new_keys))
# set access permissions and ownership properly
tools.write_file(auth_keys, lambda f: f.write(new_keys))
# set access permissions and ownership properly
- os.chmod(dot_ssh, 0700)
+ os.chmod(dot_ssh, 0
o
700)
os.chown(dot_ssh, uid, gid)
os.chown(dot_ssh, uid, gid)
- os.chmod(auth_keys, 0600)
+ os.chmod(auth_keys, 0
o
600)
os.chown(auth_keys, uid, gid)
# set self.keys to new_keys only when all of the above ops succeed
os.chown(auth_keys, uid, gid)
# set self.keys to new_keys only when all of the above ops succeed
@@
-153,14
+156,18
@@
class Account:
# which is a static method, they need to become static as well
# needs to be done before sliver starts (checked with vs and lxc)
@staticmethod
# which is a static method, they need to become static as well
# needs to be done before sliver starts (checked with vs and lxc)
@staticmethod
- def mount_ssh_dir (slicename): return Account._manage_ssh_dir (slicename, do_mount=True)
+ def mount_ssh_dir (slicename):
+ return Account._manage_ssh_dir (slicename, do_mount=True)
@staticmethod
@staticmethod
- def umount_ssh_dir (slicename): return Account._manage_ssh_dir (slicename, do_mount=False)
+ def umount_ssh_dir (slicename):
+ return Account._manage_ssh_dir (slicename, do_mount=False)
# bind mount / umount root side dir to sliver side
@staticmethod
def _manage_ssh_dir (slicename, do_mount):
# bind mount / umount root side dir to sliver side
@staticmethod
def _manage_ssh_dir (slicename, do_mount):
- logger.log("_manage_ssh_dir, requested to "+("mount" if do_mount else "umount")+" ssh dir for "+ slicename)
+ logger.log("_manage_ssh_dir, requested to " +
+ ( "mount" if do_mount else "umount" ) +
+ " ssh dir for "+ slicename)
try:
root_ssh = "/home/{}/.ssh".format(slicename)
sliver_ssh = "/vservers/{}/home/{}/.ssh".format(slicename, slicename)
try:
root_ssh = "/home/{}/.ssh".format(slicename)
sliver_ssh = "/vservers/{}/home/{}/.ssh".format(slicename, slicename)
@@
-190,8
+197,8
@@
class Account:
msg = "OK" if umounted else "WARNING: FAILED"
logger.log("_manage_ssh_dir: umounted {} - {}"
.format(sliver_ssh, msg))
msg = "OK" if umounted else "WARNING: FAILED"
logger.log("_manage_ssh_dir: umounted {} - {}"
.format(sliver_ssh, msg))
- except:
- logger.log_exc("_manage_ssh_dir failed
"
, name=slicename)
+ except
Exception as e
:
+ logger.log_exc("_manage_ssh_dir failed
: {}".format(e)
, name=slicename)
class Worker:
class Worker:
@@
-225,7
+232,8
@@
class Worker:
# this sliver has the lease, it is safe to start it
if not self.is_running():
self.start(rec)
# this sliver has the lease, it is safe to start it
if not self.is_running():
self.start(rec)
- else: self.configure(rec)
+ else:
+ self.configure(rec)
else:
# not having the lease, do not start it
self.configure(rec)
else:
# not having the lease, do not start it
self.configure(rec)
@@
-266,20
+274,28
@@
class Worker:
else:
account_needs_reimage = self._acct.needs_reimage(target_slicefamily)
if account_needs_reimage:
else:
account_needs_reimage = self._acct.needs_reimage(target_slicefamily)
if account_needs_reimage:
- logger.log("Worker.needs_reimage ({}) - account needs reimage (tmp: DRY RUN)".format(self.name))
+ logger.log("Worker.needs_reimage ({}) - account needs reimage (tmp: DRY RUN)"
+ .format(self.name))
else:
else:
- logger.verbose("Worker.needs_reimage ({}) - everything fine".format(self.name))
+ logger.verbose("Worker.needs_reimage ({}) - everything fine"
+ .format(self.name))
return account_needs_reimage
def _destroy(self, curr_class):
self._acct = None
if curr_class:
destroy_sem.acquire()
return account_needs_reimage
def _destroy(self, curr_class):
self._acct = None
if curr_class:
destroy_sem.acquire()
- try: curr_class.destroy(self.name)
- finally: destroy_sem.release()
+ try:
+ logger.verbose("account._destroy is callling destroy from {}"
+ .format(curr_class.__name__))
+ curr_class.destroy(self.name)
+ finally:
+ destroy_sem.release()
def _get_class(self):
def _get_class(self):
- try: shell = pwd.getpwnam(self.name)[6]
- except KeyError: return None
+ try:
+ shell = pwd.getpwnam(self.name)[6]
+ except KeyError:
+ return None
return shell_acct_class[shell]
return shell_acct_class[shell]