Skip to content
Snippets Groups Projects
Commit 0d19fc52 authored by sveseli's avatar sveseli
Browse files

need to create group if it does not exist

parent f52bf34c
No related branches found
No related tags found
No related merge requests found
...@@ -165,10 +165,25 @@ class LdapLinuxPlatformUtility: ...@@ -165,10 +165,25 @@ class LdapLinuxPlatformUtility:
logger.error('Could not add user %s to group %s: %s' % (username, groupName, ex)) logger.error('Could not add user %s to group %s: %s' % (username, groupName, ex))
raise InternalError(exception=ex) raise InternalError(exception=ex)
@classmethod
def createLocalGroup(cls, name):
""" Create local group if it does not exist. """
logger = cls.getLogger()
try:
group = grp.getgrnam(name)
logger.debug('Group %s already exists' % name)
return
except KeyError, ex:
# ok, we need to create group
pass
logger.debug('Creating group %s' % name)
cmd = '%s %s' % (cls.GROUPADD_CMD, name)
cls.executeSudoCommand(cmd)
@classmethod @classmethod
def addLocalUserToGroup(cls, username, groupName): def addLocalUserToGroup(cls, username, groupName):
""" Add local user to group. """ """ Add local user to group. """
createLocalGroup(groupName)
logger = cls.getLogger() logger = cls.getLogger()
logger.debug('Adding local user %s to group %s' % (username, groupName)) logger.debug('Adding local user %s to group %s' % (username, groupName))
cmd = '%s -a %s %s' % (cls.GPASSWD_CMD, username, groupName) cmd = '%s -a %s %s' % (cls.GPASSWD_CMD, username, groupName)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment