Skip to content

Instantly share code, notes, and snippets.

@ziadsawalha
ziadsawalha / buglist.py
Created December 17, 2011 21:42
Launchpad Project Bug Lister with Milestones
#!/usr/bin/env python
#
# Lists Launchpad bugs in the console showing their targetted milestone
#
# Usage: python buglist.py [project_name]
#
# I created this when I couldn't find a way to list the bugs in Keystone and
# show their targetted milestones so I could shuffle them around
@ziadsawalha
ziadsawalha / config.py
Created December 19, 2013 19:38
Python module Generic to parse command-line, environment, keyring, and config file options dynamically
"""
Configuration Parser
Configurable parser that will parse config files, environment variables,
keyring, and command-line arguments.
Example test.ini file:
@ziadsawalha
ziadsawalha / allow_mongo_dot_keys.py
Created December 20, 2013 07:40
How to allow keys with dots in them in mongodb using python
from pymongo.son_manipulator import SONManipulator
class KeyTransform(SONManipulator):
"""Transforms keys going to database and restores them coming out.
This allows keys with dots in them to be used (but does break searching on
them unless the find command also uses the transform.
Example & test:
# To allow `.` (dots) in keys
.canvas text {
font-family: verdana;
font-size: small;
}
.canvas rect.border {
stroke: gray;
stroke-width: 1;
fill: transparent;
display: inline;
{
"credentials": [
{
//Used for all hosts not explicitely called out below
"username": "root",
"private-key": "----BEGIN ... KEY----",
},
{
@ziadsawalha
ziadsawalha / gist:9657896
Last active August 29, 2015 13:57
Get local ip addresses
import socket
def get_local_ips():
"""Return local ipaddress(es)."""
list1 = []
list2 = []
defaults = ["127.0.0.1", r"fe80::1%lo0"]
hostname = None
Traceback (most recent call last):
...
File "/Users/me/.virtualenvs/waldo/lib/python2.7/site-packages/openstack/compute/client.py", line 60, in _cs_request
resp, body = self.request(url, method, **kwargs)
File "/Users/me/.virtualenvs/waldo/lib/python2.7/site-packages/openstack/compute/client.py", line 47, in request
raise exceptions.from_response(resp, body)
BadRequest: Second simultaneous read on fileno 29 detected. Unless you really know what you're doing, make sure that only one greenthread can read any particular socket. Consider using a pools.Pool. If you do know what you're doing and want to disable this error, call eventlet.debug.hub_prevent_multiple_readers(False) (HTTP 400)
context = pyrax.create_context(id_type="rackspace", username=username, tenant_id=tenant_id)
context.auth_with_token(auth_token, tenant_id=tenant_id)
if "compute" in context.services:
servers = pyrax.connect_to_cloudservers(context=identity, region=region)
print servers.list()
else:
print "You don't have a 'compute' endpoint in your catalog"
def _safe_context_region(region=None, context=None):
"""Value to use when no region is specified."""
context = context or identity
ret = region or settings.get("region")
if not ret:
# Nothing specified; get the default from the identity object.
ret = context.get_default_region()
if not ret:
# Use the first available region
try:
@ziadsawalha
ziadsawalha / README.md
Last active August 29, 2015 14:21
Code Deployment for Humans

Project [To Be Named]

Code Deployment for Humans

Keeping up with configuration management tools is a distraction from writing beautiful code.

Let's develop a simple, elegant way to describe how our app is installed, how to run it, and what it needs.

If the focus is on our application, the description should be independent of configuration management tools (ex. Chef, Puppet), languages (Ruby, Python, JavaScript) and should work for running the app on dev laptops (Vagrant, Docker) and popular clouds (ex. AWS, OpenStack/Rackspace).