Keep Da Link

To content | To menu | To search

March 29, 2012

Python Requests hooks

Python requests is the de facto HTTP package for Python, nice API, wonderful documentation.

I had the need to sign my requests and to change the header after the request was built, here is hooks, simply call a function pre_request and your are done:

 

 

  1. def auth_sign(req):
  2.     user_id = '4f47a5f21aebcedff3001234'
  3.     secret_key = 'C21LHQ5R4RVO2U2UMTEZ'
  4.     timestamp = str(int(time.mktime(time.gmtime())))
  5.     string_to_sign = req.method + '\n' + user_id + '\n' + timestamp + '\n' + req.path_url + '\n' + req._enc_data
        sign =  base64.b64encode(hmac.new(secret_key, string_to_sign, hashlib.sha256).digest())
  6.     headers = {'X-User-ID':user_id, 'X-Expires':timestamp, 'X-Signature':sign}
  7.     req.headers.update(headers)
  8.  
  9. payload = {'name':'Test event', 'description':'Description blabla', 'category':'1'}
  10. = requests.post(API_URL + 'event', data=payload, hooks={'pre_request':auth_sign})

 

And remember to use httpie Curl for human which is using requests

Continue reading...

Feb. 28, 2012

FreeBSD vimage jails

 

I tried to use VIMAGE for jails, can be summarized as: independant network stack, firewalling, nat, a real loopback ... for your jails

First I had pf in my kernel, it does not work with VIMAGE, it will kernel panic, (as module too), so remove it (I hope it will be solved soon).

I used the package from DruidBSD: vimage boot, and used the following config:

vimage_enable="YES"     
vimage_list="testjail"
vimage_testjail_rootdir="/usr/jails/testjail"           # root directory
vimage_testjail_hostname="testjail"      # hostname
vimage_testjail_devfs_enable="YES"                      # mount devfs
vimage_testjail_vnets="vtnet1"                         # network interfaces

vtnet1 is a dedicated hard interface (from KVM) and will appears only in the jail after you start /etc/rc.d/vimage start

Nice but I need a bridge there so I needed netgraph modules, but I encounter this issue: link_elf_obj: symbol ifnet undefined, for unknown reason VIMAGE will break ng_ether if used as module, add it to your kernel then rebuild:

# Virtual networking for jail
options         VIMAGE
device          epair
device          if_bridge

option          NETGRAPH
option          NETGRAPH_ETHER

No you can use vimage_testjail_bridges="vtnet0" instead of vimage_testjail_vnets, it will automagically create a bridge visible in you jail named ng0_testjail.

Happy jailing !

 

Feb. 7, 2012

FreeBSD 9.0 ZFS root on OVH

I had so much pain to make it work so here is how to have a ZFS root with a raidz pool on 5 disks, specially with OVH without any console or kvm to debug the boot process.

The server has 5 disks that I put in raidz and boot on it, but this should apply to most installation.

Continue reading...

Jan. 5, 2012

compile and run xv6 on Mac Os X 6.828

The MIT has created xv6: an operating system for learning purpose

This works better and takes less time to create a working environnement for xv6 on Mac Os X, than the recommandations proposed on Tools used in 6.828 simply run this 

port install i386-elf-gcc
port install qemu

And change the Makefile like this:

-#TOOLPREFIX = i386-jos-elf-
+TOOLPREFIX = i386-elf-
 
-#QEMU = 
+QEMU = /opt/local/bin/qemu-system-i386
 
-CC = $(TOOLPREFIX)gcc
+CC = $(TOOLPREFIX)gcc-4.3.2

Here is a working gdb binary simply bunzip2 it then invoke it from the xv6 directory souce tree, (tested on osx Lion).

make qemu will compile and run xv6 in qemu

make qemu-dbg will run xv6 in debug mode, run gdb-target-i386-elf and c for continue

Enjoy, thanks MIT.

Continue reading...

Nov. 15, 2011

compile gevent on OSX or FreeBSD with pip

It's more a reminder to myself, gevent depends on libevent2 but the setup.py doesn't correcty look for it, a simple solution:

export CFLAGS=-I/usr/local/include
export LDFLAGS=-L/usr/local/lib
pip install gevent

change it for /opt/local/... if you are on OSX or you will get a bunch of errors

   /Developer/usr/bin/llvm-gcc-4.2 -fno-strict-aliasing -fno-common -dynamic -pipe -O2 -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/opt/local/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c gevent/core.c -o build/temp.macosx-10.7-x86_64-2.7/gevent/core.o
    In file included from gevent/core.c:225:
    gevent/libevent.h:9:19: error: event.h: No such file or directory
    gevent/libevent.h:38:20: error: evhttp.h: No such file or directory
    gevent/libevent.h:39:19: error: evdns.h: No such file or directory

By the way here is the ultimate stacks for python web dev ;)

pip install flask 
pip install requests
export CFLAGS=-I/usr/local/include
export LDFLAGS=-L/usr/local/lib
pip install gevent
pip instal ujson
pip install validictory

Oct. 14, 2011

FreeBSD 9.0 guest with virtio support in KVM

Performance are really bad for FreeBSD in KVM, one solution is to use paravirtualized driver, virIO.

Continue reading...

Install FreeBSD 9.0 with ZFS root

The "new" FreeBSD installer does not give you the options to simply install ZFS as root, so sad, here is how to do it.

Continue reading...

Aug. 31, 2011

Gimp 2.7.3 on OSX

Gimp 2.7.3 has been released but no one ports it to OSX already here is an ugly working way.

 

EDIT: The macport is now up to date so no need to do this anymore !

Continue reading...

Aug. 16, 2011

Enhance your Python

Nohting new here but a list of what you should read to be a better Python developer, for intermediate and advanced Pythoners, in no particular order.

Continue reading...

March 31, 2011

(Re)Discovering FreeBSD and ZFS

Since Sun's killers euh Oracle shutdown OpenSolaris, FreeBSD is becoming more and more attracting with ZFS port, you should really give it a try (We are back baby).

Here is a fast installation of FreeBSD with a ZFS root.

Continue reading...

- page 1 of 26 -