Port user module to python3 and 2.4 compatible syntax (#3673)
This commit is contained in:
parent
31126034b0
commit
f2212dc41a
1 changed files with 15 additions and 8 deletions
|
@ -284,7 +284,8 @@ class User(object):
|
||||||
if module.params['expires']:
|
if module.params['expires']:
|
||||||
try:
|
try:
|
||||||
self.expires = time.gmtime(module.params['expires'])
|
self.expires = time.gmtime(module.params['expires'])
|
||||||
except Exception,e:
|
except Exception:
|
||||||
|
e = get_exception()
|
||||||
module.fail_json("Invalid expires time %s: %s" %(self.expires, str(e)))
|
module.fail_json("Invalid expires time %s: %s" %(self.expires, str(e)))
|
||||||
|
|
||||||
if module.params['ssh_key_file'] is not None:
|
if module.params['ssh_key_file'] is not None:
|
||||||
|
@ -584,9 +585,10 @@ class User(object):
|
||||||
if self.module.check_mode:
|
if self.module.check_mode:
|
||||||
return (0, '', '')
|
return (0, '', '')
|
||||||
try:
|
try:
|
||||||
os.mkdir(ssh_dir, 0700)
|
os.mkdir(ssh_dir, int('0700', 8))
|
||||||
os.chown(ssh_dir, info[2], info[3])
|
os.chown(ssh_dir, info[2], info[3])
|
||||||
except OSError, e:
|
except OSError:
|
||||||
|
e = get_exception()
|
||||||
return (1, '', 'Failed to create %s: %s' % (ssh_dir, str(e)))
|
return (1, '', 'Failed to create %s: %s' % (ssh_dir, str(e)))
|
||||||
if os.path.exists(ssh_key_file):
|
if os.path.exists(ssh_key_file):
|
||||||
return (None, 'Key already exists', '')
|
return (None, 'Key already exists', '')
|
||||||
|
@ -656,12 +658,14 @@ class User(object):
|
||||||
if os.path.exists(skeleton):
|
if os.path.exists(skeleton):
|
||||||
try:
|
try:
|
||||||
shutil.copytree(skeleton, path, symlinks=True)
|
shutil.copytree(skeleton, path, symlinks=True)
|
||||||
except OSError, e:
|
except OSError:
|
||||||
|
e = get_exception()
|
||||||
self.module.exit_json(failed=True, msg="%s" % e)
|
self.module.exit_json(failed=True, msg="%s" % e)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
os.makedirs(path)
|
os.makedirs(path)
|
||||||
except OSError, e:
|
except OSError:
|
||||||
|
e = get_exception()
|
||||||
self.module.exit_json(failed=True, msg="%s" % e)
|
self.module.exit_json(failed=True, msg="%s" % e)
|
||||||
|
|
||||||
def chown_homedir(self, uid, gid, path):
|
def chown_homedir(self, uid, gid, path):
|
||||||
|
@ -672,7 +676,8 @@ class User(object):
|
||||||
os.chown(path, uid, gid)
|
os.chown(path, uid, gid)
|
||||||
for f in files:
|
for f in files:
|
||||||
os.chown(os.path.join(root, f), uid, gid)
|
os.chown(os.path.join(root, f), uid, gid)
|
||||||
except OSError, e:
|
except OSError:
|
||||||
|
e = get_exception()
|
||||||
self.module.exit_json(failed=True, msg="%s" % e)
|
self.module.exit_json(failed=True, msg="%s" % e)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1290,7 +1295,8 @@ class SunOS(User):
|
||||||
line = ':'.join(fields)
|
line = ':'.join(fields)
|
||||||
lines.append('%s\n' % line)
|
lines.append('%s\n' % line)
|
||||||
open(self.SHADOWFILE, 'w+').writelines(lines)
|
open(self.SHADOWFILE, 'w+').writelines(lines)
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to update users password: %s" % str(err))
|
self.module.fail_json(msg="failed to update users password: %s" % str(err))
|
||||||
|
|
||||||
return (rc, out, err)
|
return (rc, out, err)
|
||||||
|
@ -1377,7 +1383,8 @@ class SunOS(User):
|
||||||
lines.append('%s\n' % line)
|
lines.append('%s\n' % line)
|
||||||
open(self.SHADOWFILE, 'w+').writelines(lines)
|
open(self.SHADOWFILE, 'w+').writelines(lines)
|
||||||
rc = 0
|
rc = 0
|
||||||
except Exception, err:
|
except Exception:
|
||||||
|
err = get_exception()
|
||||||
self.module.fail_json(msg="failed to update users password: %s" % str(err))
|
self.module.fail_json(msg="failed to update users password: %s" % str(err))
|
||||||
|
|
||||||
return (rc, out, err)
|
return (rc, out, err)
|
||||||
|
|
Loading…
Reference in a new issue