[openlmi-scripts] bugfixes and system command improvements
Michal Minar
miminar at fedoraproject.org
Mon Mar 10 14:32:45 UTC 2014
commit 73c9611a35596d4bfdc2e1e1cb5466888c5471ab
Author: Michal Minar <miminar at redhat.com>
Date: Mon Mar 10 15:31:07 2014 +0100
bugfixes and system command improvements
...lmi-scripts-0.2.7-smart_hostname_fallback.patch | 77 ++++++++++
...lmi-scripts-0.2.7-storage_error_reporting.patch | 16 ++
...lmi-scripts-0.2.7-storage_thinlv_provides.patch | 84 +++++++++++
openlmi-scripts-0.2.7-system_improvements.patch | 147 ++++++++++++++++++++
openlmi-scripts.spec | 36 ++++--
5 files changed, 350 insertions(+), 10 deletions(-)
---
diff --git a/openlmi-scripts-0.2.7-smart_hostname_fallback.patch b/openlmi-scripts-0.2.7-smart_hostname_fallback.patch
new file mode 100644
index 0000000..f78c08d
--- /dev/null
+++ b/openlmi-scripts-0.2.7-smart_hostname_fallback.patch
@@ -0,0 +1,77 @@
+diff --git a/lmi/scripts/_metacommand/__init__.py b/lmi/scripts/_metacommand/__init__.py
+index 244f0cf..92bfab2 100644
+--- a/lmi/scripts/_metacommand/__init__.py
++++ b/lmi/scripts/_metacommand/__init__.py
+@@ -133,8 +133,9 @@ class MetaCommand(object):
+ if self._session is None:
+ if ( not self._options['--host']
+ and not self._options['--hosts-file']):
+- LOG().info('No hosts given, using "localhost".')
+- self._options['--host'] = ['localhost']
++ self._options['--host'] = [util.get_default_hostname()]
++ LOG().info('No hosts given, using "%s".',
++ self._options['--host'][0])
+ hostnames = []
+ # credentials loaded from file
+ credentials = {}
+diff --git a/lmi/scripts/_metacommand/util.py b/lmi/scripts/_metacommand/util.py
+index 08e5948..15686a3 100644
+--- a/lmi/scripts/_metacommand/util.py
++++ b/lmi/scripts/_metacommand/util.py
+@@ -33,9 +33,11 @@ Meta-command utility module.
+
+ import logging
+ import logging.config
++import os
+ import pkg_resources
+ import platform
+ import re
++import socket
+ import sys
+ import urlparse
+
+@@ -44,6 +46,8 @@ from lmi.scripts.common import get_logger
+ from lmi.scripts.common import lmi_logging
+
+ PYTHON_EGG_NAME = "openlmi-scripts"
++#: Service name identifying tcp port used to connect to CIMOM.
++DEFAULT_BROKER_SERVICE_NAME = 'wbem-https'
+
+ RE_NETLOC = re.compile(r'^((?P<username>[^:@]+)(:(?P<password>[^@]+))?@)?'
+ r'(?P<hostname>[^:]+)(:(?P<port>\d+))?$')
+@@ -226,3 +230,35 @@ def parse_hosts_file(hosts_file):
+ hostnames.append(line.strip())
+ return get_hosts_credentials(hostnames)
+
++def get_default_hostname(port=None):
++ """
++ Choose default hostname to connect to. If logged as root, this will default
++ to localhost, which results in unix socket being used for connection.
++ Otherwise use full qualified domain name and hostname will be tried in this
++ order. If they are not address-resolvable, '127.0.0.1' is returned.
++
++ This function shall be used only if no uri is specified on command line.
++
++ :param port: Port of desired service running on host (CIMOM broker).
++ This defaults to :py:attr:`DEFAULT_BROKER_SERVICE_NAME`
++ :type port: string or int
++ """
++ if port is None:
++ port = DEFAULT_BROKER_SERVICE_NAME
++ # Functions used to get hostname. first resolvable result will be used.
++ name_getters = []
++ if os.getuid() != 0:
++ # Use non-'localhost' name only if we'are not logged in as root
++ # for it prevents the use of unix socket.
++ name_getters.extend([socket.getfqdn, socket.gethostname])
++ name_getters.append(lambda: 'localhost')
++ for name_func in name_getters:
++ try:
++ hostname = name_func()
++ socket.getaddrinfo(hostname, port)
++ break
++ except socket.gaierror:
++ pass
++ else:
++ hostname = '127.0.0.1'
++ return hostname
diff --git a/openlmi-scripts-0.2.7-storage_error_reporting.patch b/openlmi-scripts-0.2.7-storage_error_reporting.patch
new file mode 100644
index 0000000..1221bcb
--- /dev/null
+++ b/openlmi-scripts-0.2.7-storage_error_reporting.patch
@@ -0,0 +1,16 @@
+diff --git a/commands/storage/lmi/scripts/storage/mount.py b/commands/storage/lmi/scripts/storage/mount.py
+index c94bc5a..e379d0b 100644
+--- a/commands/storage/lmi/scripts/storage/mount.py
++++ b/commands/storage/lmi/scripts/storage/mount.py
+@@ -178,9 +178,8 @@ def mount_create(ns, device, mountpoint, fs_type=None, options=None):
+ FileSystemSpec=device)
+ msg = '%s on %s' % (device, mountpoint)
+ if ret != 0:
+- errname = service.SyncCreateMount.CreateMountValues.value_name(ret)
+- raise LmiFailed('Cannot create mount: %s: %s.' % (
+- msg, errname))
++ raise LmiFailed('Cannot create mount: %s: %s' % (
++ msg, _err))
+
+ LOG().info('Successfully created mount: %s', msg)
+
diff --git a/openlmi-scripts-0.2.7-storage_thinlv_provides.patch b/openlmi-scripts-0.2.7-storage_thinlv_provides.patch
new file mode 100644
index 0000000..dd2a2cd
--- /dev/null
+++ b/openlmi-scripts-0.2.7-storage_thinlv_provides.patch
@@ -0,0 +1,84 @@
+diff --git a/commands/storage/lmi/scripts/storage/common.py b/commands/storage/lmi/scripts/storage/common.py
+index 57824cf..ea43e7f 100644
+--- a/commands/storage/lmi/scripts/storage/common.py
++++ b/commands/storage/lmi/scripts/storage/common.py
+@@ -354,6 +354,15 @@ def get_parents(ns, obj, deep=False):
+ yield parent
+
+ elif lmi_isinstance(obj, ns.CIM_StoragePool):
++ # find VGs of the thin pool
++ assoc_class = "LMI_VGAllocatedFromStoragePool"
++ if assoc_class in ns.classes():
++ parents = obj.associators(
++ AssocClass=assoc_class,
++ Role="Dependent")
++ for parent in parents:
++ yield parent
++
+ # find physical volumes of the VG
+ parents = obj.associators(
+ AssocClass="LMI_VGAssociatedComponentExtent",
+@@ -438,6 +447,15 @@ def get_children(ns, obj, deep=False):
+ yield c
+
+ elif lmi_isinstance(obj, ns.CIM_StoragePool):
++ # find thin pools from the VG
++ assoc_class = "LMI_VGAllocatedFromStoragePool"
++ if assoc_class in ns.classes():
++ children = obj.associators(
++ AssocClass=assoc_class,
++ Role="Antecedent")
++ for child in children:
++ yield child
++
+ # find LVs allocated from the VG
+ children = obj.associators(
+ AssocClass="LMI_LVAllocatedFromStoragePool",
+diff --git a/commands/storage/lmi/scripts/storage/lvm.py b/commands/storage/lmi/scripts/storage/lvm.py
+index af76dcc..15db230 100644
+--- a/commands/storage/lmi/scripts/storage/lvm.py
++++ b/commands/storage/lmi/scripts/storage/lvm.py
+@@ -279,10 +279,11 @@ def get_tps(ns):
+
+ :rtype: list of LMIInstance/LMI_VGStoragePool
+ """
+- LOG().debug("get_vgs: Loading list of all thin pools.")
+- for vg in ns.LMI_VGStoragePool.instances():
+- if vg.SpaceLimitDetermination:
+- yield vg
++ if "LMI_VGAllocatedFromStoragePool" in ns.classes():
++ LOG().debug("get_tps: Loading list of all thin pools.")
++ for vg in ns.LMI_VGStoragePool.instances():
++ if vg.SpaceLimitDetermination:
++ yield vg
+
+ def get_tp_vgs(ns, tp):
+ """
+diff --git a/commands/storage/lmi/scripts/storage/storage_cmd.py b/commands/storage/lmi/scripts/storage/storage_cmd.py
+index f8945cf..218b617 100644
+--- a/commands/storage/lmi/scripts/storage/storage_cmd.py
++++ b/commands/storage/lmi/scripts/storage/storage_cmd.py
+@@ -307,6 +307,8 @@ class Tree(command.LmiLister):
+ # Add *all* LMI_VGStoragePools.
+ for vg in lvm.get_vgs(ns):
+ devices[self.get_obj_id(ns, vg)] = vg
++ for tp in lvm.get_tps(ns):
++ devices[self.get_obj_id(ns, tp)] = tp
+
+ # deps = array of tuples (parent devid, child devid)
+ # Load all dependencies, calling get_children iteratively is slow
+@@ -355,6 +357,14 @@ class Tree(command.LmiLister):
+ self.get_obj_id(ns, i.GroupComponent))
+ for i in ns.LMI_VGAssociatedComponentExtent.instances()]
+
++ # Add VG-ThinPool dependencies from LMI_VGAllocatedFromStoragePool
++ if "LMI_VGAllocatedFromStoragePool" in ns.classes():
++ LOG().debug("Loading VGAllocatedFromStoragePool associations.")
++ deps += [
++ (self.get_obj_id(ns, i.Antecedent),
++ self.get_obj_id(ns, i.Dependent))
++ for i in ns.LMI_VGAllocatedFromStoragePool.instances()]
++
+ # queue = array of tuples (devid, level), queue of items to inspect
+ # and display
+ queue = []
diff --git a/openlmi-scripts-0.2.7-system_improvements.patch b/openlmi-scripts-0.2.7-system_improvements.patch
new file mode 100644
index 0000000..500383c
--- /dev/null
+++ b/openlmi-scripts-0.2.7-system_improvements.patch
@@ -0,0 +1,147 @@
+diff --git a/commands/system/README.md b/commands/system/README.md
+index b80dfa4..728eb01 100644
+--- a/commands/system/README.md
++++ b/commands/system/README.md
+@@ -1,3 +1,5 @@
+ General system information available in OpenLMI providers.
+
+ This command allows to list general information about system.
++
++Requires: openlmi-scripts-service
+diff --git a/commands/system/lmi/scripts/system/__init__.py b/commands/system/lmi/scripts/system/__init__.py
+index bdec7c8..9588ec3 100644
+--- a/commands/system/lmi/scripts/system/__init__.py
++++ b/commands/system/lmi/scripts/system/__init__.py
+@@ -32,6 +32,8 @@ LMI system client library.
+ """
+
+ from lmi.scripts.common import get_computer_system
++from lmi.scripts.service import get_service
++from lmi.shell.LMIExceptions import LMIClassNotFound
+
+ def _cache_replies(ns, class_name, method):
+ """
+@@ -106,6 +108,8 @@ def get_system_info(ns):
+ """
+ result = get_hostname(ns)
+ result += get_hwinfo(ns)
++ result += get_osinfo(ns)
++ result += get_servicesinfo(ns)
+ return result
+
+ def get_hostname(ns):
+@@ -122,7 +126,10 @@ def get_hwinfo(ns):
+ :rtype: List of tuples
+ """
+ # Chassis
+- chassis = get_single_instance(ns, 'LMI_Chassis')
++ try:
++ chassis = get_single_instance(ns, 'LMI_Chassis')
++ except LMIClassNotFound:
++ chassis = None
+ if chassis:
+ hwinfo = chassis.Manufacturer
+ if chassis.Model and chassis.Model != 'Not Specified' \
+@@ -137,13 +144,19 @@ def get_hwinfo(ns):
+ else:
+ hwinfo = 'N/A'
+ # CPUs
+- cpus = get_all_instances(ns, 'LMI_Processor')
++ try:
++ cpus = get_all_instances(ns, 'LMI_Processor')
++ except LMIClassNotFound:
++ cpus = None
+ if cpus:
+ cpus_str = '%dx %s' % (len(cpus), cpus[0].Name)
+ else:
+ cpus_str = 'N/A'
+ # Memory
+- memory = get_single_instance(ns, 'LMI_Memory')
++ try:
++ memory = get_single_instance(ns, 'LMI_Memory')
++ except LMIClassNotFound:
++ memory = None
+ if memory:
+ memory_size = format_memory_size(memory.NumberOfBlocks)
+ else:
+@@ -154,3 +167,67 @@ def get_hwinfo(ns):
+ ('Processors:', cpus_str),
+ ('Memory:', memory_size)]
+ return result
++
++def get_osinfo(ns):
++ """
++ :returns: Tabular data of system OS info.
++ :rtype: List of tuples
++ """
++ # OS
++ try:
++ os = get_single_instance(ns, 'PG_OperatingSystem')
++ except LMIClassNotFound:
++ os = None
++ os_str = ''
++ kernel_str = ''
++ if os:
++ os_str = os.Caption
++ kernel_str = os.Version
++ if not os_str:
++ os_str = 'N/A'
++ if not kernel_str:
++ kernel_str = 'N/A'
++ # Result
++ result = [
++ ('OS:', os_str),
++ ('Kernel:', kernel_str)]
++ return result
++
++def get_servicesinfo(ns):
++ """
++ :returns: Tabular data of some system services.
++ :rtype: List of tuples
++ """
++ # Firewall
++ try:
++ fw = ''
++ firewalld = get_service(ns, 'firewalld.service')
++ if firewalld and firewalld.Status == 'OK':
++ fw = 'on (firewalld)'
++ else:
++ iptables = get_service(ns, 'iptables.service')
++ if iptables and iptables.Status == 'OK':
++ fw = 'on (iptables)'
++ if not fw:
++ fw = 'off'
++ except LMIClassNotFound:
++ fw = 'N/A'
++ # Logging
++ try:
++ logging = ''
++ journald = get_service(ns, 'systemd-journald.service')
++ if journald and journald.Status == 'OK':
++ logging = 'on (journald)'
++ else:
++ rsyslog = get_service(ns, 'rsyslog.service')
++ if rsyslog and rsyslog.Status == 'OK':
++ logging = 'on (rsyslog)'
++ if not logging:
++ logging = 'off'
++ except LMIClassNotFound:
++ logging = 'N/A'
++ # Result
++ result = [
++ ('Firewall:', fw),
++ ('Logging:', logging)]
++ return result
+diff --git a/commands/system/setup.py b/commands/system/setup.py
+index 616a3e9..57b07a7 100644
+--- a/commands/system/setup.py
++++ b/commands/system/setup.py
+@@ -30,7 +30,7 @@ setup(
+ 'Environment :: Console',
+ ],
+
+- install_requires=['openlmi-scripts >= 0.2.7'],
++ install_requires=['openlmi-scripts >= 0.2.7', 'openlmi-scripts-service'],
+
+ namespace_packages=['lmi', 'lmi.scripts'],
+ packages=['lmi', 'lmi.scripts', 'lmi.scripts.system'],
diff --git a/openlmi-scripts.spec b/openlmi-scripts.spec
index 54a48b7..edc06c9 100644
--- a/openlmi-scripts.spec
+++ b/openlmi-scripts.spec
@@ -1,12 +1,13 @@
%global commit 8563d295e503cab96c3b1651fa55413a7f589641
%global shortcommit %(c=%{commit}; echo ${c:0:7})
%global openlmi_scripts_version 0.2.7
+%global openlmi_scripts_service_version 0.1.2
%global commands logicalfile service software storage hardware
%global commands %{commands} networking system account powermanagement
Name: openlmi-scripts
Version: %{openlmi_scripts_version}
-Release: 7%{?dist}
+Release: 8%{?dist}
Summary: Client-side python modules and command line utilities
License: BSD
@@ -35,6 +36,10 @@ Patch4: openlmi-scripts-0.2.7-storage_thinlv_checks.patch
Patch5: openlmi-scripts-0.2.7-software_search.patch
Patch6: openlmi-scripts-0.2.7-networking_fixes.patch
Patch7: openlmi-scripts-0.2.7-duplicate_headers.patch
+Patch8: openlmi-scripts-0.2.7-system_improvements.patch
+Patch9: openlmi-scripts-0.2.7-storage_thinlv_provides.patch
+Patch10: openlmi-scripts-0.2.7-storage_error_reporting.patch
+Patch11: openlmi-scripts-0.2.7-smart_hostname_fallback.patch
%description
Client-side python modules and command line utilities.
@@ -57,7 +62,7 @@ provider and command line wrapper.
%package service
Summary: Client scripts for OpenLMI Service provider
-Version: 0.1.2
+Version: %{openlmi_scripts_service_version}
Requires: %{name} = %{openlmi_scripts_version}-%{release}
%description service
@@ -105,6 +110,7 @@ provider and command line wrapper.
Summary: Client scripts providing general system informations
Version: 0.0.2
Requires: %{name} = %{openlmi_scripts_version}-%{release}
+Requires: %{name}-service = %{openlmi_scripts_service_version}-%{release}
%description system
This package contains client side python library for few OpenLMI providers and
@@ -131,14 +137,18 @@ provider and command line wrapper.
%prep
%setup -qn %{name}-%{commit}
-%patch0 -p1 -b .hardware_support_older_providers
-%patch1 -p1 -b .storage_mount_fix
-%patch2 -p1 -b .service_error_handling
-%patch3 -p1 -b .doc_built-ins
-%patch4 -p1 -b .storage_thinlv_checks
-%patch5 -p1 -b .software_search
-%patch6 -p1 -b .networking_fixes
-%patch7 -p1 -b .duplicate_headers
+%patch0 -p1 -b .hardware_support_older_providers
+%patch1 -p1 -b .storage_mount_fix
+%patch2 -p1 -b .service_error_handling
+%patch3 -p1 -b .doc_built-ins
+%patch4 -p1 -b .storage_thinlv_checks
+%patch5 -p1 -b .software_search
+%patch6 -p1 -b .networking_fixes
+%patch7 -p1 -b .duplicate_headers
+%patch8 -p1 -b .system_improvements
+%patch9 -p1 -b .storage_thinlv_provides
+%patch10 -p1 -b .storage_error_reporting
+%patch11 -p1 -b .smart_hostname_fallback
%build
%{__python} setup.py build
@@ -251,6 +261,12 @@ install -m 644 README.md COPYING Changelog $RPM_BUILD_ROOT/%{_docdir}/%{name}
%{python_sitelib}/openlmi_scripts_powermanagement-*
%changelog
+* Mon Mar 10 2014 Michal Minar <miminar at redhat.com> 0.2.7-8
+- Fixed listing of thin volumes/groups in provides.
+- Smart hostname selection when no hosts are given.
+- System command improvements.
+- Fixed storage error reporting.
+
* Wed Mar 05 2014 Michal Minar <miminar at redhat.com> 0.2.7-7
- Fixed few networking bugs.
- Fixed duplicate headers.
More information about the scm-commits
mailing list