Skip to content

Commit

Permalink
Adding new LSHW Discoveries
Browse files Browse the repository at this point in the history
- LSHWProcessors
- LSHWMemory
- adding those to the correct __init__s
  • Loading branch information
struegamer committed Apr 8, 2014
1 parent 143fcfb commit f692b62
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 0 deletions.
Expand Up @@ -27,3 +27,5 @@
from .lshw import LSHWGenerics # noqa
from .lshw import LSHWDisks # noqa
from .lshw import LSHWStorage # noqa
from .lshw import LSHWMemory # noqa
from .lshw import LSHWProcessors # noqa
Expand Up @@ -21,3 +21,5 @@
from .lshw_generics import LSHWGenerics # noqa
from .lshw_disks import LSHWDisks # noqa
from .lshw_storage import LSHWStorage # noqa
from .lshw_processors import LSHWProcessor # noqa
from .lshw_memory import LSHWMemory # noqa
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
#
#
# (DC)² - DataCenter Deployment Control
# Copyright (C) 2010, 2011, 2012, 2013, 2014 Stephan Adig <sh@sourcecode.de>
# 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.
#

import sys

try:
from lxml import etree
except ImportError as e:
print('No lxml installed')
print(e)
sys.exit(1)

from .lshw_base import LSHWBase


class LSHWMemory(LSHWBase):
_NODE_CLASS_NAME = 'memory'

def __init__(self):
super(LSHWMemory, self).__init__()

def _find_data(self):
find_memory = etree.XPath(".//node[@class='{0}']".format(
self._NODE_CLASS_NAME))

for mem in find_memory(self._inventory):
_memory = {}
for mem_tag in mem:
if mem_tag.tag == 'configuration':
_memory['configuration']
for config in mem_tag:
config_settings = config.attrib
_memory['configuration'][self._adjust_keys(
config_settings['id'])] =\
config_settings['value']
elif mem_tag.tag == 'capabilities':
_memory['capabilities'] = {}
for cap in mem_tag:
cap_data = cap.attrib
_memory['capabilities'][self._adjust_keys(
cap_data['id'])] = cap.text
elif mem_tag.tag == 'resources':
_memory['resources'] = {}
for resource in mem_tag:
resource_data = resource.attrib
_memory['capabilities'][self._adjust_keys(
resource_data['id'])] =\
resource_data['value']
else:
_memory[mem_tag.tag] = mem_tag.text
self._data.append(_memory)
@@ -0,0 +1,68 @@
# -*- coding: utf-8 -*-
#
#
# (DC)² - DataCenter Deployment Control
# Copyright (C) 2010, 2011, 2012, 2013, 2014 Stephan Adig <sh@sourcecode.de>
# 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.
#

import sys

try:
from lxml import etree
except ImportError as e:
print('No lxml installed')
print(e)
sys.exit(1)

from .lshw_base import LSHWBase


class LSHWProcessors(LSHWBase):
_NODE_CLASS_NAME = 'processor'

def __init__(self):
super(LSHWProcessors, self).__init__()

def _find_data(self):
find_cpus = etree.XPath(".//node[@class='{0}]".format(
self._NODE_CLASS_NAME))

for cpu in find_cpus(self._inventory):
_cpus = {}
for cpu_tag in cpu:
if cpu_tag.tag == 'configuration':
_cpus['configuration'] = {}
for config in cpu_tag:
config_settings = config.attrib
_cpus['configuration'][self._adjust_keys(
config_settings['id'])] =\
config_settings['value']
elif cpu_tag.tag == 'capabilities':
_cpus['capabilities'] = {}
for cap in cpu_tag:
cap_data = cap.attrib
_cpus['capabilities'][self._adjust_keys(
cap_data['id'])] = cap.text
elif cpu_tag.tag == 'resources':
_cpus['resources'] = {}
for resource in cpu_tag:
resource_data = resource.attrib
_cpus['resources'][self._adjust_keys(
resource_data['id'])] =\
resource_data['value']
else:
_cpus[cpu_tag.tag] = cpu_tag.text
self._data.append(_cpus)

0 comments on commit f692b62

Please sign in to comment.