This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@when('rel.connected') | |
def handle_rel(rel): | |
hookenv.log('There are {} remote units'.format(rel.remote_count())) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', { |