Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

converted parsers to use the new generic parser #30

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)