From 913ef66ebe3af8aba3b91669d8f63dd151756960 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Wed, 30 May 2018 07:25:35 +0000 Subject: [PATCH 1/3] Changed status --- reactive/simple_react.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/reactive/simple_react.py b/reactive/simple_react.py index 0da8636..a5ac1d4 100644 --- a/reactive/simple_react.py +++ b/reactive/simple_react.py @@ -1,4 +1,5 @@ from charms.reactive import when, when_not, set_state +from charmhelpers.core.hookenv import status_set @when_not('simple-react.installed') @@ -15,4 +16,5 @@ def install_simple_react(): # * https://github.com/juju-solutions/layer-basic#overview # print("I hope this is logged!") + status_set('active', 'Install done') set_state('simple-react.installed') From aabc6a1c2624b6556af874efffeaac634c6060bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Hallb=C3=A4ck?= Date: Wed, 30 May 2018 12:28:59 +0000 Subject: [PATCH 2/3] Added some APT installations --- .gitignore | 1 + layer.yaml | 12 +++++++++++- reactive/simple_react.py | 13 ++++++++++--- 3 files changed, 22 insertions(+), 4 deletions(-) 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..8d26ed9 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 +options: + basic: + packages: + - python3-psycopg2 + apt: + packages: + - git + - bzr diff --git a/reactive/simple_react.py b/reactive/simple_react.py index a5ac1d4..3552b16 100644 --- a/reactive/simple_react.py +++ b/reactive/simple_react.py @@ -1,8 +1,15 @@ from charms.reactive import when, when_not, set_state -from charmhelpers.core.hookenv import status_set +from charmhelpers.core.hookenv import status_set, log +import charms.apt + +@when_not('apt.installed.git') +def not_installed_yet(): + log("Waiting for git to be installed") + status_set('waiting', 'Waiting for git to be installed') @when_not('simple-react.installed') +@when('apt.installed.git') def install_simple_react(): # Do your setup here. # @@ -15,6 +22,6 @@ def install_simple_react(): # * https://jujucharms.com/docs/devel/developer-getting-started # * https://github.com/juju-solutions/layer-basic#overview # - print("I hope this is logged!") - status_set('active', 'Install done') + log("Git is now finally installed") + status_set('active', 'Git is now finally installed') set_state('simple-react.installed') From 057c39bf6871cc207764d1407de0bbf2e146b4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johan=20Hallb=C3=A4ck?= Date: Thu, 31 May 2018 14:16:18 +0000 Subject: [PATCH 3/3] My own work from the Thursday lab --- layer.yaml | 8 ++++---- metadata.yaml | 3 +++ reactive/simple_react.py | 34 +++++++++++++++------------------- 3 files changed, 22 insertions(+), 23 deletions(-) diff --git a/layer.yaml b/layer.yaml index 8d26ed9..81dae31 100644 --- a/layer.yaml +++ b/layer.yaml @@ -1,11 +1,11 @@ includes: - layer:basic - layer:apt + - interface:mysql options: - basic: - packages: - - python3-psycopg2 +# basic: +# packages: +# - python3-psycopg2 apt: packages: - git - - bzr 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 3552b16..9c17e64 100644 --- a/reactive/simple_react.py +++ b/reactive/simple_react.py @@ -1,27 +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('apt.installed.git') -def not_installed_yet(): - log("Waiting for git to be installed") - status_set('waiting', 'Waiting for git to be installed') +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_not('simple-react.installed') @when('apt.installed.git') -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 - # - log("Git is now finally installed") - status_set('active', 'Git is now finally installed') - set_state('simple-react.installed') +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())