Merge bootstack-ops:jjo-p-o-e-creds into bootstack-ops:master

Proposed by JuanJo Ciarlante
Status: Merged
Merged at revision: 656040d256b6bd788187f7c0ac331d4718fd57ba
Proposed branch: bootstack-ops:jjo-p-o-e-creds
Merge into: bootstack-ops:master
Diff against target: 253 lines (+117/-20)
7 files modified
ops-bundle/devel/opsdeploy-prometheus.yaml (+8/-7)
ops-bundle/devel/prometheus.codetree (+4/-5)
ops-bundle/manifest-prometheus (+3/-1)
ops-bundle/production/opsdeploy-prometheus.yaml (+21/-2)
ops-bundle/production/prometheus.codetree (+4/-5)
ops-bundle/scripts/juju_bundle_export.sh (+1/-0)
ops-bundle/scripts/prometheus_exporter_creds.py (+76/-0)
Reviewer Review Type Date Requested Status
Legacy - Canonical WTFB Pending
Review via email: mp+322262@code.launchpad.net

Commit message

[jjo] add p-o-e charm instrumentation for its os-credentials settings + other fixes

Description of the change

[jjo] add p-o-e charm instrumentation for its os-credentials settings + other fixes

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/ops-bundle/devel/opsdeploy-prometheus.yaml b/ops-bundle/devel/opsdeploy-prometheus.yaml
2index fef0e9e..485400c 100644
3--- a/ops-bundle/devel/opsdeploy-prometheus.yaml
4+++ b/ops-bundle/devel/opsdeploy-prometheus.yaml
5@@ -5,7 +5,7 @@ nil:
6 services: {}
7
8 ops-bundle-prometheus:
9- inherits: [ secrets, bsdeploy ]
10+ inherits: [ secrets, bsdeploy, poe-secrets ]
11 series: xenial
12 overrides:
13 snap_proxy: "http://10.76.12.1:8000"
14@@ -29,7 +29,7 @@ ops-bundle-prometheus:
15 telegraf:
16 charm: telegraf
17 options:
18- hostname: '{unit}'
19+ hostname: '{host}'
20 prometheus_output_port: default
21
22 # WIP
23@@ -39,9 +39,9 @@ ops-bundle-prometheus:
24 # to: *PROMSTACK_TO
25 #
26 # # snap -> needs to be at metal or juju2 lxd
27-# prometheus-openstack-exporter:
28-# charm: prometheus-openstack-exporter
29-# to: *PROMSTACK_TO
30+ prometheus-openstack-exporter:
31+ charm: prometheus-openstack-exporter
32+ to: *PROMSTACK_TO
33
34 relations:
35 # Connect the grafana -> prometheus -> telegraf stack
36@@ -49,7 +49,8 @@ ops-bundle-prometheus:
37 - ["telegraf:prometheus-client", "prometheus:target"]
38 # Deploy telegraf on : os-hosts xor nova-compute, etc
39 - ["telegraf:juju-info", "os-hosts"]
40-# WIP
41+# WIP: alertmanager
42 # - ["prometheus:alertmanager-service", "prometheus-alertmanager:alertmanager-service"]
43+# WIP: prometheus-openstack-exporter
44 # - ["prometheus-openstack-exporter", "keystone"]
45-# - ["prometheus-openstack-exporter", "prometheus:target"]
46+ - ["prometheus-openstack-exporter", "prometheus:target"]
47diff --git a/ops-bundle/devel/prometheus.codetree b/ops-bundle/devel/prometheus.codetree
48index 455ea24..aafc6e1 100644
49--- a/ops-bundle/devel/prometheus.codetree
50+++ b/ops-bundle/devel/prometheus.codetree
51@@ -1,7 +1,6 @@
52 # Reporting
53-prometheus git+https://git.launchpad.net/prometheus-charm
54-grafana git+https://git.launchpad.net/grafana-charm
55-prometheus-alertmanager git+https://git.launchpad.net/prometheus-alertmanager-charm
56-telegraf git+https://git.launchpad.net/telegraf-charm
57-#prometheus-openstack-exporter cs:~jjo/prometheus-openstack-exporter
58+prometheus cs:~prometheus-charmers/prometheus
59+grafana cs:~prometheus-charmers/grafana
60+telegraf cs:telegraf
61 prometheus-openstack-exporter git+https://git.launchpad.net/~jjo/bootstack-ops/+git/prometheus-openstack-exporter-charm
62+#prometheus-openstack-exporter cs:~jjo/prometheus-openstack-exporter
63diff --git a/ops-bundle/manifest-prometheus b/ops-bundle/manifest-prometheus
64index 9bd0bcb..b044a49 100644
65--- a/ops-bundle/manifest-prometheus
66+++ b/ops-bundle/manifest-prometheus
67@@ -3,12 +3,14 @@
68
69 # Create bundle and codetree from running env
70 script config=scripts/juju_bundle_export.sh OUT_BUNDLE=bsdeploy.yaml OUT_CODETREE=bsdeploy.codetree NAME=bsdeploy
71+script config=scripts/prometheus_exporter_creds.py DEPLOY_BUNDLE=bsdeploy.yaml DEPLOY_NAME=bsdeploy OUT_FILE=poe-secrets.yaml
72
73 # Collect Charms for running env
74 collect config=bsdeploy.codetree
75
76 # Collect Charms for added services
77 collect config=prometheus.codetree
78+# mojo collect --options config=prometheus.codetree
79
80 # Some hints for peeking diffs
81 # mojo deploy-diff --options local=secrets,bsdeploy.yaml config=opsdeploy-prometheus.yaml target=ops-bundle-prometheus
82@@ -18,4 +20,4 @@ collect config=prometheus.codetree
83 # Deploy services
84 # "nil" deploy just inherits from running, should not deploy anything
85 #deploy local=secrets,bsdeploy.yaml config=opsdeploy-prometheus.yaml target=nil
86-deploy local=secrets,bsdeploy.yaml config=opsdeploy-prometheus.yaml target=ops-bundle-prometheus
87+deploy local=secrets,poe-secrets.yaml,bsdeploy.yaml config=opsdeploy-prometheus.yaml target=ops-bundle-prometheus
88diff --git a/ops-bundle/production/opsdeploy-prometheus.yaml b/ops-bundle/production/opsdeploy-prometheus.yaml
89index f9fd133..485400c 100644
90--- a/ops-bundle/production/opsdeploy-prometheus.yaml
91+++ b/ops-bundle/production/opsdeploy-prometheus.yaml
92@@ -5,7 +5,7 @@ nil:
93 services: {}
94
95 ops-bundle-prometheus:
96- inherits: [ secrets, bsdeploy ]
97+ inherits: [ secrets, bsdeploy, poe-secrets ]
98 series: xenial
99 overrides:
100 snap_proxy: "http://10.76.12.1:8000"
101@@ -15,23 +15,42 @@ ops-bundle-prometheus:
102 charm: prometheus
103 to: *PROMSTACK_TO
104 options:
105+
106 # non snap -> could be LXC'd
107 grafana:
108 charm: grafana
109 to: *PROMSTACK_TO
110 options:
111+ ## XXX: must go to secrets.yaml
112+ admin_password: admin
113 install_file: https://grafanarel.s3.amazonaws.com/builds/grafana_4.1.2-1486989747_amd64.deb
114
115 # subord -> will land on relation to ppal services (os-hosts or nova-compute, etc)
116 telegraf:
117 charm: telegraf
118 options:
119- hostname: '{unit}'
120+ hostname: '{host}'
121 prometheus_output_port: default
122
123+# WIP
124+# # snap -> needs to be at metal or juju2 lxd
125+# prometheus-alertmanager:
126+# charm: prometheus-alertmanager
127+# to: *PROMSTACK_TO
128+#
129+# # snap -> needs to be at metal or juju2 lxd
130+ prometheus-openstack-exporter:
131+ charm: prometheus-openstack-exporter
132+ to: *PROMSTACK_TO
133+
134 relations:
135 # Connect the grafana -> prometheus -> telegraf stack
136 - ["prometheus:grafana-source", "grafana:grafana-source"]
137 - ["telegraf:prometheus-client", "prometheus:target"]
138 # Deploy telegraf on : os-hosts xor nova-compute, etc
139 - ["telegraf:juju-info", "os-hosts"]
140+# WIP: alertmanager
141+# - ["prometheus:alertmanager-service", "prometheus-alertmanager:alertmanager-service"]
142+# WIP: prometheus-openstack-exporter
143+# - ["prometheus-openstack-exporter", "keystone"]
144+ - ["prometheus-openstack-exporter", "prometheus:target"]
145diff --git a/ops-bundle/production/prometheus.codetree b/ops-bundle/production/prometheus.codetree
146index cd999eb..aafc6e1 100644
147--- a/ops-bundle/production/prometheus.codetree
148+++ b/ops-bundle/production/prometheus.codetree
149@@ -1,7 +1,6 @@
150 # Reporting
151-prometheus git+https://git.launchpad.net/prometheus-charm
152-grafana git+https://git.launchpad.net/grafana-charm
153-#prometheus-alertmanager git+https://git.launchpad.net/prometheus-alertmanager-charm
154-telegraf git+https://git.launchpad.net/telegraf-charm
155+prometheus cs:~prometheus-charmers/prometheus
156+grafana cs:~prometheus-charmers/grafana
157+telegraf cs:telegraf
158+prometheus-openstack-exporter git+https://git.launchpad.net/~jjo/bootstack-ops/+git/prometheus-openstack-exporter-charm
159 #prometheus-openstack-exporter cs:~jjo/prometheus-openstack-exporter
160-#prometheus-openstack-exporter git+https://git.launchpad.net/~jjo/bootstack-ops/+git/prometheus-openstack-exporter-charm
161diff --git a/ops-bundle/scripts/juju_bundle_export.sh b/ops-bundle/scripts/juju_bundle_export.sh
162index 56e68ef..f0c8e93 100755
163--- a/ops-bundle/scripts/juju_bundle_export.sh
164+++ b/ops-bundle/scripts/juju_bundle_export.sh
165@@ -8,5 +8,6 @@ PY_SCRIPT=${0%.sh}.py
166 (set -x
167 $PY_SCRIPT -o ${MOJO_LOCAL_DIR}/${OUT_BUNDLE} -c ${MOJO_SPEC_DIR}/${MOJO_STAGE}/${OUT_CODETREE} --name ${NAME}
168 # HACK: above script will create xenial/CHARM while mojo likes ./CHARM
169+rm -rf ${MOJO_BUILD_DIR:?}/*
170 ln -sfn . ${MOJO_BUILD_DIR}/xenial
171 )
172diff --git a/ops-bundle/scripts/prometheus_exporter_creds.py b/ops-bundle/scripts/prometheus_exporter_creds.py
173new file mode 100755
174index 0000000..8ccfb6e
175--- /dev/null
176+++ b/ops-bundle/scripts/prometheus_exporter_creds.py
177@@ -0,0 +1,76 @@
178+#!/usr/bin/env python3
179+# XXX(jjo) HACK to ease os-credentials settings for p-o-e charm,
180+# crafted from bundle's keystone settings as saved from running env
181+# NOTE this is very mojo specific, as it not only relies on MOJO_LOCAL_DIR
182+# but also wants args passed as env vars (mojo manifest line)
183+import os
184+import yaml
185+import logging
186+
187+logging.basicConfig()
188+logger = logging.getLogger()
189+
190+# The bundle file where running env was saved
191+deploy_bundle = "{}/{}".format(
192+ os.environ['MOJO_LOCAL_DIR'],
193+ os.environ['DEPLOY_BUNDLE'])
194+
195+# Then deployment name inside the bundle, e.g. 'bsdeploy'
196+deploy_name = os.environ['DEPLOY_NAME']
197+
198+# Output secrets.yaml file for p-o-e charm, it'll have
199+# 'os-credentials' and 'ssl_ca' settings
200+out_file = os.environ.get('OUT_FILE')
201+if out_file:
202+ out_file = "{}/{}".format(os.environ['MOJO_LOCAL_DIR'], out_file)
203+
204+# Output deployment name which contains p-o-e charm secrets
205+out_name = os.environ.get('OUT_NAME', 'poe-secrets')
206+auth_url = os.environ.get('OS_AUTH_URL')
207+
208+# Load DEPLOY_BUNDLE[DEPLOY_NAME]'s keystone config
209+deploy = yaml.load(open(deploy_bundle).read())[deploy_name]
210+ks_config = deploy['services']['keystone']['options']
211+
212+# Having OS_AUTH_URL from the running shell env would be great,
213+# else try some educated guess
214+if not auth_url:
215+ logging.warning("No 'OS_AUTH_URL' in environment, guessing from keystone")
216+ hostname = ks_config.get('os-public-hostname', ks_config.get('vip'))
217+ proto = 'https' if ks_config.get('https-service-endpoints') else 'http'
218+ auth_url = '{}://{}:5000/v2.0'.format(proto, hostname)
219+
220+logging.info(
221+ "out_file: {}, out_name: {}, deploy_name: {}, auth_url: {}".format(
222+ out_file, out_name, deploy_name, auth_url))
223+
224+# os-credentials must be a string'd YAML, i.e. can't directly be a python dict
225+# (as yaml.dump would save it as a yaml dict itself, while juju only supports
226+# "flat" non-structured settings)
227+poe_settings = {
228+ 'os-credentials': '{{username: {}, password: {}, region_name: {}, auth_url: "{}" }}'.format( # noqa
229+ 'Admin', ks_config['admin-password'],
230+ ks_config['region'], auth_url)
231+}
232+
233+# Only save ssl_ca if present in keystone
234+ssl_ca = ks_config.get('ssl_ca')
235+if ssl_ca:
236+ poe_settings.update({'ssl_ca': ssl_ca})
237+
238+# Output mini-bundle with just p-o-e secrets, meant to be used
239+# as part of local= mojo manifest line, then inherited from
240+# prometheus.yaml main bundle
241+out_content = {
242+ out_name: {
243+ 'services': {
244+ 'prometheus-openstack-exporter': {
245+ 'options': poe_settings
246+ }
247+ }
248+ }
249+}
250+
251+# print to stdout if no OUT_FILE
252+print_kw = {'file': open(out_file, 'w')} if out_file else {}
253+print(yaml.dump(out_content, default_flow_style=False), **print_kw)

Subscribers

People subscribed via source and target branches

to all changes: