Skip to content

Commit

Permalink
Merge branch 'master' of gitlab.sourcecode.de:sadig/dc2
Browse files Browse the repository at this point in the history
  • Loading branch information
struegamer committed Mar 31, 2014
2 parents ef9beb1 + 4519b27 commit 57abe3e
Show file tree
Hide file tree
Showing 7 changed files with 145 additions and 16 deletions.
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
0.10.2
0.11.1
Expand Up @@ -17,5 +17,7 @@
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#

from lshw_nics import LSHWNics # noqa
from lshw_generics import LSHWGenerics # noqa
from .lshw_nics import LSHWNics # noqa
from .lshw_generics import LSHWGenerics # noqa
from .lshw_disks import LSHWDisks # noqa
from .lshw_storage import LSHWStorage # noqa
Expand Up @@ -33,8 +33,17 @@ class LSHWBase(object):

def __init__(self):
self._inventory = None
self._data = []
self._get_lshw_data()
self._find_data()

def _get_lshw_data(self):
lshw_output = subprocess.check_output([self._LSHW_BIN, '-xml'])
self._inventory = etree.XML(lshw_output.decode('utf-8'))

def _find_data(self):
pass

def _get_data(self):
return self._data
data = property(_get_data)
@@ -0,0 +1,65 @@
# -*- 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 LSHWDisks(LSHWBase):
_NODE_CLASS_NAME = 'disk'

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

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

for disk in find_disks(self._inventory):
_disks = {}
for disk_tag in disk:
if disk_tag.tag == 'configuration':
_disks['configuration'] = {}
for config in disk_tag:
config_settings = config.attrib
_disks['configuration'][config_settings['id']] =\
config_settings['value']
elif disk_tag.tag == 'capabilities':
_disks['capabilities'] = {}
for cap in disk_tag:
cap_data = cap.attrib
_disks['capabilities'][cap_data['id']] = cap.text
elif disk_tag.tag == 'resources':
_disks['resources'] = {}
for resource in disk_tag:
resource_data = resource.attrib
_disks['resources'][resource_data['type']] =\
resource_data['value']
else:
_disks[disk_tag.tag] = disk_tag.text
self._data.append(_disks)
Expand Up @@ -33,8 +33,6 @@ class LSHWGenerics(LSHWBase):

def __init__(self):
super(LSHWGenerics, self).__init__()
self._data = []
self._find_data()

def _find_data(self):
find_generics = etree.XPath(".//node[@class='{0}']".format(
Expand Down Expand Up @@ -62,7 +60,3 @@ def _find_data(self):
else:
_generics[generic_tag.tag] = generic_tag.text
self._data.append(_generics)

def _get_data(self):
return self._data
data = property(_get_data)
Expand Up @@ -33,10 +33,8 @@ class LSHWNics(LSHWBase):

def __init__(self):
super(LSHWNics, self).__init__()
self._data = []
self._find_nics()

def _find_nics(self):
def _find_data(self):
find_nics = etree.XPath(".//node[@class='{0}']".format(
self._NODE_CLASS_NAME))
for nic in find_nics(self._inventory):
Expand All @@ -62,7 +60,3 @@ def _find_nics(self):
else:
_nics[nic_tag.tag] = nic_tag.text
self._data.append(_nics)

def _get_data(self):
return self._data
data = property(_get_data)
@@ -0,0 +1,65 @@
# -*- 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 LSHWStorage(LSHWBase):
_NODE_CLASS_NAME = 'storage'

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

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

for storage_bus in find_storage(self._inventory):
_storages = {}
for storage_tag in storage_bus:
if storage_tag.tag == 'configuratrion':
_storages['configuration'] = {}
for config in storage_tag:
config_settings = config.attrib
_storages['configuration'][config_settings['id']] =\
config_settings['value']
elif storage_tag.tag == 'capabilities':
_storages['capabilities'] = {}
for cap in storage_tag:
cap_data = cap.attrib
_storages['capabilities'][cap_data['id']] = cap.text
elif storage_tag.tag == 'resources':
_storages['resources'] = {}
for resource in storage_tag:
resource_data = resource.attrib
_storages['resources'][resource_data['type']] =\
resource_data['value']
else:
_storages[storage_tag.tag] = storage_tag.text
self._data.append(_storages)

0 comments on commit 57abe3e

Please sign in to comment.