Skip to content

Instantly share code, notes, and snippets.

View joshgachnang's full-sized avatar

Josh Gachnang joshgachnang

View GitHub Profile
@joshgachnang
joshgachnang / gist:2305367
Created April 4, 2012 20:32
Python Random Alphanumeric String
import random
import string
# Returns a random alphanumeric string of length 'length'
def random_key(length):
key = ''
for i in range(length):
key += random.choice(string.lowercase + string.uppercase + string.digits)
return key
@joshgachnang
joshgachnang / gist:2306795
Last active April 30, 2024 03:34
Bash Check Username of User Running Script
if [ "$(whoami)" != "username" ]; then
echo "Script must be run as user: username"
exit 255
fi
@joshgachnang
joshgachnang / gist:2306856
Created April 5, 2012 00:33
Bash Generate Random Alphanumeric Password
# Generates a 16 character password.
function password {
RET=$(cat /dev/urandom | tr -cd [:alnum:] | head -c ${1:-16})
}
@joshgachnang
joshgachnang / gist:9237670
Last active August 29, 2015 13:56
Swift temp url
def _get_swift_temp_urls(self, url):
try:
key = SWIFT_TEMP_URL_KEY.encode('ascii', 'ignore')
except UnicodeDecodeError:
raise ValueError('SWIFT_TEMP_URL_KEY must be an ascii key.')
try:
temp_url_duration = int(SWIFT_TEMP_URL_DURATION)
except ValueError:
raise ValueError('SWIFT_TEMP_URL_DURATION must be an integer.')
method = SWIFT_TEMP_URL_METHOD
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/eventlet/hubs/hub.py", line 346, in fire_timers
timer()
File "/usr/local/lib/python2.7/dist-packages/eventlet/hubs/timer.py", line 56, in __call__
cb(*args, **kw)
File "/usr/local/lib/python2.7/dist-packages/eventlet/greenthread.py", line 194, in main
result = function(*args, **kwargs)
File "/opt/stack/ironic/ironic/conductor/task_manager.py", line 102, in wrapper
return f(*args, **kwargs)
File "/opt/stack/ironic/ironic/conductor/utils.py", line 54, in node_power_action
Traceback (most recent call last):
File "/data/dev/ironic-teeth-driver/.tox/pep8/local/lib/python2.7/site-packages/hacking/core.py", line 427, in is_module_for_sure
__import__(mod)
File "/data/dev/ironic-teeth-driver/.tox/pep8/src/ironic/ironic/__init__.py", line 22, in <module>
eventlet.monkey_patch(os=False)
AttributeError: 'module' object has no attribute 'monkey_patch'
import csv
import requests
import sys
IRONIC_BASE_URL = "http://10.127.75.253:6385/v1/"
def upload(row):
payload = {
"driver_info": {
Traceback (most recent call last):
File "/data/dev/ironic-python-agent/.tox/py27/local/lib/python2.7/site-packages/mock.py", line 1201, in patched
return func(*args, **keywargs)
File "/data/dev/ironic-python-agent/ironic_python_agent/tests/agent.py", line 253, in test__get_kernel_params_fail
params = agent_cmd._get_kernel_params()
File "ironic_python_agent/cmd/agent.py", line 31, in _get_kernel_params
LOG.exception('Could not read /proc/cmdline: {e}'.format(e=e))
File "/usr/lib/python2.7/logging/__init__.py", line 1445, in exception
self.logger.error(msg, *args, **kwargs)
File "/usr/lib/python2.7/logging/__init__.py", line 1166, in error
{
'city': 'Oakland, CA',
'high': 60.84,
'low': 60.84,
'sunrise': '2014-05-03 13:09:57',
'sunset': '2014-05-04 03:01:49',
'temperature': 60.84
'conditions': ['Clouds'],
'forecast': [{'date': '2014-05-03',
'day': 74.88,
{
"networks": [ // a network is attached to one link and contains a set of L3 configs, such as IP/netmask or whether to dhcp
{
"id": "servicenet", //required
"type": "ipv4-static", //required
"link": "servicenet_vlan", //required, single link
"ip": "10.0.0.5",
"gateway_ip": "10.0.0.1",
"netmask": "255.255.0.0"
"dns_nameservers": ["10.0.3.2"],