diff --git a/.gitignore b/.gitignore index fbf02d9..8559810 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *swp builds +deps diff --git a/layer.yaml b/layer.yaml index 102cf18..81dae31 100644 --- a/layer.yaml +++ b/layer.yaml @@ -1 +1,11 @@ -includes: ['layer:basic'] # if you use any interfaces, add them here +includes: + - layer:basic + - layer:apt + - interface:mysql +options: +# basic: +# packages: +# - python3-psycopg2 + apt: + packages: + - git diff --git a/metadata.yaml b/metadata.yaml index 3323217..c76399d 100644 --- a/metadata.yaml +++ b/metadata.yaml @@ -9,3 +9,6 @@ tags: - misc subordinate: false series: ['xenial'] +requires: + mysqlbackend: + interface: mysql diff --git a/reactive/simple_react.py b/reactive/simple_react.py index 0da8636..9c17e64 100644 --- a/reactive/simple_react.py +++ b/reactive/simple_react.py @@ -1,18 +1,23 @@ from charms.reactive import when, when_not, set_state +from charmhelpers.core.hookenv import status_set, log +from charms.reactive import endpoint_from_flag +import charms.apt -@when_not('simple-react.installed') -def install_simple_react(): - # Do your setup here. - # - # If your charm has other dependencies before it can install, - # add those as @when() clauses above., or as additional @when() - # decorated handlers below - # - # See the following for information about reactive charms: - # - # * https://jujucharms.com/docs/devel/developer-getting-started - # * https://github.com/juju-solutions/layer-basic#overview - # - print("I hope this is logged!") - set_state('simple-react.installed') +@when_not('apt.installed.git') +def git_not_installed_yet(): + log("DEBUG: 1: Waiting for git to be installed") + status_set('waiting', 'DEBUG: 1: Waiting for git to be installed') + +@when('apt.installed.git') +def git_installed(): + log('DEBUG: 2: Git is now installed, waiting for db to be connected') + set_state('simple-react.wait4db') + status_set('blocked', 'Waiting for db to be connected') + +@when('mysqlbackend.available') +@when('simple-react.wait4db') +def announce_no_db(): + mysql = endpoint_from_flag('mysqlbackend.available') + log('DEBUG: 3: The MySQL backend is not yet available at ' + mysql.connection_string()) + status_set('active', 'The MySQL backend is available at ' + mysql.connection_string())