Skip to content

Instantly share code, notes, and snippets.

View SEJeff's full-sized avatar

Jeff Schroeder SEJeff

View GitHub Profile
@SEJeff
SEJeff / human_readable_sizes.py
Created February 27, 2012 22:35
Nifty python function for turning machine readable bytes into human readable sizes
def hr_bytes(size):
'''
This just returns the bytes in a human readable format.
'''
hr = lambda s:[(s%1024**i and "%.1f"%(s/1024.0**i) or str(s/1024**i))+x.strip() for i,x in enumerate(' KMGTPEZY') if s<1024**(i+1) or i==8][0]
return hr(size)
@SEJeff
SEJeff / djangomodule.py
Created February 28, 2012 00:37 — forked from fatbox/djangomodule.py
Load Django modules from within a Salt module
"""
This allows you to import Django modules into a Salt module
"""
import logging
import sys
import os
log = logging.getLogger(__name__)
include:
- apt
# our custom sources
/etc/apt/sources.list.d/fatbox.list:
file:
- managed
- source: salt://fatbox/debian/apt/fatbox.list
- owner: root
- group: root
/etc/salt/minion:
file:
- managed
- owner: root
- group: root
- mode: 444
- source: salt://salt/files/salt-minion.config
- template: jinja
- context:
{% if grains['fqdn'] == 'clients.fatbox.ca' %}
@SEJeff
SEJeff / djangomodule.py
Created March 28, 2012 21:46 — forked from fatbox/djangomodule.py
Load Django modules from within a Salt module
"""
This allows you to import Django modules into a Salt module
"""
import logging
import sys
import os
log = logging.getLogger(__name__)
@SEJeff
SEJeff / salt_mock.py
Created April 5, 2012 17:03 — forked from tgecho/salt_mock.py
Brainstormed mock for testing salt states and modules
class Mock(object):
def __init__(self):
history = []
unmet_expectations = []
def __call__(self, func, *args, **kwargs):
"""
Here we can grab a copy of the actual function/state and insert
the Mock object as __salt__ so the usual calls to
@SEJeff
SEJeff / state.yaml
Created May 11, 2012 21:54
states + context + templates from @herlo
/home/kojiadmin/.koji/config:
file.managed:
- source: salt://koji/files/config
- user: kojiadmin
- group: kojiadmin
- mode: 644
- makedirs: true
- template: jinja
- context:
kojiweb_url: "http://koji2.egavas.org/koji/"
@SEJeff
SEJeff / gist:2669205
Created May 12, 2012 21:30
Good example state that configures redis
/etc/redis/redis.conf:
file.managed:
- source: salt://redis/redis.conf
- user: redis
- group: redis
- mode: 644
- template: jinja
- require:
- file: /etc/redis
- cmd: 'make && make install'
@SEJeff
SEJeff / yaml_ordered_dict.py
Created May 21, 2012 23:28 — forked from enaeseth/yaml_ordered_dict.py
Load YAML mappings as ordered dictionaries
import yaml
import yaml.constructor
try:
# included in standard lib from Python 2.7
from collections import OrderedDict
except ImportError:
# try importing the backported drop-in replacement
# it's available on PyPI
from ordereddict import OrderedDict
@SEJeff
SEJeff / gist:2769055
Created May 22, 2012 13:29 — forked from kadel/gist:2768868
Salt watch statement and requires example
ganglia-monitor:
pkg:
- installed
service:
- running
# Since the service name is ganglia-monitor and the daemon binary is gmond
- sig: '^gmond'
- watch:
- file: /etc/ganglia/gmond.conf
- pkg: ganglia-monitor