diff options
author | Peter Hatina <phatina@redhat.com> | 2012-10-08 12:25:40 +0200 |
---|---|---|
committer | Peter Hatina <phatina@redhat.com> | 2012-10-08 12:25:40 +0200 |
commit | 2432fde4e7106da58ba0fa62e06e90df7dcc42bf (patch) | |
tree | 2ddcbeee2173e75697e1b3fb834ba31ee2e5f8c7 | |
parent | 167c13bdf07c2a86ff7043b4b874073556858e69 (diff) | |
download | openlmi-providers-2432fde4e7106da58ba0fa62e06e90df7dcc42bf.tar.gz openlmi-providers-2432fde4e7106da58ba0fa62e06e90df7dcc42bf.tar.xz openlmi-providers-2432fde4e7106da58ba0fa62e06e90df7dcc42bf.zip |
cli-tools moved to its own repo
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | cli-tools/CMakeLists.txt | 34 | ||||
-rwxr-xr-x | cli-tools/cura-power.py | 74 | ||||
-rwxr-xr-x | cli-tools/cura-service.py | 92 | ||||
-rwxr-xr-x | cli-tools/cura-user.py | 181 | ||||
-rw-r--r-- | cli-tools/cura/__init__.py | 0 | ||||
-rw-r--r-- | cli-tools/cura/cura_address.py | 79 | ||||
-rw-r--r-- | cli-tools/cura/cura_client_power.py | 72 | ||||
-rw-r--r-- | cli-tools/cura/cura_client_service.py | 135 | ||||
-rw-r--r-- | cli-tools/cura/cura_client_user.py | 154 | ||||
-rw-r--r-- | cli-tools/cura/cura_options.py | 62 | ||||
-rw-r--r-- | cli-tools/setup.py | 29 |
13 files changed, 0 insertions, 914 deletions
@@ -3,5 +3,4 @@ build/ .gitignore *.kdev4 -*.pyc diff --git a/CMakeLists.txt b/CMakeLists.txt index 58de8a1..f32881d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,6 @@ find_package(KonkretCMPI REQUIRED) add_subdirectory(src) add_subdirectory(mof) -add_subdirectory(cli-tools) install(PROGRAMS register.sh reg2pegasus.py DESTINATION share/cura-providers) install(FILES cmake/modules/CuraMacros.cmake DESTINATION share/cmake/Modules) diff --git a/cli-tools/CMakeLists.txt b/cli-tools/CMakeLists.txt deleted file mode 100644 index da392b1..0000000 --- a/cli-tools/CMakeLists.txt +++ /dev/null @@ -1,34 +0,0 @@ -cmake_minimum_required(VERSION 2.6) - -set(PYTHON python) -set(PYTHON_BIN_PATH bin) -exec_program( - ${PYTHON} - ARGS "-c \"from distutils.sysconfig import get_python_lib; print(get_python_lib())\"" - OUTPUT_VARIABLE PYTHON_SITE_PACKAGES_PATH -) - -add_custom_target( - PythonInstall ALL - COMMAND ${PYTHON} setup.py install - --install-lib ${PYTHON_SITE_PACKAGES_PATH} - --install-scripts ${PYTHON_BIN_PATH} - --root install - WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} -) - -install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/install/bin - DESTINATION ${CMAKE_INSTALL_PREFIX} - FILES_MATCHING - PATTERN "*.py" - PERMISSIONS - OWNER_READ OWNER_WRITE OWNER_EXECUTE - GROUP_READ GROUP_EXECUTE - WORLD_READ WORLD_EXECUTE -) - -install( - DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/install/usr/lib - DESTINATION ${CMAKE_INSTALL_PREFIX} -) diff --git a/cli-tools/cura-power.py b/cli-tools/cura-power.py deleted file mode 100755 index 4a22d38..0000000 --- a/cli-tools/cura-power.py +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> -# -# 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, see <http://www.gnu.org/licenses/>. - -import sys - -from cura.cura_options import CuraBasicOptions -from cura.cura_address import CuraIpv4Addr, CuraIpv4AddrGenerator -from cura.cura_client_power import CuraPowerClient - -class CuraPowerOptions(CuraBasicOptions): - def __init__(self): - super(self.__class__, self).__init__( - "Available actions:\n" - " poweroff, reboot, suspend, hibernate\n" - " force-poweroff, force-reboot\n") - self.m_parser.set_usage("Usage %prog [options] action") - - @property - def good(self): - return len(self.m_pos_options) == 1 - - @property - def action(self): - return self.m_pos_options[0] if self.good and self.m_pos_options[0] else "" - -if __name__ == "__main__": - options = CuraPowerOptions() - options.parse(sys.argv) - if not options.good: - sys.stderr.write( - "Wrong tool usage. Run " + __file__ + - " --help for detailed help.\n") - sys.exit(1) - - client_failed = False - client_hostnames = CuraIpv4AddrGenerator(options.hostname).enumerate() - client_action = options.action.lower() - for client_hostname in client_hostnames: - if not len(client_hostname): - continue - client = CuraPowerClient(client_hostname, options.username, options.password) - actions = { - "reboot": (client.reboot, "Reboot: "), - "poweroff": (client.poweroff, "Poweroff: "), - "suspend": (client.suspend, "Suspend: "), - "hibernate": (client.hibernate, "Hibernate: ") - } - - if not client_action in actions: - sys.stdout.write("No such action to perform!\n") - sys.exit(1) - - (rval, rparam) = actions[client_action][0]() - if rval: - sys.stdout.write("%s: %s\n" % (client_hostname, - actions[client_action][1] + rparam if rparam else "ok")) - else: - sys.stderr.write("%s: %s\n" % (client_hostname, rparam)) - client_failed = True - - sys.exit(client_failed) diff --git a/cli-tools/cura-service.py b/cli-tools/cura-service.py deleted file mode 100755 index aab2876..0000000 --- a/cli-tools/cura-service.py +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> -# -# 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, see <http://www.gnu.org/licenses/>. - -import sys - -from cura.cura_options import CuraBasicOptions -from cura.cura_address import CuraIpv4Addr, CuraIpv4AddrGenerator -from cura.cura_client_service import CuraServiceClient - -class CuraServiceOptions(CuraBasicOptions): - def __init__(self): - super(self.__class__, self).__init__( - "Available actions:\n" - " start, stop, restart, enable, disable, reload,\n" - " try-restart, cond-restart, reload-or-restart,\n" - " reload-or-try-restart, status\n") - self.m_parser.set_usage("Usage: %prog [options] action service") - - @property - def good(self): - return len(self.m_pos_options) == 2 - - @property - def action(self): - return self.m_pos_options[0] if self.good and self.m_pos_options[0] else "" - - @property - def service(self): - if not self.good: - return "" - return self.m_pos_options[1] if self.good and self.m_pos_options[1] else "" - -if __name__ == "__main__": - options = CuraServiceOptions() - options.parse(sys.argv) - if not options.good: - sys.stderr.write( - "Wrong tool usage. Run " + __file__ + - " --help for detailed help.\n") - sys.exit(1) - - client_failed = False - client_hostnames = CuraIpv4AddrGenerator(options.hostname).enumerate() - client_action = options.action.lower() - for client_hostname in client_hostnames: - if not len(client_hostname): - continue - client = CuraServiceClient(client_hostname, options.username, options.password) - (service, rparam) = client.serviceFind(options.service) - if not service: - sys.stderr.write("%s: %s\n" % (client_hostname, rparam)) - continue - actions = { - "start": (service.start, "Start: "), - "stop": (service.stop, "Stop: "), - "restart": (service.restart, "Restart: "), - "enable": (service.enable, "Enabling: "), - "disable": (service.disable, "Disabling: "), - "reload": (service.reload, "Reload: "), - "try-restart": (service.tryRestart, "Try to restart: "), - "cond-restart": (service.condRestart, "Conditional restart: "), - "reload-or-restart": (service.reloadRestart, "Reload or restart: "), - "reload-or-try-restart": (service.reloadTryRestart, "Reload or try restart: "), - "status": (service.status, "Service status: ") - } - - if not client_action in actions: - sys.stderr.write("No such action to perform!\n") - sys.exit(1) - - (rval, rparam) = actions[client_action][0]() - if rval: - sys.stdout.write("%s: %s\n" % (client_hostname, - actions[client_action][1] + rparam if rparam else "ok")) - else: - sys.stderr.write("%s: %s\n" % (client_hostname, rparam)) - client_failed = True - - sys.exit(client_failed) diff --git a/cli-tools/cura-user.py b/cli-tools/cura-user.py deleted file mode 100755 index e229fb6..0000000 --- a/cli-tools/cura-user.py +++ /dev/null @@ -1,181 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> -# -# 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, see <http://www.gnu.org/licenses/>. - -import os -import sys - -from cura.cura_options import CuraBasicOptions -from cura.cura_address import CuraIpv4Addr, CuraIpv4AddrGenerator -from cura.cura_client_user import CuraUserClient - -class CuraUserOptions(CuraBasicOptions): - def __init__(self): - script_name = os.path.basename(__file__) - super(self.__class__, self).__init__( - "Available actions:\n" - " list-users, list-groups, group-members\n" - " useradd\n\n" - "Group-members:\n" - " " + script_name + " [options] group-members groupName\n\n" - "Useradd:\n" - " " + script_name + " [options] useradd newUsername\n\n") - self.m_parser.set_usage("Usage: %prog [options] action") - self.m_parser.add_option("-s", "--shell", - action = "store", - dest = "shell", - help = "login shell of the new account") - self.m_parser.add_option("-r", "--system-account", - action = "store_true", - dest = "system_account", - help = "create a system account") - self.m_parser.add_option("-m", "--create-home", - action = "store_true", - dest = "create_home", - help = "create the user's home directory") - self.m_parser.add_option("-M", "--no-create-home", - action = "store_false", - dest = "create_home", - help = "do not create the user's home directory") - self.m_parser.add_option("-N", "--no-user-group", - action = "store_false", - dest = "create_group", - help = "do not create a group with the same name as the user") - self.m_parser.add_option("-g", "--gid", - action = "store", - dest = "gid", - help = "name or ID of the primary group of the new account") - self.m_parser.add_option("", "--gecos", - action = "store", - dest = "gecos", - help = "GECOS information for new user") - self.m_parser.add_option("-d", "--home-dir", - action = "store", - dest = "home_dir", - help = "home directory of the new account") - self.m_parser.add_option("-n", "--new-password", - action = "store", - dest = "new_password", - help = "password for the new account") - self.m_parser.add_option("-i", "--uid", - action = "store", - dest = "uid", - help = "user ID of the new account") - - @property - def good(self): - if not len(self.m_pos_options): - return False - elif self.m_pos_options[0] == "group-members": - return len(self.m_pos_options) == 2 - elif self.m_pos_options[0] == "useradd": - return len(self.m_pos_options) == 2 - return len(self.m_pos_options) == 1 - - @property - def action(self): - return self.m_pos_options[0] if self.good and self.m_pos_options[0] else "" - - @property - def group(self): - return self.m_pos_options[1] if self.good and self.m_pos_options[1] else "" - - @property - def newUsername(self): - return self.m_pos_options[1] if self.good and self.m_pos_options[1] else "" - - @property - def shell(self): - return self.m_options.shell if self.good and self.m_options.shell else "" - - @property - def systemAccount(self): - return self.m_options.system_account if self.good and self.m_options.system_account else False - - @property - def createHome(self): - return self.m_options.create_home in (None, True) if self.good else False - - @property - def createGroup(self): - return self.m_options.create_group in (None, True) if self.good else True - - @property - def gid(self): - return self.m_options.gid if self.good and self.m_options.gid else "" - - @property - def gecos(self): - return self.m_options.gecos if self.good and self.m_options.gecos else "" - - @property - def homeDir(self): - return self.m_options.home_dir if self.good and self.m_options.home_dir else "" - - @property - def newPassword(self): - return self.m_options.new_password if self.good and self.m_options.new_password else "" - - @property - def uid(self): - return self.m_options.uid if self.good and self.m_options.uid else "" - -if __name__ == "__main__": - options = CuraUserOptions() - options.parse(sys.argv) - if not options.good: - sys.stderr.write( - "Wrong tool usage. Run " + __file__ + " --help for detailed help.\n") - sys.exit(1) - - client_failed = False - client_hostnames = CuraIpv4AddrGenerator(options.hostname).enumerate() - client_action = options.action.lower() - for client_hostname in client_hostnames: - if not len(client_hostname): - continue - client = CuraUserClient(client_hostname, options.username, options.password) - actions = { - "list-users" : client.listUsers, - "list-groups" : client.listGroups - } - - if client_action == "group-members": - (rval, rparam) = client.listGroupMembers(options.group) - elif client_action == "useradd": - (rval, rparam) = client.userAdd( - options.newUsername, - shell = options.shell, - systemAccount = options.systemAccount, - createHome = options.createHome, - createGroup = options.createGroup, - homeDir = options.homeDir, - uid = options.uid, - gid = options.gid, - password = options.newPassword, - gecos = options.gecos) - elif client_action in actions: - (rval, rparam) = actions[client_action]() - else: - sys.stderr.write("No such action to perform!\n") - sys.exit(1) - - if rval: - sys.stdout.write("%s: %s\n" % (client_hostname, rparam if rparam else "ok")) - else: - sys.stderr.write("%s: %s\n" % (client_hostname, rparam)) - client_failed = True - - sys.exit(client_failed) diff --git a/cli-tools/cura/__init__.py b/cli-tools/cura/__init__.py deleted file mode 100644 index e69de29..0000000 --- a/cli-tools/cura/__init__.py +++ /dev/null diff --git a/cli-tools/cura/cura_address.py b/cli-tools/cura/cura_address.py deleted file mode 100644 index 467a1c2..0000000 --- a/cli-tools/cura/cura_address.py +++ /dev/null @@ -1,79 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> -# -# 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, see <http://www.gnu.org/licenses/>. - -import re -import sys -import itertools - -class CuraIpv4Addr: - class CuraIpv4Member: - def __init__(self, member): - self.m_member = member - - def enumerate(self): - pattern = re.compile("^{(.*)}$") - match = pattern.search(self.m_member) - member = match.group(1) if match else [] - if not member: - return [self.m_member] - ranges = (x.split("-") for x in member.split(";")) - try: - members = [] - for r in ranges: - if not 0 <= int(r[0]) <= 255 or not 0 <= int(r[-1]) <= 255: - return [] - low = int(r[0]) - high = int(r[-1]) - if low > high: - low, high = high, low - members += [str(i) for i in range(low, high + 1)] - except ValueError: - return [] - return members - - def __init__(self, addr_pattern): - self.m_addr_pattern = addr_pattern - - def enumerate(self): - str_members = self.m_addr_pattern.split(".") - if len(str_members) != 4: - return [] - members = [] - for m in str_members: - ipm = CuraIpv4Addr.CuraIpv4Member(m) - members.append(ipm) - addresses = members[3].enumerate() - if not addresses: - return [] - for i in reversed(range(0, 3)): - combined = [] - members_to_combine = members[i].enumerate() - if not members_to_combine: - return [] - for r in itertools.product(members_to_combine, addresses): - combined.append(".".join([r[0], r[1]])) - addresses = combined - return sorted(set(addresses)) - -class CuraIpv4AddrGenerator: - def __init__(self, addresses): - self.m_addresses = addresses - - def enumerate(self): - rval = [] - for addr in self.m_addresses.split(","): - rval += CuraIpv4Addr(addr).enumerate() - return rval diff --git a/cli-tools/cura/cura_client_power.py b/cli-tools/cura/cura_client_power.py deleted file mode 100644 index c2e7b27..0000000 --- a/cli-tools/cura/cura_client_power.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> -# -# 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, see <http://www.gnu.org/licenses/>. - -import pywbem - -class CuraPowerClient(): - POWER_CLASS_NAME = "LMI_PowerManagementService" - POWER_STATE_SUSPEND = 4 - POWER_STATE_FORCE_REBOOT = 5 - POWER_STATE_HIBERNATE = 7 - POWER_STATE_FORCE_POWEROFF = 8 - POWER_STATE_POWEROFF = 12 - POWER_STATE_REBOOT = 15 - - def __init__(self, hostname, username="", password=""): - self.m_hostname = hostname - self.m_username = username - self.m_password = password - self.m_cliconn = pywbem.WBEMConnection("https://" + self.m_hostname, - (self.m_username, self.m_password)) - - def __getPowerInstance(self): - try: - inst_name_list = self.m_cliconn.EnumerateInstanceNames( - CuraPowerClient.POWER_CLASS_NAME) - except pywbem.cim_operations.CIMError, e: - return (None, e.args[1]) - except pywbem.cim_http.AuthError, e: - return (None, e.args[0]) - inst_list = self.m_cliconn.GetInstance(inst_name_list[0], - LocalOnly=False) - return (inst_list, "") - - def __powerCallMethod(self, method, **params): - (inst, rparam) = self.__getPowerInstance() - if not inst: - return (False, rparam) - try: - (rval, rparams) = self.m_cliconn.InvokeMethod(method, - inst.path, **params) - except pywbem.cim_operations.CIMError, e: - return (False, e.args[1]) - return (rval in (0, 4096), "") - - def poweroff(self): - return self.__powerCallMethod("RequestPowerStateChange", - PowerState=pywbem.Uint16(CuraPowerClient.POWER_STATE_POWEROFF)) - - def reboot(self): - return self.__powerCallMethod("RequestPowerStateChange", - PowerState=pywbem.Uint16(CuraPowerClient.POWER_STATE_REBOOT)) - - def suspend(self): - return self.__powerCallMethod("RequestPowerStateChange", - PowerState=pywbem.Uint16(CuraPowerClient.POWER_STATE_SUSPEND)) - - def hibernate(self): - return self.__powerCallMethod("RequestPowerStateChange", - PowerState=pywbem.Uint16(CuraPowerClient.POWER_STATE_HIBERNATE)) diff --git a/cli-tools/cura/cura_client_service.py b/cli-tools/cura/cura_client_service.py deleted file mode 100644 index cf2235e..0000000 --- a/cli-tools/cura/cura_client_service.py +++ /dev/null @@ -1,135 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> -# -# 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, see <http://www.gnu.org/licenses/>. - -import pywbem - -class CuraService(): - def __init__(self, client, inst): - self.m_client = client - self.m_instance = inst - - def start(self): - return self.m_client.serviceStart(self.m_instance) - - def stop(self): - return self.m_client.serviceStop(self.m_instance) - - def restart(self): - return self.m_client.serviceRestart(self.m_instance) - - def enable(self): - return self.m_client.serviceEnable(self.m_instance) - - def disable(self): - return self.m_client.serviceDisable(self.m_instance) - - def reload(self): - return self.m_client.serviceReload(self.m_instance) - - def tryRestart(self): - return self.m_client.serviceTryRestart(self.m_instance) - - def condRestart(self): - return self.m_client.serviceCondRestart(self.m_instance) - - def reloadRestart(self): - return self.m_client.serviceReloadRestart(self.m_instance) - - def reloadTryRestart(self): - return self.m_client.serviceReloadTryRestart(self.m_instance) - - def status(self): - return self.m_client.serviceStatus(self.m_instance) - -class CuraServiceClient(): - SERVICE_CLASS_NAME = "LMI_Service" - - def __init__(self, hostname, username = "", password = ""): - self.m_hostname = hostname - self.m_username = username - self.m_password = password - self.m_cliconn = pywbem.WBEMConnection("https://" + self.m_hostname, - (self.m_username, self.m_password)) - - def __serviceGetInstance(self, service): - try: - inst_name_list = self.m_cliconn.EnumerateInstanceNames( - CuraServiceClient.SERVICE_CLASS_NAME) - except pywbem.cim_operations.CIMError, e: - return (None, e.args[1]) - except pywbem.cim_http.AuthError, e: - return (None, e.args[0]) - inst_name = filter(lambda n: n["Name"] == service, inst_name_list) - if not len(inst_name): - return (None, "No such service '" + service + "' found.") - inst_list = self.m_cliconn.GetInstance(inst_name[0], - LocalOnly = False) - return (inst_list, "") - - def __serviceCallMethod(self, service, method): - (inst, rparam) = self.__serviceGetInstance(service) if type(service) == str else (service, "") - if not inst: - return (False, rparam) - try: - (rval, params) = self.m_cliconn.InvokeMethod(method, inst.path) - except pywbem.cim_operations.CIMError, e: - return (False, e.args[1] + ": '" + method + "'") - return (rval == 0, "") - - def __serviceGetProperty(self, service, prop): - (inst, rparam) = self.__serviceGetInstance(service) if type(service) == str else (service, "") - if not inst or not prop in inst: - return (False, rparam) - return (True, inst[prop]) - - def serviceFind(self, service): - (inst, rparam) = self.__serviceGetInstance(service) - if not inst: - return (None, rparam) - return (CuraService(self, inst), "") - - def serviceStart(self, service): - return self.__serviceCallMethod(service, "StartService") - - def serviceStop(self, service): - return self.__serviceCallMethod(service, "StopService") - - def serviceRestart(self, service): - return self.__serviceCallMethod(service, "RestartService") - - def serviceEnable(self, service): - return self.__serviceCallMethod(service, "TurnServiceOn") - - def serviceDisable(self, service): - return self.__serviceCallMethod(service, "TurnServiceOff") - - def serviceReload(self, service): - return self.__serviceCallMethod(service, "ReloadService") - - def serviceTryRestart(self, service): - return self.__serviceCallMethod(service, "TryRestartService") - - def serviceCondRestart(self, service): - return self.__serviceCallMethod(service, "CondRestartService") - - def serviceReloadRestart(self, service): - return self.__serviceCallMethod(service, "ReloadOrRestartService") - - def serviceReloadTryRestart(self, service): - return self.__serviceCallMethod(service, "ReloadOrTryRestartService") - - def serviceStatus(self, service): - return self.__serviceGetProperty(service, "Status") diff --git a/cli-tools/cura/cura_client_user.py b/cli-tools/cura/cura_client_user.py deleted file mode 100644 index 3f92dc3..0000000 --- a/cli-tools/cura/cura_client_user.py +++ /dev/null @@ -1,154 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> -# -# 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, see <http://www.gnu.org/licenses/>. - -import sys -import pywbem - -class CuraUserClient(): - USER_CLASS_NAME = "LMI_Account" - GROUP_CLASS_NAME = "LMI_Group" - MEMBER_OF_GROUP_CLASS_NAME = "LMI_MemberOfGroup" - ASSIGNED_IDENTITY_CLASS_NAME = "LMI_AssignedAccountIdentity" - ACCOUNT_MANAGEMENT_SERVICE_CLASS_NAME = "LMI_AccountManagementService" - COMPUTER_SYSTEM_CLASS_NAME = "CIM_ComputerSystem" - - def __init__(self, hostname, username = "", password = ""): - self.m_hostname = hostname - self.m_username = username - self.m_password = password - self.m_cliconn = pywbem.WBEMConnection("https://" + self.m_hostname, - (self.m_username, self.m_password)) - - def __getInstances(self, klass, filter_name = ""): - try: - inst_name_list = self.m_cliconn.EnumerateInstanceNames(klass) - except pywbem.cim_operations.CIMError, e: - return (None, e.args[1]) - except pywbem.cim_http.AuthError, e: - return (None, e.args[0]) - inst_names = inst_name_list - if len(filter_name): - inst_names = filter(lambda n: n["Name"] == filter_name, inst_name_list) - inst_list = [] - for i in inst_names: - inst_list.append(self.m_cliconn.GetInstance(i, LocalOnly = False)) - if not len(inst_list): - return (None, "Not found") - return (inst_list, "") - - def __getUserInstances(self): - return self.__getInstances(CuraUserClient.USER_CLASS_NAME) - - def __getGroupInstances(self): - return self.__getInstances(CuraUserClient.GROUP_CLASS_NAME) - - def __getAccountManagementInstance(self): - return self.__getInstances(CuraUserClient.ACCOUNT_MANAGEMENT_SERVICE_CLASS_NAME) - - def __getComputerSystemInstance(self): - return self.__getInstances(CuraUserClient.COMPUTER_SYSTEM_CLASS_NAME) - - def __getMemberGroups(self, inst): - members = [] - identities = self.m_cliconn.Associators(inst.path, - AssocClass = CuraUserClient.ASSIGNED_IDENTITY_CLASS_NAME) - for identity in identities: - accounts = self.m_cliconn.Associators(identity.path, - AssocClass = CuraUserClient.MEMBER_OF_GROUP_CLASS_NAME) - members.extend(accounts) - return members - - def __getGroupMembers(self, inst): - members = [] - for g in inst: - identities = self.m_cliconn.Associators(g.path, - AssocClass = CuraUserClient.MEMBER_OF_GROUP_CLASS_NAME) - for i in identities: - accounts = self.m_cliconn.Associators(i.path, - AssocClass = CuraUserClient.ASSIGNED_IDENTITY_CLASS_NAME) - for a in accounts: - members.append(a["Name"]) - return members - - def listUsers(self): - (inst_list, rparam) = self.__getUserInstances() - if not inst_list: - return (False, "No users found") - sys.stdout.write("%s:\n" % self.m_hostname) - try: - for i in inst_list: - groups = self.__getMemberGroups(i) - gid = groups[0]["InstanceID"].split(":")[-1] - sys.stdout.write("%s:x:%s:%s:%s:%s:%s\n" % - (i["Name"], i["UserID"], gid, i["ElementName"], - i["HomeDirectory"], i["LoginShell"])) - except pywbem.cim_operations.CIMError, e: - return (False, e.args[1]) - return (True, "") - - def listGroups(self): - (inst_list, rparam) = self.__getGroupInstances() - if not inst_list: - return (False, "No groups found") - for i in inst_list: - sys.stdout.write("%s:%s\n" % - (i["Name"], i["InstanceID"].split(":")[-1])) - return (True, "") - - def listGroupMembers(self, member): - (inst_list, rparam) = self.__getInstances( - CuraUserClient.GROUP_CLASS_NAME, member) - if not inst_list: - return (False, "No such group '%s' found" % member) - members = self.__getGroupMembers(inst_list) - for m in members: - sys.stdout.write("%s\n" % m) - return (True, "") - - def userAdd(self, user_name, **params): - (inst_management, rparam) = self.__getAccountManagementInstance() - if not inst_management: - return (False, rparam) - # We are using the first and only instance present. - # For KVM_ComputerSystem, there has be some CLI option added. - inst_management = inst_management[0] - (inst_computer_system, rparam) = self.__getComputerSystemInstance() - if not inst_computer_system: - return (False, rparam) - user_params = { "Name" : user_name } - user_params["DontCreateHome"] = not params["createHome"] - user_params["System"] = inst_computer_system[0].path - user_params["DontCreateGroup"] = not params["createGroup"] - if params["shell"]: - user_params["Shell"] = params["shell"] - if params["systemAccount"]: - user_params["SystemAccount"] = params["systemAccount"] - if params["gid"]: - user_params["GID"] = pywbem.Uint32(params["gid"]) - if params["gecos"]: - user_params["GECOS"] = params["gecos"] - if params["homeDir"]: - user_params["HomeDirectory"] = params["homeDir"] - if params["password"]: - user_params["Password"] = params["password"] - if params["uid"]: - user_params["UID"] = pywbem.Uint32(params["uid"]) - try: - (account, identity) = self.m_cliconn.InvokeMethod( - "CreateAccount", inst_management.path, **user_params) - except pywbem.CIMError, e: - return (False, e.args[1]) - return (account != None, "") diff --git a/cli-tools/cura/cura_options.py b/cli-tools/cura/cura_options.py deleted file mode 100644 index 429740a..0000000 --- a/cli-tools/cura/cura_options.py +++ /dev/null @@ -1,62 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> -# -# 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, see <http://www.gnu.org/licenses/>. - -import sys -import optparse - -class CuraBasicOptions(object): - def __init__(self, epil = ""): - optparse.OptionParser.format_epilog = lambda self, formatter: self.epilog - self.m_parser = optparse.OptionParser( - add_help_option = False, - epilog = epil) - self.m_parser.add_option("", "--help", - action="help", - help = "print this message") - self.m_parser.add_option("-h", "--hostname", - action = "store", - dest = "hostname", - help = "remote machine hostname") - self.m_parser.add_option("-u", "--username", - action = "store", - dest = "username", - help = "remote machine username") - self.m_parser.add_option("-p", "--password", - action = "store", - dest = "password", - help = "remote machine password") - - def parse(self, argv): - (self.m_options, self.m_pos_options) = self.m_parser.parse_args(argv[1:]) - - def printHelp(self): - self.m_parser.print_help() - - @property - def good(self): - return len(self.m_pos_options) == 0 - - @property - def hostname(self): - return self.m_options.hostname if self.m_options.hostname else "" - - @property - def username(self): - return self.m_options.username if self.m_options.username else "" - - @property - def password(self): - return self.m_options.password if self.m_options.password else "" diff --git a/cli-tools/setup.py b/cli-tools/setup.py deleted file mode 100644 index 0232b4d..0000000 --- a/cli-tools/setup.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env python -# Copyright (C) 2012 Peter Hatina <phatina@redhat.com> -# -# 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, see <http://www.gnu.org/licenses/>. - -from setuptools import setup - -setup( - name = "cura", - version = "0.1", - author = "Peter Hatina", - author_email = "phatina@redhat.com", - description = "CLI tools interfacing cura-providers.", - license = "GPLv2", - keywords = "cura service user power", - packages = ["cura"], - scripts = ["cura-service.py", "cura-power.py", "cura-user.py"] -) |