Skip to content

Commit

Permalink
converted parsers to use the new generic parser
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael Rice committed Nov 27, 2014
1 parent a392f47 commit 1ab430e
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
22 changes: 16 additions & 6 deletions tests/vcenter_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ def test_get_all_vcenters(self):
d1 = {
'username': 'root',
'instanceUuid': '137E2125-73EB-4E1B-BF03-2B6CD396E6AC',
'monitor': 'false',
'vcServerId': '1',
'valueType': 'Unique ID',
'hostname': '172.16.214.129',
'meter': 'true',
'monitor': 'false',
'value': 'datacenter-2',
'id': '1',
'version': '5.5.0',
'meter': 'true',
'active': 'true',
'fullname': 'VMware vCenter Server 5.5.0 build-1945287 (Sim)',
'id': '1'
'customerId': '3',
'objectType': 'Data Center'
}
self.assertDictEqual(d1, vcenters[0])

Expand All @@ -65,13 +70,18 @@ def test_get_vcenter_by_id_found(self):
d1 = {
'username': 'root',
'instanceUuid': '137E2125-73EB-4E1B-BF03-2B6CD396E6AC',
'monitor': 'false',
'vcServerId': '1',
'valueType': 'Unique ID',
'hostname': '172.16.214.129',
'meter': 'true',
'monitor': 'false',
'value': 'datacenter-2',
'id': '1',
'version': '5.5.0',
'meter': 'true',
'active': 'true',
'fullname': 'VMware vCenter Server 5.5.0 build-1945287 (Sim)',
'id': '1'
'customerId': '3',
'objectType': 'Data Center'
}
self.assertIsNotNone(vc)
self.assertIsInstance(vc, dict)
Expand Down
10 changes: 3 additions & 7 deletions thunderhead/parser/rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
# limitations under the License.

from xml.etree import ElementTree as etree
from thunderhead.parser.generic_parser import PayloadParser


def parse_all_rules(body):
Expand All @@ -36,10 +37,5 @@ def parse_rule(body):


def _parse_rule(rule):
v = {}
for rule_info in rule.getchildren():
# this is messy but it seems cleaner than dealing with the namespace
tag = rule_info.tag.split("}")[1][0:]
text = rule_info.text
v[tag] = text
return v
rule_parser = PayloadParser()
return rule_parser.parse(rule)
11 changes: 4 additions & 7 deletions thunderhead/parser/vcenter.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

from xml.etree import ElementTree as etree

from thunderhead.parser.generic_parser import PayloadParser


def parse_all_vcenters(body):
"""
Expand Down Expand Up @@ -76,10 +78,5 @@ def parse_vcenter(body):


def _parse_vcenter(vcenter):
v = {}
for vcenter_info in vcenter.getchildren():
# this is messy but it seems cleaner than dealing with the namespace
tag = vcenter_info.tag.split("}")[1][0:]
text = vcenter_info.text
v[tag] = text
return v
vcenter_parser = PayloadParser()
return vcenter_parser.parse(vcenter)

0 comments on commit 1ab430e

Please sign in to comment.