summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2014-02-25 16:49:15 +0100
committerMichal Minar <miminar@redhat.com>2014-02-26 12:39:56 +0100
commitf287e2521b8e9c26d79afd009e2a57ef43e3661c (patch)
treed378d06be6b226ac8ef3b5b497c4154e57ec7dc1
parent7e1e3f12432c27ad5433ac86e35ce0e482edd95b (diff)
downloadopenlmi-scripts-f287e2521b8e9c26d79afd009e2a57ef43e3661c.tar.gz
openlmi-scripts-f287e2521b8e9c26d79afd009e2a57ef43e3661c.tar.xz
openlmi-scripts-f287e2521b8e9c26d79afd009e2a57ef43e3661c.zip
hardware: remove unstable features
Disks introspection is not yet stable in openlmi-hardware provider, remove the support for now.
-rw-r--r--commands/hardware/lmi/scripts/hardware/__init__.py139
-rw-r--r--commands/hardware/lmi/scripts/hardware/cmd.py6
2 files changed, 13 insertions, 132 deletions
diff --git a/commands/hardware/lmi/scripts/hardware/__init__.py b/commands/hardware/lmi/scripts/hardware/__init__.py
index c077d70..56e1f04 100644
--- a/commands/hardware/lmi/scripts/hardware/__init__.py
+++ b/commands/hardware/lmi/scripts/hardware/__init__.py
@@ -34,6 +34,7 @@ LMI hardware provider client library.
import pywbem
+from lmi.shell import LMIClassNotFound
from lmi.scripts.common import get_logger
from lmi.scripts.common import get_computer_system
@@ -63,9 +64,17 @@ def _cache_replies(ns, class_name, method):
# keep the cache until namespace object changes
cache.clear()
_cache_replies.cache = (ns, cache)
- if not (class_name, method) in cache:
- i = getattr(ns, class_name)
- cache[(class_name, method)] = getattr(i, method)()
+ try:
+ if not (class_name, method) in cache:
+ i = getattr(ns, class_name)
+ cache[(class_name, method)] = getattr(i, method)()
+ except (LMIClassNotFound, pywbem.CIMError) as err:
+ if ( isinstance(err, pywbem.CIMError)
+ and err.args[0] != pywbem.CIM_ERR_NOT_SUPPORTED):
+ raise
+ LOG().info('System has old openlmi-hardware package installed,'
+ ' class "%s" is not available.', class_name)
+ return []
return cache[(class_name, method)]
def get_single_instance(ns, class_name):
@@ -88,14 +97,7 @@ def get_all_instances(ns, class_name):
:returns: List of instances of instance_name
:rtype: List of :py:class:`lmi.shell.LMIInstance`
"""
- try:
- return _cache_replies(ns, class_name, 'instances')
- except pywbem.CIMError as err:
- if err.args[0] == pywbem.CIM_ERR_NOT_SUPPORTED:
- LOG().info('System has old openlmi-hardware package installed,'
- ' class "%s" is not available.', class_name)
- return []
- raise
+ return _cache_replies(ns, class_name, 'instances')
def get_hostname(ns):
"""
@@ -176,8 +178,6 @@ def get_all_info(ns):
result += get_cpu_info(ns)
result.append(EMPTY_LINE)
result += get_memory_info(ns)
- result.append(EMPTY_LINE)
- result += get_disks_info(ns)
STANDALONE = True
return result
@@ -313,116 +313,3 @@ def get_memory_info(ns):
result.append(('Slots:', slots))
return result
-def get_disks_info(ns):
- """
- :returns: Tabular data of disk info.
- :rtype: List of tuples
- """
- result = init_result(ns)
- result.append(('Disks:', ''))
-
- hdds = get_all_instances(ns, 'LMI_DiskDrive')
- if not hdds:
- result.append((' N/A', ''))
- return result
-
- first_disk = True
-
- for hdd in hdds:
- phys_hdds = hdd.associators(ResultClass='LMI_DiskPhysicalPackage')
- manufacturer = ''
- model = ''
- if phys_hdds:
- manufacturer = phys_hdds[0].Manufacturer
- model = phys_hdds[0].Model
- if not manufacturer:
- manufacturer = 'N/A'
- if not model:
- model = 'N/A'
-
- form_factor_dict = {
- 3: '5.25"',
- 4: '3.5"',
- 5: '2.5"',
- 6: '1.8"',}
- if hdd.FormFactor in form_factor_dict:
- form_factor = form_factor_dict[hdd.FormFactor]
- else:
- form_factor = 'N/A'
-
- if hdd.RPM != 0xffffffff:
- rpm = hdd.RPM
- else:
- rpm = 'N/A'
-
- if hdd.DiskType == 2:
- disk_type = 'HDD'
- elif hdd.DiskType == 3:
- disk_type = 'SSD'
- else:
- disk_type = 'N/A'
-
- port_type = ''
- port_speed_current = ''
- port_speed_max = ''
- hdd_endpoints = hdd.associators(
- ResultClass='LMI_DiskDriveATAProtocolEndpoint')
- if hdd_endpoints:
- hdd_ports = hdd_endpoints[0].associators(
- ResultClass='LMI_DiskDriveATAPort')
- if hdd_ports:
- if hdd_ports[0].PortType:
- port_type = ns.LMI_DiskDriveATAPort.PortTypeValues.value_name(
- hdd_ports[0].PortType)
- if hdd_ports[0].Speed:
- port_speed_current = '%.1f Gb/s' % \
- (float(hdd_ports[0].Speed) / 1000000000.0)
- if hdd_ports[0].MaxSpeed:
- port_speed_max = '%.1f Gb/s' % \
- (float(hdd_ports[0].MaxSpeed) / 1000000000.0)
- if not port_type:
- port_type = 'N/A'
- if not port_speed_current:
- port_speed_current = 'N/A Gb/s'
- if not port_speed_max:
- port_speed_max = 'N/A Gb/s'
-
- status_to_color = {
- 'OK': GREEN_COLOR,
- 'Unknown': YELLOW_COLOR,
- 'Predictive Failure': RED_COLOR,}
- if hdd.OperationalStatus:
- smart = ns.LMI_DiskDrive.OperationalStatusValues.value_name(
- hdd.OperationalStatus[0])
- smart = get_colored_string(smart, status_to_color[smart])
- else:
- smart = get_colored_string('Unknown', YELLOW_COLOR)
-
- temp = getattr(hdd, 'Temperature', None)
- if temp:
- temp_str = '%d' % temp
- else:
- temp_str = 'N/A'
- temp_str += u' °C'
-
- if not first_disk:
- result.append(EMPTY_LINE)
- else:
- first_disk = False
-
- if hdd.Name != hdd.DeviceID and hdd.Name != model:
- result.append((' %s' % hdd.DeviceID, hdd.Name))
- else:
- result.append((' %s' % hdd.DeviceID, ''))
- result += [(' Manufacturer:', manufacturer),
- (' Model:', model),
- (' Capacity:', format_memory_size(hdd.Capacity)),
- (' Form Factor:', form_factor),
- (' HDD/SSD:', disk_type),
- (' RPM:', rpm),
- (' Port Type:', port_type),
- (' Port Speed:', '%s current, %s max' % \
- (port_speed_current, port_speed_max)),
- (' SMART Status:', smart),
- (' Temperature:', temp_str)]
- return result
diff --git a/commands/hardware/lmi/scripts/hardware/cmd.py b/commands/hardware/lmi/scripts/hardware/cmd.py
index e57e3be..985645d 100644
--- a/commands/hardware/lmi/scripts/hardware/cmd.py
+++ b/commands/hardware/lmi/scripts/hardware/cmd.py
@@ -36,7 +36,6 @@ Usage:
%(cmd)s motherboard
%(cmd)s cpu
%(cmd)s memory
- %(cmd)s disks
Commands:
all Display all available information.
@@ -44,7 +43,6 @@ Commands:
motherboard Display motherboard information.
cpu Display processor information.
memory Display memory information.
- disks Display disks information.
"""
from lmi.scripts.common import command
@@ -67,9 +65,6 @@ class Cpu(HwBase):
class Memory(HwBase):
CALLABLE = 'lmi.scripts.hardware:get_memory_info'
-class Disks(HwBase):
- CALLABLE = 'lmi.scripts.hardware:get_disks_info'
-
Hardware = command.register_subcommands(
'Hardware', __doc__,
{ 'all' : All
@@ -77,7 +72,6 @@ Hardware = command.register_subcommands(
, 'motherboard' : Motherboard
, 'cpu' : Cpu
, 'memory' : Memory
- , 'disks' : Disks
},
fallback_command=All
)