Skip to content

Instantly share code, notes, and snippets.

View ljjjustin's full-sized avatar

Jiajun Liu ljjjustin

View GitHub Profile
#!/bin/bash
SRCBR=br-int
PPORT=patch-tun
TAP=tap-${SRCBR}
OLD_PS1="$PS1"
cleanup() {
ovs-vsctl clear bridge ${SRCBR} mirrors
@ljjjustin
ljjjustin / bootstrap-ssh-key
Created August 16, 2018 02:27
bootstrap ssh key
#!/usr/bin/expect -f
set host [ lindex $argv 0 ]
set timeout 10
set password xxxxxx
spawn ssh-copy-id root@${host}
#!/bin/sh
NODE1=10.71.84.53
REGISTRY=quay.io/coreos/etcd
docker run \
-p 2379:2379 \
-p 2380:2380 \
--name etcd ${REGISTRY}:latest \
/usr/local/bin/etcd \
@ljjjustin
ljjjustin / ipmi-poweroff.go
Created March 27, 2018 09:46
go demo: IPMI poweroff
package main
import (
"fmt"
"os"
"strconv"
ipmi "github.com/vmware/goipmi"
)
@ljjjustin
ljjjustin / election.sql
Last active April 1, 2024 08:29
leader election using mysql
create table election (
id int(10) unsigned not null auto_increment,
name varchar(128) not null default '',
node varchar(128) not null default '',
last_seen timestamp not null default CURRENT_TIMESTAMP,
primary key (id),
unique key uniq_idx_name(name)
) engine=InnoDB;
#!/bin/bash
## purge record if resource_id is null
mysql -e "use transformer; delete from associations where resource_id='';"
mysql -e "use transformer; delete from associations where resource_type='OS::Cinder::VolumeAttachment';"
mysql -e "use transformer; drop table if exists tobe_deleted_ids; create table tobe_deleted_ids (resource_id varchar(80));"
## search nova related associations
mysql -e "insert into transformer.tobe_deleted_ids select resource_id from transformer.associations, (select uuid from nova.instances where nova.instances.deleted !=0) as vm where transformer.associations.resource_id=vm.uuid"
#!/bin/bash
if [ $# -ne 1 ]; then
echo "usage: $0 <volume id>"
fi
volume_id=$1
## check if volume exists
if cinder show ${volume_id} | grep -q 'No volume'; then
#!/bin/bash
if [ $# -ne 1 ]; then
echo "usage: $0 <image name>"
exit
fi
image=$1
rbd -p pool-beishu snap unprotect ${image}@snap
rbd -p pool-beishu snap rm ${image}@snap
#!/bin/bash
if [ $# -ne 1 ]; then
echo "usage: $0 <image name>"
exit
fi
image=$1
rbd -p pool-beishu snap unprotect ${image}@snap
rbd -p pool-beishu snap rm ${image}@snap
@ljjjustin
ljjjustin / sslvpn.sh
Created December 12, 2017 01:26
setup ssh vpn in one script
#!/bin/bash
vpn_server=10.70.239.196
vpn_tunnel_id=8
vpn_ip_prefix=192.168.48
vpn_monitor_port=50008
ensure_tun_device() {
local host=$1
local device=$2