Skip to content

Instantly share code, notes, and snippets.

View johnsca's full-sized avatar

Cory Johns johnsca

View GitHub Profile
class Bundle(dict)
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._normalize_bundle()
def _normalize_bundle(self):
""" Normalizes bundle for things
like applications vs. services
"""
if 'services' in self:
import asyncio
import threading
import time
def thread_func():
print('thread_func: start')
async def inner_async(loop):
print('inner_async: start')
await asyncio.sleep(1, loop=loop)
from charms.reactive.context import relation_endpoint
@when('charm.installed', 'relation_endpoint.db.ready')
def handler():
render_config(hostnames=relation_endpoint.user_db.hostnames)
relation_endpoint.admin_db.hostnames
@johnsca
johnsca / handlers.py
Created June 7, 2017 15:38
charms.reactive remote count
@when('rel.connected')
def handle_rel(rel):
hookenv.log('There are {} remote units'.format(rel.remote_count()))
@johnsca
johnsca / c.py
Last active May 25, 2017 22:31
proof-of-concept async subprocess file tail
#!/usr/bin/python3
import asyncio
import aiofiles
import textwrap
consumer = textwrap.dedent(
"""
for i in {1..5}; do
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
from charms.leadership import leader_set # important; don't use hookenv.leader_set
@when('leadership.is_leader')
def change_leader():
leader_set(hostname=hookenv.unit_private_ip())
leader_set(public_ip=hookenv.unit_public_ip())
leader_set(username='cluster')
leader_set(init=True)
@johnsca
johnsca / services.py
Last active August 29, 2015 14:06
Chamilo charm services block
def manage():
manager = ServiceManager([
{
'service': 'apache2',
'ports': [80],
'provided_data': [helpers.HttpRelation()], # interfaces provided by this charm
'required_data': [ # requirements for this charm to be started
helpers.RequiredConfig('domain', 'pass'),
helpers.MysqlRelation(),
helpers.StoredContext('chamilo-secret.json', {