Skip to content

Instantly share code, notes, and snippets.

View jimbaker's full-sized avatar

Jim Baker jimbaker

View GitHub Profile
@jimbaker
jimbaker / host-label-put.diff
Created October 11, 2016 06:00
Add host label PUT support
diff --git a/craton/api/v1/resources/inventory/hosts.py b/craton/api/v1/resources/inventory/hosts.py
index 39264a5..39be56a 100644
--- a/craton/api/v1/resources/inventory/hosts.py
+++ b/craton/api/v1/resources/inventory/hosts.py
@@ -97,10 +97,10 @@ class HostsLabels(base.Resource):
Update existing device label entirely, or add if it does
not exist.
"""
- print(request.json)
+ import sys; print(request.json, file=sys.stderr)
@jimbaker
jimbaker / worker.rst
Created September 15, 2016 16:18
Description of the worker interaction

Workers are specialized as follows:

  • OpenStack Ansible, consuming that endpoint - we may want to assume Docker here
  • Generalized Docker-based commands, using docker-py to wrap

All workers have the following environment variables set:

  • CRATON_URL - URL for the Craton API endpoint
  • CRATON_TOKEN - time-limited, scoped token (inventory + keys) for working with the Craton service
@jimbaker
jimbaker / craton-lightning-talk.md
Created September 15, 2016 15:51
Lightning talk for Craton - need to add slides; also create elevator pitch

It's Friday. You have an embargoed fix you need to apply this weekend. Your cloud has 50 - or maybe 500 - or maybe 50000 physical hosts or more. Can you deploy this patch across your cloud, without causing customer outages? And without introducing new problems?

Fleet management is the answer; and the Craton project implements this approach.

Think of the hardware in your data center as a fleet, much like an admiral with his or her ships. This admiral knows ship positions,

@jimbaker
jimbaker / build-and-run-fixture-docker-container.sh
Created September 14, 2016 15:31
Some initial commands to setup and run a test container fixture using Docker CLI - for real test code, this should be wrapped in a Python UnitTest class and use docker-py
docker build -t craton-inventory:latest .
# assign a random (ephemeral) port to our localhost's interface for
# the container's 8080; this ensures we are not tying up 8080 for
# testing!
docker run -p 127.0.0.1::8080 -d craton-inventory:latest
# get the container name/uuid along with the exposed port for 8080;
# in the case below, it's sick_lichterman and 32775 respectively
# for real usage, this should be done programmatically using docker-py
@jimbaker
jimbaker / test_ordereddict_jy.py
Created September 9, 2016 16:29
Test to demonstrate that pure Python OrderedDict in Jython 2.7 is not threadsafe
from collections import OrderedDict
from test import test_support
import threading
import time
import unittest
class ThreadSafetyTestCase(unittest.TestCase):
def run_threads(self, f, num=10):
@jimbaker
jimbaker / device-refactor.diff
Last active September 6, 2016 23:37
Minor updates, including refactoring Device to capture parent-child relationship (device tree), along with variable inheritance
diff --git a/craton/db/sqlalchemy/alembic/versions/ffdc1a500db1_craton_inventory_init.py b/craton/db/sqlalchemy/alembic/versions/ffdc1a500db1_craton_inventory_init.py
index 4032017..513476e 100644
--- a/craton/db/sqlalchemy/alembic/versions/ffdc1a500db1_craton_inventory_init.py
+++ b/craton/db/sqlalchemy/alembic/versions/ffdc1a500db1_craton_inventory_init.py
@@ -41,7 +41,7 @@ def upgrade():
sa.Column('region_id', sa.Integer(), nullable=False),
sa.Column('cell_id', sa.Integer(), nullable=True),
sa.Column('project_id', sa.Integer(), nullable=False),
- sa.PrimaryKeyConstraint('id')
+ sa.PrimaryKeyConstraint('id'),
@jimbaker
jimbaker / test_cc.py
Last active November 15, 2016 15:29
Some basic testing of cratonclient
from __future__ import print_function
from ipaddress import ip_address
# Ideally we have some __init__ support to reduce different import locations
from cratonclient.session import Session
from cratonclient.v1.client import Client as CratonClient
from cratonclient.v1.hosts import HostManager
# useful to generate some inventory with
# $ python tools/generate_fake_data.py --url http://127.0.0.1:8080/v1 --user demo --project $UUID --key demo
@jimbaker
jimbaker / setup.diff
Last active August 31, 2016 23:05
Some various updates to Craton's startup to make it work better - for Syed
diff --git a/setup.cfg b/setup.cfg
index d4033d4..1d72ff5 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -25,6 +25,7 @@ packages =
[entry_points]
console_scripts =
+ craton-api = craton.cmd.api:main
craton-worker = craton.cmd.worker:main
@jimbaker
jimbaker / rebind-sys-exit.txt
Last active August 16, 2016 00:15
Rebind sys.exit in Jython
$ ~/jython2.7.0/bin/jython
Jython 2.7.0 (default:9987c746f838, Apr 29 2015, 02:25:11)
[Java HotSpot(TM) 64-Bit Server VM (Oracle Corporation)] on java1.7.0_75
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> def f(*args):
... print "tried to exit %r" % (args,)
...
>>> sys.exit = f
>>> sys.exit(-1)
@jimbaker
jimbaker / audit.py
Last active July 28, 2016 16:50
Craton client ideas for defining, submitting workflows for execution
from cratonclient.v1 import make_session, inventory
# audit workflow
session = make_session(...) # or use CRATON_* environ variables...
osa_base = inventory.Workflow(session).get('openstack-ansible')
# Defines a new workflow, based on an existing one;
# in this case we have specific support for OSA containers;
# although presumably we don't see this actually applying here