Skip to main content

Posts

How to use DocOpt to generate Command Line Interface (CLI) tools

DocOpt is library that can generate beautiful command line interfaces using python. It is an alternative to ArgParse/OptParse and makes generating CLI interfaces a breeze. When generating CLI using ArgParse/OptParse we need to create a hierarchy of modules and submodules and link them together.  This process is tedious and debugging the errors is cumbersome. Instead, DocOpt parses the docstring (__doc__) of the file and generates a parser automatically. The docstring should be defined based on POSIX command description syntax. An example: $fincalc -h Usage: fincalc (si|simple-interest) -p <principal> -i <interest> -t <tenure> [--daily] [--plot-graph] fincalc (fd|fixed-deposit) -p <principal> -i <interest> -t <tenure> [--plot-graph] fincalc sip -p <principal> -i <interest> -t <tenure> [--plot-graph] fincalc emi -p <principal> -i <interest> -t <tenure> fincalc cagr -p <principal> -r <return...

How to map Docker container's eth0 interface to its host VethXXX interface

In order to troubleshoot a network issue, we will need to figure out the veth end points connecting a container to its host. There are multiple ways of going about this problem, I will show 2 simple ways and point out to a third. # Technique-1: Quick & Simple Get the interface details inside the container: / # ip addr show eth0 9 : eth0@ if 10 : mtu 1500 qdisc noqueue     link/ether 02:42:ac:11:00:03 brd ff:ff:ff:ff:ff:ff     inet 172.17.0.3/16 brd 172.17.255.255 scope global eth0        valid_lft forever preferred_lft forever The output is telling us that, the veth has two end points. One end point is called eth0@if10 which is assigned to the container and on the host the other end point will be named as vethxxx@if9. Lets check the host to confirm this. root@botserver1:~# ip a | grep  veth 10 : vetha708f89@ if9 : mtu 1500 qdisc noqueue master docker0 state UP group default Cool. The host has a vet...

WILT: Recover a deleted GIT branch

Lets say you just deleted your gits local and remote branches and wanted to recover them back. You can start by recovering the local branch and pushing it onto the remote. To start with, you need to execute the following command and figure out the SHA1 of the last commit you did onto your deleted branch $ git reflog dcdae48 HEAD@{0}: checkout: moving xxxxxxxxxxxxx 74041c0 HEAD@{1}: commit: UT fixes. 2045bbd HEAD@{2}: commit (merge): xxxxxxxxxxxxx e099ba5 HEAD@{3}: checkout: moving xxxxxxxxxxxxx be0992e HEAD@{4}: checkout: moving xxxxxxxxxxxxx The commits are listed from latest to oldest. Pick up the latest commit with your changes for the deleted branch. Lets say 74041c0 . Now checkout the master of your branch and merge the changes from the selected commit onto it. $ git checkout master $ git merge 74041c0 You can also create a branch directly from the SHA1: $ git branch SHA1 or $ git checkout -b SHA1 Resolve any merge conflicts that may arise and your...

WILT: How to reset your forgotten password on IRC

IRC is the platform OpenStack members use to coordinate and have weekly syncups. I recently upgraded my system and in the process lost the saved password for my account. The process to reset was a little difficult to figure out but turns out to be fairly simple. All you need to do is to execute the following command: /msg NickServ SENDPASS your-account-name

Solved: Fix for Git clone failure due to GnuTLS recv error (-9)

My devstack installation was failing with an error reported by the GnuTLS module as shown below: $ git clone https://github.com/openstack/horizon.git /opt/stack/horizon --branch master Cloning into '/opt/stack/horizon'... remote: Counting objects: 154213, done. remote: Compressing objects: 100% (11/11), done. error: RPC failed; curl 56 GnuTLS recv error (-9): A TLS packet with unexpected length was received. fatal: The remote end hung up unexpectedly fatal: early EOF fatal: index-pack failed The following Git config changes fixed the issue for me. Am hoping it will be useful for someone out there: $ git config http.sslVerify false $ git config --global http.postBuffer 1048576000

Fixing Openstack Cirros VM : atkbd serio0: Use setkeycodes 00 error

When a Cirros VM is launched in Openstack Newton using the latest branch code you may encounter an error which prevents you from logging into VM's console. As soon as you start typing the username 'cirros' you may find the following error message getting printed on the console: atkbd serio0: Unknown key released (translates Set 2, ................) atkbd serio0: Use 'setkeycodes 00 ' to make it known This is a known issue and is tracked @ https://bugs.launchpad.net/devstack/+bug/1619554 I had tough time finding a solution to this problem and the solution turns out to be quite a simple one. This issue is occurring due to a bug in the latest noVNC code and is tracked @ https://bugs.launchpad.net/horizon/+bug/1622684 This problem can be solved in two ways (as a workaround): 1. Set NOVNC_BRANCH=v0.6.0 in your local.conf file and restack 2. cd /opt/stack/noVNC     git checkout v0.6.0     Now go to your VM console and refresh it. It should start wo...

WILT: Fixing Virtual box shared clipboard issue

I have a Windows 10 laptop (host) which uses Virtualbox as the hypervisor. In the Virtualbox, I have a Ubuntu 16.10 VM. Once in a while its required to copy text between the VM and the host and Virtualbox has a feature to enable bi-directional shared clipboard: This feature does not work sometimes. After going through some discussion forums I came across the below suggestion which solved this problem. Run the following commands on the VM: sudo VBoxClient-all stop sudo VBoxClient-all start