2008-04-05 23:22:12 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-07-02 11:14:47 +02:00
|
|
|
#
|
2008-04-05 23:22:12 +02:00
|
|
|
# Copyright (C) 2007, 2008 by Jan Dittberner.
|
2007-07-02 11:14:47 +02:00
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful, but
|
|
|
|
# WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
|
|
|
|
# USA.
|
|
|
|
#
|
|
|
|
# Version: $Id$
|
2008-06-07 23:25:35 +02:00
|
|
|
"""This module provides the command line interface code for system
|
|
|
|
user management."""
|
|
|
|
from gnuviechadmin.cli.CliCommand import CliCommand
|
2008-06-06 21:20:18 +02:00
|
|
|
import sys
|
2007-07-02 11:14:47 +02:00
|
|
|
|
|
|
|
|
2008-06-07 23:25:35 +02:00
|
|
|
class SysuserCli(CliCommand):
|
|
|
|
"""Command line interface command for system user management.
|
|
|
|
|
|
|
|
This class implements `gnuviechadmin.cli.CliCommand.CliCommand`.
|
|
|
|
"""
|
2007-07-02 11:14:47 +02:00
|
|
|
|
2009-08-01 21:35:43 +02:00
|
|
|
@staticmethod
|
|
|
|
def setup_argparser(subparsers):
|
|
|
|
parser = subparsers.add_parser(
|
|
|
|
'sysuser',
|
|
|
|
help = _('manage system users'))
|
|
|
|
parser.set_defaults(commandclass=SysuserCli)
|
|
|
|
cmdsub = parser.add_subparsers(
|
|
|
|
title = _('sysuser subcommands'),
|
|
|
|
dest = 'subcommand')
|
|
|
|
cmdparser = cmdsub.add_parser(
|
|
|
|
'create',
|
|
|
|
help = _('create a new system user with the given options.'))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-n', '--username',
|
|
|
|
help = _('the system user name'))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-t', '--usertype',
|
|
|
|
help = _('the numeric user type'))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'--home',
|
|
|
|
help = _('the home directory'))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-s', '--shell',
|
|
|
|
help = _('true if the user should get shell access'))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-p', '--password', dest = 'clearpass',
|
|
|
|
help = _('the password for the user'))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-c', '--clientid', required = True,
|
|
|
|
help = _('the client id'))
|
|
|
|
cmdparser = cmdsub.add_parser(
|
|
|
|
'list',
|
|
|
|
help = _('list existing system users.'))
|
|
|
|
cmdparser = cmdsub.add_parser(
|
|
|
|
'delete',
|
|
|
|
help = _('delete a system user.'))
|
|
|
|
cmdparser.add_argument(
|
|
|
|
'-s', '--sysuserid', required = True,
|
|
|
|
help = _('the system user id'))
|
2007-07-02 11:14:47 +02:00
|
|
|
|
2009-08-01 21:35:43 +02:00
|
|
|
def _execute(self):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Executes `subcommand`.
|
|
|
|
|
|
|
|
This method implements `CliCommand._execute()`.
|
|
|
|
"""
|
2009-08-01 21:35:43 +02:00
|
|
|
self.logger.debug("execute %s", self.args)
|
2007-07-02 11:14:47 +02:00
|
|
|
from gnuviechadmin.backend import sysuser
|
|
|
|
from gnuviechadmin import exceptions
|
2009-08-01 21:35:43 +02:00
|
|
|
sh = sysuser.SysuserHandler(self.config, self.args.verbose)
|
|
|
|
if self.args.subcommand == "create":
|
2007-07-02 11:14:47 +02:00
|
|
|
try:
|
2009-08-01 21:35:43 +02:00
|
|
|
mysysuser = sh.create(**self.args.__dict__)
|
|
|
|
if self.args.verbose:
|
2007-07-02 11:14:47 +02:00
|
|
|
print mysysuser
|
|
|
|
except exceptions.CreationFailedError, cfe:
|
|
|
|
print cfe
|
|
|
|
sys.exit(2)
|
2009-08-01 21:35:43 +02:00
|
|
|
elif self.args.subcommand == "list":
|
|
|
|
sysusers = sh.fetchall()
|
2007-07-02 11:14:47 +02:00
|
|
|
for su in sysusers:
|
|
|
|
print su
|
2009-08-01 21:35:43 +02:00
|
|
|
elif self.args.subcommand == "delete":
|
|
|
|
sh.delete(self.args.sysuserid)
|
2007-07-02 11:14:47 +02:00
|
|
|
|
2009-08-01 21:35:43 +02:00
|
|
|
def __init__(self, args, config):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Constructor for the sysuser command."""
|
2009-08-01 21:35:43 +02:00
|
|
|
CliCommand.__init__(self, args, config)
|