Skip to content

Instantly share code, notes, and snippets.

@lindsm
Created December 12, 2014 22:17
Show Gist options
  • Save lindsm/e719705353124b965e90 to your computer and use it in GitHub Desktop.
Save lindsm/e719705353124b965e90 to your computer and use it in GitHub Desktop.
import xml.etree.ElementTree as ET
def get_hosts(xml_file):
''' xml.file -> list
For every sin in a given xml_file, return a list containing the FQDN.
'''
tree = ET.parse(xml_file)
root = tree.getroot()
sins = []
for server in root.iter('sin'):
hostname = server.get('host')
sins.append(hostname)
else:
return sins
def count_hosts(xml_file):
''' string --> int
For a given xml_file return the integer count of sins.
count_hosts(env.xml)
>>>24
'''
tree = ET.parse(xml_file)
root = tree.getroot()
count = 0
for server in root.iter('sin'):
count += 1
else:
return count
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment