def from_juniper(self, data, device, commands=None): """Do all the magic to parse Junos interfaces""" self.raw = data results = [] for xml in data: jdata = xmltodict.parse(ET.tostring(xml), postprocessor=strip_juniper_namespace, xml_attribs=False) # xml needs to die a quick, but painful death sysupinfo = None if 'system-uptime-information' in jdata['rpc-reply']: sysupinfo = jdata['rpc-reply']['system-uptime-information'] elif 'multi-routing-engine-results' in jdata['rpc-reply']: try: sysupinfo = jdata['rpc-reply'][ 'multi-routing-engine-results'][ 'multi-routing-engine-item'][ 'system-uptime-information'] except: pass if sysupinfo == None: currtime = 'Unable to parse' ## need to turn this into an error else: currtime = sysupinfo['current-time']['date-time'] # => '2013-02-20 21:41:40 UTC' fmt = '%Y-%m-%d %H:%M:%S %Z' r = self._parse_datetime(currtime, fmt) jdata = {'current-time': r} #self.data.append({'device':device,'data':jdata}) results.append(jdata) self.store_results(device, results)
def from_juniper(self, data, device): """Do all the magic to parse Junos interfaces""" self.raw = data results=[] for xml in data: jdata = xmltodict.parse( ET.tostring(xml), postprocessor=strip_juniper_namespace, xml_attribs=False ) # xml needs to die a quick, but painful death sysupinfo = None if 'system-uptime-information' in jdata['rpc-reply']: sysupinfo = jdata['rpc-reply']['system-uptime-information'] elif 'multi-routing-engine-results' in jdata['rpc-reply']: try: sysupinfo = jdata['rpc-reply']['multi-routing-engine-results']['multi-routing-engine-item']['system-uptime-information'] except: pass if sysupinfo == None: currtime = 'Unable to parse' ## need to turn this into an error else: currtime = sysupinfo['current-time']['date-time'] # => '2013-02-20 21:41:40 UTC' fmt = '%Y-%m-%d %H:%M:%S %Z' r = self._parse_datetime(currtime, fmt) jdata = {'current-time':r} #self.data.append({'device':device,'data':jdata}) results.append(jdata) self.store_results(device, results)
def from_juniper(self, data, device, commands=None): """Do all the magic to parse Junos interfaces""" # print 'device:', device # print 'data len:', len(data) self.raw = data results = [] for xml in data: jdata = xmltodict.parse(ET.tostring(xml), postprocessor=strip_juniper_namespace, xml_attribs=False) ## ## Leaving jdata structure native until I have a chance ## to look at it (and other vendors' results) and restructure ## into something sane. ## At that point, I will want to make sure that all vendors ## return a dict with the same structure. ## self.data.append({"device": device, "data": jdata}) results.append(jdata) self.store_results(device, results)
def from_juniper(self, data, device, commands=None): """Do all the magic to parse Junos interfaces""" #print 'device:', device #print 'data len:', len(data) self.raw = data results = [] for xml in data: jdata = xmltodict.parse(ET.tostring(xml), postprocessor=strip_juniper_namespace, xml_attribs=False) ## ## Leaving jdata structure native until I have a chance ## to look at it (and other vendors' results) and restructure ## into something sane. ## At that point, I will want to make sure that all vendors ## return a dict with the same structure. ## self.data.append({'device': device, 'data': jdata}) results.append(jdata) self.store_results(device, results)