Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dm-docs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hammonds
dm-docs
Commits
e536f7ab
Commit
e536f7ab
authored
9 years ago
by
sveseli
Browse files
Options
Downloads
Patches
Plain Diff
modifications to platform utilities that enable resetting group members
parent
f31f93fc
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/python/dm/common/utility/ldapLinuxPlatformUtility.py
+26
-3
26 additions, 3 deletions
src/python/dm/common/utility/ldapLinuxPlatformUtility.py
src/python/dm/common/utility/linuxUtility.py
+9
-0
9 additions, 0 deletions
src/python/dm/common/utility/linuxUtility.py
with
35 additions
and
3 deletions
src/python/dm/common/utility/ldapLinuxPlatformUtility.py
+
26
−
3
View file @
e536f7ab
...
...
@@ -164,6 +164,31 @@ class LdapLinuxPlatformUtility:
logger
.
error
(
'
Could not add user %s to group %s: %s
'
%
(
username
,
groupName
,
ex
))
raise
InternalError
(
exception
=
ex
)
def
setGroupUsers
(
self
,
groupName
,
usernameList
):
"""
Set list of users for a given group.
"""
logger
=
self
.
getLogger
()
ldapClient
=
self
.
getLdapClient
()
groupName
=
str
(
groupName
)
try
:
groupDn
=
self
.
groupDnFormat
%
groupName
resultList
=
ldapClient
.
search_s
(
groupDn
,
ldap
.
SCOPE_BASE
)
groupTuple
=
resultList
[
0
]
groupAttrs
=
groupTuple
[
1
]
except
Exception
,
ex
:
raise
InternalError
(
exception
=
ex
)
logger
.
debug
(
'
Setting users %s for group %s
'
%
(
usernameList
,
groupName
))
memberUidList
=
[]
for
username
in
usernameList
:
memberUidList
.
append
(
str
(
username
))
groupAttrs2
=
copy
.
copy
(
groupAttrs
)
groupAttrs2
[
'
memberUid
'
]
=
memberUidList
try
:
groupLdif
=
ldap
.
modlist
.
modifyModlist
(
groupAttrs
,
groupAttrs2
)
ldapClient
.
modify_s
(
groupDn
,
groupLdif
)
except
Exception
,
ex
:
logger
.
error
(
'
Could not set users %s for group %s: %s
'
%
(
usernameList
,
groupName
,
ex
))
raise
InternalError
(
exception
=
ex
)
@classmethod
def
setPathReadExecutePermissionsForGroup
(
cls
,
path
,
groupName
):
"""
Set path permissions for the given group.
"""
...
...
@@ -184,7 +209,5 @@ class LdapLinuxPlatformUtility:
if
__name__
==
'
__main__
'
:
utility
=
LdapLinuxPlatformUtility
(
'
ldaps://dmid-vm.xray.aps.anl.gov:636
'
,
'
uid=dmadmin,ou=People,o=aps.anl.gov,dc=aps,dc=anl,dc=gov
'
,
'
/tmp/ldapPassword
'
,
groupDnFormat
=
'
cn=%s,ou=DM,ou=Group,o=aps.anl.gov,dc=aps,dc=anl,dc=gov
'
,
minGidNumber
=
66000
)
utility
.
createGroup
(
u
'
exp9
'
)
#utility.createGroup('dmgp000001_TOF')
utility
.
addUserToGroup
(
u
'
rs1
'
,
u
'
exp9
'
)
utility
.
setGroupUsers
(
u
'
exp9
'
,
[
'
sveseli
'
,
'
bfrosik
'
])
This diff is collapsed.
Click to expand it.
src/python/dm/common/utility/linuxUtility.py
+
9
−
0
View file @
e536f7ab
...
...
@@ -11,6 +11,7 @@ class LinuxUtility:
USERMOD_CMD
=
'
/usr/sbin/usermod
'
SETFACL_CMD
=
'
/usr/bin/setfacl
'
CHOWN_CMD
=
'
/bin/chown
'
GPASSWD_CMD
=
'
/usr/bin/gpasswd
'
@classmethod
def
getLogger
(
cls
):
...
...
@@ -45,6 +46,14 @@ class LinuxUtility:
cmd
=
'
%s -a -G %s %s
'
%
(
cls
.
USERMOD_CMD
,
groupName
,
username
)
cls
.
executeSudoCommand
(
cmd
)
@classmethod
def
setGroupUsers
(
cls
,
groupName
,
usernameList
):
"""
Set list of users for a given group.
"""
logger
=
cls
.
getLogger
()
logger
.
debug
(
'
Setting group %s users to: %s
'
%
(
groupName
,
username
))
cmd
=
'
%s -M
"
%s
"
%s
'
%
(
cls
.
GPASSWD_CMD
,
'
,
'
.
join
(
usernameList
),
groupName
)
cls
.
executeSudoCommand
(
cmd
)
@classmethod
def
setPathReadExecutePermissionsForGroup
(
cls
,
path
,
groupName
):
"""
Set path permissions for the given group.
"""
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment