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
remove svn keywords
[nodemanager.git]
/
plugins
/
specialaccounts.py
diff --git
a/plugins/specialaccounts.py
b/plugins/specialaccounts.py
index
fb33688
..
2cbda58
100644
(file)
--- a/
plugins/specialaccounts.py
+++ b/
plugins/specialaccounts.py
@@
-1,13
+1,11
@@
#!/usr/bin/python -tt
# vim:set ts=4 sw=4 expandtab:
#
#!/usr/bin/python -tt
# vim:set ts=4 sw=4 expandtab:
#
-# $Id$
-# $URL$
#
# NodeManager plugin to create special accounts
"""
#
# NodeManager plugin to create special accounts
"""
-
Have NM
create/populate accounts/ssh keys for special persons such as root, site_admin, etc.
+create/populate accounts/ssh keys for special persons such as root, site_admin, etc.
"""
"""
@@
-25,11
+23,11
@@
import tools
# right after conf_files
priority = 3
# right after conf_files
priority = 3
-def start(
options, conf
):
- logger.log("
personkey
s: plugin starting up...")
+def start():
+ logger.log("
specialaccount
s: plugin starting up...")
def GetSlivers(data, conf = None, plc = None):
def GetSlivers(data, conf = None, plc = None):
- if 'accounts' not in data:
+ if 'accounts' not in data:
logger.log_missing_data("specialaccounts.GetSlivers",'accounts')
return
logger.log_missing_data("specialaccounts.GetSlivers",'accounts')
return
@@
-50,21
+48,17
@@
def GetSlivers(data, conf = None, plc = None):
if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh)
auth_keys = os.path.join(dot_ssh,'authorized_keys')
if not os.access(dot_ssh, os.F_OK): os.mkdir(dot_ssh)
auth_keys = os.path.join(dot_ssh,'authorized_keys')
-
logger.log("specialaccounts: new keys = %s" % auth_keys
)
- fd, fname = tempfile.mkstemp('','authorized_keys',dot_ssh)
+
# catenate all keys in string, add newlines just in case (looks like keys already have this, but
)
+ auth_keys_contents = '\n'.join(new_keys)+'\n'
- for key in new_keys:
- os.write(fd,key)
-
os.write(fd,'\n'
)
+ changes = tools.replace_file_with_string(auth_keys,auth_keys_contents)
+ if changes:
+
logger.log("specialaccounts: keys file changed: %s" % auth_keys
)
- os.close(fd)
- if os.path.exists(auth_keys): os.unlink(auth_keys)
- os.rename(fname, auth_keys)
-
- # set permissions properly
+ # always set permissions properly
os.chmod(dot_ssh, 0700)
os.chown(dot_ssh, uid,gid)
os.chmod(auth_keys, 0600)
os.chown(auth_keys, uid,gid)
os.chmod(dot_ssh, 0700)
os.chown(dot_ssh, uid,gid)
os.chmod(auth_keys, 0600)
os.chown(auth_keys, uid,gid)
- logger.log('specialacounts: installed ssh keys for %s' % name)
+ logger.log('specialac
c
ounts: installed ssh keys for %s' % name)