Wednesday, May 29, 2013

splitting words into syllables with python

There is one very easy way to achieve it:

pip install pyhyphen

from hyphen import Hyphenator
from hyphen.dictools import *

for lang in ['es_MX', 'es_SP']:
        if not is_installed(lang): install(lang)
h_mx = Hyphenator('es_MX')
print h_mx.syllables(u"modernismo")

For more info:

Just in case you wondered, I need this as I'm working on mastering a mnemonic system based on the phonetic sound of words.

Monday, May 27, 2013

A virtual IP? What for? #linux

Layman's definition.
 It's an additional IP you assign to an interface by creating a virtual interface upon a real interface.

What for?
 For high availability scenarios, in which a service connects to a virtual IP pointing to a service (i.e. a database) .
1. The service breaks and a standby takes over bringing up the same virtual IP address automatically.
2. The application server reconnects to the standby as if nothing happened.

What kind of IP?
 Any available IP on the same network as the primary interface.


- An application server is associated to a database on
(address pointing to the database's virtual interface)
- The database server breaks down
- Bring down its virtual interface (if possible)
- On the standby server bring up the virtual interface with a virtual IP address.
ifconfig p2p1:0 inet netmask

- Refresh the arp cache on a neighbouring server (that in which the application making use of the service is hosted).
arping -U -w 1  -I p2p1

(no response is expected)

- From the same neighbour:

64 bytes from icmp_seq=1 ttl=64 time=0.538 ms
64 bytes from icmp_seq=2 ttl=64 time=0.318 ms
64 bytes from icmp_seq=3 ttl=64 time=0.320 ms
64 bytes from icmp_seq=4 ttl=64 time=0.623 ms
64 bytes from icmp_seq=5 ttl=64 time=0.278 ms
64 bytes from icmp_seq=6 ttl=64 time=0.287 ms
64 bytes from icmp_seq=7 ttl=64 time=0.197 ms
64 bytes from icmp_seq=8 ttl=64 time=0.280 ms

- Provided a standby database takes over as a part of a failover procedure, it must take over the same virtual IP.

- Care must be taken to make sure that the old database server's virtual interface gets brought down so it doesn't cause havoc (lookup the term STONITH)
- If using Dynamic Host Configuration Protocol make sure the virtual IP doesn't get assigned to any host automatically by restricting automatic leases to a lower range.


Tuesday, May 7, 2013

python-fabric. Easing multiple servers administration

I'm deploying a test scenario involving 16 pristine virtual machines and as a lazy administrator I'd hate to do the same configuration 16 times, that's what python-fabric is useful for.

From the official website:

What is Fabric?

As the README says:
Fabric is a Python (2.5 or higher) library and command-line tool for streamlining the use of SSH for application deployment or systems administration tasks.
More specifically, Fabric is:
  • A tool that lets you execute arbitrary Python functions via the command line;
  • A library of subroutines (built on top of a lower-level library) to make executing shell commands over SSH easy and Pythonic.
Naturally, most users combine these two things, using Fabric to write and execute Python functions, or tasks, to automate interactions with remote servers. Let’s take a look.

This is my first script which copies my public key into the test machines:

from fabric.api import local,env

hosts = []
for i in range(1,17):
   hosts.append( "box%d" % i)

env.hosts= hosts
def test_ssh():
         local("""ssh -o PasswordAuthentication=no root@%s "ifconfig | grep  -E  'inet.*192.168.0' | sed 's/\s\s*/ /g' | cut -d' ' -f3" """
      except SystemExit as e:
         local("ssh-copy-id root@%s"

If you have to administer multiple machines on a daily basis, I advice you give python-fabric a try.