Repository : http://git.fedorahosted.org/cgit/cura-tools.git
On branch : master
commit 3760f122668f9f1ebcc029581d13c5b5d78405d3 Author: Peter Hatina phatina@redhat.com Date: Mon Dec 10 11:02:10 2012 +0100
switch to LmiReturnValue wherever possible
cli-tools/lmi-ip.py | 8 ++-- cli-tools/lmi-power.py | 2 +- cli-tools/lmi-service.py | 11 ++++-- cli-tools/lmi-user.py | 6 ++-- cli-tools/lmi/lmi_client_base.py | 51 +++++++++++++++-------------- cli-tools/lmi/lmi_client_ip.py | 61 ++++++++++++++++++----------------- cli-tools/lmi/lmi_client_power.py | 10 +++--- cli-tools/lmi/lmi_client_service.py | 29 ++++++++-------- cli-tools/lmi/lmi_client_shell.py | 25 ++++++-------- cli-tools/lmi/lmi_client_user.py | 45 +++++++++++++------------ 10 files changed, 127 insertions(+), 121 deletions(-)
diff --git a/cli-tools/lmi-ip.py b/cli-tools/lmi-ip.py index e32f192..d548ab8 100755 --- a/cli-tools/lmi-ip.py +++ b/cli-tools/lmi-ip.py @@ -141,13 +141,13 @@ if __name__ == "__main__": if options.object == LmiIpOptions.OBJ_ADDR: if options.operation == LmiIpOptions.OP_SHOW: if options.device: - (rval, errorstr) = client.ip_list_devices(options.device) + (rval, _, errorstr) = client.ip_list_devices(options.device) else: - (rval, errorstr) = client.ip_list_devices() + (rval, _, errorstr) = client.ip_list_devices() elif options.operation == LmiIpOptions.OP_SET: - (rval, errorstr) = client.ip_set_address(options.device, options.ifaddr) + (rval, _, errorstr) = client.ip_set_address(options.device, options.ifaddr) elif options.operation == LmiIpOptions.OP_DEL: - (rval, errorstr) = client.ip_del_address(options.device) + (rval, _, errorstr) = client.ip_del_address(options.device) elif options.object == LmiIpOptions.OBJ_ROUTE: # TODO: implement sys.stderr.write("Route operation not implemented yet!\n") diff --git a/cli-tools/lmi-power.py b/cli-tools/lmi-power.py index 0e5a87c..380d0de 100755 --- a/cli-tools/lmi-power.py +++ b/cli-tools/lmi-power.py @@ -61,7 +61,7 @@ if __name__ == "__main__": sys.stdout.write("No such action to perform!\n") sys.exit(1)
- (rval, errorstr) = actions[client_action][0]() + (rval, _, errorstr) = actions[client_action][0]() if rval: sys.stdout.write("%s: %s\n" % (client_hostname.name, actions[client_action][1] + errorstr if errorstr else "ok")) diff --git a/cli-tools/lmi-service.py b/cli-tools/lmi-service.py index 324254a..826f7f3 100755 --- a/cli-tools/lmi-service.py +++ b/cli-tools/lmi-service.py @@ -57,7 +57,7 @@ if __name__ == "__main__": if not client_hostname: continue client = LmiServiceClient(client_hostname.name, options.username, options.password) - (service, errorstr) = client.service_find(options.service) + (service, _, errorstr) = client.service_find(options.service) if not service: sys.stderr.write("%s: %s\n" % (client_hostname.name, errorstr)) client_failed = True @@ -80,10 +80,15 @@ if __name__ == "__main__": sys.stderr.write("No such action to perform!\n") sys.exit(1)
- (rval, errorstr) = actions[client_action][0]() + (rval, rparams, errorstr) = actions[client_action][0]() if rval: + msg = "ok" + if errorstr: + msg = errorstr + elif "Message" in rparams: + msg = rparams["Message"] sys.stdout.write("%s: %s\n" % (client_hostname.name, - actions[client_action][1] + errorstr if errorstr else "ok")) + actions[client_action][1] + msg)) else: sys.stderr.write("%s: %s\n" % (client_hostname.name, errorstr)) client_failed = True diff --git a/cli-tools/lmi-user.py b/cli-tools/lmi-user.py index 1b0887f..63deeab 100755 --- a/cli-tools/lmi-user.py +++ b/cli-tools/lmi-user.py @@ -152,9 +152,9 @@ if __name__ == "__main__": }
if client_action == "group-members": - (rval, errorstr) = client.list_group_members(options.group) + (rval, _, errorstr) = client.list_group_members(options.group) elif client_action == "useradd": - (rval, errorstr) = client.user_add( + (rval, _, errorstr) = client.user_add( options.new_username, shell = options.shell, systemAccount = options.system_account, @@ -166,7 +166,7 @@ if __name__ == "__main__": password = options.new_password, gecos = options.gecos) elif client_action in actions: - (rval, errorstr) = actions[client_action]() + (rval, _, errorstr) = actions[client_action]() else: sys.stderr.write("No such action to perform!\n") sys.exit(1) diff --git a/cli-tools/lmi/lmi_client_base.py b/cli-tools/lmi/lmi_client_base.py index 0bc23ff..639839b 100644 --- a/cli-tools/lmi/lmi_client_base.py +++ b/cli-tools/lmi/lmi_client_base.py @@ -68,76 +68,79 @@ class LmiBaseClient(object): try: inst_name_list = self._cliconn.EnumerateInstanceNames(klass, **kwargs) except pywbem.cim_operations.CIMError, e: - return (None, e.args[1]) + return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[1]) except pywbem.cim_http.AuthError, e: - return (None, e.args[0]) - return (inst_name_list, "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[0]) + return LmiReturnValue(rval = inst_name_list, rparams = {}, errorstr = "")
def _get_instance(self, path, **kwargs): inst = self._cliconn.GetInstance(path, **kwargs) if not inst: - return (None, "No such class instance") - return (inst, "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = "No such class instance") + return LmiReturnValue(rval = inst, rparams = {}, errorstr = "")
def _get_instances(self, klass, filter_key = "", **kwargs): - (inst_name_list, errorstr) = self._get_instance_names(klass, **kwargs) + key = "Name" + if "Key" in kwargs: + key = kwargs["Key"] + kwargs.pop("Key") + (inst_name_list, rparams, errorstr) = self._get_instance_names(klass, **kwargs) if not inst_name_list: - return (None, errorstr) + return LmiReturnValue(rval = None, rparams = {}, errorstr = errorstr) inst_names = inst_name_list if len(filter_key): - key = kwargs["Key"] if "Key" in kwargs else "Name" inst_names = filter(lambda n: n[key] == filter_key, inst_name_list) inst_list = [] for i in inst_names: inst_list.append(self._cliconn.GetInstance(i, LocalOnly = False)) if not len(inst_list): - return (None, "Not found" if not "ErrorMsg" in kwargs else kwargs["ErrorMsg"]) - return (inst_list, "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = "Not found" if not "ErrorMsg" in kwargs else kwargs["ErrorMsg"]) + return LmiReturnValue(rval = inst_list, rparams = rparams, errorstr = "")
def _delete_instance(self, obj): try: self._cliconn.DeleteInstance(obj.path) except pywbem.cim_operations.CIMError, e: - return (False, e.args[1]) - return (True, "") + return LmiReturnValue(rval = False, rparams = {}, errorstr = e.args[1]) + return LmiReturnValue(rval = True, rparams = {}, errorstr = "")
def _get_class_names(self, namespace = None, **kwargs): try: class_name_list = self._cliconn.EnumerateClassNames(namespace, **kwargs) except pywbem.cim_operations.CIMError, e: - return (None, e.args[1]) + return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[1]) except pywbem.cim_http.AuthError, e: - return (None, e.args[0]) - return (class_name_list, "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[0]) + return LmiReturnValue(rval = class_name_list, rparams = {}, errorstr = "")
def _get_classes(self, namespace = None, **kwargs): try: class_list = self._cliconn.EnumerateClasses(namespace, **kwargs) except pywbem.cim_operations.CIMError, e: - return (None, e.args[1]) + return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[1]) except pywbem.cim_http.AuthError, e: - return (None, e.args[0]) - return (class_list, "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[0]) + return LmiReturnValue(rval = class_list, rparams = {}, errorstr = "")
def _get_class(self, class_name, namespace = None, **kwargs): try: klass = self._cliconn.GetClass(class_name, namespace, **kwargs) except pywbem.cim_operations.CIMError, e: - return (None, e.args[1]) + return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[1]) except pywbem.cim_http.AuthError, e: - return (None, e.args[0]) - return (klass, "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = e.args[0]) + return LmiReturnValue(rval = klass, rparams = {}, errorstr = "")
def _call_method_raw(self, instance, method, **params): try: (rval, rparams) = self._cliconn.InvokeMethod(method, instance.path, **params) except pywbem.cim_operations.CIMError, e: - return (-1, {}, e.args[1] + ": '" + method + "'") - return (rval, rparams, "") + return LmiReturnValue(rval = -1, rparams = {}, errorstr = e.args[1] + ": '" + method + "'") + return LmiReturnValue(rval = rval, rparams = rparams, errorstr = "")
def _call_method(self, instance, method, **params): (rval, rparams, errorstr) = self._call_method_raw(instance, method, **params) - return (rval == 0, rparams, errorstr) + return LmiReturnValue(rval = rval == 0, rparams = rparams, errorstr = errorstr)
def _get_associators(self, instance, **params): return self._cliconn.Associators(instance.path, **params) diff --git a/cli-tools/lmi/lmi_client_ip.py b/cli-tools/lmi/lmi_client_ip.py index 7dc4df8..af6bd04 100644 --- a/cli-tools/lmi/lmi_client_ip.py +++ b/cli-tools/lmi/lmi_client_ip.py @@ -16,6 +16,7 @@ import sys import pywbem from lmi_client_base import LmiBaseClient +from lmi_client_base import LmiReturnValue from lmi_address import LmiIpv4Addr
class LmiIpClient(LmiBaseClient): @@ -30,13 +31,14 @@ class LmiIpClient(LmiBaseClient): super(self.__class__, self).__init__(hostname, username, password)
def __ip_get_ip_protocol_endpoint_instances(self, device = ""): - (inst_list, errorstr) = self._get_instances(LmiIpClient.IP_PROTOCOL_ENDPOINT_CLASS_NAME) + (inst_list, rparams, errorstr) = self._get_instances(LmiIpClient.IP_PROTOCOL_ENDPOINT_CLASS_NAME) if not inst_list: - return (None, errorstr) + return LmiReturnValue(rval = None, rparams = {}, errorstr = errorstr) rval_inst_list = filter(lambda n: device == n["Name"].split("_")[0], inst_list) if device else inst_list if not rval_inst_list: - return (None, "No such device '%s' found" % device) - return (rval_inst_list if len(rval_inst_list) > 1 else rval_inst_list[0], "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = "No such device '%s' found" % device) + return LmiReturnValue(rval = rval_inst_list if len(rval_inst_list) > 1 else rval_inst_list[0], + rparams = rparams, errorstr = "")
def __ip_print_device_info(self, device): device_list = device if type(device) == list else [device] @@ -56,30 +58,30 @@ class LmiIpClient(LmiBaseClient): return self._get_instances(LmiIpClient.LMI_ETHERNET_PORT_CLASS_NAME, device, Key = "DeviceID")
def __ip_get_ip_assignment_setting_data(self, device): - (inst_list, errorstr) = self._get_instances(LmiIpClient.LMI_IP_ASSIGNMENT_SETTING_DATA_CLASS_NAME) + (inst_list, rparams, errorstr) = self._get_instances(LmiIpClient.LMI_IP_ASSIGNMENT_SETTING_DATA_CLASS_NAME) if not inst_list: - return (None, errorstr) + return LmiReturnValue(rval = None, rparams = {}, errorstr = errorstr) inst_list = inst_list if type(inst_list) == list else [inst_list] rval_inst_list = filter(lambda x: x["Caption"] == "static-" + device, inst_list) if not rval_inst_list: - return (None, "No IP setting for device %s found" % device) - return (rval_inst_list, "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = "No IP setting for device %s found" % device) + return LmiReturnValue(rval = rval_inst_list, rparams = rparams, errorstr = "")
def __ip_remove_static_settings(self, device): - (inst_list, errorstr) = self.__ip_get_ip_assignment_setting_data(device) + (inst_list, rparams, errorstr) = self.__ip_get_ip_assignment_setting_data(device) if not inst_list: - return (False, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) for inst in inst_list: - (rval, errorstr) = self._delete_instance(inst) + (rval, rparams, errorstr) = self._delete_instance(inst) if not rval: - return (False, errorstr) - return (True, "") + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) + return LmiReturnValue(rval = True, rparams = rparams, errorstr = "")
def __ip_create_static_setting(self, device, address, **kwargs): self.__ip_remove_static_settings(device) - (device_inst, errorstr) = self.__ip_get_ethernet_port_instance(device) + (device_inst, rparams, errorstr) = self.__ip_get_ethernet_port_instance(device) if not device_inst: - return (False, {}, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) if type(device_inst) is list: device_inst = device_inst[0] prot_type = self.__ip_get_address_type(address) @@ -110,43 +112,42 @@ class LmiIpClient(LmiBaseClient): args["IPv6SearchDomains"] = kwargs["SearchDomains"] if "PrefixLength" in kwargs: args["IPv6PrefixLength"] = pywbem.Uint8(kwargs["PrefixLength"]) - (configuration_inst, errorstr) = self._get_instances(LmiIpClient.IP_CONFIGURATION_SERVICE_CLASS_NAME) + (configuration_inst, rparams, errorstr) = self._get_instances(LmiIpClient.IP_CONFIGURATION_SERVICE_CLASS_NAME) if not configuration_inst: - return (False, {}, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) if type(configuration_inst) is list: configuration_inst = configuration_inst[0] return self._call_method(configuration_inst, "CreateStaticSetting", **args)
def __ip_apply_static_setting(self, device, setting_inst): - (configuration_inst, errorstr) = self._get_instances(LmiIpClient.IP_CONFIGURATION_SERVICE_CLASS_NAME) + (configuration_inst, rparams, errorstr) = self._get_instances(LmiIpClient.IP_CONFIGURATION_SERVICE_CLASS_NAME) if not configuration_inst: - return (False, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) if type(configuration_inst) is list: configuration_inst = configuration_inst[0] - (device_inst, errorstr) = self.__ip_get_ip_protocol_endpoint_instances(device) + (device_inst, rparams, errorstr) = self.__ip_get_ip_protocol_endpoint_instances(device) if type(device_inst) is list: device_inst = device_inst[0] if not device_inst: - return (False, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) args = { "Configuration": setting_inst.path, "Endpoint" : device_inst.path } - (rval, rparam, errorstr) = self._call_method(configuration_inst, "ApplySettingToIPProtocolEndpoint", **args) - return (rval, errorstr) + return self._call_method(configuration_inst, "ApplySettingToIPProtocolEndpoint", **args)
def ip_list_devices(self, device = ""): - (inst_list, errorstr) = self.__ip_get_ip_protocol_endpoint_instances(device) + (inst_list, rparams, errorstr) = self.__ip_get_ip_protocol_endpoint_instances(device) if not inst_list: - return (False, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) self.__ip_print_device_info(inst_list) - return (True, "") + return LmiReturnValue(rval = True, rparams = rparams, errorstr = "")
def ip_set_address(self, device, address, **kwargs): - (rval, rparam, errorstr) = self.__ip_create_static_setting(device, address, **kwargs) - if not rval: - return (False, errorstr) - setting_inst = self._cliconn.GetInstance(rparam["SettingData"], LocalOnly = False) + rval = self.__ip_create_static_setting(device, address, **kwargs) + if not rval.rval: + return rval + setting_inst = self._cliconn.GetInstance(rval.rparams["SettingData"], LocalOnly = False) return self.__ip_apply_static_setting(device, setting_inst)
def ip_del_address(self, device): diff --git a/cli-tools/lmi/lmi_client_power.py b/cli-tools/lmi/lmi_client_power.py index aa66230..7682e88 100644 --- a/cli-tools/lmi/lmi_client_power.py +++ b/cli-tools/lmi/lmi_client_power.py @@ -15,6 +15,7 @@
import pywbem from lmi_client_base import LmiBaseClient +from lmi_client_base import LmiReturnValue
class LmiPowerClient(LmiBaseClient): POWER_CLASS_NAME = "LMI_PowerManagementService" @@ -29,12 +30,11 @@ class LmiPowerClient(LmiBaseClient): super(self.__class__, self).__init__(hostname, username, password)
def __power_call_method(self, method, **params): - (inst, rparam) = self._get_instances(LmiPowerClient.POWER_CLASS_NAME) + (inst, rparams, errorstr) = self._get_instances(LmiPowerClient.POWER_CLASS_NAME) if not inst: - return (False, rparam) - (rval, _, errorstr) = self._call_method(inst[0], method, **params) - rval = rval in (0, 4096) - return (rval, "" if rval else errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) + (rval, rparams, errorstr) = self._call_method_raw(inst[0], method, **params) + return LmiReturnValue(rval = rval in (0, 4096), rparams = rparams, errorstr = "")
def poweroff(self): return self.__power_call_method("RequestPowerStateChange", diff --git a/cli-tools/lmi/lmi_client_service.py b/cli-tools/lmi/lmi_client_service.py index bab9c24..4412b99 100644 --- a/cli-tools/lmi/lmi_client_service.py +++ b/cli-tools/lmi/lmi_client_service.py @@ -15,6 +15,7 @@
import pywbem from lmi_client_base import LmiBaseClient +from lmi_client_base import LmiReturnValue
class LmiService(object): def __init__(self, client, inst): @@ -61,31 +62,29 @@ class LmiServiceClient(LmiBaseClient): super(self.__class__, self).__init__(hostname, username, password)
def __service_get_instance(self, service): - (inst, errorstr) = self._get_instances( - LmiServiceClient.SERVICE_CLASS_NAME, service, - ErrorMsg = "No such service '" + service + "' found") + (inst, rparams, errorstr) = self._get_instances( + LmiServiceClient.SERVICE_CLASS_NAME, service) if not inst: - return (None, errorstr) - return (inst[0], "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = errorstr) + return LmiReturnValue(rval = inst[0], rparams = rparams, errorstr = "")
def __service_call_method(self, service, method): - (inst, errorstr) = self.__service_get_instance(service) if type(service) == str else (service, "") + (inst, rparams, errorstr) = self.__service_get_instance(service) if type(service) == str else (service, {}, "") if not inst: - return (False, errorstr) - (rval, _, errorstr) = self._call_method(inst, method) - return (rval, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) + return self._call_method(inst, method)
def __service_get_property(self, service, prop): - (inst, errorstr) = self.__service_get_instance(service) if type(service) == str else (service, "") + (inst, _, errorstr) = self.__service_get_instance(service) if type(service) == str else (service, {}, "") if not inst or not prop in inst: - return (False, errorstr) - return (True, inst[prop]) + return LmiReturnValue(rval = None, rparams = {}, errorstr = errorstr) + return LmiReturnValue(rval = True, rparams = { "Message" : inst[prop] }, errorstr = "")
def service_find(self, service): - (inst, errorstr) = self.__service_get_instance(service) + (inst, rparams, errorstr) = self.__service_get_instance(service) if not inst: - return (None, errorstr) - return (LmiService(self, inst), "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = errorstr) + return LmiReturnValue(rval = LmiService(self, inst), rparams = rparams, errorstr = "")
def service_start(self, service): return self.__service_call_method(service, "StartService") diff --git a/cli-tools/lmi/lmi_client_shell.py b/cli-tools/lmi/lmi_client_shell.py index 3dc7d9d..b5382ca 100644 --- a/cli-tools/lmi/lmi_client_shell.py +++ b/cli-tools/lmi/lmi_client_shell.py @@ -214,7 +214,7 @@ class _LmiNamespace(BaseObject): self._name = name
def __getattr__(self, name): - (klass, errorstr) = self._client.get_class(name, self._name, LocalOnly = False) + (klass, _, errorstr) = self._client.get_class(name, self._name, LocalOnly = False) if not klass: return None return _LmiClass(self._client, self, klass) @@ -223,7 +223,7 @@ class _LmiNamespace(BaseObject): return "%s(namespace='%s', ...)" % (self.__class__.__name__, self._name)
def classes(self, filter_key = "", exact_match = False): - (class_name_list, errorstr) = self._client.get_class_names(self._name) + (class_name_list, _, errorstr) = self._client.get_class_names(self._name) if not class_name_list: return [] if filter_key: @@ -286,7 +286,7 @@ class _LmiClass(BaseObject): _LmiXmlFormatter(self._class.tocimxml()).fancy_format(self._client.interactive)
def instances(self, filter_key = "", **kwargs): - instance_list = self._client.get_instances(self._class.classname, filter_key, **kwargs) + (instance_list, _, errorstr) = self._client.get_instances(self._class.classname, filter_key, **kwargs) if not instance_list: return [] result = [] @@ -331,11 +331,11 @@ class _LmiInstanceName(BaseObject): return "%s(...)" % self.__class__.__name__
def to_instance(self): - (cim_inst, errorstr) = self._client.get_instance(self._instance_name) + (cim_inst, _, errorstr) = self._client.get_instance(self._instance_name) if not cim_inst: return None lmi_namespace = _LmiNamespace(self._client, self._instance_name.namespace) - (cim_class, errorstr) = self._client.get_class( + (cim_class, _, errorstr) = self._client.get_class( self._instance_name.classname, self._instance_name.namespace, LocalOnly = False) @@ -361,7 +361,7 @@ class _LmiInstance(BaseObject): lmi_rparams = {} for (key, value) in rparams.iteritems(): if isinstance(value, pywbem.cim_obj.CIMInstance): - (lmi_class, errorstr) = self._client.get_class(value.classname, + (lmi_class, _, errorstr) = self._client.get_class(value.classname, value.namespace, LocalOnly = False) if not lmi_class: return None @@ -372,7 +372,7 @@ class _LmiInstance(BaseObject): result = [] for m in value: if isinstance(m, pywbem.cim_obj.CIMInstance): - (lmi_class, errorstr) = self._client.get_class(m.classname, + (lmi_class, _, errorstr) = self._client.get_class(m.classname, m.namespace, LocalOnly = False) if not lmi_class: return None @@ -408,7 +408,7 @@ class _LmiInstance(BaseObject): if not lmi_rparams: # NOTE: this is wrong! What should we do? return return_value - (new_inst, errorstr) = self._client.get_instance(self._instance.path) + (new_inst, _, errorstr) = self._client.get_instance(self._instance.path) if not new_inst: # NOTE: this is wrong! What should we do? return return_value @@ -442,7 +442,7 @@ class _LmiInstance(BaseObject): return "%s(classname='%s', ...)" % (self.__class__.__name__, self.classname)
def __methods(self): - (klass, errorstr) = self._client.get_class(self._inst.classname, self._class.namespace, + (klass, _, errorstr) = self._client.get_class(self._inst.classname, self._class.namespace, LocalOnly = False) if not klass: return [] @@ -488,7 +488,7 @@ class _LmiInstance(BaseObject): assoc_args["Props"] = Props associators_list = self._client.get_associators(self._inst, **assoc_args) for i in associators_list: - (cim_class, errorstr) = self._client.get_class(i.classname, i.path.namespace, + (cim_class, _, errorstr) = self._client.get_class(i.classname, i.path.namespace, LocalOnly = False) if not cim_class: return [] @@ -523,10 +523,7 @@ class _LmiShellClient(LmiBaseClient): return self._get_instance(path, LocalOnly = False)
def get_instances(self, class_name, filter_key = "", **kwargs): - (instance_list, _) = self._get_instances(class_name, filter_key, **kwargs) - if not instance_list: - return None - return instance_list + return self._get_instances(class_name, filter_key, **kwargs)
def get_class(self, class_name, namespace = None, **kwargs): return self._get_class(class_name, namespace, **kwargs) diff --git a/cli-tools/lmi/lmi_client_user.py b/cli-tools/lmi/lmi_client_user.py index 977cb8f..aab0f62 100644 --- a/cli-tools/lmi/lmi_client_user.py +++ b/cli-tools/lmi/lmi_client_user.py @@ -16,6 +16,7 @@ import sys import pywbem from lmi_client_base import LmiBaseClient +from lmi_client_base import LmiReturnValue
class LmiUserClient(LmiBaseClient): USER_CLASS_NAME = "LMI_Account" @@ -35,16 +36,16 @@ class LmiUserClient(LmiBaseClient): return self._get_instances(LmiUserClient.GROUP_CLASS_NAME)
def __get_account_management_instance(self): - (inst, errorstr) = self._get_instances(LmiUserClient.ACCOUNT_MANAGEMENT_SERVICE_CLASS_NAME) + (inst, rparams, errorstr) = self._get_instances(LmiUserClient.ACCOUNT_MANAGEMENT_SERVICE_CLASS_NAME) if not inst: - return (None, errorstr) - return (inst[0], "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = errorstr) + return LmiReturnValue(rval = inst[0], rparams = rparams, errorstr = "")
def __get_computer_system_instance(self): - (inst, errorstr) = self._get_instances(LmiUserClient.COMPUTER_SYSTEM_CLASS_NAME) + (inst, rparams, errorstr) = self._get_instances(LmiUserClient.COMPUTER_SYSTEM_CLASS_NAME) if not inst: - return (None, errorstr) - return (inst[0], "") + return LmiReturnValue(rval = None, rparams = {}, errorstr = errorstr) + return LmiReturnValue(rval = inst[0], rparams = rparams, errorstr = "")
def __get_member_groups(self, inst): members = [] @@ -69,9 +70,9 @@ class LmiUserClient(LmiBaseClient): return members
def list_users(self): - (inst_list, errorstr) = self.__get_user_instances() + (inst_list, rparams, errorstr) = self.__get_user_instances() if not inst_list: - return (False, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) try: for i in inst_list: groups = self.__get_member_groups(i) @@ -80,37 +81,37 @@ class LmiUserClient(LmiBaseClient): (i["Name"], i["UserID"], gid, i["ElementName"], i["HomeDirectory"], i["LoginShell"])) except pywbem.cim_operations.CIMError, e: - return (False, e.args[1]) - return (True, "") + return LmiReturnValue(rval = False, rparams = {}, errorstr = e.args[1]) + return LmiReturnValue(rval = True, rparams = rparams, errorstr = "")
def list_groups(self): - (inst_list, errorstr) = self.__get_group_instances() + (inst_list, rparams, errorstr) = self.__get_group_instances() if not inst_list: - return (False, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) for i in inst_list: sys.stdout.write("%s:%s\n" % (i["Name"], i["InstanceID"].split(":")[-1])) - return (True, "") + return LmiReturnValue(rval = True, rparams = rparams, errorstr = "")
def list_group_members(self, member): - (inst_list, errorstr) = self._get_instances( + (inst_list, rparams, errorstr) = self._get_instances( LmiUserClient.GROUP_CLASS_NAME, member) if not inst_list: - return (False, "No such group '%s' found" % member) + return LmiReturnValue(rval = False, rparams = {}, errorstr = "No such group '%s' found" % member) members = self.__get_group_members(inst_list) for m in members: sys.stdout.write("%s\n" % m) - return (True, "") + return LmiReturnValue(rval = True, rparams = rparams, errorstr = "")
def user_add(self, user_name, **params): - (inst_management, errorstr) = self.__get_account_management_instance() + (inst_management, rparams, errorstr) = self.__get_account_management_instance() if not inst_management: - return (False, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) # We are using the first and only instance present. # For KVM_ComputerSystem, there has be some CLI option added. - (inst_computer_system, errorstr) = self.__get_computer_system_instance() + (inst_computer_system, rparams, errorstr) = self.__get_computer_system_instance() if not inst_computer_system: - return (False, errorstr) + return LmiReturnValue(rval = False, rparams = {}, errorstr = errorstr) user_params = { "Name" : user_name } user_params["DontCreateHome"] = not params["createHome"] user_params["System"] = inst_computer_system.path @@ -133,5 +134,5 @@ class LmiUserClient(LmiBaseClient): (account, identity) = self._cliconn.InvokeMethod( "CreateAccount", inst_management.path, **user_params) except pywbem.CIMError, e: - return (False, e.args[1]) - return (account != None, "") + return LmiReturnValue(rval = False, rparams = {}, errorstr = e.args[1]) + return LmiReturnValue(rval = not account is None, rparams = rparams, errorstr = "")
cura-tools-devel@lists.fedorahosted.org