Merge lp:~jacekn/charms/trusty/grafana/grafana-url into lp:~canonical-is-sa/charms/trusty/grafana/layer-grafana

Proposed by Jacek Nykis
Status: Merged
Merged at revision: 35
Proposed branch: lp:~jacekn/charms/trusty/grafana/grafana-url
Merge into: lp:~canonical-is-sa/charms/trusty/grafana/layer-grafana
Diff against target: 72 lines (+28/-8)
2 files modified
config.yaml (+11/-2)
reactive/grafana.py (+17/-6)
To merge this branch: bzr merge lp:~jacekn/charms/trusty/grafana/grafana-url
Reviewer Review Type Date Requested Status
Neale Pickett (community) Approve
Review via email: mp+293147@code.launchpad.net

Description of the change

Allow grafana to be installed from http URL, needed until we package it

To post a comment you must log in.
Revision history for this message
Neale Pickett (neale) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2016-03-16 17:22:22 +0000
3+++ config.yaml 2016-04-27 16:52:58 +0000
4@@ -22,13 +22,22 @@
5 install_keys: |
6 - ""
7 - ""
8+ install_file:
9+ default: ""
10+ type: string
11+ description: |
12+ Location where grafana .deb file can be found. If set install_sources and
13+ install_keys options are ignored. Example:
14+ install_file: http://my.company.com/packages/grafana/grafana_3.0.0_amd64.deb
15 app_mode:
16 default: 'production'
17 type: string
18 description: 'production or development'
19 datasources:
20- default: |
21- - 'prometheus,BootStack Prometheus,proxy,http://localhost:9090,,,'
22+ default: ""
23+ description: |
24+ List of datasources in format:
25+ - 'prometheus,BootStack Prometheus,proxy,http://localhost:9090,,,'
26 type: string
27 description: |
28 - type,name,access,url,password,user,database
29
30=== modified file 'reactive/grafana.py'
31--- reactive/grafana.py 2016-04-27 15:09:30 +0000
32+++ reactive/grafana.py 2016-04-27 16:52:58 +0000
33@@ -3,6 +3,8 @@
34 import glob
35 import hashlib
36 import datetime
37+import requests
38+import subprocess
39 from time import sleep
40 from charmhelpers import fetch
41 from charmhelpers.core import host, hookenv, unitdata
42@@ -30,17 +32,26 @@
43 SVCNAME = 'grafana-server'
44 GRAFANA_INI = '/etc/grafana/grafana.ini'
45 GRAFANA_INI_TMPL = 'grafana.ini.j2'
46+GRAFANA_DEPS = ['libfontconfig1']
47
48
49 def install_packages():
50 config = hookenv.config()
51 install_opts = ('install_sources', 'install_keys')
52- if not any(config.changed(opt) for opt in install_opts):
53- return
54- hookenv.status_set('maintenance', 'Installing deb pkgs')
55- packages = ['grafana']
56- fetch.configure_sources(update=True)
57- fetch.apt_install(packages)
58+ if config.changed('install_file'):
59+ hookenv.status_set('maintenance', 'Installing deb pkgs')
60+ fetch.apt_install(GRAFANA_DEPS)
61+ pkg_file = '/tmp/grafana.deb'
62+ with open(pkg_file, 'wb') as f:
63+ r = requests.get(config.get('install_file'), stream=True)
64+ for block in r.iter_content(1024):
65+ f.write(block)
66+ subprocess.check_call(['dpkg', '-i', pkg_file])
67+ elif any(config.changed(opt) for opt in install_opts):
68+ hookenv.status_set('maintenance', 'Installing deb pkgs')
69+ packages = ['grafana']
70+ fetch.configure_sources(update=True)
71+ fetch.apt_install(packages)
72 hookenv.status_set('maintenance', 'Waiting for start')
73
74

Subscribers

People subscribed via source and target branches

to all changes: