1001QA.NET

Simplicity is the ultimate sophistication

Font Size

SCREEN

Layout

Cpanel

Python & Net Prog.

Windows Subsystem for Linux–Windows 10 is morphing into an All-in-One OS

Due to my regular work activities I disconnected myself from the Windows CLI and Windows in general for a long time. I was looking for a way to run Ansible on Windows when I came across WSL (Windows Subsystem for Linux). Wonderful surprise. I think that Microsoft changed the direction and instead of fighting Linux they decided to embrace it. An Azure SME that works for Microsoft was telling us that behind the curtain Azure has tons of Linux. Well now it is becoming available in any regular Windows 10 machine via WSL. It does not have a guy, not yet and it is missing some low level utils (ex tcpdump does not work yet) but I am confident that, litle by little) we will soon have a coherent and self sufficient WSL

You can read more about it here https://blogs.msdn.microsoft.com/commandline/2018/05/15/build-2018-recap/ (this includes the installation procedure)

 

Well done Microsoft!

Looking ahead when using TextFSM to extract information from text

TextFSM is a very useful Python module that can be used to extract information from a text and store the information in a tabular structure (table/spreadsheet etc)

The idea behind the TextFM is to create a template for each specific text you need to process (output of command) and to use that template to extract the information. You will define the column using the keyword “Value” in your template and then you will create rules to process each line.

There is a particular situation like below when you want to save all data collected from the lines between two similar lines (the lines containing the word “interface” in our case). I could not figure out other way to look ahead other than the below. The trick is suggested by the author of the module in his example of using lists. In our case we do not want lists but we just want to look ahead ….

interface Loopback1
interface Eth1/1
  speed 100
  duplex full
interface Eth1/2
  duplex full
interface Eth1/3
  speed 100

Your template could look like below

Value Required Interface (\S+)
Value Speed (\d+)
Value Duplex (full)

Start
# the below line will not save the record at
# the first hit because $Interface=''
# the second time the rule is hit (when we reach
# the next interface) it will save the already collected record) ^interface ->Continue.Record ^\s+speed ${Speed} ^\s+duplex ${Duplex} ^\interface ${Interface}

so you are saving the record only after looking forward for each interface line, processing the config lines and save when you hit the next "interface” line.

This is an important trick because that is the only way to look ahead... as far as I can tell (might be wrong I am just started using this)

    Python -useful links

    Image result for python iconI mostly use Python for Windows. Here are a couple of links that I always end up using in order to solve problems related to intalling Python packages under Windows.

    Most of the libraries that I have had to use are either not updated to the latest Python version or they require compiling from source which brings in another problem: you need the use the right compiler. So here are the links:

    Home Python & Net Prog.