Skip to content

Instantly share code, notes, and snippets.

View mrcrilly's full-sized avatar

Michael Crilly mrcrilly

View GitHub Profile
@mrcrilly
mrcrilly / subnet_endpoint.py
Created January 30, 2014 02:55
SQLAlchemy Subnet help
@app.route('/subnets/edit/<int:subnetid>', methods=['GET', 'POST'])
def subnets_edit(subnetid):
target = Subnet.query.get(subnetid)
form = subnet.SubnetForm(obj=target)
if form.validate_on_submit():
try:
ipaddress.IPv4Network(form.subnet.data.decode())
except ipaddress.AddressValueError as e:
flash(u"Error in address: {}".format(e.message), category='danger')
@mrcrilly
mrcrilly / reports.html
Created January 31, 2014 09:45
NVD3 Template
{% extends "base.html" %}
{% block title %}VS VLAN DB - Reports{% endblock %}
{% block css %}
<link href="{{url_for('static', filename='assests/css/nv.d3.min.css')}}" rel="stylesheet">
<style type="text/css">
/*#chart .pie {
width: 300px;
height: 300px;
}*/
</style>
@mrcrilly
mrcrilly / simples
Created March 12, 2014 16:01
BDD Tests
$ env/bin/behave -kt organisation -t save
Feature: Portal Showback Database Models # features/portaldatabase.feature:1
@organisation @save
Scenario Outline: I want to save a new organisation # features/portaldatabase.feature:45
Given i have a new organisation, "Crilly Ltd" # features/steps/portaldatabase.py:9 0.000s
When i create a new organisation object # features/steps/portaldatabase.py:14 0.001s
And i have an organisation model back called "<Organisation: Crilly Ltd>" # features/steps/portaldatabase.py:73 0.000s
And i save the organisation object to the database # features/steps/portaldatabase.py:132 0.008s
And i query the database for the organisation "Crilly Ltd" # features/steps/portaldatabase.py:61 0.002s
@mrcrilly
mrcrilly / scenario_outline.feature
Created March 12, 2014 16:09
"Scenario Outline" example
Feature: Portal Showback Database Models
# Creating models
@organisation @create
Scenario Outline: I want to create a new organisation
Given i have a new organisation, <Org Name>
When i create a new organisation object
Then i will have an organisation model back called <Org Object Name>
@mrcrilly
mrcrilly / sqla-snip
Created March 25, 2014 17:59
SQLALchemy Exception Snip
Exception in thread Thread-20:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 808, in __bootstrap_inner
self.run()
File "/home/movedx/Documents/Git/project-showback/showback/endpoints.py", line 42, in run
self.compute_stats(device)
File "/home/movedx/Documents/Git/project-showback/showback/endpoints.py", line 58, in compute_stats
if not self.db.query(CPUStatistic).filter(CPUStatistic.epoch==epoch).filter(CPUStatistic.device==device).first():
File "/home/movedx/Documents/Git/project-showback/env/local/lib/python2.7/site-packages/sqlalchemy/sql/operators.py", line 296, in __eq__
return self.operate(eq, other)
@mrcrilly
mrcrilly / sqlalchemy_threading.py
Last active August 29, 2015 13:57
SQLAlchemy Threading
db_engine = create_engine(app.config['SQLALCHEMY_DATABASE_URI'])
dbo = scoped_session(sessionmaker(autocommit=False, autoflush=False, bind=db_engine))
class ThreadedCollector(threading.Thread):
def __init__(self, collector, queue):
self.collector = collector
self.queue = queue
threading.Thread.__init__(self)
@mrcrilly
mrcrilly / worker.py
Created March 27, 2014 13:53
RabbitMQ Worker Problem
def worker_callback(self, ch, method, properties, body):
if self.debugging: logging.debug("Worker received work: {0}".format(body))
work = json.loads(body)
device = Device.query.filter_by(name=work['description']).first()
if not device:
if self.debugging:
logging.error("Failed to find device in database: {0}. Message will be acknowledged.".format(work['description']))
---
- hosts: puppetmasters
remote_user: user
sudo: true
vars:
development_path: "/home/movedx/Documents/Git"
remote_path: "/etc/puppet/modules"
tasks:
- name: Push the module to the remove Puppet Master(s)
synchronize: src={{development_path}}/{{module_name}}/. dest={{remote_path}}/{{module_name}}
@mrcrilly
mrcrilly / deploy.txt
Created April 2, 2014 12:08
Module Deploy
$ ./deploy_module core ssh
PLAY [puppetmasters] **********************************************************
GATHERING FACTS ***************************************************************
ok: [a.b.c.d]
TASK: [Push the module to the remote Puppet Master(s)] ************************
changed: [a.b.c.d]
@mrcrilly
mrcrilly / puppet.conf
Created April 4, 2014 08:38
Puppet Master
### File managed with puppet ###
## Module: 'puppet'
## Template source: 'MODULES/puppet/templates/puppet.conf.erb'
[main]
# The Puppet log directory.
# The default value is '$vardir/log'.
logdir = /var/log/puppet
# Where Puppet PID files are kept.