Skip to content

Instantly share code, notes, and snippets.

View ekohl's full-sized avatar

Ewoud Kohl van Wijngaarden ekohl

View GitHub Profile
@ekohl
ekohl / demo.py
Created September 18, 2010 09:14
#!/usr/bin/python
def even(list):
"""
Returns all even numbers in the given list
>>> even(range(10))
[0, 2, 4, 6, 8]
"""
return filter(lambda x: x%2==0, list)
@ekohl
ekohl / libvirt2ganeti.py
Created February 22, 2011 11:17
Initial stab at libvirt to ganeti
import libvirt
from lxml import etree
sort_disks = lambda d: next(d.iter("target")).get("dev")
def main(host, opts):
#Connect to some hypervisor.
conn=libvirt.open("qemu:///system")
#Iterate through all available domains.
class PowerShellVmsResource {
enum Method { GET, ADD };
enum Detail {
DISKS("$_.getmemorystatistics(); $_.getcpustatistics(); "),
STATISTICS("$_.getdiskimages(); ");
public final String powershell;
@ekohl
ekohl / sdN_hook.py
Created August 17, 2011 17:40
RHEV 3 block device passthrough
#!/usr/bin/python
import os
import hooking
domxml = hooking.read_domxml()
devs = domxml.getElementsByTagName('devices')[0]
for passthrough in os.environ.get('passthrough', '').split(';'):
@ekohl
ekohl / domainsort.py
Created September 2, 2011 10:47
Sort domain names by their extension
#!/usr/bin/env python
import sys
domains = sys.stdin.read().split()
domains = sorted(list(reversed(domain.split("."))) for domain in domains)
domains = [ ".".join(reversed(domain)) for domain in domains ]
print "\n".join(domains)
@ekohl
ekohl / phonelog.py
Created September 29, 2011 11:12
Phone logging daemon
#!/usr/bin/env python
from optparse import OptionParser
from sqlalchemy import create_engine, Column, Integer, String, DateTime
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm.session import sessionmaker
from textwrap import dedent
from threading import Thread
import socket
import datetime
import logging
@ekohl
ekohl / gist:1600855
Created January 12, 2012 14:35
git insteadof
[url "git://github.com/"]
insteadOf = "gh:"
[url "git@github.com:"]
pushInsteadOf = "gh:"
class vmware {
if ($::virtual == 'vmware') {
yumrepo {'vmware-tools':
name => 'VMware Tools',
baseurl => 'http://packages.vmware.com/tools/esx/5.0/rhel$releasever/$basearch',
enabled => 1,
gpgcheck => 1,
gpgkey => 'http://packages.vmware.com/tools/VMWARE-PACKAGING-GPG-KEY.pub',
exclude => 'vmware-tools-libraries-x',
}
@ekohl
ekohl / listdir.c
Created June 1, 2012 11:41 — forked from anonymous/listdir.c.txt
listdir.c
#define _GNU_SOURCE
#include <dirent.h> /* Defines DT_* constants */
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <sys/syscall.h>
#define handle_error(msg) \
class proxy (
$ipaddr,
$netmask,
$gateway,
$reverse_domain,
$ntpservers = ['nl.pool.ntp.org'],
$dhcp = true,
$dhcp_range = false,
$dns = true,
$puppetca = false,