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
|
|
|
|
2008-06-06 21:20:18 +02:00
|
|
|
name = "sysuser"
|
2007-07-02 11:14:47 +02:00
|
|
|
description = "manage system users"
|
2008-06-06 21:20:18 +02:00
|
|
|
_optionmap = {
|
|
|
|
"create": ("create a new system user with the given options.",
|
|
|
|
[(["-n", "--username"], "username",
|
|
|
|
"the system user name", False),
|
|
|
|
(["-t", "--usertype"], "usertype",
|
|
|
|
"the numeric user type", False),
|
|
|
|
(["-h", "--home"], "home",
|
|
|
|
"the home directory", False),
|
|
|
|
(["-s", "--shell"], "shell",
|
|
|
|
"true if the user should get shell access", False),
|
|
|
|
(["-p", "--password"], "clearpass",
|
|
|
|
"the password for the user", False),
|
|
|
|
(["-c", "--clientid"], "clientid",
|
|
|
|
"the client id", True)]),
|
|
|
|
"list": ("list existing system users.", []),
|
|
|
|
"delete": ("delete a system user.",
|
|
|
|
[(["-s", "--sysuserid"], "sysuserid",
|
|
|
|
"the system user id", True)])}
|
2007-07-02 11:14:47 +02:00
|
|
|
|
|
|
|
def _execute(self, subcommand):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Executes `subcommand`.
|
|
|
|
|
|
|
|
This method implements `CliCommand._execute()`.
|
|
|
|
"""
|
2007-07-09 08:46:36 +02:00
|
|
|
self.logger.debug("execute %s with data %s", subcommand,
|
|
|
|
str(self._data))
|
2007-07-02 11:14:47 +02:00
|
|
|
from gnuviechadmin.backend import sysuser
|
|
|
|
from gnuviechadmin import exceptions
|
|
|
|
if subcommand == "create":
|
|
|
|
try:
|
|
|
|
mysysuser = sysuser.SysuserHandler(self._verbose).create(
|
|
|
|
**self._data)
|
|
|
|
if self._verbose:
|
|
|
|
print mysysuser
|
|
|
|
except exceptions.CreationFailedError, cfe:
|
|
|
|
self._usage()
|
|
|
|
print cfe
|
|
|
|
sys.exit(2)
|
|
|
|
elif subcommand == "list":
|
|
|
|
sysusers = sysuser.SysuserHandler(self._verbose).fetchall()
|
|
|
|
for su in sysusers:
|
|
|
|
print su
|
|
|
|
elif subcommand == "delete":
|
|
|
|
sysuser.SysuserHandler(self._verbose).delete(
|
|
|
|
self._data["sysuserid"])
|
|
|
|
|
|
|
|
def __init__(self, argv):
|
2008-06-07 23:25:35 +02:00
|
|
|
"""Constructor for the sysuser command."""
|
2007-07-02 11:14:47 +02:00
|
|
|
CliCommand.CliCommand.__init__(self, argv)
|