def get_facts(self): facts = {} try: self.device.op(cmd='<show><system><info></info></system></show>') system_info_xml = xmltodict.parse(self.device.xml_root()) system_info_json = json.dumps( system_info_xml['response']['result']['system']) system_info = json.loads(system_info_json) except AttributeError: system_info = {} if system_info: facts['hostname'] = system_info['hostname'] facts['vendor'] = py23_compat.text_type('Palo Alto Networks') facts['uptime'] = int( convert_uptime_string_seconds(system_info['uptime'])) facts['os_version'] = system_info['sw-version'] facts['serial_number'] = system_info['serial'] facts['model'] = system_info['model'] facts['fqdn'] = py23_compat.text_type('N/A') facts['interface_list'] = self._extract_interface_list() facts['interface_list'].sort() return facts
def get_facts(self): facts = {} try: self.device.op(cmd='<show><system><info></info></system></show>') system_info_xml = xmltodict.parse(self.device.xml_root()) system_info_json = json.dumps(system_info_xml['response']['result']['system']) system_info = json.loads(system_info_json) except AttributeError: system_info = {} if system_info: facts['hostname'] = system_info['hostname'] facts['vendor'] = py23_compat.text_type('Palo Alto Networks') facts['uptime'] = int(convert_uptime_string_seconds(system_info['uptime'])) facts['os_version'] = system_info['sw-version'] facts['serial_number'] = system_info['serial'] facts['model'] = system_info['model'] facts['fqdn'] = py23_compat.text_type('N/A') facts['interface_list'] = self._extract_interface_list() facts['interface_list'].sort() return facts
def test_convert_uptime_string_seconds(self): """ Tests the parser function ```convert_uptime_string_seconds```: * check if all raw uptime strings passed return the expected uptime in seconds """ # Regex 1 self.assertEqual(convert_uptime_string_seconds('24 days, 11 hours, 25 minutes'), 2114700) self.assertEqual(convert_uptime_string_seconds('1 hour, 5 minutes'), 3900) self.assertEqual(convert_uptime_string_seconds('1 year, 2 weeks, 5 minutes'), 32745900) self.assertEqual( convert_uptime_string_seconds('95 weeks, 2 days, 10 hours, 58 minutes'), 57668280) self.assertEqual( convert_uptime_string_seconds('26 weeks, 2 days, 7 hours, 7 minutes'), 15923220) self.assertEqual( convert_uptime_string_seconds('19 weeks, 2 days, 2 hours, 2 minutes'), 11671320) self.assertEqual( convert_uptime_string_seconds('15 weeks, 3 days, 5 hours, 57 minutes'), 9352620) self.assertEqual( convert_uptime_string_seconds('1 year, 8 weeks, 15 minutes'), 36375300) self.assertEqual( convert_uptime_string_seconds('8 weeks, 2 hours, 5 minutes'), 4845900) self.assertEqual( convert_uptime_string_seconds('8 weeks, 2 hours, 1 minute'), 4845660) self.assertEqual( convert_uptime_string_seconds('2 years, 40 weeks, 1 day, 22 hours, 3 minutes'), 87429780) self.assertEqual( convert_uptime_string_seconds('2 years, 40 weeks, 1 day, 19 hours, 46 minutes'), 87421560) self.assertEqual( convert_uptime_string_seconds('1 year, 39 weeks, 15 hours, 23 minutes'), 55178580) self.assertEqual( convert_uptime_string_seconds('33 weeks, 19 hours, 12 minutes'), 20027520) self.assertEqual( convert_uptime_string_seconds('33 weeks, 19 hours, 8 minutes'), 20027280) self.assertEqual( convert_uptime_string_seconds('33 weeks, 19 hours, 10 minutes'), 20027400) self.assertEqual( convert_uptime_string_seconds('51 weeks, 5 days, 13 hours, 0 minutes'), 31323600) self.assertEqual( convert_uptime_string_seconds('51 weeks, 5 days, 12 hours, 57 minutes'), 31323420) self.assertEqual( convert_uptime_string_seconds('51 weeks, 5 days, 12 hours, 55 minutes'), 31323300) self.assertEqual( convert_uptime_string_seconds('51 weeks, 5 days, 12 hours, 58 minutes'), 31323480) # Regex 2 self.assertEqual(convert_uptime_string_seconds('114 days, 22:27:32'), 9930452) self.assertEqual(convert_uptime_string_seconds('0 days, 22:27:32'), 80852) self.assertEqual(convert_uptime_string_seconds('365 days, 5:01:44'), 31554104) # Regex 3 self.assertEqual(convert_uptime_string_seconds('7w6d5h4m3s'), 4770243) self.assertEqual(convert_uptime_string_seconds('95w2d10h58m'), 57668280) self.assertEqual(convert_uptime_string_seconds('1h5m'), 3900)
def test_convert_uptime_string_seconds(self): """ Tests the parser function ```convert_uptime_string_seconds```: * check if all raw uptime strings passed return the expected uptime in seconds """ # Regex 1 self.assertEqual( convert_uptime_string_seconds('24 days, 11 hours, 25 minutes'), 2114700) self.assertEqual(convert_uptime_string_seconds('1 hour, 5 minutes'), 3900) self.assertEqual( convert_uptime_string_seconds('1 year, 2 weeks, 5 minutes'), 32745900) self.assertEqual( convert_uptime_string_seconds( '95 weeks, 2 days, 10 hours, 58 minutes'), 57668280) self.assertEqual( convert_uptime_string_seconds( '26 weeks, 2 days, 7 hours, 7 minutes'), 15923220) self.assertEqual( convert_uptime_string_seconds( '19 weeks, 2 days, 2 hours, 2 minutes'), 11671320) self.assertEqual( convert_uptime_string_seconds( '15 weeks, 3 days, 5 hours, 57 minutes'), 9352620) self.assertEqual( convert_uptime_string_seconds('1 year, 8 weeks, 15 minutes'), 36375300) self.assertEqual( convert_uptime_string_seconds('8 weeks, 2 hours, 5 minutes'), 4845900) self.assertEqual( convert_uptime_string_seconds('8 weeks, 2 hours, 1 minute'), 4845660) self.assertEqual( convert_uptime_string_seconds( '2 years, 40 weeks, 1 day, 22 hours, 3 minutes'), 87429780) self.assertEqual( convert_uptime_string_seconds( '2 years, 40 weeks, 1 day, 19 hours, 46 minutes'), 87421560) self.assertEqual( convert_uptime_string_seconds( '1 year, 39 weeks, 15 hours, 23 minutes'), 55178580) self.assertEqual( convert_uptime_string_seconds('33 weeks, 19 hours, 12 minutes'), 20027520) self.assertEqual( convert_uptime_string_seconds('33 weeks, 19 hours, 8 minutes'), 20027280) self.assertEqual( convert_uptime_string_seconds('33 weeks, 19 hours, 10 minutes'), 20027400) self.assertEqual( convert_uptime_string_seconds( '51 weeks, 5 days, 13 hours, 0 minutes'), 31323600) self.assertEqual( convert_uptime_string_seconds( '51 weeks, 5 days, 12 hours, 57 minutes'), 31323420) self.assertEqual( convert_uptime_string_seconds( '51 weeks, 5 days, 12 hours, 55 minutes'), 31323300) self.assertEqual( convert_uptime_string_seconds( '51 weeks, 5 days, 12 hours, 58 minutes'), 31323480) # Regex 2 self.assertEqual(convert_uptime_string_seconds('114 days, 22:27:32'), 9930452) self.assertEqual(convert_uptime_string_seconds('0 days, 22:27:32'), 80852) self.assertEqual(convert_uptime_string_seconds('365 days, 5:01:44'), 31554104) # Regex 3 self.assertEqual(convert_uptime_string_seconds('7w6d5h4m3s'), 4770243) self.assertEqual(convert_uptime_string_seconds('95w2d10h58m'), 57668280) self.assertEqual(convert_uptime_string_seconds('1h5m'), 3900)