def get_interfaces(self): """FTOS implementation of get_interfaces.""" iface_entries = self._get_interfaces_detail() interfaces = {} for i, entry in enumerate(iface_entries): if len(entry['iface_name']) == 0: continue if len(entry['mac_address']) == 0: continue # init interface entry with default values iface = { 'is_enabled': False, 'is_up': False, 'description': str(entry['description']), 'mac_address': u'', 'last_flapped': 0.0, # in seconds 'speed': 0, # in megabits 'mtu': 0, } # not all interface have MAC addresses specified in `show interfaces' # so if converting it to a MAC address won't work, leave it like that try: iface['mac_address'] = mac(entry['mac_address']) except AddrFormatError: pass # set statuses if entry['admin_status'] == 'up': iface['is_enabled'] = True if entry['oper_status'] == 'up': iface['is_up'] = True # parse line_speed if re.search(r'bit$', entry['line_speed']): speed = entry['line_speed'].split(' ') if speed[1] == 'Mbit': iface['speed'] = int(speed[0]) # not sure if this ever occurs elif speed[1] == 'Gbit': iface['speed'] = int(speed[0] * 1000) # parse mtu iface['mtu'] = int(entry['mtu']) # parse last_flapped iface['last_flapped'] = float( parse_uptime(entry['last_flapped'], True)) # add interface data to dict local_intf = canonical_interface_name(entry['iface_name']) interfaces[local_intf] = iface return interfaces
def get_facts(self): """FTOS implementation of get_facts.""" # default values. facts = { 'uptime': -1, 'vendor': u'Dell EMC', 'os_version': 'Unknown', 'serial_number': 'Unknown', 'model': 'Unknown', 'hostname': 'Unknown', 'fqdn': 'Unknown', 'interface_list': [], } show_ver = self._send_command("show system stack-unit 0") if "% Error: Value out of range at \"^\" marker." in show_ver: show_ver = self._send_command("show system stack-unit 1") # parse version output for line in show_ver.splitlines(): if line.startswith('Up Time'): uptime_str = line.split(': ')[1] facts['uptime'] = parse_uptime(uptime_str) elif line.startswith('Mfg By'): facts['vendor'] = line.split(': ')[1].strip() elif ' OS Version' in line: facts['os_version'] = line.split(': ')[1].strip() elif line.startswith('FTOS Version'): facts['os_version'] = line.split(': ')[1].strip() elif line.startswith('Serial Number'): facts['serial_number'] = line.split(': ')[1].strip() elif line.startswith('Service Tag'): facts['serial_number'] = line.split(': ')[1].strip() elif line.startswith('Product Name'): facts['model'] = line.split(': ')[1].strip() elif line.startswith('Current Type'): facts['model'] = line.split(': ')[1].strip() # invoke get_interfaces and list interfaces facts['interface_list'] = sorted(self.get_interfaces().keys()) # get hostname from running config config = self.get_config('running')['running'] for line in config.splitlines(): if line.startswith('hostname '): facts['hostname'] = re.sub('^hostname ', '', line) facts['fqdn'] = facts['hostname'] break return facts
def test_parse_uptime(self, test_case): """Test parse_uptime.""" tests = [ ['32w4d3h', 19710000, True], ['1w13d3h', 1738800, True], ['04:12:34', 15154, True], ['12:34:56', 45296, True], ['32 wk, 4 day, 3 hr, 4 min', 19710240, False], ['32 wk, 4 day, 3 hr, 4 min', 19710240, False], ['32 week(s), 4 day(s), 3 hour(s), 4 minute(s)', 19710240, False], ] for t in tests: out = parse_uptime(t[0], t[2]) assert out == t[1] return {}
def get_interfaces(self): """FTOS implementation of get_interfaces.""" iface_entries = self._get_interfaces_detail() interfaces = {} for i, entry in enumerate(iface_entries): if len(entry['iface_name']) == 0: continue if len(entry['mac_address']) == 0: continue # init interface entry with default values iface = { 'is_enabled': False, 'is_up': False, 'description': entry['description'], 'mac_address': mac(entry['mac_address']), 'last_flapped': 0.0, # in seconds 'speed': 0, # in megabits } # set statuses if entry['admin_status'] == 'up': iface['is_enabled'] = True if entry['oper_status'] == 'up': iface['is_up'] = True # parse line_speed if re.search(r'bit$', entry['line_speed']): speed = entry['line_speed'].split(' ') if speed[1] == 'Mbit': iface['speed'] = int(speed[0]) # not sure if this ever occurs elif speed[1] == 'Gbit': iface['speed'] = int(speed[0]*1000) # parse last_flapped iface['last_flapped'] = float(parse_uptime(entry['last_flapped'], True)) # add interface data to dict local_intf = canonical_interface_name(entry['iface_name']) interfaces[local_intf] = iface return interfaces