Skip to content

Instantly share code, notes, and snippets.

View fabiand's full-sized avatar

Fabian Deutsch fabiand

View GitHub Profile
@fabiand
fabiand / SimpleHTTPPutServer.py
Created May 22, 2013 14:34
A simple HTTP Server supporting put
# python -m SimpleHTTPPutServer 8080
import SimpleHTTPServer
import BaseHTTPServer
class SputHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def do_PUT(self):
print self.headers
length = int(self.headers["Content-Length"])
path = self.translate_path(self.path)
with open(path, "wb") as dst:
@fabiand
fabiand / virt-pexpect.py
Last active June 22, 2021 22:13
How to auto-test an image using pexpect
import pexpect
image = "fedora-20.img"
user = "root"
password = "changeme"
# Define the qemu cmd to run
# The important bit is to redirect the serial to stdio
cmd = "qemu-kvm"
cmd += " -m 1024 -serial stdio -net user -net nic"
NODEISO=$1
IMGBASEIMG=$2
in_node() {
guestfish --ro -a $NODEISO run : mount /dev/sda1 / : mount-loop /LiveOS/squashfs.img /isolinux : mount-loop /isolinux/LiveOS/ext3fs.img / : sh "$@" ;
}
in_imgbased() {
guestfish --ro -a $IMGBASEIMG run : mount /dev/HostVG/Image-0.0 / : sh "$@" ;
}
docker-pid() { docker inspect --format="{{.State.Pid}}" $1 ; }
DSTCT=${1}
DSTPID=$(docker-pid $DSTCT)
UNCONNECTEDETH=$(nmcli -t -f device,type,connection device | egrep "ethernet:--$" | cut -d ":" -f1)
for NIC in $UNCONNECTEDETH
do
echo "Moving '$NIC' to netns of '$DSTPID'"
@contextmanager
def download_iso(w):
# do download
yield path_to_w
# do removal
with downloaded_iso("centos") as isopath:
# do stuff
##### THIS IS EQUAL TO
@fabiand
fabiand / guestfish-ova.sh
Last active January 6, 2016 09:52
Convenience script to modify the qcow image inside an RHEV OVA using guestfish
#!/usr/bin/bash
err() { echo "ERROR $@" >&2 ; }
info() { echo "INFO $@" ; }
usage() { echo -e "Usage: $0 OVAFILENAME [<guestfish arguments>]\nExtracts the given OVA, runs guestfish on the image, and creates an OVA again after quitting guestfish." ; }
[[ ! -f "$1" ]] && { usage ; exit 1 ; }
@fabiand
fabiand / test-yum-check-update.sh
Created July 29, 2016 13:13
Test case to showcase that check-update does not see an update, but update then performs one
set -ex
export LC_ALL=C
TOPDIR=$PWD/rpms
ROOT=$PWD/root
REPO="$TOPDIR"
setup() {
rm -rf "$TOPDIR" "$ROOT"
set -ex
export LC_ALL=C
TOPDIR=$PWD/rpms
ROOT=$PWD/root
REPO="$TOPDIR"
setup() {
rm -rf "$TOPDIR" "$ROOT"
@fabiand
fabiand / net.yaml
Last active February 16, 2017 11:46
Story:
After a class is declared, a Network object can be created, which is getting
associated to such a class. The network object itself contains the logical
netowkr informations - eventually even IPAM needs to be discussed.
An interface on a VM is getting connected to a network.
---
kind: Network
metadata:

Keybase proof

I hereby claim:

  • I am fabiand on github.
  • I am fabiand (https://keybase.io/fabiand) on keybase.
  • I have a public key ASDFpvAiVJbqU0BD9fd2yA7RA-IdHOT8bLf4OA_WQaQe3go

To claim this, I am signing this object: