Skip to content

Instantly share code, notes, and snippets.

@rtomaszewski
rtomaszewski / gil_threads_test.py
Created July 31, 2012 20:39
An example of multithreaded python code that creates about 500 long running threads
import threading
import datetime
import time
from random import random
class ThreadClass(threading.Thread):
def set_id(self, id):
self.id=id
def dummy_delay(self):
@rtomaszewski
rtomaszewski / example_debug.py
Created July 29, 2012 19:41
Primitive logging functions in your python scripts that are buffered before will be printed on the stdout
# Try to execute the script in two different modes to see the difference
#
# $ python log.py | tee log
# <noting for a long time>
#
# $ python -u log.py | tee log
# my log message 0
#
import time
@rtomaszewski
rtomaszewski / naive_cloud_api_limits.py
Created July 29, 2012 17:53
Naive API trying to create too many cloud server
def cs_create(self, count, sample_nr):
name='test' + str(int(time.time()))
image=112
flavor=1
log("[%2d][%2d] creating image: " % (sample_nr, count) + pformat( {'name': name, 'image' : image, 'flavor' : flavor } ) )
sm=self.cs.servers
server=sm.create(name, image, flavor)
@rtomaszewski
rtomaszewski / cloud_api_limits.py
Created July 29, 2012 17:49
Be aware of the cloud API limitations when creating cloud servers
# example code that creates cloud server and try not to hit the cloud API climits
cs_count=13 # number of cs to build
build_nr=1
delayed_10s=False
while build_nr <= cs_count :
if 0==build_nr % 11 and not delayed_10s:
time.sleep(60+10)
import XenAPI
s=XenAPI.Session('http://localhost/')
s.login_with_password('root', 'password')
s.xenapi.VM.get_all()
Out[30]:
['OpaqueRef:fed9f387-359c-5e34-04b3-7e9de0271e9b',
'OpaqueRef:f21c711b-5de7-fb1f-5320-ea4b8fbbdac2',
...
'OpaqueRef:0032adf3-04d3-6cf7-94fe-9d06af09bec7']
@rtomaszewski
rtomaszewski / isolated-network-vm.sh
Created May 19, 2014 21:27
create a vm on isolated network
# (1)
$ xe vm-copy vm=vm-10 new-name-label=gateway-vm
$ xe network-list
$ xe vif-create network-uuid=b211707c-0f56-b33e-22b0-ad1816914b8a device=3 vm-uuid=4fb0febb-5659-f9b5-abf6-21cd63632c5b
$ xe vif-plug uuid=02600ba0-b040-733f-bcce-e64661dcb352
$ xe console vm=gateway-vm
# (2)
root@gateway-vm:/etc/network# cat interfaces
@rtomaszewski
rtomaszewski / import-vms.sh
Created May 17, 2014 23:04
create more vms using the import functions from xenserver
xe vm-export filename=vm-label1-export1.xva vm=vm-label
for i in $(seq 2 10); do
name="vm-$i"
echo -n "creating vm $name "
uuid=$(xe vm-import filename=vm-label1-export1.xva preserve=false)
xe vm-param-set name-label=$name uuid=$uuid
xe vm-start vm=$name
done
#!/bin/bash
set -e
set -x
template=`xe template-list name-label="Ubuntu Lucid Lynx 10.04 (64-bit)" --minimal`
vm=`xe vm-install template=$template new-name-label=vm-label`
network=`xe network-list bridge=xenbr0 --minimal`
vif=`xe vif-create vm-uuid=$vm network-uuid=$network device=0`
xe vm-param-set uuid=$vm other-config:install-repository=http://archive.ubuntu.com/ubuntu
@rtomaszewski
rtomaszewski / vmware-workstation-xenserver.conf
Created May 14, 2014 22:41
VMware Workstation VM config for XenServer
.encoding = "windows-1252"
config.version = "8"
virtualHW.version = "8"
numvcpus = "4"
scsi0.present = "TRUE"
scsi0.virtualDev = "lsilogic"
memsize = "4096"
scsi0:0.present = "TRUE"
scsi0:0.fileName = "xenserver5.vmdk"
ide1:0.present = "TRUE"
@rtomaszewski
rtomaszewski / gist-type-command.c
Created March 30, 2014 19:15
Uses stdin of the shell to simulate input string and type a command to run.
#include <strings.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>