Exemple #1
0
 def get_fru(self):
     out = self.tool('fru', 'print')
     ipmi = parse.pairs(out)
     # remove (ID XX) from the top-level keys
     ipmi = dict((re.sub(r'\s*[(][^)]*[)]', '', k), v)
                 for (k, v) in ipmi.iteritems())
     return nullify(ipmi)
Exemple #2
0
def parse_lshw(as_string):
    parser = ET.ETCompatXMLParser(recover=True)
    response = ET.fromstring(as_string, parser=parser)
    if response.tag.upper() != 'NODE':
        return None, as_string
    for element in response.findall('.//'):
        for k in element.attrib.keys():
            try:
                v = element.attrib[k]
            except UnicodeDecodeError:
                continue # value has bytes not possible to decode with UTF-8
            if (element.tag, k) in _tag_translation_pairs:
                try:
                    element.tag = v
                except ValueError:
                    pass
                continue
            if (element.tag, k) in _text_translation_pairs:
                element.text = v
                continue
            if k == 'units':
                value = ET.Element(b'value')
                value.text = element.text
                element.text = ''
                element.append(value)
            child = ET.Element(k)
            child.text = v
            element.append(child)
    return nullify(etree_to_dict(response, _converters=[
                _nullify,
                int,
                float,
                lck.xml.converters._datetime,
                lck.xml.converters._datetime_strip_tz,
            ]))[1]
Exemple #3
0
 def get_fru(self):
     out = self.tool('fru', 'print')
     ipmi = parse.pairs(out)
     # remove (ID XX) from the top-level keys
     ipmi = dict((re.sub(r'\s*[(][^)]*[)]', '', k), v)
                 for (k, v) in ipmi.iteritems())
     return nullify(ipmi)
Exemple #4
0
def hp_xmldata(hostname, timeout=10):
    try:
        url = urlopen("https://{}/xmldata?item=all".format(hostname),
            timeout=timeout)
        try:
            data = url.read()
        finally:
            url.close()
    except (URLError, httplib.InvalidURL, httplib.BadStatusLine):
        return
    else:
        if not url.info().get('Content-Type', '').startswith('text/xml'):
            return
        data = data.decode('utf-8', 'replace').encode('utf-8')
        rimp = ET.fromstring(data)
        if rimp.tag.upper() != 'RIMP':
            return
        return nullify(
            etree_to_dict(
                rimp,
                _converters=[
                    _nullify,
                    int,
                    float,
                    lck.xml.converters._datetime,
                    lck.xml.converters._datetime_strip_tz
                ],
            )
        )[1]
Exemple #5
0
def _get_hp_xml_data(ip_address, timeout=10):
    try:
        url = urlopen(
            "https://{}/xmldata?item=all".format(ip_address),
            timeout=timeout,
        )
        try:
            data = url.read()
        finally:
            url.close()
    except (URLError, httplib.InvalidURL, httplib.BadStatusLine) as e:
        raise IncompatibleAnswerError('Incompatible answer (%s).' % unicode(e))
    else:
        if not url.info().get('Content-Type', '').startswith('text/xml'):
            raise IncompatibleAnswerError(
                'Incompatible answer (improper content type).', )
        data = data.decode('utf-8', 'replace').encode('utf-8')
        rimp = ET.fromstring(data)
        if rimp.tag.upper() != 'RIMP':
            raise IncompatibleAnswerError(
                'Incompatible answer (unknown content).', )
        return nullify(
            etree_to_dict(
                rimp,
                _converters=[
                    _nullify, int, float, lck.xml.converters._datetime,
                    lck.xml.converters._datetime_strip_tz
                ],
            ))[1]
Exemple #6
0
def _get_hp_xml_data(ip_address, timeout=10):
    try:
        url = urlopen(
            "https://{}/xmldata?item=all".format(ip_address),
            timeout=timeout,
        )
        try:
            data = url.read()
        finally:
            url.close()
    except (URLError, httplib.InvalidURL, httplib.BadStatusLine) as e:
        raise IncompatibleAnswerError('Incompatible answer (%s).' % unicode(e))
    else:
        if not url.info().get('Content-Type', '').startswith('text/xml'):
            raise IncompatibleAnswerError(
                'Incompatible answer (improper content type).',
            )
        data = data.decode('utf-8', 'replace').encode('utf-8')
        rimp = ET.fromstring(data)
        if rimp.tag.upper() != 'RIMP':
            raise IncompatibleAnswerError(
                'Incompatible answer (unknown content).',
            )
        return nullify(
            etree_to_dict(
                rimp,
                _converters=[
                    _nullify,
                    int,
                    float,
                    lck.xml.converters._datetime,
                    lck.xml.converters._datetime_strip_tz
                ],
            )
        )[1]
Exemple #7
0
def hp_xmldata(hostname, timeout=10):
    try:
        url = urlopen("https://{}/xmldata?item=all".format(hostname), timeout=timeout)
        try:
            data = url.read()
        finally:
            url.close()
    except (URLError, httplib.InvalidURL, httplib.BadStatusLine):
        return None, ""
    else:
        if not url.info().get("Content-Type", "").startswith("text/xml"):
            return None, ""
        data = data.decode("utf-8", "replace").encode("utf-8")
        rimp = ET.fromstring(data)
        if rimp.tag.upper() != "RIMP":
            return None, data
        return (
            nullify(
                etree_to_dict(
                    rimp,
                    _converters=[
                        _nullify,
                        int,
                        float,
                        lck.xml.converters._datetime,
                        lck.xml.converters._datetime_strip_tz,
                    ],
                )
            )[1],
            data,
        )
Exemple #8
0
def hp_xmldata(hostname, timeout=10):
    try:
        url = urlopen("https://{}/xmldata?item=all".format(hostname),
            timeout=timeout)
        try:
            data = url.read()
        finally:
            url.close()
    except (URLError, httplib.InvalidURL, httplib.BadStatusLine):
        return
    else:
        if not url.info().get('Content-Type', '').startswith('text/xml'):
            return
        data = data.decode('utf-8', 'replace').encode('utf-8')
        rimp = ET.fromstring(data)
        if rimp.tag.upper() != 'RIMP':
            return
        return nullify(
            etree_to_dict(
                rimp,
                _converters=[
                    _nullify,
                    int,
                    float,
                    lck.xml.converters._datetime,
                    lck.xml.converters._datetime_strip_tz
                ],
            )
        )[1]
Exemple #9
0
def parse_lshw(raw_data):
    parser = ET.ETCompatXMLParser(recover=True)
    response = ET.fromstring(raw_data, parser=parser)
    if response.tag and response.tag.upper() == 'LIST':
        response = response[0]
    elif response.tag and response.tag.upper() == 'NODE':
        pass
    else:
        raise Error('Lshw parse error.')
    for element in response.findall('.//'):
        for k in element.attrib.keys():
            try:
                v = element.attrib[k]
            except UnicodeDecodeError:
                continue   # value has bytes not possible to decode with UTF-8
            if (element.tag, k) in TAG_TRANSLATION_PAIRS:
                try:
                    element.tag = v
                except ValueError:
                    pass
                continue
            if (element.tag, k) in TEXT_TRANSLATION_PAIRS:
                element.text = v
                continue
            if k == 'units':
                value = ET.Element(b'value')
                value.text = element.text
                element.text = ''
                element.append(value)
            child = ET.Element(k)
            child.text = v
            element.append(child)
    return nullify(
        etree_to_dict(
            response,
            _converters=[
                _nullify,
                int,
                float,
                lck.xml.converters._datetime,
                lck.xml.converters._datetime_strip_tz,
            ],
        ),
    )[1]
Exemple #10
0
def parse_lshw(as_string):
    parser = ET.ETCompatXMLParser(recover=True)
    response = ET.fromstring(as_string, parser=parser)
    if response.tag.upper() != 'NODE':
        return None, as_string
    for element in response.findall('.//'):
        for k in element.attrib.keys():
            try:
                v = element.attrib[k]
            except UnicodeDecodeError:
                continue  # value has bytes not possible to decode with UTF-8
            if (element.tag, k) in _tag_translation_pairs:
                try:
                    element.tag = v
                except ValueError:
                    pass
                continue
            if (element.tag, k) in _text_translation_pairs:
                element.text = v
                continue
            if k == 'units':
                value = ET.Element(b'value')
                value.text = element.text
                element.text = ''
                element.append(value)
            child = ET.Element(k)
            child.text = v
            element.append(child)
    return nullify(
        etree_to_dict(response,
                      _converters=[
                          _nullify,
                          int,
                          float,
                          lck.xml.converters._datetime,
                          lck.xml.converters._datetime_strip_tz,
                      ]))[1]
Exemple #11
0
def _get_ipmi_fru(ipmitool):
    fru = parse.pairs(ipmitool.command('fru', 'print'))
    # remove (ID XX) from the top-level keys
    fru = dict((REMOVE_ID_REGEX.sub('', k), v) for (k, v) in fru.iteritems())
    return nullify(fru)
Exemple #12
0
def _get_ipmi_fru(ipmitool):
    fru = parse.pairs(ipmitool.command('fru', 'print'))
    # remove (ID XX) from the top-level keys
    fru = dict((REMOVE_ID_REGEX.sub('', k), v) for (k, v) in fru.iteritems())
    return nullify(fru)
Exemple #13
0
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from django.test import TestCase
from lck.lang import nullify

from ralph.scan.plugins.hp_oa import _get_parent_device, _handle_subdevices
from ralph.scan.tests.plugins.samples.hp_oa import HP_OA_SAMPLE


HP_OA_SAMPLE = nullify(HP_OA_SAMPLE)


class HpOaPluginTest(TestCase):
    def test_get_parent_device(self):
        self.assertEqual(
            _get_parent_device(HP_OA_SAMPLE),
            {
                'model_name': 'HP BladeSystem c7000 Enclosure G2',
                'rack': 'Rack_208',
                'serial_number': '9B8925V2C9',
                'type': 'blade system',
            },
        )

    def test_handle_subdevices(self):
        sample_device_info = {}
Exemple #14
0
# -*- coding: utf-8 -*-

from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

from django.test import TestCase
from lck.lang import nullify

from ralph.scan.plugins.hp_oa import _get_parent_device, _handle_subdevices
from ralph.scan.tests.plugins.samples.hp_oa import HP_OA_SAMPLE


HP_OA_SAMPLE = nullify(HP_OA_SAMPLE)


class HpOaPluginTest(TestCase):

    def test_get_parent_device(self):
        self.assertEqual(
            _get_parent_device(HP_OA_SAMPLE),
            {
                'model_name': 'HP BladeSystem c7000 Enclosure G2',
                'rack': 'Rack_208',
                'serial_number': '9B8925V2C9',
                'type': 'blade system',
            },
        )

    def test_handle_subdevices(self):