Skip to content

Instantly share code, notes, and snippets.

import collections
class TransformedDict(collections.MutableMapping):
def __init__(self, *args, **kwargs):
self.store = dict()
self.update(dict(*args, **kwargs)) # use the free update to set keys
def __getitem__(self, key):
return self.store[self.__keytransform__(key)]
python yourscript.py 2>&1 | awk '/ line / {file = gensub(/,/, "", "", $2); line = $4} END {printf("vim +%d %s\n",line, file)}'
# first example, data from different sources
---
openstack:
nova:
location:
source: link!openstack.hw.node0
conf:
source: link!/parent/location/fs/etc/nova/nova.conf
hw:
---
openstack:
nodes:
.backend: "sqlite!nodes.db"
keys:
.backend: "memcached!10.2.50.90:5553"
---
#!/bin/sh
IP=172.16.128.1
SOURCE_CMD="ssh root@${IP} ps w"
#SOURCE_CMD="cat /tmp/tpl"
while :; do
ping -W1 -c1 ${IP} && break
done
@metacoma
metacoma / sh
Created March 1, 2016 11:40
populate env
export IMAGE_ID=`nova image-list | awk '/TestVM/ {print $2}'` export NET_ID=`nova net-list | awk '/net04 / {print $2}'`; export FLAVOR_ID=`nova flavor-list | awk '/m1.micro/ {print $2}'`; seq 1 15 | xargs -tI% sh -c 'nova add-floating-ip `nova boot vm% --image $IMAGE_ID --flavor=${FLAVOR_ID} --nic net-id=$NET_ID | awk "/ id / {print \\$4}"` `nova floating-ip-create | awk "/[0-9]+?\.[0-9]+\./ {print \\$2}"`'
@metacoma
metacoma / ruby
Created March 2, 2016 20:40
upload host facts
#!/usr/bin/ruby
#
#
require 'astute'
require 'net/http'
require 'pp'
require 'yaml'
require 'json'
@metacoma
metacoma / ruby
Last active March 3, 2016 16:57
controller upgrade
def router_data(node, router_id):
stdout, _ = ssh.call(["/bin/bash", "-c", ". /root/openrc &&"
"neutron l3-agent-list-hosting-router "
"{0} -f json".format(router_id)],
stdout=subprocess.PIPE, node=node)
try:
return json.loads(stdout)[0]
except:
@metacoma
metacoma / shell
Last active March 4, 2016 14:33
trust for user
#!/bin/sh
KEYSTONE_USER=`cat /etc/fuel/astute.yaml | python -c 'import yaml, sys; print yaml.load(sys.stdin)["FUEL_ACCESS"]["user"]'`
KEYSTONE_PASS=`cat /etc/fuel/astute.yaml | python -c 'import yaml, sys; print yaml.load(sys.stdin)["FUEL_ACCESS"]["password"]'`
KEYSTONE_TENANT=admin
KEYSTONE_URL="http://127.0.0.1:5000/v3"
function auth_data() {
cat<<EOF
auth:
In [1]: from keystoneclient import session
In [2]: from keystoneclient.v3 import client as auth_client
In [3]: trustor_auth = auth_client.Client(auth_url = 'http://10.21.10.2:5000/v3', username = 'admin', password = 'admin', tenant_name = 'admin')
In [4]: sess = session.Session()
In [5]: trustor = auth_client.Client(session=sess, auth=trustor_auth)
In [7]: t = trustee.trusts.create(trustor_user = trustor_auth.get_user_id(sess), trustee_user = trustor_auth.get_user_id(sess), project = trustor_auth.get_project_id(sess), role_names = ['admin'], mpersonation=False, expires_at=None)
In [8]: t.id
Out[8]: u'c5135ad6d6cc4b5d8f108a66290e6303'