Merge lp:~corey.bryant/charms/trusty/neutron-api/contrib.python.packages into lp:~openstack-charmers-archive/charms/trusty/neutron-api/next
- Trusty Tahr (14.04)
- contrib.python.packages
- Merge into next
Status: | Merged |
---|---|
Merged at revision: | 64 |
Proposed branch: | lp:~corey.bryant/charms/trusty/neutron-api/contrib.python.packages |
Merge into: | lp:~openstack-charmers-archive/charms/trusty/neutron-api/next |
Diff against target: |
3322 lines (+1045/-524) 27 files modified
charm-helpers-sync.yaml (+1/-0) hooks/charmhelpers/__init__.py (+22/-0) hooks/charmhelpers/contrib/hahelpers/cluster.py (+16/-7) hooks/charmhelpers/contrib/network/ip.py (+52/-50) hooks/charmhelpers/contrib/openstack/amulet/deployment.py (+2/-1) hooks/charmhelpers/contrib/openstack/amulet/utils.py (+3/-1) hooks/charmhelpers/contrib/openstack/context.py (+319/-226) hooks/charmhelpers/contrib/openstack/ip.py (+41/-27) hooks/charmhelpers/contrib/openstack/neutron.py (+20/-4) hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg (+2/-2) hooks/charmhelpers/contrib/openstack/templating.py (+5/-5) hooks/charmhelpers/contrib/openstack/utils.py (+146/-13) hooks/charmhelpers/contrib/python/packages.py (+77/-0) hooks/charmhelpers/contrib/storage/linux/ceph.py (+89/-102) hooks/charmhelpers/contrib/storage/linux/loopback.py (+4/-4) hooks/charmhelpers/contrib/storage/linux/lvm.py (+1/-0) hooks/charmhelpers/contrib/storage/linux/utils.py (+3/-2) hooks/charmhelpers/core/fstab.py (+10/-8) hooks/charmhelpers/core/hookenv.py (+41/-15) hooks/charmhelpers/core/host.py (+51/-20) hooks/charmhelpers/core/services/__init__.py (+2/-2) hooks/charmhelpers/core/services/helpers.py (+9/-5) hooks/charmhelpers/core/templating.py (+2/-1) hooks/charmhelpers/fetch/__init__.py (+18/-12) hooks/charmhelpers/fetch/archiveurl.py (+53/-16) hooks/charmhelpers/fetch/bzrurl.py (+5/-1) hooks/charmhelpers/fetch/giturl.py (+51/-0) |
To merge this branch: | bzr merge lp:~corey.bryant/charms/trusty/neutron-api/contrib.python.packages |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
OpenStack Charmers | Pending | ||
Review via email: mp+244325@code.launchpad.net |
Commit message
Description of the change
uosci-testing-bot (uosci-testing-bot) wrote : | # |
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #128 neutron-api-next for corey.bryant mp244325
UNIT FAIL: unit-test failed
UNIT Results (max last 2 lines):
FAILED (errors=3)
make: *** [unit_test] Error 1
Full unit test output: pastebin not avail., cmd error
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #78 neutron-api-next for corey.bryant mp244325
AMULET FAIL: amulet-test missing
AMULET Results (max last 2 lines):
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.
Full amulet test output: pastebin not avail., cmd error
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #186 neutron-api-next for corey.bryant mp244325
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #149 neutron-api-next for corey.bryant mp244325
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #104 neutron-api-next for corey.bryant mp244325
AMULET FAIL: amulet-test missing
AMULET Results (max last 2 lines):
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.
Full amulet test output: pastebin not avail., cmd error
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #195 neutron-api-next for corey.bryant mp244325
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #158 neutron-api-next for corey.bryant mp244325
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #113 neutron-api-next for corey.bryant mp244325
AMULET FAIL: amulet-test missing
AMULET Results (max last 2 lines):
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.
Full amulet test output: pastebin not avail., cmd error
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_lint_check #229 neutron-api-next for corey.bryant mp244325
LINT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_unit_test #192 neutron-api-next for corey.bryant mp244325
UNIT OK: passed
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #146 neutron-api-next for corey.bryant mp244325
AMULET FAIL: amulet-test missing
AMULET Results (max last 2 lines):
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.
Full amulet test output: pastebin not avail., cmd error
Build: http://
uosci-testing-bot (uosci-testing-bot) wrote : | # |
charm_amulet_test #68 neutron-api-next for corey.bryant mp244325
AMULET FAIL: no-tear-
AMULET FAIL: amulet-test missing
AMULET Results (max last 2 lines):
INFO:root:Search string not found in makefile target commands.
ERROR:root:No make target was executed.
Full amulet test output: http://
Build: http://
Preview Diff
1 | === modified file 'charm-helpers-sync.yaml' | |||
2 | --- charm-helpers-sync.yaml 2014-10-02 09:18:00 +0000 | |||
3 | +++ charm-helpers-sync.yaml 2014-12-11 17:56:40 +0000 | |||
4 | @@ -9,3 +9,4 @@ | |||
5 | 9 | - contrib.storage.linux | 9 | - contrib.storage.linux |
6 | 10 | - payload.execd | 10 | - payload.execd |
7 | 11 | - contrib.network.ip | 11 | - contrib.network.ip |
8 | 12 | - contrib.python.packages | ||
9 | 12 | 13 | ||
10 | === added file 'hooks/charmhelpers/__init__.py' | |||
11 | --- hooks/charmhelpers/__init__.py 1970-01-01 00:00:00 +0000 | |||
12 | +++ hooks/charmhelpers/__init__.py 2014-12-11 17:56:40 +0000 | |||
13 | @@ -0,0 +1,22 @@ | |||
14 | 1 | # Bootstrap charm-helpers, installing its dependencies if necessary using | ||
15 | 2 | # only standard libraries. | ||
16 | 3 | import subprocess | ||
17 | 4 | import sys | ||
18 | 5 | |||
19 | 6 | try: | ||
20 | 7 | import six # flake8: noqa | ||
21 | 8 | except ImportError: | ||
22 | 9 | if sys.version_info.major == 2: | ||
23 | 10 | subprocess.check_call(['apt-get', 'install', '-y', 'python-six']) | ||
24 | 11 | else: | ||
25 | 12 | subprocess.check_call(['apt-get', 'install', '-y', 'python3-six']) | ||
26 | 13 | import six # flake8: noqa | ||
27 | 14 | |||
28 | 15 | try: | ||
29 | 16 | import yaml # flake8: noqa | ||
30 | 17 | except ImportError: | ||
31 | 18 | if sys.version_info.major == 2: | ||
32 | 19 | subprocess.check_call(['apt-get', 'install', '-y', 'python-yaml']) | ||
33 | 20 | else: | ||
34 | 21 | subprocess.check_call(['apt-get', 'install', '-y', 'python3-yaml']) | ||
35 | 22 | import yaml # flake8: noqa | ||
36 | 0 | 23 | ||
37 | === removed file 'hooks/charmhelpers/__init__.py' | |||
38 | === modified file 'hooks/charmhelpers/contrib/hahelpers/cluster.py' | |||
39 | --- hooks/charmhelpers/contrib/hahelpers/cluster.py 2014-10-02 09:18:00 +0000 | |||
40 | +++ hooks/charmhelpers/contrib/hahelpers/cluster.py 2014-12-11 17:56:40 +0000 | |||
41 | @@ -13,9 +13,10 @@ | |||
42 | 13 | 13 | ||
43 | 14 | import subprocess | 14 | import subprocess |
44 | 15 | import os | 15 | import os |
45 | 16 | |||
46 | 17 | from socket import gethostname as get_unit_hostname | 16 | from socket import gethostname as get_unit_hostname |
47 | 18 | 17 | ||
48 | 18 | import six | ||
49 | 19 | |||
50 | 19 | from charmhelpers.core.hookenv import ( | 20 | from charmhelpers.core.hookenv import ( |
51 | 20 | log, | 21 | log, |
52 | 21 | relation_ids, | 22 | relation_ids, |
53 | @@ -77,7 +78,7 @@ | |||
54 | 77 | "show", resource | 78 | "show", resource |
55 | 78 | ] | 79 | ] |
56 | 79 | try: | 80 | try: |
58 | 80 | status = subprocess.check_output(cmd) | 81 | status = subprocess.check_output(cmd).decode('UTF-8') |
59 | 81 | except subprocess.CalledProcessError: | 82 | except subprocess.CalledProcessError: |
60 | 82 | return False | 83 | return False |
61 | 83 | else: | 84 | else: |
62 | @@ -150,34 +151,42 @@ | |||
63 | 150 | return False | 151 | return False |
64 | 151 | 152 | ||
65 | 152 | 153 | ||
67 | 153 | def determine_api_port(public_port): | 154 | def determine_api_port(public_port, singlenode_mode=False): |
68 | 154 | ''' | 155 | ''' |
69 | 155 | Determine correct API server listening port based on | 156 | Determine correct API server listening port based on |
70 | 156 | existence of HTTPS reverse proxy and/or haproxy. | 157 | existence of HTTPS reverse proxy and/or haproxy. |
71 | 157 | 158 | ||
72 | 158 | public_port: int: standard public port for given service | 159 | public_port: int: standard public port for given service |
73 | 159 | 160 | ||
74 | 161 | singlenode_mode: boolean: Shuffle ports when only a single unit is present | ||
75 | 162 | |||
76 | 160 | returns: int: the correct listening port for the API service | 163 | returns: int: the correct listening port for the API service |
77 | 161 | ''' | 164 | ''' |
78 | 162 | i = 0 | 165 | i = 0 |
80 | 163 | if len(peer_units()) > 0 or is_clustered(): | 166 | if singlenode_mode: |
81 | 167 | i += 1 | ||
82 | 168 | elif len(peer_units()) > 0 or is_clustered(): | ||
83 | 164 | i += 1 | 169 | i += 1 |
84 | 165 | if https(): | 170 | if https(): |
85 | 166 | i += 1 | 171 | i += 1 |
86 | 167 | return public_port - (i * 10) | 172 | return public_port - (i * 10) |
87 | 168 | 173 | ||
88 | 169 | 174 | ||
90 | 170 | def determine_apache_port(public_port): | 175 | def determine_apache_port(public_port, singlenode_mode=False): |
91 | 171 | ''' | 176 | ''' |
92 | 172 | Description: Determine correct apache listening port based on public IP + | 177 | Description: Determine correct apache listening port based on public IP + |
93 | 173 | state of the cluster. | 178 | state of the cluster. |
94 | 174 | 179 | ||
95 | 175 | public_port: int: standard public port for given service | 180 | public_port: int: standard public port for given service |
96 | 176 | 181 | ||
97 | 182 | singlenode_mode: boolean: Shuffle ports when only a single unit is present | ||
98 | 183 | |||
99 | 177 | returns: int: the correct listening port for the HAProxy service | 184 | returns: int: the correct listening port for the HAProxy service |
100 | 178 | ''' | 185 | ''' |
101 | 179 | i = 0 | 186 | i = 0 |
103 | 180 | if len(peer_units()) > 0 or is_clustered(): | 187 | if singlenode_mode: |
104 | 188 | i += 1 | ||
105 | 189 | elif len(peer_units()) > 0 or is_clustered(): | ||
106 | 181 | i += 1 | 190 | i += 1 |
107 | 182 | return public_port - (i * 10) | 191 | return public_port - (i * 10) |
108 | 183 | 192 | ||
109 | @@ -197,7 +206,7 @@ | |||
110 | 197 | for setting in settings: | 206 | for setting in settings: |
111 | 198 | conf[setting] = config_get(setting) | 207 | conf[setting] = config_get(setting) |
112 | 199 | missing = [] | 208 | missing = [] |
114 | 200 | [missing.append(s) for s, v in conf.iteritems() if v is None] | 209 | [missing.append(s) for s, v in six.iteritems(conf) if v is None] |
115 | 201 | if missing: | 210 | if missing: |
116 | 202 | log('Insufficient config data to configure hacluster.', level=ERROR) | 211 | log('Insufficient config data to configure hacluster.', level=ERROR) |
117 | 203 | raise HAIncompleteConfig | 212 | raise HAIncompleteConfig |
118 | 204 | 213 | ||
119 | === modified file 'hooks/charmhelpers/contrib/network/ip.py' | |||
120 | --- hooks/charmhelpers/contrib/network/ip.py 2014-10-09 10:34:27 +0000 | |||
121 | +++ hooks/charmhelpers/contrib/network/ip.py 2014-12-11 17:56:40 +0000 | |||
122 | @@ -1,15 +1,12 @@ | |||
123 | 1 | import glob | 1 | import glob |
124 | 2 | import re | 2 | import re |
125 | 3 | import subprocess | 3 | import subprocess |
126 | 4 | import sys | ||
127 | 5 | 4 | ||
128 | 6 | from functools import partial | 5 | from functools import partial |
129 | 7 | 6 | ||
130 | 8 | from charmhelpers.core.hookenv import unit_get | 7 | from charmhelpers.core.hookenv import unit_get |
131 | 9 | from charmhelpers.fetch import apt_install | 8 | from charmhelpers.fetch import apt_install |
132 | 10 | from charmhelpers.core.hookenv import ( | 9 | from charmhelpers.core.hookenv import ( |
133 | 11 | WARNING, | ||
134 | 12 | ERROR, | ||
135 | 13 | log | 10 | log |
136 | 14 | ) | 11 | ) |
137 | 15 | 12 | ||
138 | @@ -34,31 +31,28 @@ | |||
139 | 34 | network) | 31 | network) |
140 | 35 | 32 | ||
141 | 36 | 33 | ||
142 | 34 | def no_ip_found_error_out(network): | ||
143 | 35 | errmsg = ("No IP address found in network: %s" % network) | ||
144 | 36 | raise ValueError(errmsg) | ||
145 | 37 | |||
146 | 38 | |||
147 | 37 | def get_address_in_network(network, fallback=None, fatal=False): | 39 | def get_address_in_network(network, fallback=None, fatal=False): |
150 | 38 | """ | 40 | """Get an IPv4 or IPv6 address within the network from the host. |
149 | 39 | Get an IPv4 or IPv6 address within the network from the host. | ||
151 | 40 | 41 | ||
152 | 41 | :param network (str): CIDR presentation format. For example, | 42 | :param network (str): CIDR presentation format. For example, |
153 | 42 | '192.168.1.0/24'. | 43 | '192.168.1.0/24'. |
154 | 43 | :param fallback (str): If no address is found, return fallback. | 44 | :param fallback (str): If no address is found, return fallback. |
155 | 44 | :param fatal (boolean): If no address is found, fallback is not | 45 | :param fatal (boolean): If no address is found, fallback is not |
156 | 45 | set and fatal is True then exit(1). | 46 | set and fatal is True then exit(1). |
157 | 46 | |||
158 | 47 | """ | 47 | """ |
159 | 48 | |||
160 | 49 | def not_found_error_out(): | ||
161 | 50 | log("No IP address found in network: %s" % network, | ||
162 | 51 | level=ERROR) | ||
163 | 52 | sys.exit(1) | ||
164 | 53 | |||
165 | 54 | if network is None: | 48 | if network is None: |
166 | 55 | if fallback is not None: | 49 | if fallback is not None: |
167 | 56 | return fallback | 50 | return fallback |
168 | 51 | |||
169 | 52 | if fatal: | ||
170 | 53 | no_ip_found_error_out(network) | ||
171 | 57 | else: | 54 | else: |
176 | 58 | if fatal: | 55 | return None |
173 | 59 | not_found_error_out() | ||
174 | 60 | else: | ||
175 | 61 | return None | ||
177 | 62 | 56 | ||
178 | 63 | _validate_cidr(network) | 57 | _validate_cidr(network) |
179 | 64 | network = netaddr.IPNetwork(network) | 58 | network = netaddr.IPNetwork(network) |
180 | @@ -70,6 +64,7 @@ | |||
181 | 70 | cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask)) | 64 | cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask)) |
182 | 71 | if cidr in network: | 65 | if cidr in network: |
183 | 72 | return str(cidr.ip) | 66 | return str(cidr.ip) |
184 | 67 | |||
185 | 73 | if network.version == 6 and netifaces.AF_INET6 in addresses: | 68 | if network.version == 6 and netifaces.AF_INET6 in addresses: |
186 | 74 | for addr in addresses[netifaces.AF_INET6]: | 69 | for addr in addresses[netifaces.AF_INET6]: |
187 | 75 | if not addr['addr'].startswith('fe80'): | 70 | if not addr['addr'].startswith('fe80'): |
188 | @@ -82,20 +77,20 @@ | |||
189 | 82 | return fallback | 77 | return fallback |
190 | 83 | 78 | ||
191 | 84 | if fatal: | 79 | if fatal: |
193 | 85 | not_found_error_out() | 80 | no_ip_found_error_out(network) |
194 | 86 | 81 | ||
195 | 87 | return None | 82 | return None |
196 | 88 | 83 | ||
197 | 89 | 84 | ||
198 | 90 | def is_ipv6(address): | 85 | def is_ipv6(address): |
200 | 91 | '''Determine whether provided address is IPv6 or not''' | 86 | """Determine whether provided address is IPv6 or not.""" |
201 | 92 | try: | 87 | try: |
202 | 93 | address = netaddr.IPAddress(address) | 88 | address = netaddr.IPAddress(address) |
203 | 94 | except netaddr.AddrFormatError: | 89 | except netaddr.AddrFormatError: |
204 | 95 | # probably a hostname - so not an address at all! | 90 | # probably a hostname - so not an address at all! |
205 | 96 | return False | 91 | return False |
208 | 97 | else: | 92 | |
209 | 98 | return address.version == 6 | 93 | return address.version == 6 |
210 | 99 | 94 | ||
211 | 100 | 95 | ||
212 | 101 | def is_address_in_network(network, address): | 96 | def is_address_in_network(network, address): |
213 | @@ -113,11 +108,13 @@ | |||
214 | 113 | except (netaddr.core.AddrFormatError, ValueError): | 108 | except (netaddr.core.AddrFormatError, ValueError): |
215 | 114 | raise ValueError("Network (%s) is not in CIDR presentation format" % | 109 | raise ValueError("Network (%s) is not in CIDR presentation format" % |
216 | 115 | network) | 110 | network) |
217 | 111 | |||
218 | 116 | try: | 112 | try: |
219 | 117 | address = netaddr.IPAddress(address) | 113 | address = netaddr.IPAddress(address) |
220 | 118 | except (netaddr.core.AddrFormatError, ValueError): | 114 | except (netaddr.core.AddrFormatError, ValueError): |
221 | 119 | raise ValueError("Address (%s) is not in correct presentation format" % | 115 | raise ValueError("Address (%s) is not in correct presentation format" % |
222 | 120 | address) | 116 | address) |
223 | 117 | |||
224 | 121 | if address in network: | 118 | if address in network: |
225 | 122 | return True | 119 | return True |
226 | 123 | else: | 120 | else: |
227 | @@ -147,6 +144,7 @@ | |||
228 | 147 | return iface | 144 | return iface |
229 | 148 | else: | 145 | else: |
230 | 149 | return addresses[netifaces.AF_INET][0][key] | 146 | return addresses[netifaces.AF_INET][0][key] |
231 | 147 | |||
232 | 150 | if address.version == 6 and netifaces.AF_INET6 in addresses: | 148 | if address.version == 6 and netifaces.AF_INET6 in addresses: |
233 | 151 | for addr in addresses[netifaces.AF_INET6]: | 149 | for addr in addresses[netifaces.AF_INET6]: |
234 | 152 | if not addr['addr'].startswith('fe80'): | 150 | if not addr['addr'].startswith('fe80'): |
235 | @@ -160,41 +158,42 @@ | |||
236 | 160 | return str(cidr).split('/')[1] | 158 | return str(cidr).split('/')[1] |
237 | 161 | else: | 159 | else: |
238 | 162 | return addr[key] | 160 | return addr[key] |
239 | 161 | |||
240 | 163 | return None | 162 | return None |
241 | 164 | 163 | ||
242 | 165 | 164 | ||
243 | 166 | get_iface_for_address = partial(_get_for_address, key='iface') | 165 | get_iface_for_address = partial(_get_for_address, key='iface') |
244 | 167 | 166 | ||
245 | 167 | |||
246 | 168 | get_netmask_for_address = partial(_get_for_address, key='netmask') | 168 | get_netmask_for_address = partial(_get_for_address, key='netmask') |
247 | 169 | 169 | ||
248 | 170 | 170 | ||
249 | 171 | def format_ipv6_addr(address): | 171 | def format_ipv6_addr(address): |
252 | 172 | """ | 172 | """If address is IPv6, wrap it in '[]' otherwise return None. |
253 | 173 | IPv6 needs to be wrapped with [] in url link to parse correctly. | 173 | |
254 | 174 | This is required by most configuration files when specifying IPv6 | ||
255 | 175 | addresses. | ||
256 | 174 | """ | 176 | """ |
257 | 175 | if is_ipv6(address): | 177 | if is_ipv6(address): |
262 | 176 | address = "[%s]" % address | 178 | return "[%s]" % address |
259 | 177 | else: | ||
260 | 178 | log("Not a valid ipv6 address: %s" % address, level=WARNING) | ||
261 | 179 | address = None | ||
263 | 180 | 179 | ||
265 | 181 | return address | 180 | return None |
266 | 182 | 181 | ||
267 | 183 | 182 | ||
268 | 184 | def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False, | 183 | def get_iface_addr(iface='eth0', inet_type='AF_INET', inc_aliases=False, |
269 | 185 | fatal=True, exc_list=None): | 184 | fatal=True, exc_list=None): |
273 | 186 | """ | 185 | """Return the assigned IP address for a given interface, if any.""" |
271 | 187 | Return the assigned IP address for a given interface, if any, or []. | ||
272 | 188 | """ | ||
274 | 189 | # Extract nic if passed /dev/ethX | 186 | # Extract nic if passed /dev/ethX |
275 | 190 | if '/' in iface: | 187 | if '/' in iface: |
276 | 191 | iface = iface.split('/')[-1] | 188 | iface = iface.split('/')[-1] |
277 | 189 | |||
278 | 192 | if not exc_list: | 190 | if not exc_list: |
279 | 193 | exc_list = [] | 191 | exc_list = [] |
280 | 192 | |||
281 | 194 | try: | 193 | try: |
282 | 195 | inet_num = getattr(netifaces, inet_type) | 194 | inet_num = getattr(netifaces, inet_type) |
283 | 196 | except AttributeError: | 195 | except AttributeError: |
285 | 197 | raise Exception('Unknown inet type ' + str(inet_type)) | 196 | raise Exception("Unknown inet type '%s'" % str(inet_type)) |
286 | 198 | 197 | ||
287 | 199 | interfaces = netifaces.interfaces() | 198 | interfaces = netifaces.interfaces() |
288 | 200 | if inc_aliases: | 199 | if inc_aliases: |
289 | @@ -202,15 +201,18 @@ | |||
290 | 202 | for _iface in interfaces: | 201 | for _iface in interfaces: |
291 | 203 | if iface == _iface or _iface.split(':')[0] == iface: | 202 | if iface == _iface or _iface.split(':')[0] == iface: |
292 | 204 | ifaces.append(_iface) | 203 | ifaces.append(_iface) |
293 | 204 | |||
294 | 205 | if fatal and not ifaces: | 205 | if fatal and not ifaces: |
295 | 206 | raise Exception("Invalid interface '%s'" % iface) | 206 | raise Exception("Invalid interface '%s'" % iface) |
296 | 207 | |||
297 | 207 | ifaces.sort() | 208 | ifaces.sort() |
298 | 208 | else: | 209 | else: |
299 | 209 | if iface not in interfaces: | 210 | if iface not in interfaces: |
300 | 210 | if fatal: | 211 | if fatal: |
302 | 211 | raise Exception("%s not found " % (iface)) | 212 | raise Exception("Interface '%s' not found " % (iface)) |
303 | 212 | else: | 213 | else: |
304 | 213 | return [] | 214 | return [] |
305 | 215 | |||
306 | 214 | else: | 216 | else: |
307 | 215 | ifaces = [iface] | 217 | ifaces = [iface] |
308 | 216 | 218 | ||
309 | @@ -221,10 +223,13 @@ | |||
310 | 221 | for entry in net_info[inet_num]: | 223 | for entry in net_info[inet_num]: |
311 | 222 | if 'addr' in entry and entry['addr'] not in exc_list: | 224 | if 'addr' in entry and entry['addr'] not in exc_list: |
312 | 223 | addresses.append(entry['addr']) | 225 | addresses.append(entry['addr']) |
313 | 226 | |||
314 | 224 | if fatal and not addresses: | 227 | if fatal and not addresses: |
315 | 225 | raise Exception("Interface '%s' doesn't have any %s addresses." % | 228 | raise Exception("Interface '%s' doesn't have any %s addresses." % |
316 | 226 | (iface, inet_type)) | 229 | (iface, inet_type)) |
318 | 227 | return addresses | 230 | |
319 | 231 | return sorted(addresses) | ||
320 | 232 | |||
321 | 228 | 233 | ||
322 | 229 | get_ipv4_addr = partial(get_iface_addr, inet_type='AF_INET') | 234 | get_ipv4_addr = partial(get_iface_addr, inet_type='AF_INET') |
323 | 230 | 235 | ||
324 | @@ -241,6 +246,7 @@ | |||
325 | 241 | raw = re.match(ll_key, _addr) | 246 | raw = re.match(ll_key, _addr) |
326 | 242 | if raw: | 247 | if raw: |
327 | 243 | _addr = raw.group(1) | 248 | _addr = raw.group(1) |
328 | 249 | |||
329 | 244 | if _addr == addr: | 250 | if _addr == addr: |
330 | 245 | log("Address '%s' is configured on iface '%s'" % | 251 | log("Address '%s' is configured on iface '%s'" % |
331 | 246 | (addr, iface)) | 252 | (addr, iface)) |
332 | @@ -251,8 +257,9 @@ | |||
333 | 251 | 257 | ||
334 | 252 | 258 | ||
335 | 253 | def sniff_iface(f): | 259 | def sniff_iface(f): |
338 | 254 | """If no iface provided, inject net iface inferred from unit private | 260 | """Ensure decorated function is called with a value for iface. |
339 | 255 | address. | 261 | |
340 | 262 | If no iface provided, inject net iface inferred from unit private address. | ||
341 | 256 | """ | 263 | """ |
342 | 257 | def iface_sniffer(*args, **kwargs): | 264 | def iface_sniffer(*args, **kwargs): |
343 | 258 | if not kwargs.get('iface', None): | 265 | if not kwargs.get('iface', None): |
344 | @@ -295,7 +302,7 @@ | |||
345 | 295 | if global_addrs: | 302 | if global_addrs: |
346 | 296 | # Make sure any found global addresses are not temporary | 303 | # Make sure any found global addresses are not temporary |
347 | 297 | cmd = ['ip', 'addr', 'show', iface] | 304 | cmd = ['ip', 'addr', 'show', iface] |
349 | 298 | out = subprocess.check_output(cmd) | 305 | out = subprocess.check_output(cmd).decode('UTF-8') |
350 | 299 | if dynamic_only: | 306 | if dynamic_only: |
351 | 300 | key = re.compile("inet6 (.+)/[0-9]+ scope global dynamic.*") | 307 | key = re.compile("inet6 (.+)/[0-9]+ scope global dynamic.*") |
352 | 301 | else: | 308 | else: |
353 | @@ -317,33 +324,28 @@ | |||
354 | 317 | return addrs | 324 | return addrs |
355 | 318 | 325 | ||
356 | 319 | if fatal: | 326 | if fatal: |
358 | 320 | raise Exception("Interface '%s' doesn't have a scope global " | 327 | raise Exception("Interface '%s' does not have a scope global " |
359 | 321 | "non-temporary ipv6 address." % iface) | 328 | "non-temporary ipv6 address." % iface) |
360 | 322 | 329 | ||
361 | 323 | return [] | 330 | return [] |
362 | 324 | 331 | ||
363 | 325 | 332 | ||
364 | 326 | def get_bridges(vnic_dir='/sys/devices/virtual/net'): | 333 | def get_bridges(vnic_dir='/sys/devices/virtual/net'): |
370 | 327 | """ | 334 | """Return a list of bridges on the system.""" |
371 | 328 | Return a list of bridges on the system or [] | 335 | b_regex = "%s/*/bridge" % vnic_dir |
372 | 329 | """ | 336 | return [x.replace(vnic_dir, '').split('/')[1] for x in glob.glob(b_regex)] |
368 | 330 | b_rgex = vnic_dir + '/*/bridge' | ||
369 | 331 | return [x.replace(vnic_dir, '').split('/')[1] for x in glob.glob(b_rgex)] | ||
373 | 332 | 337 | ||
374 | 333 | 338 | ||
375 | 334 | def get_bridge_nics(bridge, vnic_dir='/sys/devices/virtual/net'): | 339 | def get_bridge_nics(bridge, vnic_dir='/sys/devices/virtual/net'): |
381 | 335 | """ | 340 | """Return a list of nics comprising a given bridge on the system.""" |
382 | 336 | Return a list of nics comprising a given bridge on the system or [] | 341 | brif_regex = "%s/%s/brif/*" % (vnic_dir, bridge) |
383 | 337 | """ | 342 | return [x.split('/')[-1] for x in glob.glob(brif_regex)] |
379 | 338 | brif_rgex = "%s/%s/brif/*" % (vnic_dir, bridge) | ||
380 | 339 | return [x.split('/')[-1] for x in glob.glob(brif_rgex)] | ||
384 | 340 | 343 | ||
385 | 341 | 344 | ||
386 | 342 | def is_bridge_member(nic): | 345 | def is_bridge_member(nic): |
390 | 343 | """ | 346 | """Check if a given nic is a member of a bridge.""" |
388 | 344 | Check if a given nic is a member of a bridge | ||
389 | 345 | """ | ||
391 | 346 | for bridge in get_bridges(): | 347 | for bridge in get_bridges(): |
392 | 347 | if nic in get_bridge_nics(bridge): | 348 | if nic in get_bridge_nics(bridge): |
393 | 348 | return True | 349 | return True |
394 | 350 | |||
395 | 349 | return False | 351 | return False |
396 | 350 | 352 | ||
397 | === modified file 'hooks/charmhelpers/contrib/openstack/amulet/deployment.py' | |||
398 | --- hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2014-10-02 09:18:00 +0000 | |||
399 | +++ hooks/charmhelpers/contrib/openstack/amulet/deployment.py 2014-12-11 17:56:40 +0000 | |||
400 | @@ -1,3 +1,4 @@ | |||
401 | 1 | import six | ||
402 | 1 | from charmhelpers.contrib.amulet.deployment import ( | 2 | from charmhelpers.contrib.amulet.deployment import ( |
403 | 2 | AmuletDeployment | 3 | AmuletDeployment |
404 | 3 | ) | 4 | ) |
405 | @@ -69,7 +70,7 @@ | |||
406 | 69 | 70 | ||
407 | 70 | def _configure_services(self, configs): | 71 | def _configure_services(self, configs): |
408 | 71 | """Configure all of the services.""" | 72 | """Configure all of the services.""" |
410 | 72 | for service, config in configs.iteritems(): | 73 | for service, config in six.iteritems(configs): |
411 | 73 | self.d.configure(service, config) | 74 | self.d.configure(service, config) |
412 | 74 | 75 | ||
413 | 75 | def _get_openstack_release(self): | 76 | def _get_openstack_release(self): |
414 | 76 | 77 | ||
415 | === modified file 'hooks/charmhelpers/contrib/openstack/amulet/utils.py' | |||
416 | --- hooks/charmhelpers/contrib/openstack/amulet/utils.py 2014-10-02 09:18:00 +0000 | |||
417 | +++ hooks/charmhelpers/contrib/openstack/amulet/utils.py 2014-12-11 17:56:40 +0000 | |||
418 | @@ -7,6 +7,8 @@ | |||
419 | 7 | import keystoneclient.v2_0 as keystone_client | 7 | import keystoneclient.v2_0 as keystone_client |
420 | 8 | import novaclient.v1_1.client as nova_client | 8 | import novaclient.v1_1.client as nova_client |
421 | 9 | 9 | ||
422 | 10 | import six | ||
423 | 11 | |||
424 | 10 | from charmhelpers.contrib.amulet.utils import ( | 12 | from charmhelpers.contrib.amulet.utils import ( |
425 | 11 | AmuletUtils | 13 | AmuletUtils |
426 | 12 | ) | 14 | ) |
427 | @@ -60,7 +62,7 @@ | |||
428 | 60 | expected service catalog endpoints. | 62 | expected service catalog endpoints. |
429 | 61 | """ | 63 | """ |
430 | 62 | self.log.debug('actual: {}'.format(repr(actual))) | 64 | self.log.debug('actual: {}'.format(repr(actual))) |
432 | 63 | for k, v in expected.iteritems(): | 65 | for k, v in six.iteritems(expected): |
433 | 64 | if k in actual: | 66 | if k in actual: |
434 | 65 | ret = self._validate_dict_data(expected[k][0], actual[k][0]) | 67 | ret = self._validate_dict_data(expected[k][0], actual[k][0]) |
435 | 66 | if ret: | 68 | if ret: |
436 | 67 | 69 | ||
437 | === modified file 'hooks/charmhelpers/contrib/openstack/context.py' | |||
438 | --- hooks/charmhelpers/contrib/openstack/context.py 2014-10-07 12:29:50 +0000 | |||
439 | +++ hooks/charmhelpers/contrib/openstack/context.py 2014-12-11 17:56:40 +0000 | |||
440 | @@ -1,20 +1,18 @@ | |||
441 | 1 | import json | 1 | import json |
442 | 2 | import os | 2 | import os |
443 | 3 | import time | 3 | import time |
444 | 4 | |||
445 | 5 | from base64 import b64decode | 4 | from base64 import b64decode |
446 | 5 | from subprocess import check_call | ||
447 | 6 | 6 | ||
451 | 7 | from subprocess import ( | 7 | import six |
449 | 8 | check_call | ||
450 | 9 | ) | ||
452 | 10 | 8 | ||
453 | 11 | from charmhelpers.fetch import ( | 9 | from charmhelpers.fetch import ( |
454 | 12 | apt_install, | 10 | apt_install, |
455 | 13 | filter_installed_packages, | 11 | filter_installed_packages, |
456 | 14 | ) | 12 | ) |
457 | 15 | |||
458 | 16 | from charmhelpers.core.hookenv import ( | 13 | from charmhelpers.core.hookenv import ( |
459 | 17 | config, | 14 | config, |
460 | 15 | is_relation_made, | ||
461 | 18 | local_unit, | 16 | local_unit, |
462 | 19 | log, | 17 | log, |
463 | 20 | relation_get, | 18 | relation_get, |
464 | @@ -23,43 +21,40 @@ | |||
465 | 23 | relation_set, | 21 | relation_set, |
466 | 24 | unit_get, | 22 | unit_get, |
467 | 25 | unit_private_ip, | 23 | unit_private_ip, |
468 | 24 | DEBUG, | ||
469 | 25 | INFO, | ||
470 | 26 | WARNING, | ||
471 | 26 | ERROR, | 27 | ERROR, |
472 | 27 | INFO | ||
473 | 28 | ) | 28 | ) |
474 | 29 | |||
475 | 30 | from charmhelpers.core.host import ( | 29 | from charmhelpers.core.host import ( |
476 | 31 | mkdir, | 30 | mkdir, |
478 | 32 | write_file | 31 | write_file, |
479 | 33 | ) | 32 | ) |
480 | 34 | |||
481 | 35 | from charmhelpers.contrib.hahelpers.cluster import ( | 33 | from charmhelpers.contrib.hahelpers.cluster import ( |
482 | 36 | determine_apache_port, | 34 | determine_apache_port, |
483 | 37 | determine_api_port, | 35 | determine_api_port, |
484 | 38 | https, | 36 | https, |
486 | 39 | is_clustered | 37 | is_clustered, |
487 | 40 | ) | 38 | ) |
488 | 41 | |||
489 | 42 | from charmhelpers.contrib.hahelpers.apache import ( | 39 | from charmhelpers.contrib.hahelpers.apache import ( |
490 | 43 | get_cert, | 40 | get_cert, |
491 | 44 | get_ca_cert, | 41 | get_ca_cert, |
492 | 45 | install_ca_cert, | 42 | install_ca_cert, |
493 | 46 | ) | 43 | ) |
494 | 47 | |||
495 | 48 | from charmhelpers.contrib.openstack.neutron import ( | 44 | from charmhelpers.contrib.openstack.neutron import ( |
496 | 49 | neutron_plugin_attribute, | 45 | neutron_plugin_attribute, |
497 | 50 | ) | 46 | ) |
498 | 51 | |||
499 | 52 | from charmhelpers.contrib.network.ip import ( | 47 | from charmhelpers.contrib.network.ip import ( |
500 | 53 | get_address_in_network, | 48 | get_address_in_network, |
501 | 54 | get_ipv6_addr, | 49 | get_ipv6_addr, |
502 | 55 | get_netmask_for_address, | 50 | get_netmask_for_address, |
503 | 56 | format_ipv6_addr, | 51 | format_ipv6_addr, |
505 | 57 | is_address_in_network | 52 | is_address_in_network, |
506 | 58 | ) | 53 | ) |
507 | 59 | |||
508 | 60 | from charmhelpers.contrib.openstack.utils import get_host_ip | 54 | from charmhelpers.contrib.openstack.utils import get_host_ip |
509 | 61 | 55 | ||
510 | 62 | CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' | 56 | CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt' |
511 | 57 | ADDRESS_TYPES = ['admin', 'internal', 'public'] | ||
512 | 63 | 58 | ||
513 | 64 | 59 | ||
514 | 65 | class OSContextError(Exception): | 60 | class OSContextError(Exception): |
515 | @@ -67,7 +62,7 @@ | |||
516 | 67 | 62 | ||
517 | 68 | 63 | ||
518 | 69 | def ensure_packages(packages): | 64 | def ensure_packages(packages): |
520 | 70 | '''Install but do not upgrade required plugin packages''' | 65 | """Install but do not upgrade required plugin packages.""" |
521 | 71 | required = filter_installed_packages(packages) | 66 | required = filter_installed_packages(packages) |
522 | 72 | if required: | 67 | if required: |
523 | 73 | apt_install(required, fatal=True) | 68 | apt_install(required, fatal=True) |
524 | @@ -75,20 +70,27 @@ | |||
525 | 75 | 70 | ||
526 | 76 | def context_complete(ctxt): | 71 | def context_complete(ctxt): |
527 | 77 | _missing = [] | 72 | _missing = [] |
529 | 78 | for k, v in ctxt.iteritems(): | 73 | for k, v in six.iteritems(ctxt): |
530 | 79 | if v is None or v == '': | 74 | if v is None or v == '': |
531 | 80 | _missing.append(k) | 75 | _missing.append(k) |
532 | 76 | |||
533 | 81 | if _missing: | 77 | if _missing: |
535 | 82 | log('Missing required data: %s' % ' '.join(_missing), level='INFO') | 78 | log('Missing required data: %s' % ' '.join(_missing), level=INFO) |
536 | 83 | return False | 79 | return False |
537 | 80 | |||
538 | 84 | return True | 81 | return True |
539 | 85 | 82 | ||
540 | 86 | 83 | ||
541 | 87 | def config_flags_parser(config_flags): | 84 | def config_flags_parser(config_flags): |
542 | 85 | """Parses config flags string into dict. | ||
543 | 86 | |||
544 | 87 | The provided config_flags string may be a list of comma-separated values | ||
545 | 88 | which themselves may be comma-separated list of values. | ||
546 | 89 | """ | ||
547 | 88 | if config_flags.find('==') >= 0: | 90 | if config_flags.find('==') >= 0: |
550 | 89 | log("config_flags is not in expected format (key=value)", | 91 | log("config_flags is not in expected format (key=value)", level=ERROR) |
549 | 90 | level=ERROR) | ||
551 | 91 | raise OSContextError | 92 | raise OSContextError |
552 | 93 | |||
553 | 92 | # strip the following from each value. | 94 | # strip the following from each value. |
554 | 93 | post_strippers = ' ,' | 95 | post_strippers = ' ,' |
555 | 94 | # we strip any leading/trailing '=' or ' ' from the string then | 96 | # we strip any leading/trailing '=' or ' ' from the string then |
556 | @@ -96,7 +98,7 @@ | |||
557 | 96 | split = config_flags.strip(' =').split('=') | 98 | split = config_flags.strip(' =').split('=') |
558 | 97 | limit = len(split) | 99 | limit = len(split) |
559 | 98 | flags = {} | 100 | flags = {} |
561 | 99 | for i in xrange(0, limit - 1): | 101 | for i in range(0, limit - 1): |
562 | 100 | current = split[i] | 102 | current = split[i] |
563 | 101 | next = split[i + 1] | 103 | next = split[i + 1] |
564 | 102 | vindex = next.rfind(',') | 104 | vindex = next.rfind(',') |
565 | @@ -111,17 +113,18 @@ | |||
566 | 111 | # if this not the first entry, expect an embedded key. | 113 | # if this not the first entry, expect an embedded key. |
567 | 112 | index = current.rfind(',') | 114 | index = current.rfind(',') |
568 | 113 | if index < 0: | 115 | if index < 0: |
571 | 114 | log("invalid config value(s) at index %s" % (i), | 116 | log("Invalid config value(s) at index %s" % (i), level=ERROR) |
570 | 115 | level=ERROR) | ||
572 | 116 | raise OSContextError | 117 | raise OSContextError |
573 | 117 | key = current[index + 1:] | 118 | key = current[index + 1:] |
574 | 118 | 119 | ||
575 | 119 | # Add to collection. | 120 | # Add to collection. |
576 | 120 | flags[key.strip(post_strippers)] = value.rstrip(post_strippers) | 121 | flags[key.strip(post_strippers)] = value.rstrip(post_strippers) |
577 | 122 | |||
578 | 121 | return flags | 123 | return flags |
579 | 122 | 124 | ||
580 | 123 | 125 | ||
581 | 124 | class OSContextGenerator(object): | 126 | class OSContextGenerator(object): |
582 | 127 | """Base class for all context generators.""" | ||
583 | 125 | interfaces = [] | 128 | interfaces = [] |
584 | 126 | 129 | ||
585 | 127 | def __call__(self): | 130 | def __call__(self): |
586 | @@ -133,11 +136,11 @@ | |||
587 | 133 | 136 | ||
588 | 134 | def __init__(self, | 137 | def __init__(self, |
589 | 135 | database=None, user=None, relation_prefix=None, ssl_dir=None): | 138 | database=None, user=None, relation_prefix=None, ssl_dir=None): |
595 | 136 | ''' | 139 | """Allows inspecting relation for settings prefixed with |
596 | 137 | Allows inspecting relation for settings prefixed with relation_prefix. | 140 | relation_prefix. This is useful for parsing access for multiple |
597 | 138 | This is useful for parsing access for multiple databases returned via | 141 | databases returned via the shared-db interface (eg, nova_password, |
598 | 139 | the shared-db interface (eg, nova_password, quantum_password) | 142 | quantum_password) |
599 | 140 | ''' | 143 | """ |
600 | 141 | self.relation_prefix = relation_prefix | 144 | self.relation_prefix = relation_prefix |
601 | 142 | self.database = database | 145 | self.database = database |
602 | 143 | self.user = user | 146 | self.user = user |
603 | @@ -147,9 +150,8 @@ | |||
604 | 147 | self.database = self.database or config('database') | 150 | self.database = self.database or config('database') |
605 | 148 | self.user = self.user or config('database-user') | 151 | self.user = self.user or config('database-user') |
606 | 149 | if None in [self.database, self.user]: | 152 | if None in [self.database, self.user]: |
610 | 150 | log('Could not generate shared_db context. ' | 153 | log("Could not generate shared_db context. Missing required charm " |
611 | 151 | 'Missing required charm config options. ' | 154 | "config options. (database name and user)", level=ERROR) |
609 | 152 | '(database name and user)') | ||
612 | 153 | raise OSContextError | 155 | raise OSContextError |
613 | 154 | 156 | ||
614 | 155 | ctxt = {} | 157 | ctxt = {} |
615 | @@ -202,23 +204,24 @@ | |||
616 | 202 | def __call__(self): | 204 | def __call__(self): |
617 | 203 | self.database = self.database or config('database') | 205 | self.database = self.database or config('database') |
618 | 204 | if self.database is None: | 206 | if self.database is None: |
622 | 205 | log('Could not generate postgresql_db context. ' | 207 | log('Could not generate postgresql_db context. Missing required ' |
623 | 206 | 'Missing required charm config options. ' | 208 | 'charm config options. (database name)', level=ERROR) |
621 | 207 | '(database name)') | ||
624 | 208 | raise OSContextError | 209 | raise OSContextError |
625 | 210 | |||
626 | 209 | ctxt = {} | 211 | ctxt = {} |
627 | 210 | |||
628 | 211 | for rid in relation_ids(self.interfaces[0]): | 212 | for rid in relation_ids(self.interfaces[0]): |
629 | 212 | for unit in related_units(rid): | 213 | for unit in related_units(rid): |
637 | 213 | ctxt = { | 214 | rel_host = relation_get('host', rid=rid, unit=unit) |
638 | 214 | 'database_host': relation_get('host', rid=rid, unit=unit), | 215 | rel_user = relation_get('user', rid=rid, unit=unit) |
639 | 215 | 'database': self.database, | 216 | rel_passwd = relation_get('password', rid=rid, unit=unit) |
640 | 216 | 'database_user': relation_get('user', rid=rid, unit=unit), | 217 | ctxt = {'database_host': rel_host, |
641 | 217 | 'database_password': relation_get('password', rid=rid, unit=unit), | 218 | 'database': self.database, |
642 | 218 | 'database_type': 'postgresql', | 219 | 'database_user': rel_user, |
643 | 219 | } | 220 | 'database_password': rel_passwd, |
644 | 221 | 'database_type': 'postgresql'} | ||
645 | 220 | if context_complete(ctxt): | 222 | if context_complete(ctxt): |
646 | 221 | return ctxt | 223 | return ctxt |
647 | 224 | |||
648 | 222 | return {} | 225 | return {} |
649 | 223 | 226 | ||
650 | 224 | 227 | ||
651 | @@ -227,23 +230,29 @@ | |||
652 | 227 | ca_path = os.path.join(ssl_dir, 'db-client.ca') | 230 | ca_path = os.path.join(ssl_dir, 'db-client.ca') |
653 | 228 | with open(ca_path, 'w') as fh: | 231 | with open(ca_path, 'w') as fh: |
654 | 229 | fh.write(b64decode(rdata['ssl_ca'])) | 232 | fh.write(b64decode(rdata['ssl_ca'])) |
655 | 233 | |||
656 | 230 | ctxt['database_ssl_ca'] = ca_path | 234 | ctxt['database_ssl_ca'] = ca_path |
657 | 231 | elif 'ssl_ca' in rdata: | 235 | elif 'ssl_ca' in rdata: |
659 | 232 | log("Charm not setup for ssl support but ssl ca found") | 236 | log("Charm not setup for ssl support but ssl ca found", level=INFO) |
660 | 233 | return ctxt | 237 | return ctxt |
661 | 238 | |||
662 | 234 | if 'ssl_cert' in rdata: | 239 | if 'ssl_cert' in rdata: |
663 | 235 | cert_path = os.path.join( | 240 | cert_path = os.path.join( |
664 | 236 | ssl_dir, 'db-client.cert') | 241 | ssl_dir, 'db-client.cert') |
665 | 237 | if not os.path.exists(cert_path): | 242 | if not os.path.exists(cert_path): |
667 | 238 | log("Waiting 1m for ssl client cert validity") | 243 | log("Waiting 1m for ssl client cert validity", level=INFO) |
668 | 239 | time.sleep(60) | 244 | time.sleep(60) |
669 | 245 | |||
670 | 240 | with open(cert_path, 'w') as fh: | 246 | with open(cert_path, 'w') as fh: |
671 | 241 | fh.write(b64decode(rdata['ssl_cert'])) | 247 | fh.write(b64decode(rdata['ssl_cert'])) |
672 | 248 | |||
673 | 242 | ctxt['database_ssl_cert'] = cert_path | 249 | ctxt['database_ssl_cert'] = cert_path |
674 | 243 | key_path = os.path.join(ssl_dir, 'db-client.key') | 250 | key_path = os.path.join(ssl_dir, 'db-client.key') |
675 | 244 | with open(key_path, 'w') as fh: | 251 | with open(key_path, 'w') as fh: |
676 | 245 | fh.write(b64decode(rdata['ssl_key'])) | 252 | fh.write(b64decode(rdata['ssl_key'])) |
677 | 253 | |||
678 | 246 | ctxt['database_ssl_key'] = key_path | 254 | ctxt['database_ssl_key'] = key_path |
679 | 255 | |||
680 | 247 | return ctxt | 256 | return ctxt |
681 | 248 | 257 | ||
682 | 249 | 258 | ||
683 | @@ -251,9 +260,8 @@ | |||
684 | 251 | interfaces = ['identity-service'] | 260 | interfaces = ['identity-service'] |
685 | 252 | 261 | ||
686 | 253 | def __call__(self): | 262 | def __call__(self): |
688 | 254 | log('Generating template context for identity-service') | 263 | log('Generating template context for identity-service', level=DEBUG) |
689 | 255 | ctxt = {} | 264 | ctxt = {} |
690 | 256 | |||
691 | 257 | for rid in relation_ids('identity-service'): | 265 | for rid in relation_ids('identity-service'): |
692 | 258 | for unit in related_units(rid): | 266 | for unit in related_units(rid): |
693 | 259 | rdata = relation_get(rid=rid, unit=unit) | 267 | rdata = relation_get(rid=rid, unit=unit) |
694 | @@ -261,26 +269,24 @@ | |||
695 | 261 | serv_host = format_ipv6_addr(serv_host) or serv_host | 269 | serv_host = format_ipv6_addr(serv_host) or serv_host |
696 | 262 | auth_host = rdata.get('auth_host') | 270 | auth_host = rdata.get('auth_host') |
697 | 263 | auth_host = format_ipv6_addr(auth_host) or auth_host | 271 | auth_host = format_ipv6_addr(auth_host) or auth_host |
712 | 264 | 272 | svc_protocol = rdata.get('service_protocol') or 'http' | |
713 | 265 | ctxt = { | 273 | auth_protocol = rdata.get('auth_protocol') or 'http' |
714 | 266 | 'service_port': rdata.get('service_port'), | 274 | ctxt = {'service_port': rdata.get('service_port'), |
715 | 267 | 'service_host': serv_host, | 275 | 'service_host': serv_host, |
716 | 268 | 'auth_host': auth_host, | 276 | 'auth_host': auth_host, |
717 | 269 | 'auth_port': rdata.get('auth_port'), | 277 | 'auth_port': rdata.get('auth_port'), |
718 | 270 | 'admin_tenant_name': rdata.get('service_tenant'), | 278 | 'admin_tenant_name': rdata.get('service_tenant'), |
719 | 271 | 'admin_user': rdata.get('service_username'), | 279 | 'admin_user': rdata.get('service_username'), |
720 | 272 | 'admin_password': rdata.get('service_password'), | 280 | 'admin_password': rdata.get('service_password'), |
721 | 273 | 'service_protocol': | 281 | 'service_protocol': svc_protocol, |
722 | 274 | rdata.get('service_protocol') or 'http', | 282 | 'auth_protocol': auth_protocol} |
709 | 275 | 'auth_protocol': | ||
710 | 276 | rdata.get('auth_protocol') or 'http', | ||
711 | 277 | } | ||
723 | 278 | if context_complete(ctxt): | 283 | if context_complete(ctxt): |
724 | 279 | # NOTE(jamespage) this is required for >= icehouse | 284 | # NOTE(jamespage) this is required for >= icehouse |
725 | 280 | # so a missing value just indicates keystone needs | 285 | # so a missing value just indicates keystone needs |
726 | 281 | # upgrading | 286 | # upgrading |
727 | 282 | ctxt['admin_tenant_id'] = rdata.get('service_tenant_id') | 287 | ctxt['admin_tenant_id'] = rdata.get('service_tenant_id') |
728 | 283 | return ctxt | 288 | return ctxt |
729 | 289 | |||
730 | 284 | return {} | 290 | return {} |
731 | 285 | 291 | ||
732 | 286 | 292 | ||
733 | @@ -293,21 +299,23 @@ | |||
734 | 293 | self.interfaces = [rel_name] | 299 | self.interfaces = [rel_name] |
735 | 294 | 300 | ||
736 | 295 | def __call__(self): | 301 | def __call__(self): |
738 | 296 | log('Generating template context for amqp') | 302 | log('Generating template context for amqp', level=DEBUG) |
739 | 297 | conf = config() | 303 | conf = config() |
740 | 298 | user_setting = 'rabbit-user' | ||
741 | 299 | vhost_setting = 'rabbit-vhost' | ||
742 | 300 | if self.relation_prefix: | 304 | if self.relation_prefix: |
745 | 301 | user_setting = self.relation_prefix + '-rabbit-user' | 305 | user_setting = '%s-rabbit-user' % (self.relation_prefix) |
746 | 302 | vhost_setting = self.relation_prefix + '-rabbit-vhost' | 306 | vhost_setting = '%s-rabbit-vhost' % (self.relation_prefix) |
747 | 307 | else: | ||
748 | 308 | user_setting = 'rabbit-user' | ||
749 | 309 | vhost_setting = 'rabbit-vhost' | ||
750 | 303 | 310 | ||
751 | 304 | try: | 311 | try: |
752 | 305 | username = conf[user_setting] | 312 | username = conf[user_setting] |
753 | 306 | vhost = conf[vhost_setting] | 313 | vhost = conf[vhost_setting] |
754 | 307 | except KeyError as e: | 314 | except KeyError as e: |
757 | 308 | log('Could not generate shared_db context. ' | 315 | log('Could not generate shared_db context. Missing required charm ' |
758 | 309 | 'Missing required charm config options: %s.' % e) | 316 | 'config options: %s.' % e, level=ERROR) |
759 | 310 | raise OSContextError | 317 | raise OSContextError |
760 | 318 | |||
761 | 311 | ctxt = {} | 319 | ctxt = {} |
762 | 312 | for rid in relation_ids(self.rel_name): | 320 | for rid in relation_ids(self.rel_name): |
763 | 313 | ha_vip_only = False | 321 | ha_vip_only = False |
764 | @@ -321,6 +329,7 @@ | |||
765 | 321 | host = relation_get('private-address', rid=rid, unit=unit) | 329 | host = relation_get('private-address', rid=rid, unit=unit) |
766 | 322 | host = format_ipv6_addr(host) or host | 330 | host = format_ipv6_addr(host) or host |
767 | 323 | ctxt['rabbitmq_host'] = host | 331 | ctxt['rabbitmq_host'] = host |
768 | 332 | |||
769 | 324 | ctxt.update({ | 333 | ctxt.update({ |
770 | 325 | 'rabbitmq_user': username, | 334 | 'rabbitmq_user': username, |
771 | 326 | 'rabbitmq_password': relation_get('password', rid=rid, | 335 | 'rabbitmq_password': relation_get('password', rid=rid, |
772 | @@ -331,6 +340,7 @@ | |||
773 | 331 | ssl_port = relation_get('ssl_port', rid=rid, unit=unit) | 340 | ssl_port = relation_get('ssl_port', rid=rid, unit=unit) |
774 | 332 | if ssl_port: | 341 | if ssl_port: |
775 | 333 | ctxt['rabbit_ssl_port'] = ssl_port | 342 | ctxt['rabbit_ssl_port'] = ssl_port |
776 | 343 | |||
777 | 334 | ssl_ca = relation_get('ssl_ca', rid=rid, unit=unit) | 344 | ssl_ca = relation_get('ssl_ca', rid=rid, unit=unit) |
778 | 335 | if ssl_ca: | 345 | if ssl_ca: |
779 | 336 | ctxt['rabbit_ssl_ca'] = ssl_ca | 346 | ctxt['rabbit_ssl_ca'] = ssl_ca |
780 | @@ -344,41 +354,45 @@ | |||
781 | 344 | if context_complete(ctxt): | 354 | if context_complete(ctxt): |
782 | 345 | if 'rabbit_ssl_ca' in ctxt: | 355 | if 'rabbit_ssl_ca' in ctxt: |
783 | 346 | if not self.ssl_dir: | 356 | if not self.ssl_dir: |
786 | 347 | log(("Charm not setup for ssl support " | 357 | log("Charm not setup for ssl support but ssl ca " |
787 | 348 | "but ssl ca found")) | 358 | "found", level=INFO) |
788 | 349 | break | 359 | break |
789 | 360 | |||
790 | 350 | ca_path = os.path.join( | 361 | ca_path = os.path.join( |
791 | 351 | self.ssl_dir, 'rabbit-client-ca.pem') | 362 | self.ssl_dir, 'rabbit-client-ca.pem') |
792 | 352 | with open(ca_path, 'w') as fh: | 363 | with open(ca_path, 'w') as fh: |
793 | 353 | fh.write(b64decode(ctxt['rabbit_ssl_ca'])) | 364 | fh.write(b64decode(ctxt['rabbit_ssl_ca'])) |
794 | 354 | ctxt['rabbit_ssl_ca'] = ca_path | 365 | ctxt['rabbit_ssl_ca'] = ca_path |
795 | 366 | |||
796 | 355 | # Sufficient information found = break out! | 367 | # Sufficient information found = break out! |
797 | 356 | break | 368 | break |
798 | 369 | |||
799 | 357 | # Used for active/active rabbitmq >= grizzly | 370 | # Used for active/active rabbitmq >= grizzly |
802 | 358 | if ('clustered' not in ctxt or ha_vip_only) \ | 371 | if (('clustered' not in ctxt or ha_vip_only) and |
803 | 359 | and len(related_units(rid)) > 1: | 372 | len(related_units(rid)) > 1): |
804 | 360 | rabbitmq_hosts = [] | 373 | rabbitmq_hosts = [] |
805 | 361 | for unit in related_units(rid): | 374 | for unit in related_units(rid): |
806 | 362 | host = relation_get('private-address', rid=rid, unit=unit) | 375 | host = relation_get('private-address', rid=rid, unit=unit) |
807 | 363 | host = format_ipv6_addr(host) or host | 376 | host = format_ipv6_addr(host) or host |
808 | 364 | rabbitmq_hosts.append(host) | 377 | rabbitmq_hosts.append(host) |
810 | 365 | ctxt['rabbitmq_hosts'] = ','.join(rabbitmq_hosts) | 378 | |
811 | 379 | ctxt['rabbitmq_hosts'] = ','.join(sorted(rabbitmq_hosts)) | ||
812 | 380 | |||
813 | 366 | if not context_complete(ctxt): | 381 | if not context_complete(ctxt): |
814 | 367 | return {} | 382 | return {} |
817 | 368 | else: | 383 | |
818 | 369 | return ctxt | 384 | return ctxt |
819 | 370 | 385 | ||
820 | 371 | 386 | ||
821 | 372 | class CephContext(OSContextGenerator): | 387 | class CephContext(OSContextGenerator): |
822 | 388 | """Generates context for /etc/ceph/ceph.conf templates.""" | ||
823 | 373 | interfaces = ['ceph'] | 389 | interfaces = ['ceph'] |
824 | 374 | 390 | ||
825 | 375 | def __call__(self): | 391 | def __call__(self): |
826 | 376 | '''This generates context for /etc/ceph/ceph.conf templates''' | ||
827 | 377 | if not relation_ids('ceph'): | 392 | if not relation_ids('ceph'): |
828 | 378 | return {} | 393 | return {} |
829 | 379 | 394 | ||
832 | 380 | log('Generating template context for ceph') | 395 | log('Generating template context for ceph', level=DEBUG) |
831 | 381 | |||
833 | 382 | mon_hosts = [] | 396 | mon_hosts = [] |
834 | 383 | auth = None | 397 | auth = None |
835 | 384 | key = None | 398 | key = None |
836 | @@ -387,18 +401,18 @@ | |||
837 | 387 | for unit in related_units(rid): | 401 | for unit in related_units(rid): |
838 | 388 | auth = relation_get('auth', rid=rid, unit=unit) | 402 | auth = relation_get('auth', rid=rid, unit=unit) |
839 | 389 | key = relation_get('key', rid=rid, unit=unit) | 403 | key = relation_get('key', rid=rid, unit=unit) |
843 | 390 | ceph_addr = \ | 404 | ceph_pub_addr = relation_get('ceph-public-address', rid=rid, |
844 | 391 | relation_get('ceph-public-address', rid=rid, unit=unit) or \ | 405 | unit=unit) |
845 | 392 | relation_get('private-address', rid=rid, unit=unit) | 406 | unit_priv_addr = relation_get('private-address', rid=rid, |
846 | 407 | unit=unit) | ||
847 | 408 | ceph_addr = ceph_pub_addr or unit_priv_addr | ||
848 | 393 | ceph_addr = format_ipv6_addr(ceph_addr) or ceph_addr | 409 | ceph_addr = format_ipv6_addr(ceph_addr) or ceph_addr |
849 | 394 | mon_hosts.append(ceph_addr) | 410 | mon_hosts.append(ceph_addr) |
850 | 395 | 411 | ||
857 | 396 | ctxt = { | 412 | ctxt = {'mon_hosts': ' '.join(sorted(mon_hosts)), |
858 | 397 | 'mon_hosts': ' '.join(mon_hosts), | 413 | 'auth': auth, |
859 | 398 | 'auth': auth, | 414 | 'key': key, |
860 | 399 | 'key': key, | 415 | 'use_syslog': use_syslog} |
855 | 400 | 'use_syslog': use_syslog | ||
856 | 401 | } | ||
861 | 402 | 416 | ||
862 | 403 | if not os.path.isdir('/etc/ceph'): | 417 | if not os.path.isdir('/etc/ceph'): |
863 | 404 | os.mkdir('/etc/ceph') | 418 | os.mkdir('/etc/ceph') |
864 | @@ -407,79 +421,68 @@ | |||
865 | 407 | return {} | 421 | return {} |
866 | 408 | 422 | ||
867 | 409 | ensure_packages(['ceph-common']) | 423 | ensure_packages(['ceph-common']) |
868 | 410 | |||
869 | 411 | return ctxt | 424 | return ctxt |
870 | 412 | 425 | ||
871 | 413 | 426 | ||
872 | 414 | ADDRESS_TYPES = ['admin', 'internal', 'public'] | ||
873 | 415 | |||
874 | 416 | |||
875 | 417 | class HAProxyContext(OSContextGenerator): | 427 | class HAProxyContext(OSContextGenerator): |
876 | 428 | """Provides half a context for the haproxy template, which describes | ||
877 | 429 | all peers to be included in the cluster. Each charm needs to include | ||
878 | 430 | its own context generator that describes the port mapping. | ||
879 | 431 | """ | ||
880 | 418 | interfaces = ['cluster'] | 432 | interfaces = ['cluster'] |
881 | 419 | 433 | ||
882 | 434 | def __init__(self, singlenode_mode=False): | ||
883 | 435 | self.singlenode_mode = singlenode_mode | ||
884 | 436 | |||
885 | 420 | def __call__(self): | 437 | def __call__(self): |
892 | 421 | ''' | 438 | if not relation_ids('cluster') and not self.singlenode_mode: |
887 | 422 | Builds half a context for the haproxy template, which describes | ||
888 | 423 | all peers to be included in the cluster. Each charm needs to include | ||
889 | 424 | its own context generator that describes the port mapping. | ||
890 | 425 | ''' | ||
891 | 426 | if not relation_ids('cluster'): | ||
893 | 427 | return {} | 439 | return {} |
894 | 428 | 440 | ||
895 | 429 | l_unit = local_unit().replace('/', '-') | ||
896 | 430 | |||
897 | 431 | if config('prefer-ipv6'): | 441 | if config('prefer-ipv6'): |
898 | 432 | addr = get_ipv6_addr(exc_list=[config('vip')])[0] | 442 | addr = get_ipv6_addr(exc_list=[config('vip')])[0] |
899 | 433 | else: | 443 | else: |
900 | 434 | addr = get_host_ip(unit_get('private-address')) | 444 | addr = get_host_ip(unit_get('private-address')) |
901 | 435 | 445 | ||
902 | 446 | l_unit = local_unit().replace('/', '-') | ||
903 | 436 | cluster_hosts = {} | 447 | cluster_hosts = {} |
904 | 437 | 448 | ||
905 | 438 | # NOTE(jamespage): build out map of configured network endpoints | 449 | # NOTE(jamespage): build out map of configured network endpoints |
906 | 439 | # and associated backends | 450 | # and associated backends |
907 | 440 | for addr_type in ADDRESS_TYPES: | 451 | for addr_type in ADDRESS_TYPES: |
910 | 441 | laddr = get_address_in_network( | 452 | cfg_opt = 'os-{}-network'.format(addr_type) |
911 | 442 | config('os-{}-network'.format(addr_type))) | 453 | laddr = get_address_in_network(config(cfg_opt)) |
912 | 443 | if laddr: | 454 | if laddr: |
920 | 444 | cluster_hosts[laddr] = {} | 455 | netmask = get_netmask_for_address(laddr) |
921 | 445 | cluster_hosts[laddr]['network'] = "{}/{}".format( | 456 | cluster_hosts[laddr] = {'network': "{}/{}".format(laddr, |
922 | 446 | laddr, | 457 | netmask), |
923 | 447 | get_netmask_for_address(laddr) | 458 | 'backends': {l_unit: laddr}} |
917 | 448 | ) | ||
918 | 449 | cluster_hosts[laddr]['backends'] = {} | ||
919 | 450 | cluster_hosts[laddr]['backends'][l_unit] = laddr | ||
924 | 451 | for rid in relation_ids('cluster'): | 459 | for rid in relation_ids('cluster'): |
925 | 452 | for unit in related_units(rid): | 460 | for unit in related_units(rid): |
926 | 453 | _unit = unit.replace('/', '-') | ||
927 | 454 | _laddr = relation_get('{}-address'.format(addr_type), | 461 | _laddr = relation_get('{}-address'.format(addr_type), |
928 | 455 | rid=rid, unit=unit) | 462 | rid=rid, unit=unit) |
929 | 456 | if _laddr: | 463 | if _laddr: |
930 | 464 | _unit = unit.replace('/', '-') | ||
931 | 457 | cluster_hosts[laddr]['backends'][_unit] = _laddr | 465 | cluster_hosts[laddr]['backends'][_unit] = _laddr |
932 | 458 | 466 | ||
933 | 459 | # NOTE(jamespage) no split configurations found, just use | 467 | # NOTE(jamespage) no split configurations found, just use |
934 | 460 | # private addresses | 468 | # private addresses |
935 | 461 | if not cluster_hosts: | 469 | if not cluster_hosts: |
943 | 462 | cluster_hosts[addr] = {} | 470 | netmask = get_netmask_for_address(addr) |
944 | 463 | cluster_hosts[addr]['network'] = "{}/{}".format( | 471 | cluster_hosts[addr] = {'network': "{}/{}".format(addr, netmask), |
945 | 464 | addr, | 472 | 'backends': {l_unit: addr}} |
939 | 465 | get_netmask_for_address(addr) | ||
940 | 466 | ) | ||
941 | 467 | cluster_hosts[addr]['backends'] = {} | ||
942 | 468 | cluster_hosts[addr]['backends'][l_unit] = addr | ||
946 | 469 | for rid in relation_ids('cluster'): | 473 | for rid in relation_ids('cluster'): |
947 | 470 | for unit in related_units(rid): | 474 | for unit in related_units(rid): |
948 | 471 | _unit = unit.replace('/', '-') | ||
949 | 472 | _laddr = relation_get('private-address', | 475 | _laddr = relation_get('private-address', |
950 | 473 | rid=rid, unit=unit) | 476 | rid=rid, unit=unit) |
951 | 474 | if _laddr: | 477 | if _laddr: |
952 | 478 | _unit = unit.replace('/', '-') | ||
953 | 475 | cluster_hosts[addr]['backends'][_unit] = _laddr | 479 | cluster_hosts[addr]['backends'][_unit] = _laddr |
954 | 476 | 480 | ||
958 | 477 | ctxt = { | 481 | ctxt = {'frontends': cluster_hosts} |
956 | 478 | 'frontends': cluster_hosts, | ||
957 | 479 | } | ||
959 | 480 | 482 | ||
960 | 481 | if config('haproxy-server-timeout'): | 483 | if config('haproxy-server-timeout'): |
961 | 482 | ctxt['haproxy_server_timeout'] = config('haproxy-server-timeout') | 484 | ctxt['haproxy_server_timeout'] = config('haproxy-server-timeout') |
962 | 485 | |||
963 | 483 | if config('haproxy-client-timeout'): | 486 | if config('haproxy-client-timeout'): |
964 | 484 | ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout') | 487 | ctxt['haproxy_client_timeout'] = config('haproxy-client-timeout') |
965 | 485 | 488 | ||
966 | @@ -493,13 +496,18 @@ | |||
967 | 493 | ctxt['stat_port'] = ':8888' | 496 | ctxt['stat_port'] = ':8888' |
968 | 494 | 497 | ||
969 | 495 | for frontend in cluster_hosts: | 498 | for frontend in cluster_hosts: |
971 | 496 | if len(cluster_hosts[frontend]['backends']) > 1: | 499 | if (len(cluster_hosts[frontend]['backends']) > 1 or |
972 | 500 | self.singlenode_mode): | ||
973 | 497 | # Enable haproxy when we have enough peers. | 501 | # Enable haproxy when we have enough peers. |
975 | 498 | log('Ensuring haproxy enabled in /etc/default/haproxy.') | 502 | log('Ensuring haproxy enabled in /etc/default/haproxy.', |
976 | 503 | level=DEBUG) | ||
977 | 499 | with open('/etc/default/haproxy', 'w') as out: | 504 | with open('/etc/default/haproxy', 'w') as out: |
978 | 500 | out.write('ENABLED=1\n') | 505 | out.write('ENABLED=1\n') |
979 | 506 | |||
980 | 501 | return ctxt | 507 | return ctxt |
982 | 502 | log('HAProxy context is incomplete, this unit has no peers.') | 508 | |
983 | 509 | log('HAProxy context is incomplete, this unit has no peers.', | ||
984 | 510 | level=INFO) | ||
985 | 503 | return {} | 511 | return {} |
986 | 504 | 512 | ||
987 | 505 | 513 | ||
988 | @@ -507,29 +515,28 @@ | |||
989 | 507 | interfaces = ['image-service'] | 515 | interfaces = ['image-service'] |
990 | 508 | 516 | ||
991 | 509 | def __call__(self): | 517 | def __call__(self): |
997 | 510 | ''' | 518 | """Obtains the glance API server from the image-service relation. |
998 | 511 | Obtains the glance API server from the image-service relation. Useful | 519 | Useful in nova and cinder (currently). |
999 | 512 | in nova and cinder (currently). | 520 | """ |
1000 | 513 | ''' | 521 | log('Generating template context for image-service.', level=DEBUG) |
996 | 514 | log('Generating template context for image-service.') | ||
1001 | 515 | rids = relation_ids('image-service') | 522 | rids = relation_ids('image-service') |
1002 | 516 | if not rids: | 523 | if not rids: |
1003 | 517 | return {} | 524 | return {} |
1004 | 525 | |||
1005 | 518 | for rid in rids: | 526 | for rid in rids: |
1006 | 519 | for unit in related_units(rid): | 527 | for unit in related_units(rid): |
1007 | 520 | api_server = relation_get('glance-api-server', | 528 | api_server = relation_get('glance-api-server', |
1008 | 521 | rid=rid, unit=unit) | 529 | rid=rid, unit=unit) |
1009 | 522 | if api_server: | 530 | if api_server: |
1010 | 523 | return {'glance_api_servers': api_server} | 531 | return {'glance_api_servers': api_server} |
1013 | 524 | log('ImageService context is incomplete. ' | 532 | |
1014 | 525 | 'Missing required relation data.') | 533 | log("ImageService context is incomplete. Missing required relation " |
1015 | 534 | "data.", level=INFO) | ||
1016 | 526 | return {} | 535 | return {} |
1017 | 527 | 536 | ||
1018 | 528 | 537 | ||
1019 | 529 | class ApacheSSLContext(OSContextGenerator): | 538 | class ApacheSSLContext(OSContextGenerator): |
1023 | 530 | 539 | """Generates a context for an apache vhost configuration that configures | |
1021 | 531 | """ | ||
1022 | 532 | Generates a context for an apache vhost configuration that configures | ||
1024 | 533 | HTTPS reverse proxying for one or many endpoints. Generated context | 540 | HTTPS reverse proxying for one or many endpoints. Generated context |
1025 | 534 | looks something like:: | 541 | looks something like:: |
1026 | 535 | 542 | ||
1027 | @@ -563,6 +570,7 @@ | |||
1028 | 563 | else: | 570 | else: |
1029 | 564 | cert_filename = 'cert' | 571 | cert_filename = 'cert' |
1030 | 565 | key_filename = 'key' | 572 | key_filename = 'key' |
1031 | 573 | |||
1032 | 566 | write_file(path=os.path.join(ssl_dir, cert_filename), | 574 | write_file(path=os.path.join(ssl_dir, cert_filename), |
1033 | 567 | content=b64decode(cert)) | 575 | content=b64decode(cert)) |
1034 | 568 | write_file(path=os.path.join(ssl_dir, key_filename), | 576 | write_file(path=os.path.join(ssl_dir, key_filename), |
1035 | @@ -574,7 +582,8 @@ | |||
1036 | 574 | install_ca_cert(b64decode(ca_cert)) | 582 | install_ca_cert(b64decode(ca_cert)) |
1037 | 575 | 583 | ||
1038 | 576 | def canonical_names(self): | 584 | def canonical_names(self): |
1040 | 577 | '''Figure out which canonical names clients will access this service''' | 585 | """Figure out which canonical names clients will access this service. |
1041 | 586 | """ | ||
1042 | 578 | cns = [] | 587 | cns = [] |
1043 | 579 | for r_id in relation_ids('identity-service'): | 588 | for r_id in relation_ids('identity-service'): |
1044 | 580 | for unit in related_units(r_id): | 589 | for unit in related_units(r_id): |
1045 | @@ -582,55 +591,80 @@ | |||
1046 | 582 | for k in rdata: | 591 | for k in rdata: |
1047 | 583 | if k.startswith('ssl_key_'): | 592 | if k.startswith('ssl_key_'): |
1048 | 584 | cns.append(k.lstrip('ssl_key_')) | 593 | cns.append(k.lstrip('ssl_key_')) |
1050 | 585 | return list(set(cns)) | 594 | |
1051 | 595 | return sorted(list(set(cns))) | ||
1052 | 596 | |||
1053 | 597 | def get_network_addresses(self): | ||
1054 | 598 | """For each network configured, return corresponding address and vip | ||
1055 | 599 | (if available). | ||
1056 | 600 | |||
1057 | 601 | Returns a list of tuples of the form: | ||
1058 | 602 | |||
1059 | 603 | [(address_in_net_a, vip_in_net_a), | ||
1060 | 604 | (address_in_net_b, vip_in_net_b), | ||
1061 | 605 | ...] | ||
1062 | 606 | |||
1063 | 607 | or, if no vip(s) available: | ||
1064 | 608 | |||
1065 | 609 | [(address_in_net_a, address_in_net_a), | ||
1066 | 610 | (address_in_net_b, address_in_net_b), | ||
1067 | 611 | ...] | ||
1068 | 612 | """ | ||
1069 | 613 | addresses = [] | ||
1070 | 614 | if config('vip'): | ||
1071 | 615 | vips = config('vip').split() | ||
1072 | 616 | else: | ||
1073 | 617 | vips = [] | ||
1074 | 618 | |||
1075 | 619 | for net_type in ['os-internal-network', 'os-admin-network', | ||
1076 | 620 | 'os-public-network']: | ||
1077 | 621 | addr = get_address_in_network(config(net_type), | ||
1078 | 622 | unit_get('private-address')) | ||
1079 | 623 | if len(vips) > 1 and is_clustered(): | ||
1080 | 624 | if not config(net_type): | ||
1081 | 625 | log("Multiple networks configured but net_type " | ||
1082 | 626 | "is None (%s)." % net_type, level=WARNING) | ||
1083 | 627 | continue | ||
1084 | 628 | |||
1085 | 629 | for vip in vips: | ||
1086 | 630 | if is_address_in_network(config(net_type), vip): | ||
1087 | 631 | addresses.append((addr, vip)) | ||
1088 | 632 | break | ||
1089 | 633 | |||
1090 | 634 | elif is_clustered() and config('vip'): | ||
1091 | 635 | addresses.append((addr, config('vip'))) | ||
1092 | 636 | else: | ||
1093 | 637 | addresses.append((addr, addr)) | ||
1094 | 638 | |||
1095 | 639 | return sorted(addresses) | ||
1096 | 586 | 640 | ||
1097 | 587 | def __call__(self): | 641 | def __call__(self): |
1099 | 588 | if isinstance(self.external_ports, basestring): | 642 | if isinstance(self.external_ports, six.string_types): |
1100 | 589 | self.external_ports = [self.external_ports] | 643 | self.external_ports = [self.external_ports] |
1102 | 590 | if (not self.external_ports or not https()): | 644 | |
1103 | 645 | if not self.external_ports or not https(): | ||
1104 | 591 | return {} | 646 | return {} |
1105 | 592 | 647 | ||
1106 | 593 | self.configure_ca() | 648 | self.configure_ca() |
1107 | 594 | self.enable_modules() | 649 | self.enable_modules() |
1108 | 595 | 650 | ||
1114 | 596 | ctxt = { | 651 | ctxt = {'namespace': self.service_namespace, |
1115 | 597 | 'namespace': self.service_namespace, | 652 | 'endpoints': [], |
1116 | 598 | 'endpoints': [], | 653 | 'ext_ports': []} |
1112 | 599 | 'ext_ports': [] | ||
1113 | 600 | } | ||
1117 | 601 | 654 | ||
1118 | 602 | for cn in self.canonical_names(): | 655 | for cn in self.canonical_names(): |
1119 | 603 | self.configure_cert(cn) | 656 | self.configure_cert(cn) |
1120 | 604 | 657 | ||
1143 | 605 | addresses = [] | 658 | addresses = self.get_network_addresses() |
1144 | 606 | vips = [] | 659 | for address, endpoint in sorted(set(addresses)): |
1123 | 607 | if config('vip'): | ||
1124 | 608 | vips = config('vip').split() | ||
1125 | 609 | |||
1126 | 610 | for network_type in ['os-internal-network', | ||
1127 | 611 | 'os-admin-network', | ||
1128 | 612 | 'os-public-network']: | ||
1129 | 613 | address = get_address_in_network(config(network_type), | ||
1130 | 614 | unit_get('private-address')) | ||
1131 | 615 | if len(vips) > 0 and is_clustered(): | ||
1132 | 616 | for vip in vips: | ||
1133 | 617 | if is_address_in_network(config(network_type), | ||
1134 | 618 | vip): | ||
1135 | 619 | addresses.append((address, vip)) | ||
1136 | 620 | break | ||
1137 | 621 | elif is_clustered(): | ||
1138 | 622 | addresses.append((address, config('vip'))) | ||
1139 | 623 | else: | ||
1140 | 624 | addresses.append((address, address)) | ||
1141 | 625 | |||
1142 | 626 | for address, endpoint in set(addresses): | ||
1145 | 627 | for api_port in self.external_ports: | 660 | for api_port in self.external_ports: |
1146 | 628 | ext_port = determine_apache_port(api_port) | 661 | ext_port = determine_apache_port(api_port) |
1147 | 629 | int_port = determine_api_port(api_port) | 662 | int_port = determine_api_port(api_port) |
1148 | 630 | portmap = (address, endpoint, int(ext_port), int(int_port)) | 663 | portmap = (address, endpoint, int(ext_port), int(int_port)) |
1149 | 631 | ctxt['endpoints'].append(portmap) | 664 | ctxt['endpoints'].append(portmap) |
1150 | 632 | ctxt['ext_ports'].append(int(ext_port)) | 665 | ctxt['ext_ports'].append(int(ext_port)) |
1152 | 633 | ctxt['ext_ports'] = list(set(ctxt['ext_ports'])) | 666 | |
1153 | 667 | ctxt['ext_ports'] = sorted(list(set(ctxt['ext_ports']))) | ||
1154 | 634 | return ctxt | 668 | return ctxt |
1155 | 635 | 669 | ||
1156 | 636 | 670 | ||
1157 | @@ -647,21 +681,23 @@ | |||
1158 | 647 | 681 | ||
1159 | 648 | @property | 682 | @property |
1160 | 649 | def packages(self): | 683 | def packages(self): |
1163 | 650 | return neutron_plugin_attribute( | 684 | return neutron_plugin_attribute(self.plugin, 'packages', |
1164 | 651 | self.plugin, 'packages', self.network_manager) | 685 | self.network_manager) |
1165 | 652 | 686 | ||
1166 | 653 | @property | 687 | @property |
1167 | 654 | def neutron_security_groups(self): | 688 | def neutron_security_groups(self): |
1168 | 655 | return None | 689 | return None |
1169 | 656 | 690 | ||
1170 | 657 | def _ensure_packages(self): | 691 | def _ensure_packages(self): |
1172 | 658 | [ensure_packages(pkgs) for pkgs in self.packages] | 692 | for pkgs in self.packages: |
1173 | 693 | ensure_packages(pkgs) | ||
1174 | 659 | 694 | ||
1175 | 660 | def _save_flag_file(self): | 695 | def _save_flag_file(self): |
1176 | 661 | if self.network_manager == 'quantum': | 696 | if self.network_manager == 'quantum': |
1177 | 662 | _file = '/etc/nova/quantum_plugin.conf' | 697 | _file = '/etc/nova/quantum_plugin.conf' |
1178 | 663 | else: | 698 | else: |
1179 | 664 | _file = '/etc/nova/neutron_plugin.conf' | 699 | _file = '/etc/nova/neutron_plugin.conf' |
1180 | 700 | |||
1181 | 665 | with open(_file, 'wb') as out: | 701 | with open(_file, 'wb') as out: |
1182 | 666 | out.write(self.plugin + '\n') | 702 | out.write(self.plugin + '\n') |
1183 | 667 | 703 | ||
1184 | @@ -670,13 +706,11 @@ | |||
1185 | 670 | self.network_manager) | 706 | self.network_manager) |
1186 | 671 | config = neutron_plugin_attribute(self.plugin, 'config', | 707 | config = neutron_plugin_attribute(self.plugin, 'config', |
1187 | 672 | self.network_manager) | 708 | self.network_manager) |
1195 | 673 | ovs_ctxt = { | 709 | ovs_ctxt = {'core_plugin': driver, |
1196 | 674 | 'core_plugin': driver, | 710 | 'neutron_plugin': 'ovs', |
1197 | 675 | 'neutron_plugin': 'ovs', | 711 | 'neutron_security_groups': self.neutron_security_groups, |
1198 | 676 | 'neutron_security_groups': self.neutron_security_groups, | 712 | 'local_ip': unit_private_ip(), |
1199 | 677 | 'local_ip': unit_private_ip(), | 713 | 'config': config} |
1193 | 678 | 'config': config | ||
1194 | 679 | } | ||
1200 | 680 | 714 | ||
1201 | 681 | return ovs_ctxt | 715 | return ovs_ctxt |
1202 | 682 | 716 | ||
1203 | @@ -685,13 +719,11 @@ | |||
1204 | 685 | self.network_manager) | 719 | self.network_manager) |
1205 | 686 | config = neutron_plugin_attribute(self.plugin, 'config', | 720 | config = neutron_plugin_attribute(self.plugin, 'config', |
1206 | 687 | self.network_manager) | 721 | self.network_manager) |
1214 | 688 | nvp_ctxt = { | 722 | nvp_ctxt = {'core_plugin': driver, |
1215 | 689 | 'core_plugin': driver, | 723 | 'neutron_plugin': 'nvp', |
1216 | 690 | 'neutron_plugin': 'nvp', | 724 | 'neutron_security_groups': self.neutron_security_groups, |
1217 | 691 | 'neutron_security_groups': self.neutron_security_groups, | 725 | 'local_ip': unit_private_ip(), |
1218 | 692 | 'local_ip': unit_private_ip(), | 726 | 'config': config} |
1212 | 693 | 'config': config | ||
1213 | 694 | } | ||
1219 | 695 | 727 | ||
1220 | 696 | return nvp_ctxt | 728 | return nvp_ctxt |
1221 | 697 | 729 | ||
1222 | @@ -700,35 +732,50 @@ | |||
1223 | 700 | self.network_manager) | 732 | self.network_manager) |
1224 | 701 | n1kv_config = neutron_plugin_attribute(self.plugin, 'config', | 733 | n1kv_config = neutron_plugin_attribute(self.plugin, 'config', |
1225 | 702 | self.network_manager) | 734 | self.network_manager) |
1238 | 703 | n1kv_ctxt = { | 735 | n1kv_user_config_flags = config('n1kv-config-flags') |
1239 | 704 | 'core_plugin': driver, | 736 | restrict_policy_profiles = config('n1kv-restrict-policy-profiles') |
1240 | 705 | 'neutron_plugin': 'n1kv', | 737 | n1kv_ctxt = {'core_plugin': driver, |
1241 | 706 | 'neutron_security_groups': self.neutron_security_groups, | 738 | 'neutron_plugin': 'n1kv', |
1242 | 707 | 'local_ip': unit_private_ip(), | 739 | 'neutron_security_groups': self.neutron_security_groups, |
1243 | 708 | 'config': n1kv_config, | 740 | 'local_ip': unit_private_ip(), |
1244 | 709 | 'vsm_ip': config('n1kv-vsm-ip'), | 741 | 'config': n1kv_config, |
1245 | 710 | 'vsm_username': config('n1kv-vsm-username'), | 742 | 'vsm_ip': config('n1kv-vsm-ip'), |
1246 | 711 | 'vsm_password': config('n1kv-vsm-password'), | 743 | 'vsm_username': config('n1kv-vsm-username'), |
1247 | 712 | 'restrict_policy_profiles': config( | 744 | 'vsm_password': config('n1kv-vsm-password'), |
1248 | 713 | 'n1kv_restrict_policy_profiles'), | 745 | 'restrict_policy_profiles': restrict_policy_profiles} |
1249 | 714 | } | 746 | |
1250 | 747 | if n1kv_user_config_flags: | ||
1251 | 748 | flags = config_flags_parser(n1kv_user_config_flags) | ||
1252 | 749 | n1kv_ctxt['user_config_flags'] = flags | ||
1253 | 715 | 750 | ||
1254 | 716 | return n1kv_ctxt | 751 | return n1kv_ctxt |
1255 | 717 | 752 | ||
1256 | 753 | def calico_ctxt(self): | ||
1257 | 754 | driver = neutron_plugin_attribute(self.plugin, 'driver', | ||
1258 | 755 | self.network_manager) | ||
1259 | 756 | config = neutron_plugin_attribute(self.plugin, 'config', | ||
1260 | 757 | self.network_manager) | ||
1261 | 758 | calico_ctxt = {'core_plugin': driver, | ||
1262 | 759 | 'neutron_plugin': 'Calico', | ||
1263 | 760 | 'neutron_security_groups': self.neutron_security_groups, | ||
1264 | 761 | 'local_ip': unit_private_ip(), | ||
1265 | 762 | 'config': config} | ||
1266 | 763 | |||
1267 | 764 | return calico_ctxt | ||
1268 | 765 | |||
1269 | 718 | def neutron_ctxt(self): | 766 | def neutron_ctxt(self): |
1270 | 719 | if https(): | 767 | if https(): |
1271 | 720 | proto = 'https' | 768 | proto = 'https' |
1272 | 721 | else: | 769 | else: |
1273 | 722 | proto = 'http' | 770 | proto = 'http' |
1274 | 771 | |||
1275 | 723 | if is_clustered(): | 772 | if is_clustered(): |
1276 | 724 | host = config('vip') | 773 | host = config('vip') |
1277 | 725 | else: | 774 | else: |
1278 | 726 | host = unit_get('private-address') | 775 | host = unit_get('private-address') |
1284 | 727 | url = '%s://%s:%s' % (proto, host, '9696') | 776 | |
1285 | 728 | ctxt = { | 777 | ctxt = {'network_manager': self.network_manager, |
1286 | 729 | 'network_manager': self.network_manager, | 778 | 'neutron_url': '%s://%s:%s' % (proto, host, '9696')} |
1282 | 730 | 'neutron_url': url, | ||
1283 | 731 | } | ||
1287 | 732 | return ctxt | 779 | return ctxt |
1288 | 733 | 780 | ||
1289 | 734 | def __call__(self): | 781 | def __call__(self): |
1290 | @@ -748,6 +795,8 @@ | |||
1291 | 748 | ctxt.update(self.nvp_ctxt()) | 795 | ctxt.update(self.nvp_ctxt()) |
1292 | 749 | elif self.plugin == 'n1kv': | 796 | elif self.plugin == 'n1kv': |
1293 | 750 | ctxt.update(self.n1kv_ctxt()) | 797 | ctxt.update(self.n1kv_ctxt()) |
1294 | 798 | elif self.plugin == 'Calico': | ||
1295 | 799 | ctxt.update(self.calico_ctxt()) | ||
1296 | 751 | 800 | ||
1297 | 752 | alchemy_flags = config('neutron-alchemy-flags') | 801 | alchemy_flags = config('neutron-alchemy-flags') |
1298 | 753 | if alchemy_flags: | 802 | if alchemy_flags: |
1299 | @@ -759,23 +808,40 @@ | |||
1300 | 759 | 808 | ||
1301 | 760 | 809 | ||
1302 | 761 | class OSConfigFlagContext(OSContextGenerator): | 810 | class OSConfigFlagContext(OSContextGenerator): |
1307 | 762 | 811 | """Provides support for user-defined config flags. | |
1308 | 763 | """ | 812 | |
1309 | 764 | Responsible for adding user-defined config-flags in charm config to a | 813 | Users can define a comma-seperated list of key=value pairs |
1310 | 765 | template context. | 814 | in the charm configuration and apply them at any point in |
1311 | 815 | any file by using a template flag. | ||
1312 | 816 | |||
1313 | 817 | Sometimes users might want config flags inserted within a | ||
1314 | 818 | specific section so this class allows users to specify the | ||
1315 | 819 | template flag name, allowing for multiple template flags | ||
1316 | 820 | (sections) within the same context. | ||
1317 | 766 | 821 | ||
1318 | 767 | NOTE: the value of config-flags may be a comma-separated list of | 822 | NOTE: the value of config-flags may be a comma-separated list of |
1319 | 768 | key=value pairs and some Openstack config files support | 823 | key=value pairs and some Openstack config files support |
1320 | 769 | comma-separated lists as values. | 824 | comma-separated lists as values. |
1321 | 770 | """ | 825 | """ |
1322 | 771 | 826 | ||
1323 | 827 | def __init__(self, charm_flag='config-flags', | ||
1324 | 828 | template_flag='user_config_flags'): | ||
1325 | 829 | """ | ||
1326 | 830 | :param charm_flag: config flags in charm configuration. | ||
1327 | 831 | :param template_flag: insert point for user-defined flags in template | ||
1328 | 832 | file. | ||
1329 | 833 | """ | ||
1330 | 834 | super(OSConfigFlagContext, self).__init__() | ||
1331 | 835 | self._charm_flag = charm_flag | ||
1332 | 836 | self._template_flag = template_flag | ||
1333 | 837 | |||
1334 | 772 | def __call__(self): | 838 | def __call__(self): |
1336 | 773 | config_flags = config('config-flags') | 839 | config_flags = config(self._charm_flag) |
1337 | 774 | if not config_flags: | 840 | if not config_flags: |
1338 | 775 | return {} | 841 | return {} |
1339 | 776 | 842 | ||
1342 | 777 | flags = config_flags_parser(config_flags) | 843 | return {self._template_flag: |
1343 | 778 | return {'user_config_flags': flags} | 844 | config_flags_parser(config_flags)} |
1344 | 779 | 845 | ||
1345 | 780 | 846 | ||
1346 | 781 | class SubordinateConfigContext(OSContextGenerator): | 847 | class SubordinateConfigContext(OSContextGenerator): |
1347 | @@ -819,7 +885,6 @@ | |||
1348 | 819 | }, | 885 | }, |
1349 | 820 | } | 886 | } |
1350 | 821 | } | 887 | } |
1351 | 822 | |||
1352 | 823 | """ | 888 | """ |
1353 | 824 | 889 | ||
1354 | 825 | def __init__(self, service, config_file, interface): | 890 | def __init__(self, service, config_file, interface): |
1355 | @@ -849,26 +914,28 @@ | |||
1356 | 849 | 914 | ||
1357 | 850 | if self.service not in sub_config: | 915 | if self.service not in sub_config: |
1358 | 851 | log('Found subordinate_config on %s but it contained' | 916 | log('Found subordinate_config on %s but it contained' |
1360 | 852 | 'nothing for %s service' % (rid, self.service)) | 917 | 'nothing for %s service' % (rid, self.service), |
1361 | 918 | level=INFO) | ||
1362 | 853 | continue | 919 | continue |
1363 | 854 | 920 | ||
1364 | 855 | sub_config = sub_config[self.service] | 921 | sub_config = sub_config[self.service] |
1365 | 856 | if self.config_file not in sub_config: | 922 | if self.config_file not in sub_config: |
1366 | 857 | log('Found subordinate_config on %s but it contained' | 923 | log('Found subordinate_config on %s but it contained' |
1368 | 858 | 'nothing for %s' % (rid, self.config_file)) | 924 | 'nothing for %s' % (rid, self.config_file), |
1369 | 925 | level=INFO) | ||
1370 | 859 | continue | 926 | continue |
1371 | 860 | 927 | ||
1372 | 861 | sub_config = sub_config[self.config_file] | 928 | sub_config = sub_config[self.config_file] |
1374 | 862 | for k, v in sub_config.iteritems(): | 929 | for k, v in six.iteritems(sub_config): |
1375 | 863 | if k == 'sections': | 930 | if k == 'sections': |
1378 | 864 | for section, config_dict in v.iteritems(): | 931 | for section, config_dict in six.iteritems(v): |
1379 | 865 | log("adding section '%s'" % (section)) | 932 | log("adding section '%s'" % (section), |
1380 | 933 | level=DEBUG) | ||
1381 | 866 | ctxt[k][section] = config_dict | 934 | ctxt[k][section] = config_dict |
1382 | 867 | else: | 935 | else: |
1383 | 868 | ctxt[k] = v | 936 | ctxt[k] = v |
1384 | 869 | 937 | ||
1387 | 870 | log("%d section(s) found" % (len(ctxt['sections'])), level=INFO) | 938 | log("%d section(s) found" % (len(ctxt['sections'])), level=DEBUG) |
1386 | 871 | |||
1388 | 872 | return ctxt | 939 | return ctxt |
1389 | 873 | 940 | ||
1390 | 874 | 941 | ||
1391 | @@ -880,15 +947,14 @@ | |||
1392 | 880 | False if config('debug') is None else config('debug') | 947 | False if config('debug') is None else config('debug') |
1393 | 881 | ctxt['verbose'] = \ | 948 | ctxt['verbose'] = \ |
1394 | 882 | False if config('verbose') is None else config('verbose') | 949 | False if config('verbose') is None else config('verbose') |
1395 | 950 | |||
1396 | 883 | return ctxt | 951 | return ctxt |
1397 | 884 | 952 | ||
1398 | 885 | 953 | ||
1399 | 886 | class SyslogContext(OSContextGenerator): | 954 | class SyslogContext(OSContextGenerator): |
1400 | 887 | 955 | ||
1401 | 888 | def __call__(self): | 956 | def __call__(self): |
1405 | 889 | ctxt = { | 957 | ctxt = {'use_syslog': config('use-syslog')} |
1403 | 890 | 'use_syslog': config('use-syslog') | ||
1404 | 891 | } | ||
1406 | 892 | return ctxt | 958 | return ctxt |
1407 | 893 | 959 | ||
1408 | 894 | 960 | ||
1409 | @@ -896,13 +962,9 @@ | |||
1410 | 896 | 962 | ||
1411 | 897 | def __call__(self): | 963 | def __call__(self): |
1412 | 898 | if config('prefer-ipv6'): | 964 | if config('prefer-ipv6'): |
1416 | 899 | return { | 965 | return {'bind_host': '::'} |
1414 | 900 | 'bind_host': '::' | ||
1415 | 901 | } | ||
1417 | 902 | else: | 966 | else: |
1421 | 903 | return { | 967 | return {'bind_host': '0.0.0.0'} |
1419 | 904 | 'bind_host': '0.0.0.0' | ||
1420 | 905 | } | ||
1422 | 906 | 968 | ||
1423 | 907 | 969 | ||
1424 | 908 | class WorkerConfigContext(OSContextGenerator): | 970 | class WorkerConfigContext(OSContextGenerator): |
1425 | @@ -914,11 +976,42 @@ | |||
1426 | 914 | except ImportError: | 976 | except ImportError: |
1427 | 915 | apt_install('python-psutil', fatal=True) | 977 | apt_install('python-psutil', fatal=True) |
1428 | 916 | from psutil import NUM_CPUS | 978 | from psutil import NUM_CPUS |
1429 | 979 | |||
1430 | 917 | return NUM_CPUS | 980 | return NUM_CPUS |
1431 | 918 | 981 | ||
1432 | 919 | def __call__(self): | 982 | def __call__(self): |
1437 | 920 | multiplier = config('worker-multiplier') or 1 | 983 | multiplier = config('worker-multiplier') or 0 |
1438 | 921 | ctxt = { | 984 | ctxt = {"workers": self.num_cpus * multiplier} |
1439 | 922 | "workers": self.num_cpus * multiplier | 985 | return ctxt |
1440 | 923 | } | 986 | |
1441 | 987 | |||
1442 | 988 | class ZeroMQContext(OSContextGenerator): | ||
1443 | 989 | interfaces = ['zeromq-configuration'] | ||
1444 | 990 | |||
1445 | 991 | def __call__(self): | ||
1446 | 992 | ctxt = {} | ||
1447 | 993 | if is_relation_made('zeromq-configuration', 'host'): | ||
1448 | 994 | for rid in relation_ids('zeromq-configuration'): | ||
1449 | 995 | for unit in related_units(rid): | ||
1450 | 996 | ctxt['zmq_nonce'] = relation_get('nonce', unit, rid) | ||
1451 | 997 | ctxt['zmq_host'] = relation_get('host', unit, rid) | ||
1452 | 998 | |||
1453 | 999 | return ctxt | ||
1454 | 1000 | |||
1455 | 1001 | |||
1456 | 1002 | class NotificationDriverContext(OSContextGenerator): | ||
1457 | 1003 | |||
1458 | 1004 | def __init__(self, zmq_relation='zeromq-configuration', | ||
1459 | 1005 | amqp_relation='amqp'): | ||
1460 | 1006 | """ | ||
1461 | 1007 | :param zmq_relation: Name of Zeromq relation to check | ||
1462 | 1008 | """ | ||
1463 | 1009 | self.zmq_relation = zmq_relation | ||
1464 | 1010 | self.amqp_relation = amqp_relation | ||
1465 | 1011 | |||
1466 | 1012 | def __call__(self): | ||
1467 | 1013 | ctxt = {'notifications': 'False'} | ||
1468 | 1014 | if is_relation_made(self.amqp_relation): | ||
1469 | 1015 | ctxt['notifications'] = "True" | ||
1470 | 1016 | |||
1471 | 924 | return ctxt | 1017 | return ctxt |
1472 | 925 | 1018 | ||
1473 | === modified file 'hooks/charmhelpers/contrib/openstack/ip.py' | |||
1474 | --- hooks/charmhelpers/contrib/openstack/ip.py 2014-10-02 09:18:00 +0000 | |||
1475 | +++ hooks/charmhelpers/contrib/openstack/ip.py 2014-12-11 17:56:40 +0000 | |||
1476 | @@ -2,21 +2,19 @@ | |||
1477 | 2 | config, | 2 | config, |
1478 | 3 | unit_get, | 3 | unit_get, |
1479 | 4 | ) | 4 | ) |
1480 | 5 | |||
1481 | 6 | from charmhelpers.contrib.network.ip import ( | 5 | from charmhelpers.contrib.network.ip import ( |
1482 | 7 | get_address_in_network, | 6 | get_address_in_network, |
1483 | 8 | is_address_in_network, | 7 | is_address_in_network, |
1484 | 9 | is_ipv6, | 8 | is_ipv6, |
1485 | 10 | get_ipv6_addr, | 9 | get_ipv6_addr, |
1486 | 11 | ) | 10 | ) |
1487 | 12 | |||
1488 | 13 | from charmhelpers.contrib.hahelpers.cluster import is_clustered | 11 | from charmhelpers.contrib.hahelpers.cluster import is_clustered |
1489 | 14 | 12 | ||
1490 | 15 | PUBLIC = 'public' | 13 | PUBLIC = 'public' |
1491 | 16 | INTERNAL = 'int' | 14 | INTERNAL = 'int' |
1492 | 17 | ADMIN = 'admin' | 15 | ADMIN = 'admin' |
1493 | 18 | 16 | ||
1495 | 19 | _address_map = { | 17 | ADDRESS_MAP = { |
1496 | 20 | PUBLIC: { | 18 | PUBLIC: { |
1497 | 21 | 'config': 'os-public-network', | 19 | 'config': 'os-public-network', |
1498 | 22 | 'fallback': 'public-address' | 20 | 'fallback': 'public-address' |
1499 | @@ -33,16 +31,14 @@ | |||
1500 | 33 | 31 | ||
1501 | 34 | 32 | ||
1502 | 35 | def canonical_url(configs, endpoint_type=PUBLIC): | 33 | def canonical_url(configs, endpoint_type=PUBLIC): |
1505 | 36 | ''' | 34 | """Returns the correct HTTP URL to this host given the state of HTTPS |
1504 | 37 | Returns the correct HTTP URL to this host given the state of HTTPS | ||
1506 | 38 | configuration, hacluster and charm configuration. | 35 | configuration, hacluster and charm configuration. |
1507 | 39 | 36 | ||
1514 | 40 | :configs OSTemplateRenderer: A config tempating object to inspect for | 37 | :param configs: OSTemplateRenderer config templating object to inspect |
1515 | 41 | a complete https context. | 38 | for a complete https context. |
1516 | 42 | :endpoint_type str: The endpoint type to resolve. | 39 | :param endpoint_type: str endpoint type to resolve. |
1517 | 43 | 40 | :param returns: str base URL for services on the current service unit. | |
1518 | 44 | :returns str: Base URL for services on the current service unit. | 41 | """ |
1513 | 45 | ''' | ||
1519 | 46 | scheme = 'http' | 42 | scheme = 'http' |
1520 | 47 | if 'https' in configs.complete_contexts(): | 43 | if 'https' in configs.complete_contexts(): |
1521 | 48 | scheme = 'https' | 44 | scheme = 'https' |
1522 | @@ -53,27 +49,45 @@ | |||
1523 | 53 | 49 | ||
1524 | 54 | 50 | ||
1525 | 55 | def resolve_address(endpoint_type=PUBLIC): | 51 | def resolve_address(endpoint_type=PUBLIC): |
1526 | 52 | """Return unit address depending on net config. | ||
1527 | 53 | |||
1528 | 54 | If unit is clustered with vip(s) and has net splits defined, return vip on | ||
1529 | 55 | correct network. If clustered with no nets defined, return primary vip. | ||
1530 | 56 | |||
1531 | 57 | If not clustered, return unit address ensuring address is on configured net | ||
1532 | 58 | split if one is configured. | ||
1533 | 59 | |||
1534 | 60 | :param endpoint_type: Network endpoing type | ||
1535 | 61 | """ | ||
1536 | 56 | resolved_address = None | 62 | resolved_address = None |
1541 | 57 | if is_clustered(): | 63 | vips = config('vip') |
1542 | 58 | if config(_address_map[endpoint_type]['config']) is None: | 64 | if vips: |
1543 | 59 | # Assume vip is simple and pass back directly | 65 | vips = vips.split() |
1544 | 60 | resolved_address = config('vip') | 66 | |
1545 | 67 | net_type = ADDRESS_MAP[endpoint_type]['config'] | ||
1546 | 68 | net_addr = config(net_type) | ||
1547 | 69 | net_fallback = ADDRESS_MAP[endpoint_type]['fallback'] | ||
1548 | 70 | clustered = is_clustered() | ||
1549 | 71 | if clustered: | ||
1550 | 72 | if not net_addr: | ||
1551 | 73 | # If no net-splits defined, we expect a single vip | ||
1552 | 74 | resolved_address = vips[0] | ||
1553 | 61 | else: | 75 | else: |
1558 | 62 | for vip in config('vip').split(): | 76 | for vip in vips: |
1559 | 63 | if is_address_in_network( | 77 | if is_address_in_network(net_addr, vip): |
1556 | 64 | config(_address_map[endpoint_type]['config']), | ||
1557 | 65 | vip): | ||
1560 | 66 | resolved_address = vip | 78 | resolved_address = vip |
1561 | 79 | break | ||
1562 | 67 | else: | 80 | else: |
1563 | 68 | if config('prefer-ipv6'): | 81 | if config('prefer-ipv6'): |
1565 | 69 | fallback_addr = get_ipv6_addr(exc_list=[config('vip')])[0] | 82 | fallback_addr = get_ipv6_addr(exc_list=vips)[0] |
1566 | 70 | else: | 83 | else: |
1570 | 71 | fallback_addr = unit_get(_address_map[endpoint_type]['fallback']) | 84 | fallback_addr = unit_get(net_fallback) |
1571 | 72 | resolved_address = get_address_in_network( | 85 | |
1572 | 73 | config(_address_map[endpoint_type]['config']), fallback_addr) | 86 | resolved_address = get_address_in_network(net_addr, fallback_addr) |
1573 | 74 | 87 | ||
1574 | 75 | if resolved_address is None: | 88 | if resolved_address is None: |
1579 | 76 | raise ValueError('Unable to resolve a suitable IP address' | 89 | raise ValueError("Unable to resolve a suitable IP address based on " |
1580 | 77 | ' based on charm state and configuration') | 90 | "charm state and configuration. (net_type=%s, " |
1581 | 78 | else: | 91 | "clustered=%s)" % (net_type, clustered)) |
1582 | 79 | return resolved_address | 92 | |
1583 | 93 | return resolved_address | ||
1584 | 80 | 94 | ||
1585 | === modified file 'hooks/charmhelpers/contrib/openstack/neutron.py' | |||
1586 | --- hooks/charmhelpers/contrib/openstack/neutron.py 2014-06-24 11:05:17 +0000 | |||
1587 | +++ hooks/charmhelpers/contrib/openstack/neutron.py 2014-12-11 17:56:40 +0000 | |||
1588 | @@ -14,7 +14,7 @@ | |||
1589 | 14 | def headers_package(): | 14 | def headers_package(): |
1590 | 15 | """Ensures correct linux-headers for running kernel are installed, | 15 | """Ensures correct linux-headers for running kernel are installed, |
1591 | 16 | for building DKMS package""" | 16 | for building DKMS package""" |
1593 | 17 | kver = check_output(['uname', '-r']).strip() | 17 | kver = check_output(['uname', '-r']).decode('UTF-8').strip() |
1594 | 18 | return 'linux-headers-%s' % kver | 18 | return 'linux-headers-%s' % kver |
1595 | 19 | 19 | ||
1596 | 20 | QUANTUM_CONF_DIR = '/etc/quantum' | 20 | QUANTUM_CONF_DIR = '/etc/quantum' |
1597 | @@ -22,7 +22,7 @@ | |||
1598 | 22 | 22 | ||
1599 | 23 | def kernel_version(): | 23 | def kernel_version(): |
1600 | 24 | """ Retrieve the current major kernel version as a tuple e.g. (3, 13) """ | 24 | """ Retrieve the current major kernel version as a tuple e.g. (3, 13) """ |
1602 | 25 | kver = check_output(['uname', '-r']).strip() | 25 | kver = check_output(['uname', '-r']).decode('UTF-8').strip() |
1603 | 26 | kver = kver.split('.') | 26 | kver = kver.split('.') |
1604 | 27 | return (int(kver[0]), int(kver[1])) | 27 | return (int(kver[0]), int(kver[1])) |
1605 | 28 | 28 | ||
1606 | @@ -138,10 +138,25 @@ | |||
1607 | 138 | relation_prefix='neutron', | 138 | relation_prefix='neutron', |
1608 | 139 | ssl_dir=NEUTRON_CONF_DIR)], | 139 | ssl_dir=NEUTRON_CONF_DIR)], |
1609 | 140 | 'services': [], | 140 | 'services': [], |
1611 | 141 | 'packages': [['neutron-plugin-cisco']], | 141 | 'packages': [[headers_package()] + determine_dkms_package(), |
1612 | 142 | ['neutron-plugin-cisco']], | ||
1613 | 142 | 'server_packages': ['neutron-server', | 143 | 'server_packages': ['neutron-server', |
1614 | 143 | 'neutron-plugin-cisco'], | 144 | 'neutron-plugin-cisco'], |
1615 | 144 | 'server_services': ['neutron-server'] | 145 | 'server_services': ['neutron-server'] |
1616 | 146 | }, | ||
1617 | 147 | 'Calico': { | ||
1618 | 148 | 'config': '/etc/neutron/plugins/ml2/ml2_conf.ini', | ||
1619 | 149 | 'driver': 'neutron.plugins.ml2.plugin.Ml2Plugin', | ||
1620 | 150 | 'contexts': [ | ||
1621 | 151 | context.SharedDBContext(user=config('neutron-database-user'), | ||
1622 | 152 | database=config('neutron-database'), | ||
1623 | 153 | relation_prefix='neutron', | ||
1624 | 154 | ssl_dir=NEUTRON_CONF_DIR)], | ||
1625 | 155 | 'services': ['calico-compute', 'bird', 'neutron-dhcp-agent'], | ||
1626 | 156 | 'packages': [[headers_package()] + determine_dkms_package(), | ||
1627 | 157 | ['calico-compute', 'bird', 'neutron-dhcp-agent']], | ||
1628 | 158 | 'server_packages': ['neutron-server', 'calico-control'], | ||
1629 | 159 | 'server_services': ['neutron-server'] | ||
1630 | 145 | } | 160 | } |
1631 | 146 | } | 161 | } |
1632 | 147 | if release >= 'icehouse': | 162 | if release >= 'icehouse': |
1633 | @@ -162,7 +177,8 @@ | |||
1634 | 162 | elif manager == 'neutron': | 177 | elif manager == 'neutron': |
1635 | 163 | plugins = neutron_plugins() | 178 | plugins = neutron_plugins() |
1636 | 164 | else: | 179 | else: |
1638 | 165 | log('Error: Network manager does not support plugins.') | 180 | log("Network manager '%s' does not support plugins." % (manager), |
1639 | 181 | level=ERROR) | ||
1640 | 166 | raise Exception | 182 | raise Exception |
1641 | 167 | 183 | ||
1642 | 168 | try: | 184 | try: |
1643 | 169 | 185 | ||
1644 | === modified file 'hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg' | |||
1645 | --- hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2014-10-02 09:18:00 +0000 | |||
1646 | +++ hooks/charmhelpers/contrib/openstack/templates/haproxy.cfg 2014-12-11 17:56:40 +0000 | |||
1647 | @@ -35,7 +35,7 @@ | |||
1648 | 35 | stats auth admin:password | 35 | stats auth admin:password |
1649 | 36 | 36 | ||
1650 | 37 | {% if frontends -%} | 37 | {% if frontends -%} |
1652 | 38 | {% for service, ports in service_ports.iteritems() -%} | 38 | {% for service, ports in service_ports.items() -%} |
1653 | 39 | frontend tcp-in_{{ service }} | 39 | frontend tcp-in_{{ service }} |
1654 | 40 | bind *:{{ ports[0] }} | 40 | bind *:{{ ports[0] }} |
1655 | 41 | bind :::{{ ports[0] }} | 41 | bind :::{{ ports[0] }} |
1656 | @@ -46,7 +46,7 @@ | |||
1657 | 46 | {% for frontend in frontends -%} | 46 | {% for frontend in frontends -%} |
1658 | 47 | backend {{ service }}_{{ frontend }} | 47 | backend {{ service }}_{{ frontend }} |
1659 | 48 | balance leastconn | 48 | balance leastconn |
1661 | 49 | {% for unit, address in frontends[frontend]['backends'].iteritems() -%} | 49 | {% for unit, address in frontends[frontend]['backends'].items() -%} |
1662 | 50 | server {{ unit }} {{ address }}:{{ ports[1] }} check | 50 | server {{ unit }} {{ address }}:{{ ports[1] }} check |
1663 | 51 | {% endfor %} | 51 | {% endfor %} |
1664 | 52 | {% endfor -%} | 52 | {% endfor -%} |
1665 | 53 | 53 | ||
1666 | === modified file 'hooks/charmhelpers/contrib/openstack/templating.py' | |||
1667 | --- hooks/charmhelpers/contrib/openstack/templating.py 2014-06-27 11:55:45 +0000 | |||
1668 | +++ hooks/charmhelpers/contrib/openstack/templating.py 2014-12-11 17:56:40 +0000 | |||
1669 | @@ -1,13 +1,13 @@ | |||
1670 | 1 | import os | 1 | import os |
1671 | 2 | 2 | ||
1672 | 3 | import six | ||
1673 | 4 | |||
1674 | 3 | from charmhelpers.fetch import apt_install | 5 | from charmhelpers.fetch import apt_install |
1675 | 4 | |||
1676 | 5 | from charmhelpers.core.hookenv import ( | 6 | from charmhelpers.core.hookenv import ( |
1677 | 6 | log, | 7 | log, |
1678 | 7 | ERROR, | 8 | ERROR, |
1679 | 8 | INFO | 9 | INFO |
1680 | 9 | ) | 10 | ) |
1681 | 10 | |||
1682 | 11 | from charmhelpers.contrib.openstack.utils import OPENSTACK_CODENAMES | 11 | from charmhelpers.contrib.openstack.utils import OPENSTACK_CODENAMES |
1683 | 12 | 12 | ||
1684 | 13 | try: | 13 | try: |
1685 | @@ -43,7 +43,7 @@ | |||
1686 | 43 | order by OpenStack release. | 43 | order by OpenStack release. |
1687 | 44 | """ | 44 | """ |
1688 | 45 | tmpl_dirs = [(rel, os.path.join(templates_dir, rel)) | 45 | tmpl_dirs = [(rel, os.path.join(templates_dir, rel)) |
1690 | 46 | for rel in OPENSTACK_CODENAMES.itervalues()] | 46 | for rel in six.itervalues(OPENSTACK_CODENAMES)] |
1691 | 47 | 47 | ||
1692 | 48 | if not os.path.isdir(templates_dir): | 48 | if not os.path.isdir(templates_dir): |
1693 | 49 | log('Templates directory not found @ %s.' % templates_dir, | 49 | log('Templates directory not found @ %s.' % templates_dir, |
1694 | @@ -258,7 +258,7 @@ | |||
1695 | 258 | """ | 258 | """ |
1696 | 259 | Write out all registered config files. | 259 | Write out all registered config files. |
1697 | 260 | """ | 260 | """ |
1699 | 261 | [self.write(k) for k in self.templates.iterkeys()] | 261 | [self.write(k) for k in six.iterkeys(self.templates)] |
1700 | 262 | 262 | ||
1701 | 263 | def set_release(self, openstack_release): | 263 | def set_release(self, openstack_release): |
1702 | 264 | """ | 264 | """ |
1703 | @@ -275,5 +275,5 @@ | |||
1704 | 275 | ''' | 275 | ''' |
1705 | 276 | interfaces = [] | 276 | interfaces = [] |
1706 | 277 | [interfaces.extend(i.complete_contexts()) | 277 | [interfaces.extend(i.complete_contexts()) |
1708 | 278 | for i in self.templates.itervalues()] | 278 | for i in six.itervalues(self.templates)] |
1709 | 279 | return interfaces | 279 | return interfaces |
1710 | 280 | 280 | ||
1711 | === modified file 'hooks/charmhelpers/contrib/openstack/utils.py' | |||
1712 | --- hooks/charmhelpers/contrib/openstack/utils.py 2014-10-06 21:21:47 +0000 | |||
1713 | +++ hooks/charmhelpers/contrib/openstack/utils.py 2014-12-11 17:56:40 +0000 | |||
1714 | @@ -2,6 +2,7 @@ | |||
1715 | 2 | 2 | ||
1716 | 3 | # Common python helper functions used for OpenStack charms. | 3 | # Common python helper functions used for OpenStack charms. |
1717 | 4 | from collections import OrderedDict | 4 | from collections import OrderedDict |
1718 | 5 | from functools import wraps | ||
1719 | 5 | 6 | ||
1720 | 6 | import subprocess | 7 | import subprocess |
1721 | 7 | import json | 8 | import json |
1722 | @@ -9,11 +10,13 @@ | |||
1723 | 9 | import socket | 10 | import socket |
1724 | 10 | import sys | 11 | import sys |
1725 | 11 | 12 | ||
1726 | 13 | import six | ||
1727 | 14 | import yaml | ||
1728 | 15 | |||
1729 | 12 | from charmhelpers.core.hookenv import ( | 16 | from charmhelpers.core.hookenv import ( |
1730 | 13 | config, | 17 | config, |
1731 | 14 | log as juju_log, | 18 | log as juju_log, |
1732 | 15 | charm_dir, | 19 | charm_dir, |
1733 | 16 | ERROR, | ||
1734 | 17 | INFO, | 20 | INFO, |
1735 | 18 | relation_ids, | 21 | relation_ids, |
1736 | 19 | relation_set | 22 | relation_set |
1737 | @@ -30,7 +33,8 @@ | |||
1738 | 30 | ) | 33 | ) |
1739 | 31 | 34 | ||
1740 | 32 | from charmhelpers.core.host import lsb_release, mounts, umount | 35 | from charmhelpers.core.host import lsb_release, mounts, umount |
1742 | 33 | from charmhelpers.fetch import apt_install, apt_cache | 36 | from charmhelpers.fetch import apt_install, apt_cache, install_remote |
1743 | 37 | from charmhelpers.contrib.python.packages import pip_install | ||
1744 | 34 | from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk | 38 | from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk |
1745 | 35 | from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device | 39 | from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device |
1746 | 36 | 40 | ||
1747 | @@ -112,7 +116,7 @@ | |||
1748 | 112 | 116 | ||
1749 | 113 | # Best guess match based on deb string provided | 117 | # Best guess match based on deb string provided |
1750 | 114 | if src.startswith('deb') or src.startswith('ppa'): | 118 | if src.startswith('deb') or src.startswith('ppa'): |
1752 | 115 | for k, v in OPENSTACK_CODENAMES.iteritems(): | 119 | for k, v in six.iteritems(OPENSTACK_CODENAMES): |
1753 | 116 | if v in src: | 120 | if v in src: |
1754 | 117 | return v | 121 | return v |
1755 | 118 | 122 | ||
1756 | @@ -133,7 +137,7 @@ | |||
1757 | 133 | 137 | ||
1758 | 134 | def get_os_version_codename(codename): | 138 | def get_os_version_codename(codename): |
1759 | 135 | '''Determine OpenStack version number from codename.''' | 139 | '''Determine OpenStack version number from codename.''' |
1761 | 136 | for k, v in OPENSTACK_CODENAMES.iteritems(): | 140 | for k, v in six.iteritems(OPENSTACK_CODENAMES): |
1762 | 137 | if v == codename: | 141 | if v == codename: |
1763 | 138 | return k | 142 | return k |
1764 | 139 | e = 'Could not derive OpenStack version for '\ | 143 | e = 'Could not derive OpenStack version for '\ |
1765 | @@ -193,7 +197,7 @@ | |||
1766 | 193 | else: | 197 | else: |
1767 | 194 | vers_map = OPENSTACK_CODENAMES | 198 | vers_map = OPENSTACK_CODENAMES |
1768 | 195 | 199 | ||
1770 | 196 | for version, cname in vers_map.iteritems(): | 200 | for version, cname in six.iteritems(vers_map): |
1771 | 197 | if cname == codename: | 201 | if cname == codename: |
1772 | 198 | return version | 202 | return version |
1773 | 199 | # e = "Could not determine OpenStack version for package: %s" % pkg | 203 | # e = "Could not determine OpenStack version for package: %s" % pkg |
1774 | @@ -317,7 +321,7 @@ | |||
1775 | 317 | rc_script.write( | 321 | rc_script.write( |
1776 | 318 | "#!/bin/bash\n") | 322 | "#!/bin/bash\n") |
1777 | 319 | [rc_script.write('export %s=%s\n' % (u, p)) | 323 | [rc_script.write('export %s=%s\n' % (u, p)) |
1779 | 320 | for u, p in env_vars.iteritems() if u != "script_path"] | 324 | for u, p in six.iteritems(env_vars) if u != "script_path"] |
1780 | 321 | 325 | ||
1781 | 322 | 326 | ||
1782 | 323 | def openstack_upgrade_available(package): | 327 | def openstack_upgrade_available(package): |
1783 | @@ -350,8 +354,8 @@ | |||
1784 | 350 | ''' | 354 | ''' |
1785 | 351 | _none = ['None', 'none', None] | 355 | _none = ['None', 'none', None] |
1786 | 352 | if (block_device in _none): | 356 | if (block_device in _none): |
1789 | 353 | error_out('prepare_storage(): Missing required input: ' | 357 | error_out('prepare_storage(): Missing required input: block_device=%s.' |
1790 | 354 | 'block_device=%s.' % block_device, level=ERROR) | 358 | % block_device) |
1791 | 355 | 359 | ||
1792 | 356 | if block_device.startswith('/dev/'): | 360 | if block_device.startswith('/dev/'): |
1793 | 357 | bdev = block_device | 361 | bdev = block_device |
1794 | @@ -367,8 +371,7 @@ | |||
1795 | 367 | bdev = '/dev/%s' % block_device | 371 | bdev = '/dev/%s' % block_device |
1796 | 368 | 372 | ||
1797 | 369 | if not is_block_device(bdev): | 373 | if not is_block_device(bdev): |
1800 | 370 | error_out('Failed to locate valid block device at %s' % bdev, | 374 | error_out('Failed to locate valid block device at %s' % bdev) |
1799 | 371 | level=ERROR) | ||
1801 | 372 | 375 | ||
1802 | 373 | return bdev | 376 | return bdev |
1803 | 374 | 377 | ||
1804 | @@ -417,7 +420,7 @@ | |||
1805 | 417 | 420 | ||
1806 | 418 | if isinstance(address, dns.name.Name): | 421 | if isinstance(address, dns.name.Name): |
1807 | 419 | rtype = 'PTR' | 422 | rtype = 'PTR' |
1809 | 420 | elif isinstance(address, basestring): | 423 | elif isinstance(address, six.string_types): |
1810 | 421 | rtype = 'A' | 424 | rtype = 'A' |
1811 | 422 | else: | 425 | else: |
1812 | 423 | return None | 426 | return None |
1813 | @@ -468,6 +471,14 @@ | |||
1814 | 468 | return result.split('.')[0] | 471 | return result.split('.')[0] |
1815 | 469 | 472 | ||
1816 | 470 | 473 | ||
1817 | 474 | def get_matchmaker_map(mm_file='/etc/oslo/matchmaker_ring.json'): | ||
1818 | 475 | mm_map = {} | ||
1819 | 476 | if os.path.isfile(mm_file): | ||
1820 | 477 | with open(mm_file, 'r') as f: | ||
1821 | 478 | mm_map = json.load(f) | ||
1822 | 479 | return mm_map | ||
1823 | 480 | |||
1824 | 481 | |||
1825 | 471 | def sync_db_with_multi_ipv6_addresses(database, database_user, | 482 | def sync_db_with_multi_ipv6_addresses(database, database_user, |
1826 | 472 | relation_prefix=None): | 483 | relation_prefix=None): |
1827 | 473 | hosts = get_ipv6_addr(dynamic_only=False) | 484 | hosts = get_ipv6_addr(dynamic_only=False) |
1828 | @@ -477,10 +488,132 @@ | |||
1829 | 477 | 'hostname': json.dumps(hosts)} | 488 | 'hostname': json.dumps(hosts)} |
1830 | 478 | 489 | ||
1831 | 479 | if relation_prefix: | 490 | if relation_prefix: |
1834 | 480 | keys = kwargs.keys() | 491 | for key in list(kwargs.keys()): |
1833 | 481 | for key in keys: | ||
1835 | 482 | kwargs["%s_%s" % (relation_prefix, key)] = kwargs[key] | 492 | kwargs["%s_%s" % (relation_prefix, key)] = kwargs[key] |
1836 | 483 | del kwargs[key] | 493 | del kwargs[key] |
1837 | 484 | 494 | ||
1838 | 485 | for rid in relation_ids('shared-db'): | 495 | for rid in relation_ids('shared-db'): |
1839 | 486 | relation_set(relation_id=rid, **kwargs) | 496 | relation_set(relation_id=rid, **kwargs) |
1840 | 497 | |||
1841 | 498 | |||
1842 | 499 | def os_requires_version(ostack_release, pkg): | ||
1843 | 500 | """ | ||
1844 | 501 | Decorator for hook to specify minimum supported release | ||
1845 | 502 | """ | ||
1846 | 503 | def wrap(f): | ||
1847 | 504 | @wraps(f) | ||
1848 | 505 | def wrapped_f(*args): | ||
1849 | 506 | if os_release(pkg) < ostack_release: | ||
1850 | 507 | raise Exception("This hook is not supported on releases" | ||
1851 | 508 | " before %s" % ostack_release) | ||
1852 | 509 | f(*args) | ||
1853 | 510 | return wrapped_f | ||
1854 | 511 | return wrap | ||
1855 | 512 | |||
1856 | 513 | |||
1857 | 514 | def git_install_requested(): | ||
1858 | 515 | """Returns true if openstack-origin-git is specified.""" | ||
1859 | 516 | return config('openstack-origin-git') != "None" | ||
1860 | 517 | |||
1861 | 518 | |||
1862 | 519 | requirements_dir = None | ||
1863 | 520 | |||
1864 | 521 | |||
1865 | 522 | def git_clone_and_install(file_name, core_project): | ||
1866 | 523 | """Clone/install all OpenStack repos specified in yaml config file.""" | ||
1867 | 524 | global requirements_dir | ||
1868 | 525 | |||
1869 | 526 | if file_name == "None": | ||
1870 | 527 | return | ||
1871 | 528 | |||
1872 | 529 | yaml_file = os.path.join(charm_dir(), file_name) | ||
1873 | 530 | |||
1874 | 531 | # clone/install the requirements project first | ||
1875 | 532 | installed = _git_clone_and_install_subset(yaml_file, | ||
1876 | 533 | whitelist=['requirements']) | ||
1877 | 534 | if 'requirements' not in installed: | ||
1878 | 535 | error_out('requirements git repository must be specified') | ||
1879 | 536 | |||
1880 | 537 | # clone/install all other projects except requirements and the core project | ||
1881 | 538 | blacklist = ['requirements', core_project] | ||
1882 | 539 | _git_clone_and_install_subset(yaml_file, blacklist=blacklist, | ||
1883 | 540 | update_requirements=True) | ||
1884 | 541 | |||
1885 | 542 | # clone/install the core project | ||
1886 | 543 | whitelist = [core_project] | ||
1887 | 544 | installed = _git_clone_and_install_subset(yaml_file, whitelist=whitelist, | ||
1888 | 545 | update_requirements=True) | ||
1889 | 546 | if core_project not in installed: | ||
1890 | 547 | error_out('{} git repository must be specified'.format(core_project)) | ||
1891 | 548 | |||
1892 | 549 | |||
1893 | 550 | def _git_clone_and_install_subset(yaml_file, whitelist=[], blacklist=[], | ||
1894 | 551 | update_requirements=False): | ||
1895 | 552 | """Clone/install subset of OpenStack repos specified in yaml config file.""" | ||
1896 | 553 | global requirements_dir | ||
1897 | 554 | installed = [] | ||
1898 | 555 | |||
1899 | 556 | with open(yaml_file, 'r') as fd: | ||
1900 | 557 | projects = yaml.load(fd) | ||
1901 | 558 | for proj, val in projects.items(): | ||
1902 | 559 | # The project subset is chosen based on the following 3 rules: | ||
1903 | 560 | # 1) If project is in blacklist, we don't clone/install it, period. | ||
1904 | 561 | # 2) If whitelist is empty, we clone/install everything else. | ||
1905 | 562 | # 3) If whitelist is not empty, we clone/install everything in the | ||
1906 | 563 | # whitelist. | ||
1907 | 564 | if proj in blacklist: | ||
1908 | 565 | continue | ||
1909 | 566 | if whitelist and proj not in whitelist: | ||
1910 | 567 | continue | ||
1911 | 568 | repo = val['repository'] | ||
1912 | 569 | branch = val['branch'] | ||
1913 | 570 | repo_dir = _git_clone_and_install_single(repo, branch, | ||
1914 | 571 | update_requirements) | ||
1915 | 572 | if proj == 'requirements': | ||
1916 | 573 | requirements_dir = repo_dir | ||
1917 | 574 | installed.append(proj) | ||
1918 | 575 | return installed | ||
1919 | 576 | |||
1920 | 577 | |||
1921 | 578 | def _git_clone_and_install_single(repo, branch, update_requirements=False): | ||
1922 | 579 | """Clone and install a single git repository.""" | ||
1923 | 580 | dest_parent_dir = "/mnt/openstack-git/" | ||
1924 | 581 | dest_dir = os.path.join(dest_parent_dir, os.path.basename(repo)) | ||
1925 | 582 | |||
1926 | 583 | if not os.path.exists(dest_parent_dir): | ||
1927 | 584 | juju_log('Host dir not mounted at {}. ' | ||
1928 | 585 | 'Creating directory there instead.'.format(dest_parent_dir)) | ||
1929 | 586 | os.mkdir(dest_parent_dir) | ||
1930 | 587 | |||
1931 | 588 | if not os.path.exists(dest_dir): | ||
1932 | 589 | juju_log('Cloning git repo: {}, branch: {}'.format(repo, branch)) | ||
1933 | 590 | repo_dir = install_remote(repo, dest=dest_parent_dir, branch=branch) | ||
1934 | 591 | else: | ||
1935 | 592 | repo_dir = dest_dir | ||
1936 | 593 | |||
1937 | 594 | if update_requirements: | ||
1938 | 595 | if not requirements_dir: | ||
1939 | 596 | error_out('requirements repo must be cloned before ' | ||
1940 | 597 | 'updating from global requirements.') | ||
1941 | 598 | _git_update_requirements(repo_dir, requirements_dir) | ||
1942 | 599 | |||
1943 | 600 | juju_log('Installing git repo from dir: {}'.format(repo_dir)) | ||
1944 | 601 | pip_install(repo_dir) | ||
1945 | 602 | |||
1946 | 603 | return repo_dir | ||
1947 | 604 | |||
1948 | 605 | |||
1949 | 606 | def _git_update_requirements(package_dir, reqs_dir): | ||
1950 | 607 | """Update from global requirements. | ||
1951 | 608 | |||
1952 | 609 | Update an OpenStack git directory's requirements.txt and | ||
1953 | 610 | test-requirements.txt from global-requirements.txt.""" | ||
1954 | 611 | orig_dir = os.getcwd() | ||
1955 | 612 | os.chdir(reqs_dir) | ||
1956 | 613 | cmd = "python update.py {}".format(package_dir) | ||
1957 | 614 | try: | ||
1958 | 615 | subprocess.check_call(cmd.split(' ')) | ||
1959 | 616 | except subprocess.CalledProcessError: | ||
1960 | 617 | package = os.path.basename(package_dir) | ||
1961 | 618 | error_out("Error updating {} from global-requirements.txt".format(package)) | ||
1962 | 619 | os.chdir(orig_dir) | ||
1963 | 487 | 620 | ||
1964 | === added directory 'hooks/charmhelpers/contrib/python' | |||
1965 | === added file 'hooks/charmhelpers/contrib/python/__init__.py' | |||
1966 | === added file 'hooks/charmhelpers/contrib/python/packages.py' | |||
1967 | --- hooks/charmhelpers/contrib/python/packages.py 1970-01-01 00:00:00 +0000 | |||
1968 | +++ hooks/charmhelpers/contrib/python/packages.py 2014-12-11 17:56:40 +0000 | |||
1969 | @@ -0,0 +1,77 @@ | |||
1970 | 1 | #!/usr/bin/env python | ||
1971 | 2 | # coding: utf-8 | ||
1972 | 3 | |||
1973 | 4 | __author__ = "Jorge Niedbalski <jorge.niedbalski@canonical.com>" | ||
1974 | 5 | |||
1975 | 6 | from charmhelpers.fetch import apt_install, apt_update | ||
1976 | 7 | from charmhelpers.core.hookenv import log | ||
1977 | 8 | |||
1978 | 9 | try: | ||
1979 | 10 | from pip import main as pip_execute | ||
1980 | 11 | except ImportError: | ||
1981 | 12 | apt_update() | ||
1982 | 13 | apt_install('python-pip') | ||
1983 | 14 | from pip import main as pip_execute | ||
1984 | 15 | |||
1985 | 16 | |||
1986 | 17 | def parse_options(given, available): | ||
1987 | 18 | """Given a set of options, check if available""" | ||
1988 | 19 | for key, value in sorted(given.items()): | ||
1989 | 20 | if key in available: | ||
1990 | 21 | yield "--{0}={1}".format(key, value) | ||
1991 | 22 | |||
1992 | 23 | |||
1993 | 24 | def pip_install_requirements(requirements, **options): | ||
1994 | 25 | """Install a requirements file """ | ||
1995 | 26 | command = ["install"] | ||
1996 | 27 | |||
1997 | 28 | available_options = ('proxy', 'src', 'log', ) | ||
1998 | 29 | for option in parse_options(options, available_options): | ||
1999 | 30 | command.append(option) | ||
2000 | 31 | |||
2001 | 32 | command.append("-r {0}".format(requirements)) | ||
2002 | 33 | log("Installing from file: {} with options: {}".format(requirements, | ||
2003 | 34 | command)) | ||
2004 | 35 | pip_execute(command) | ||
2005 | 36 | |||
2006 | 37 | |||
2007 | 38 | def pip_install(package, fatal=False, **options): | ||
2008 | 39 | """Install a python package""" | ||
2009 | 40 | command = ["install"] | ||
2010 | 41 | |||
2011 | 42 | available_options = ('proxy', 'src', 'log', "index-url", ) | ||
2012 | 43 | for option in parse_options(options, available_options): | ||
2013 | 44 | command.append(option) | ||
2014 | 45 | |||
2015 | 46 | if isinstance(package, list): | ||
2016 | 47 | command.extend(package) | ||
2017 | 48 | else: | ||
2018 | 49 | command.append(package) | ||
2019 | 50 | |||
2020 | 51 | log("Installing {} package with options: {}".format(package, | ||
2021 | 52 | command)) | ||
2022 | 53 | pip_execute(command) | ||
2023 | 54 | |||
2024 | 55 | |||
2025 | 56 | def pip_uninstall(package, **options): | ||
2026 | 57 | """Uninstall a python package""" | ||
2027 | 58 | command = ["uninstall", "-q", "-y"] | ||
2028 | 59 | |||
2029 | 60 | available_options = ('proxy', 'log', ) | ||
2030 | 61 | for option in parse_options(options, available_options): | ||
2031 | 62 | command.append(option) | ||
2032 | 63 | |||
2033 | 64 | if isinstance(package, list): | ||
2034 | 65 | command.extend(package) | ||
2035 | 66 | else: | ||
2036 | 67 | command.append(package) | ||
2037 | 68 | |||
2038 | 69 | log("Uninstalling {} package with options: {}".format(package, | ||
2039 | 70 | command)) | ||
2040 | 71 | pip_execute(command) | ||
2041 | 72 | |||
2042 | 73 | |||
2043 | 74 | def pip_list(): | ||
2044 | 75 | """Returns the list of current python installed packages | ||
2045 | 76 | """ | ||
2046 | 77 | return pip_execute(["list"]) | ||
2047 | 0 | 78 | ||
2048 | === modified file 'hooks/charmhelpers/contrib/storage/linux/ceph.py' | |||
2049 | --- hooks/charmhelpers/contrib/storage/linux/ceph.py 2014-06-27 11:55:45 +0000 | |||
2050 | +++ hooks/charmhelpers/contrib/storage/linux/ceph.py 2014-12-11 17:56:40 +0000 | |||
2051 | @@ -16,19 +16,18 @@ | |||
2052 | 16 | from subprocess import ( | 16 | from subprocess import ( |
2053 | 17 | check_call, | 17 | check_call, |
2054 | 18 | check_output, | 18 | check_output, |
2056 | 19 | CalledProcessError | 19 | CalledProcessError, |
2057 | 20 | ) | 20 | ) |
2058 | 21 | |||
2059 | 22 | from charmhelpers.core.hookenv import ( | 21 | from charmhelpers.core.hookenv import ( |
2060 | 23 | relation_get, | 22 | relation_get, |
2061 | 24 | relation_ids, | 23 | relation_ids, |
2062 | 25 | related_units, | 24 | related_units, |
2063 | 26 | log, | 25 | log, |
2064 | 26 | DEBUG, | ||
2065 | 27 | INFO, | 27 | INFO, |
2066 | 28 | WARNING, | 28 | WARNING, |
2068 | 29 | ERROR | 29 | ERROR, |
2069 | 30 | ) | 30 | ) |
2070 | 31 | |||
2071 | 32 | from charmhelpers.core.host import ( | 31 | from charmhelpers.core.host import ( |
2072 | 33 | mount, | 32 | mount, |
2073 | 34 | mounts, | 33 | mounts, |
2074 | @@ -37,7 +36,6 @@ | |||
2075 | 37 | service_running, | 36 | service_running, |
2076 | 38 | umount, | 37 | umount, |
2077 | 39 | ) | 38 | ) |
2078 | 40 | |||
2079 | 41 | from charmhelpers.fetch import ( | 39 | from charmhelpers.fetch import ( |
2080 | 42 | apt_install, | 40 | apt_install, |
2081 | 43 | ) | 41 | ) |
2082 | @@ -56,99 +54,85 @@ | |||
2083 | 56 | 54 | ||
2084 | 57 | 55 | ||
2085 | 58 | def install(): | 56 | def install(): |
2087 | 59 | ''' Basic Ceph client installation ''' | 57 | """Basic Ceph client installation.""" |
2088 | 60 | ceph_dir = "/etc/ceph" | 58 | ceph_dir = "/etc/ceph" |
2089 | 61 | if not os.path.exists(ceph_dir): | 59 | if not os.path.exists(ceph_dir): |
2090 | 62 | os.mkdir(ceph_dir) | 60 | os.mkdir(ceph_dir) |
2091 | 61 | |||
2092 | 63 | apt_install('ceph-common', fatal=True) | 62 | apt_install('ceph-common', fatal=True) |
2093 | 64 | 63 | ||
2094 | 65 | 64 | ||
2095 | 66 | def rbd_exists(service, pool, rbd_img): | 65 | def rbd_exists(service, pool, rbd_img): |
2097 | 67 | ''' Check to see if a RADOS block device exists ''' | 66 | """Check to see if a RADOS block device exists.""" |
2098 | 68 | try: | 67 | try: |
2101 | 69 | out = check_output(['rbd', 'list', '--id', service, | 68 | out = check_output(['rbd', 'list', '--id', |
2102 | 70 | '--pool', pool]) | 69 | service, '--pool', pool]).decode('UTF-8') |
2103 | 71 | except CalledProcessError: | 70 | except CalledProcessError: |
2104 | 72 | return False | 71 | return False |
2107 | 73 | else: | 72 | |
2108 | 74 | return rbd_img in out | 73 | return rbd_img in out |
2109 | 75 | 74 | ||
2110 | 76 | 75 | ||
2111 | 77 | def create_rbd_image(service, pool, image, sizemb): | 76 | def create_rbd_image(service, pool, image, sizemb): |
2124 | 78 | ''' Create a new RADOS block device ''' | 77 | """Create a new RADOS block device.""" |
2125 | 79 | cmd = [ | 78 | cmd = ['rbd', 'create', image, '--size', str(sizemb), '--id', service, |
2126 | 80 | 'rbd', | 79 | '--pool', pool] |
2115 | 81 | 'create', | ||
2116 | 82 | image, | ||
2117 | 83 | '--size', | ||
2118 | 84 | str(sizemb), | ||
2119 | 85 | '--id', | ||
2120 | 86 | service, | ||
2121 | 87 | '--pool', | ||
2122 | 88 | pool | ||
2123 | 89 | ] | ||
2127 | 90 | check_call(cmd) | 80 | check_call(cmd) |
2128 | 91 | 81 | ||
2129 | 92 | 82 | ||
2130 | 93 | def pool_exists(service, name): | 83 | def pool_exists(service, name): |
2132 | 94 | ''' Check to see if a RADOS pool already exists ''' | 84 | """Check to see if a RADOS pool already exists.""" |
2133 | 95 | try: | 85 | try: |
2135 | 96 | out = check_output(['rados', '--id', service, 'lspools']) | 86 | out = check_output(['rados', '--id', service, |
2136 | 87 | 'lspools']).decode('UTF-8') | ||
2137 | 97 | except CalledProcessError: | 88 | except CalledProcessError: |
2138 | 98 | return False | 89 | return False |
2141 | 99 | else: | 90 | |
2142 | 100 | return name in out | 91 | return name in out |
2143 | 101 | 92 | ||
2144 | 102 | 93 | ||
2145 | 103 | def get_osds(service): | 94 | def get_osds(service): |
2150 | 104 | ''' | 95 | """Return a list of all Ceph Object Storage Daemons currently in the |
2151 | 105 | Return a list of all Ceph Object Storage Daemons | 96 | cluster. |
2152 | 106 | currently in the cluster | 97 | """ |
2149 | 107 | ''' | ||
2153 | 108 | version = ceph_version() | 98 | version = ceph_version() |
2154 | 109 | if version and version >= '0.56': | 99 | if version and version >= '0.56': |
2155 | 110 | return json.loads(check_output(['ceph', '--id', service, | 100 | return json.loads(check_output(['ceph', '--id', service, |
2163 | 111 | 'osd', 'ls', '--format=json'])) | 101 | 'osd', 'ls', |
2164 | 112 | else: | 102 | '--format=json']).decode('UTF-8')) |
2165 | 113 | return None | 103 | |
2166 | 114 | 104 | return None | |
2167 | 115 | 105 | ||
2168 | 116 | def create_pool(service, name, replicas=2): | 106 | |
2169 | 117 | ''' Create a new RADOS pool ''' | 107 | def create_pool(service, name, replicas=3): |
2170 | 108 | """Create a new RADOS pool.""" | ||
2171 | 118 | if pool_exists(service, name): | 109 | if pool_exists(service, name): |
2172 | 119 | log("Ceph pool {} already exists, skipping creation".format(name), | 110 | log("Ceph pool {} already exists, skipping creation".format(name), |
2173 | 120 | level=WARNING) | 111 | level=WARNING) |
2174 | 121 | return | 112 | return |
2175 | 113 | |||
2176 | 122 | # Calculate the number of placement groups based | 114 | # Calculate the number of placement groups based |
2177 | 123 | # on upstream recommended best practices. | 115 | # on upstream recommended best practices. |
2178 | 124 | osds = get_osds(service) | 116 | osds = get_osds(service) |
2179 | 125 | if osds: | 117 | if osds: |
2181 | 126 | pgnum = (len(osds) * 100 / replicas) | 118 | pgnum = (len(osds) * 100 // replicas) |
2182 | 127 | else: | 119 | else: |
2183 | 128 | # NOTE(james-page): Default to 200 for older ceph versions | 120 | # NOTE(james-page): Default to 200 for older ceph versions |
2184 | 129 | # which don't support OSD query from cli | 121 | # which don't support OSD query from cli |
2185 | 130 | pgnum = 200 | 122 | pgnum = 200 |
2191 | 131 | cmd = [ | 123 | |
2192 | 132 | 'ceph', '--id', service, | 124 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'create', name, str(pgnum)] |
2188 | 133 | 'osd', 'pool', 'create', | ||
2189 | 134 | name, str(pgnum) | ||
2190 | 135 | ] | ||
2193 | 136 | check_call(cmd) | 125 | check_call(cmd) |
2199 | 137 | cmd = [ | 126 | |
2200 | 138 | 'ceph', '--id', service, | 127 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'set', name, 'size', |
2201 | 139 | 'osd', 'pool', 'set', name, | 128 | str(replicas)] |
2197 | 140 | 'size', str(replicas) | ||
2198 | 141 | ] | ||
2202 | 142 | check_call(cmd) | 129 | check_call(cmd) |
2203 | 143 | 130 | ||
2204 | 144 | 131 | ||
2205 | 145 | def delete_pool(service, name): | 132 | def delete_pool(service, name): |
2212 | 146 | ''' Delete a RADOS pool from ceph ''' | 133 | """Delete a RADOS pool from ceph.""" |
2213 | 147 | cmd = [ | 134 | cmd = ['ceph', '--id', service, 'osd', 'pool', 'delete', name, |
2214 | 148 | 'ceph', '--id', service, | 135 | '--yes-i-really-really-mean-it'] |
2209 | 149 | 'osd', 'pool', 'delete', | ||
2210 | 150 | name, '--yes-i-really-really-mean-it' | ||
2211 | 151 | ] | ||
2215 | 152 | check_call(cmd) | 136 | check_call(cmd) |
2216 | 153 | 137 | ||
2217 | 154 | 138 | ||
2218 | @@ -161,44 +145,43 @@ | |||
2219 | 161 | 145 | ||
2220 | 162 | 146 | ||
2221 | 163 | def create_keyring(service, key): | 147 | def create_keyring(service, key): |
2223 | 164 | ''' Create a new Ceph keyring containing key''' | 148 | """Create a new Ceph keyring containing key.""" |
2224 | 165 | keyring = _keyring_path(service) | 149 | keyring = _keyring_path(service) |
2225 | 166 | if os.path.exists(keyring): | 150 | if os.path.exists(keyring): |
2227 | 167 | log('ceph: Keyring exists at %s.' % keyring, level=WARNING) | 151 | log('Ceph keyring exists at %s.' % keyring, level=WARNING) |
2228 | 168 | return | 152 | return |
2236 | 169 | cmd = [ | 153 | |
2237 | 170 | 'ceph-authtool', | 154 | cmd = ['ceph-authtool', keyring, '--create-keyring', |
2238 | 171 | keyring, | 155 | '--name=client.{}'.format(service), '--add-key={}'.format(key)] |
2232 | 172 | '--create-keyring', | ||
2233 | 173 | '--name=client.{}'.format(service), | ||
2234 | 174 | '--add-key={}'.format(key) | ||
2235 | 175 | ] | ||
2239 | 176 | check_call(cmd) | 156 | check_call(cmd) |
2241 | 177 | log('ceph: Created new ring at %s.' % keyring, level=INFO) | 157 | log('Created new ceph keyring at %s.' % keyring, level=DEBUG) |
2242 | 178 | 158 | ||
2243 | 179 | 159 | ||
2244 | 180 | def create_key_file(service, key): | 160 | def create_key_file(service, key): |
2246 | 181 | ''' Create a file containing key ''' | 161 | """Create a file containing key.""" |
2247 | 182 | keyfile = _keyfile_path(service) | 162 | keyfile = _keyfile_path(service) |
2248 | 183 | if os.path.exists(keyfile): | 163 | if os.path.exists(keyfile): |
2250 | 184 | log('ceph: Keyfile exists at %s.' % keyfile, level=WARNING) | 164 | log('Keyfile exists at %s.' % keyfile, level=WARNING) |
2251 | 185 | return | 165 | return |
2252 | 166 | |||
2253 | 186 | with open(keyfile, 'w') as fd: | 167 | with open(keyfile, 'w') as fd: |
2254 | 187 | fd.write(key) | 168 | fd.write(key) |
2256 | 188 | log('ceph: Created new keyfile at %s.' % keyfile, level=INFO) | 169 | |
2257 | 170 | log('Created new keyfile at %s.' % keyfile, level=INFO) | ||
2258 | 189 | 171 | ||
2259 | 190 | 172 | ||
2260 | 191 | def get_ceph_nodes(): | 173 | def get_ceph_nodes(): |
2262 | 192 | ''' Query named relation 'ceph' to detemine current nodes ''' | 174 | """Query named relation 'ceph' to determine current nodes.""" |
2263 | 193 | hosts = [] | 175 | hosts = [] |
2264 | 194 | for r_id in relation_ids('ceph'): | 176 | for r_id in relation_ids('ceph'): |
2265 | 195 | for unit in related_units(r_id): | 177 | for unit in related_units(r_id): |
2266 | 196 | hosts.append(relation_get('private-address', unit=unit, rid=r_id)) | 178 | hosts.append(relation_get('private-address', unit=unit, rid=r_id)) |
2267 | 179 | |||
2268 | 197 | return hosts | 180 | return hosts |
2269 | 198 | 181 | ||
2270 | 199 | 182 | ||
2271 | 200 | def configure(service, key, auth, use_syslog): | 183 | def configure(service, key, auth, use_syslog): |
2273 | 201 | ''' Perform basic configuration of Ceph ''' | 184 | """Perform basic configuration of Ceph.""" |
2274 | 202 | create_keyring(service, key) | 185 | create_keyring(service, key) |
2275 | 203 | create_key_file(service, key) | 186 | create_key_file(service, key) |
2276 | 204 | hosts = get_ceph_nodes() | 187 | hosts = get_ceph_nodes() |
2277 | @@ -211,17 +194,17 @@ | |||
2278 | 211 | 194 | ||
2279 | 212 | 195 | ||
2280 | 213 | def image_mapped(name): | 196 | def image_mapped(name): |
2282 | 214 | ''' Determine whether a RADOS block device is mapped locally ''' | 197 | """Determine whether a RADOS block device is mapped locally.""" |
2283 | 215 | try: | 198 | try: |
2285 | 216 | out = check_output(['rbd', 'showmapped']) | 199 | out = check_output(['rbd', 'showmapped']).decode('UTF-8') |
2286 | 217 | except CalledProcessError: | 200 | except CalledProcessError: |
2287 | 218 | return False | 201 | return False |
2290 | 219 | else: | 202 | |
2291 | 220 | return name in out | 203 | return name in out |
2292 | 221 | 204 | ||
2293 | 222 | 205 | ||
2294 | 223 | def map_block_storage(service, pool, image): | 206 | def map_block_storage(service, pool, image): |
2296 | 224 | ''' Map a RADOS block device for local use ''' | 207 | """Map a RADOS block device for local use.""" |
2297 | 225 | cmd = [ | 208 | cmd = [ |
2298 | 226 | 'rbd', | 209 | 'rbd', |
2299 | 227 | 'map', | 210 | 'map', |
2300 | @@ -235,31 +218,32 @@ | |||
2301 | 235 | 218 | ||
2302 | 236 | 219 | ||
2303 | 237 | def filesystem_mounted(fs): | 220 | def filesystem_mounted(fs): |
2305 | 238 | ''' Determine whether a filesytems is already mounted ''' | 221 | """Determine whether a filesytems is already mounted.""" |
2306 | 239 | return fs in [f for f, m in mounts()] | 222 | return fs in [f for f, m in mounts()] |
2307 | 240 | 223 | ||
2308 | 241 | 224 | ||
2309 | 242 | def make_filesystem(blk_device, fstype='ext4', timeout=10): | 225 | def make_filesystem(blk_device, fstype='ext4', timeout=10): |
2311 | 243 | ''' Make a new filesystem on the specified block device ''' | 226 | """Make a new filesystem on the specified block device.""" |
2312 | 244 | count = 0 | 227 | count = 0 |
2313 | 245 | e_noent = os.errno.ENOENT | 228 | e_noent = os.errno.ENOENT |
2314 | 246 | while not os.path.exists(blk_device): | 229 | while not os.path.exists(blk_device): |
2315 | 247 | if count >= timeout: | 230 | if count >= timeout: |
2317 | 248 | log('ceph: gave up waiting on block device %s' % blk_device, | 231 | log('Gave up waiting on block device %s' % blk_device, |
2318 | 249 | level=ERROR) | 232 | level=ERROR) |
2319 | 250 | raise IOError(e_noent, os.strerror(e_noent), blk_device) | 233 | raise IOError(e_noent, os.strerror(e_noent), blk_device) |
2322 | 251 | log('ceph: waiting for block device %s to appear' % blk_device, | 234 | |
2323 | 252 | level=INFO) | 235 | log('Waiting for block device %s to appear' % blk_device, |
2324 | 236 | level=DEBUG) | ||
2325 | 253 | count += 1 | 237 | count += 1 |
2326 | 254 | time.sleep(1) | 238 | time.sleep(1) |
2327 | 255 | else: | 239 | else: |
2329 | 256 | log('ceph: Formatting block device %s as filesystem %s.' % | 240 | log('Formatting block device %s as filesystem %s.' % |
2330 | 257 | (blk_device, fstype), level=INFO) | 241 | (blk_device, fstype), level=INFO) |
2331 | 258 | check_call(['mkfs', '-t', fstype, blk_device]) | 242 | check_call(['mkfs', '-t', fstype, blk_device]) |
2332 | 259 | 243 | ||
2333 | 260 | 244 | ||
2334 | 261 | def place_data_on_block_device(blk_device, data_src_dst): | 245 | def place_data_on_block_device(blk_device, data_src_dst): |
2336 | 262 | ''' Migrate data in data_src_dst to blk_device and then remount ''' | 246 | """Migrate data in data_src_dst to blk_device and then remount.""" |
2337 | 263 | # mount block device into /mnt | 247 | # mount block device into /mnt |
2338 | 264 | mount(blk_device, '/mnt') | 248 | mount(blk_device, '/mnt') |
2339 | 265 | # copy data to /mnt | 249 | # copy data to /mnt |
2340 | @@ -279,8 +263,8 @@ | |||
2341 | 279 | 263 | ||
2342 | 280 | # TODO: re-use | 264 | # TODO: re-use |
2343 | 281 | def modprobe(module): | 265 | def modprobe(module): |
2346 | 282 | ''' Load a kernel module and configure for auto-load on reboot ''' | 266 | """Load a kernel module and configure for auto-load on reboot.""" |
2347 | 283 | log('ceph: Loading kernel module', level=INFO) | 267 | log('Loading kernel module', level=INFO) |
2348 | 284 | cmd = ['modprobe', module] | 268 | cmd = ['modprobe', module] |
2349 | 285 | check_call(cmd) | 269 | check_call(cmd) |
2350 | 286 | with open('/etc/modules', 'r+') as modules: | 270 | with open('/etc/modules', 'r+') as modules: |
2351 | @@ -289,7 +273,7 @@ | |||
2352 | 289 | 273 | ||
2353 | 290 | 274 | ||
2354 | 291 | def copy_files(src, dst, symlinks=False, ignore=None): | 275 | def copy_files(src, dst, symlinks=False, ignore=None): |
2356 | 292 | ''' Copy files from src to dst ''' | 276 | """Copy files from src to dst.""" |
2357 | 293 | for item in os.listdir(src): | 277 | for item in os.listdir(src): |
2358 | 294 | s = os.path.join(src, item) | 278 | s = os.path.join(src, item) |
2359 | 295 | d = os.path.join(dst, item) | 279 | d = os.path.join(dst, item) |
2360 | @@ -300,9 +284,9 @@ | |||
2361 | 300 | 284 | ||
2362 | 301 | 285 | ||
2363 | 302 | def ensure_ceph_storage(service, pool, rbd_img, sizemb, mount_point, | 286 | def ensure_ceph_storage(service, pool, rbd_img, sizemb, mount_point, |
2367 | 303 | blk_device, fstype, system_services=[]): | 287 | blk_device, fstype, system_services=[], |
2368 | 304 | """ | 288 | replicas=3): |
2369 | 305 | NOTE: This function must only be called from a single service unit for | 289 | """NOTE: This function must only be called from a single service unit for |
2370 | 306 | the same rbd_img otherwise data loss will occur. | 290 | the same rbd_img otherwise data loss will occur. |
2371 | 307 | 291 | ||
2372 | 308 | Ensures given pool and RBD image exists, is mapped to a block device, | 292 | Ensures given pool and RBD image exists, is mapped to a block device, |
2373 | @@ -316,15 +300,16 @@ | |||
2374 | 316 | """ | 300 | """ |
2375 | 317 | # Ensure pool, RBD image, RBD mappings are in place. | 301 | # Ensure pool, RBD image, RBD mappings are in place. |
2376 | 318 | if not pool_exists(service, pool): | 302 | if not pool_exists(service, pool): |
2379 | 319 | log('ceph: Creating new pool {}.'.format(pool)) | 303 | log('Creating new pool {}.'.format(pool), level=INFO) |
2380 | 320 | create_pool(service, pool) | 304 | create_pool(service, pool, replicas=replicas) |
2381 | 321 | 305 | ||
2382 | 322 | if not rbd_exists(service, pool, rbd_img): | 306 | if not rbd_exists(service, pool, rbd_img): |
2384 | 323 | log('ceph: Creating RBD image ({}).'.format(rbd_img)) | 307 | log('Creating RBD image ({}).'.format(rbd_img), level=INFO) |
2385 | 324 | create_rbd_image(service, pool, rbd_img, sizemb) | 308 | create_rbd_image(service, pool, rbd_img, sizemb) |
2386 | 325 | 309 | ||
2387 | 326 | if not image_mapped(rbd_img): | 310 | if not image_mapped(rbd_img): |
2389 | 327 | log('ceph: Mapping RBD Image {} as a Block Device.'.format(rbd_img)) | 311 | log('Mapping RBD Image {} as a Block Device.'.format(rbd_img), |
2390 | 312 | level=INFO) | ||
2391 | 328 | map_block_storage(service, pool, rbd_img) | 313 | map_block_storage(service, pool, rbd_img) |
2392 | 329 | 314 | ||
2393 | 330 | # make file system | 315 | # make file system |
2394 | @@ -339,45 +324,47 @@ | |||
2395 | 339 | 324 | ||
2396 | 340 | for svc in system_services: | 325 | for svc in system_services: |
2397 | 341 | if service_running(svc): | 326 | if service_running(svc): |
2400 | 342 | log('ceph: Stopping services {} prior to migrating data.' | 327 | log('Stopping services {} prior to migrating data.' |
2401 | 343 | .format(svc)) | 328 | .format(svc), level=DEBUG) |
2402 | 344 | service_stop(svc) | 329 | service_stop(svc) |
2403 | 345 | 330 | ||
2404 | 346 | place_data_on_block_device(blk_device, mount_point) | 331 | place_data_on_block_device(blk_device, mount_point) |
2405 | 347 | 332 | ||
2406 | 348 | for svc in system_services: | 333 | for svc in system_services: |
2409 | 349 | log('ceph: Starting service {} after migrating data.' | 334 | log('Starting service {} after migrating data.' |
2410 | 350 | .format(svc)) | 335 | .format(svc), level=DEBUG) |
2411 | 351 | service_start(svc) | 336 | service_start(svc) |
2412 | 352 | 337 | ||
2413 | 353 | 338 | ||
2414 | 354 | def ensure_ceph_keyring(service, user=None, group=None): | 339 | def ensure_ceph_keyring(service, user=None, group=None): |
2418 | 355 | ''' | 340 | """Ensures a ceph keyring is created for a named service and optionally |
2419 | 356 | Ensures a ceph keyring is created for a named service | 341 | ensures user and group ownership. |
2417 | 357 | and optionally ensures user and group ownership. | ||
2420 | 358 | 342 | ||
2421 | 359 | Returns False if no ceph key is available in relation state. | 343 | Returns False if no ceph key is available in relation state. |
2423 | 360 | ''' | 344 | """ |
2424 | 361 | key = None | 345 | key = None |
2425 | 362 | for rid in relation_ids('ceph'): | 346 | for rid in relation_ids('ceph'): |
2426 | 363 | for unit in related_units(rid): | 347 | for unit in related_units(rid): |
2427 | 364 | key = relation_get('key', rid=rid, unit=unit) | 348 | key = relation_get('key', rid=rid, unit=unit) |
2428 | 365 | if key: | 349 | if key: |
2429 | 366 | break | 350 | break |
2430 | 351 | |||
2431 | 367 | if not key: | 352 | if not key: |
2432 | 368 | return False | 353 | return False |
2433 | 354 | |||
2434 | 369 | create_keyring(service=service, key=key) | 355 | create_keyring(service=service, key=key) |
2435 | 370 | keyring = _keyring_path(service) | 356 | keyring = _keyring_path(service) |
2436 | 371 | if user and group: | 357 | if user and group: |
2437 | 372 | check_call(['chown', '%s.%s' % (user, group), keyring]) | 358 | check_call(['chown', '%s.%s' % (user, group), keyring]) |
2438 | 359 | |||
2439 | 373 | return True | 360 | return True |
2440 | 374 | 361 | ||
2441 | 375 | 362 | ||
2442 | 376 | def ceph_version(): | 363 | def ceph_version(): |
2444 | 377 | ''' Retrieve the local version of ceph ''' | 364 | """Retrieve the local version of ceph.""" |
2445 | 378 | if os.path.exists('/usr/bin/ceph'): | 365 | if os.path.exists('/usr/bin/ceph'): |
2446 | 379 | cmd = ['ceph', '-v'] | 366 | cmd = ['ceph', '-v'] |
2448 | 380 | output = check_output(cmd) | 367 | output = check_output(cmd).decode('US-ASCII') |
2449 | 381 | output = output.split() | 368 | output = output.split() |
2450 | 382 | if len(output) > 3: | 369 | if len(output) > 3: |
2451 | 383 | return output[2] | 370 | return output[2] |
2452 | 384 | 371 | ||
2453 | === modified file 'hooks/charmhelpers/contrib/storage/linux/loopback.py' | |||
2454 | --- hooks/charmhelpers/contrib/storage/linux/loopback.py 2014-06-05 10:59:00 +0000 | |||
2455 | +++ hooks/charmhelpers/contrib/storage/linux/loopback.py 2014-12-11 17:56:40 +0000 | |||
2456 | @@ -1,12 +1,12 @@ | |||
2457 | 1 | |||
2458 | 2 | import os | 1 | import os |
2459 | 3 | import re | 2 | import re |
2460 | 4 | |||
2461 | 5 | from subprocess import ( | 3 | from subprocess import ( |
2462 | 6 | check_call, | 4 | check_call, |
2463 | 7 | check_output, | 5 | check_output, |
2464 | 8 | ) | 6 | ) |
2465 | 9 | 7 | ||
2466 | 8 | import six | ||
2467 | 9 | |||
2468 | 10 | 10 | ||
2469 | 11 | ################################################## | 11 | ################################################## |
2470 | 12 | # loopback device helpers. | 12 | # loopback device helpers. |
2471 | @@ -37,7 +37,7 @@ | |||
2472 | 37 | ''' | 37 | ''' |
2473 | 38 | file_path = os.path.abspath(file_path) | 38 | file_path = os.path.abspath(file_path) |
2474 | 39 | check_call(['losetup', '--find', file_path]) | 39 | check_call(['losetup', '--find', file_path]) |
2476 | 40 | for d, f in loopback_devices().iteritems(): | 40 | for d, f in six.iteritems(loopback_devices()): |
2477 | 41 | if f == file_path: | 41 | if f == file_path: |
2478 | 42 | return d | 42 | return d |
2479 | 43 | 43 | ||
2480 | @@ -51,7 +51,7 @@ | |||
2481 | 51 | 51 | ||
2482 | 52 | :returns: str: Full path to the ensured loopback device (eg, /dev/loop0) | 52 | :returns: str: Full path to the ensured loopback device (eg, /dev/loop0) |
2483 | 53 | ''' | 53 | ''' |
2485 | 54 | for d, f in loopback_devices().iteritems(): | 54 | for d, f in six.iteritems(loopback_devices()): |
2486 | 55 | if f == path: | 55 | if f == path: |
2487 | 56 | return d | 56 | return d |
2488 | 57 | 57 | ||
2489 | 58 | 58 | ||
2490 | === modified file 'hooks/charmhelpers/contrib/storage/linux/lvm.py' | |||
2491 | --- hooks/charmhelpers/contrib/storage/linux/lvm.py 2014-06-24 11:05:17 +0000 | |||
2492 | +++ hooks/charmhelpers/contrib/storage/linux/lvm.py 2014-12-11 17:56:40 +0000 | |||
2493 | @@ -61,6 +61,7 @@ | |||
2494 | 61 | vg = None | 61 | vg = None |
2495 | 62 | pvd = check_output(['pvdisplay', block_device]).splitlines() | 62 | pvd = check_output(['pvdisplay', block_device]).splitlines() |
2496 | 63 | for l in pvd: | 63 | for l in pvd: |
2497 | 64 | l = l.decode('UTF-8') | ||
2498 | 64 | if l.strip().startswith('VG Name'): | 65 | if l.strip().startswith('VG Name'): |
2499 | 65 | vg = ' '.join(l.strip().split()[2:]) | 66 | vg = ' '.join(l.strip().split()[2:]) |
2500 | 66 | return vg | 67 | return vg |
2501 | 67 | 68 | ||
2502 | === modified file 'hooks/charmhelpers/contrib/storage/linux/utils.py' | |||
2503 | --- hooks/charmhelpers/contrib/storage/linux/utils.py 2014-10-02 09:18:00 +0000 | |||
2504 | +++ hooks/charmhelpers/contrib/storage/linux/utils.py 2014-12-11 17:56:40 +0000 | |||
2505 | @@ -30,7 +30,8 @@ | |||
2506 | 30 | # sometimes sgdisk exits non-zero; this is OK, dd will clean up | 30 | # sometimes sgdisk exits non-zero; this is OK, dd will clean up |
2507 | 31 | call(['sgdisk', '--zap-all', '--mbrtogpt', | 31 | call(['sgdisk', '--zap-all', '--mbrtogpt', |
2508 | 32 | '--clear', block_device]) | 32 | '--clear', block_device]) |
2510 | 33 | dev_end = check_output(['blockdev', '--getsz', block_device]) | 33 | dev_end = check_output(['blockdev', '--getsz', |
2511 | 34 | block_device]).decode('UTF-8') | ||
2512 | 34 | gpt_end = int(dev_end.split()[0]) - 100 | 35 | gpt_end = int(dev_end.split()[0]) - 100 |
2513 | 35 | check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device), | 36 | check_call(['dd', 'if=/dev/zero', 'of=%s' % (block_device), |
2514 | 36 | 'bs=1M', 'count=1']) | 37 | 'bs=1M', 'count=1']) |
2515 | @@ -47,7 +48,7 @@ | |||
2516 | 47 | it doesn't. | 48 | it doesn't. |
2517 | 48 | ''' | 49 | ''' |
2518 | 49 | is_partition = bool(re.search(r".*[0-9]+\b", device)) | 50 | is_partition = bool(re.search(r".*[0-9]+\b", device)) |
2520 | 50 | out = check_output(['mount']) | 51 | out = check_output(['mount']).decode('UTF-8') |
2521 | 51 | if is_partition: | 52 | if is_partition: |
2522 | 52 | return bool(re.search(device + r"\b", out)) | 53 | return bool(re.search(device + r"\b", out)) |
2523 | 53 | return bool(re.search(device + r"[0-9]+\b", out)) | 54 | return bool(re.search(device + r"[0-9]+\b", out)) |
2524 | 54 | 55 | ||
2525 | === modified file 'hooks/charmhelpers/core/fstab.py' | |||
2526 | --- hooks/charmhelpers/core/fstab.py 2014-06-24 11:05:17 +0000 | |||
2527 | +++ hooks/charmhelpers/core/fstab.py 2014-12-11 17:56:40 +0000 | |||
2528 | @@ -3,10 +3,11 @@ | |||
2529 | 3 | 3 | ||
2530 | 4 | __author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>' | 4 | __author__ = 'Jorge Niedbalski R. <jorge.niedbalski@canonical.com>' |
2531 | 5 | 5 | ||
2532 | 6 | import io | ||
2533 | 6 | import os | 7 | import os |
2534 | 7 | 8 | ||
2535 | 8 | 9 | ||
2537 | 9 | class Fstab(file): | 10 | class Fstab(io.FileIO): |
2538 | 10 | """This class extends file in order to implement a file reader/writer | 11 | """This class extends file in order to implement a file reader/writer |
2539 | 11 | for file `/etc/fstab` | 12 | for file `/etc/fstab` |
2540 | 12 | """ | 13 | """ |
2541 | @@ -24,8 +25,8 @@ | |||
2542 | 24 | options = "defaults" | 25 | options = "defaults" |
2543 | 25 | 26 | ||
2544 | 26 | self.options = options | 27 | self.options = options |
2547 | 27 | self.d = d | 28 | self.d = int(d) |
2548 | 28 | self.p = p | 29 | self.p = int(p) |
2549 | 29 | 30 | ||
2550 | 30 | def __eq__(self, o): | 31 | def __eq__(self, o): |
2551 | 31 | return str(self) == str(o) | 32 | return str(self) == str(o) |
2552 | @@ -45,7 +46,7 @@ | |||
2553 | 45 | self._path = path | 46 | self._path = path |
2554 | 46 | else: | 47 | else: |
2555 | 47 | self._path = self.DEFAULT_PATH | 48 | self._path = self.DEFAULT_PATH |
2557 | 48 | file.__init__(self, self._path, 'r+') | 49 | super(Fstab, self).__init__(self._path, 'rb+') |
2558 | 49 | 50 | ||
2559 | 50 | def _hydrate_entry(self, line): | 51 | def _hydrate_entry(self, line): |
2560 | 51 | # NOTE: use split with no arguments to split on any | 52 | # NOTE: use split with no arguments to split on any |
2561 | @@ -58,8 +59,9 @@ | |||
2562 | 58 | def entries(self): | 59 | def entries(self): |
2563 | 59 | self.seek(0) | 60 | self.seek(0) |
2564 | 60 | for line in self.readlines(): | 61 | for line in self.readlines(): |
2565 | 62 | line = line.decode('us-ascii') | ||
2566 | 61 | try: | 63 | try: |
2568 | 62 | if not line.startswith("#"): | 64 | if line.strip() and not line.startswith("#"): |
2569 | 63 | yield self._hydrate_entry(line) | 65 | yield self._hydrate_entry(line) |
2570 | 64 | except ValueError: | 66 | except ValueError: |
2571 | 65 | pass | 67 | pass |
2572 | @@ -75,14 +77,14 @@ | |||
2573 | 75 | if self.get_entry_by_attr('device', entry.device): | 77 | if self.get_entry_by_attr('device', entry.device): |
2574 | 76 | return False | 78 | return False |
2575 | 77 | 79 | ||
2577 | 78 | self.write(str(entry) + '\n') | 80 | self.write((str(entry) + '\n').encode('us-ascii')) |
2578 | 79 | self.truncate() | 81 | self.truncate() |
2579 | 80 | return entry | 82 | return entry |
2580 | 81 | 83 | ||
2581 | 82 | def remove_entry(self, entry): | 84 | def remove_entry(self, entry): |
2582 | 83 | self.seek(0) | 85 | self.seek(0) |
2583 | 84 | 86 | ||
2585 | 85 | lines = self.readlines() | 87 | lines = [l.decode('us-ascii') for l in self.readlines()] |
2586 | 86 | 88 | ||
2587 | 87 | found = False | 89 | found = False |
2588 | 88 | for index, line in enumerate(lines): | 90 | for index, line in enumerate(lines): |
2589 | @@ -97,7 +99,7 @@ | |||
2590 | 97 | lines.remove(line) | 99 | lines.remove(line) |
2591 | 98 | 100 | ||
2592 | 99 | self.seek(0) | 101 | self.seek(0) |
2594 | 100 | self.write(''.join(lines)) | 102 | self.write(''.join(lines).encode('us-ascii')) |
2595 | 101 | self.truncate() | 103 | self.truncate() |
2596 | 102 | return True | 104 | return True |
2597 | 103 | 105 | ||
2598 | 104 | 106 | ||
2599 | === modified file 'hooks/charmhelpers/core/hookenv.py' | |||
2600 | --- hooks/charmhelpers/core/hookenv.py 2014-10-02 09:18:00 +0000 | |||
2601 | +++ hooks/charmhelpers/core/hookenv.py 2014-12-11 17:56:40 +0000 | |||
2602 | @@ -9,9 +9,14 @@ | |||
2603 | 9 | import yaml | 9 | import yaml |
2604 | 10 | import subprocess | 10 | import subprocess |
2605 | 11 | import sys | 11 | import sys |
2606 | 12 | import UserDict | ||
2607 | 13 | from subprocess import CalledProcessError | 12 | from subprocess import CalledProcessError |
2608 | 14 | 13 | ||
2609 | 14 | import six | ||
2610 | 15 | if not six.PY3: | ||
2611 | 16 | from UserDict import UserDict | ||
2612 | 17 | else: | ||
2613 | 18 | from collections import UserDict | ||
2614 | 19 | |||
2615 | 15 | CRITICAL = "CRITICAL" | 20 | CRITICAL = "CRITICAL" |
2616 | 16 | ERROR = "ERROR" | 21 | ERROR = "ERROR" |
2617 | 17 | WARNING = "WARNING" | 22 | WARNING = "WARNING" |
2618 | @@ -63,16 +68,18 @@ | |||
2619 | 63 | command = ['juju-log'] | 68 | command = ['juju-log'] |
2620 | 64 | if level: | 69 | if level: |
2621 | 65 | command += ['-l', level] | 70 | command += ['-l', level] |
2622 | 71 | if not isinstance(message, six.string_types): | ||
2623 | 72 | message = repr(message) | ||
2624 | 66 | command += [message] | 73 | command += [message] |
2625 | 67 | subprocess.call(command) | 74 | subprocess.call(command) |
2626 | 68 | 75 | ||
2627 | 69 | 76 | ||
2629 | 70 | class Serializable(UserDict.IterableUserDict): | 77 | class Serializable(UserDict): |
2630 | 71 | """Wrapper, an object that can be serialized to yaml or json""" | 78 | """Wrapper, an object that can be serialized to yaml or json""" |
2631 | 72 | 79 | ||
2632 | 73 | def __init__(self, obj): | 80 | def __init__(self, obj): |
2633 | 74 | # wrap the object | 81 | # wrap the object |
2635 | 75 | UserDict.IterableUserDict.__init__(self) | 82 | UserDict.__init__(self) |
2636 | 76 | self.data = obj | 83 | self.data = obj |
2637 | 77 | 84 | ||
2638 | 78 | def __getattr__(self, attr): | 85 | def __getattr__(self, attr): |
2639 | @@ -214,6 +221,12 @@ | |||
2640 | 214 | except KeyError: | 221 | except KeyError: |
2641 | 215 | return (self._prev_dict or {})[key] | 222 | return (self._prev_dict or {})[key] |
2642 | 216 | 223 | ||
2643 | 224 | def keys(self): | ||
2644 | 225 | prev_keys = [] | ||
2645 | 226 | if self._prev_dict is not None: | ||
2646 | 227 | prev_keys = self._prev_dict.keys() | ||
2647 | 228 | return list(set(prev_keys + list(dict.keys(self)))) | ||
2648 | 229 | |||
2649 | 217 | def load_previous(self, path=None): | 230 | def load_previous(self, path=None): |
2650 | 218 | """Load previous copy of config from disk. | 231 | """Load previous copy of config from disk. |
2651 | 219 | 232 | ||
2652 | @@ -263,7 +276,7 @@ | |||
2653 | 263 | 276 | ||
2654 | 264 | """ | 277 | """ |
2655 | 265 | if self._prev_dict: | 278 | if self._prev_dict: |
2657 | 266 | for k, v in self._prev_dict.iteritems(): | 279 | for k, v in six.iteritems(self._prev_dict): |
2658 | 267 | if k not in self: | 280 | if k not in self: |
2659 | 268 | self[k] = v | 281 | self[k] = v |
2660 | 269 | with open(self.path, 'w') as f: | 282 | with open(self.path, 'w') as f: |
2661 | @@ -278,7 +291,8 @@ | |||
2662 | 278 | config_cmd_line.append(scope) | 291 | config_cmd_line.append(scope) |
2663 | 279 | config_cmd_line.append('--format=json') | 292 | config_cmd_line.append('--format=json') |
2664 | 280 | try: | 293 | try: |
2666 | 281 | config_data = json.loads(subprocess.check_output(config_cmd_line)) | 294 | config_data = json.loads( |
2667 | 295 | subprocess.check_output(config_cmd_line).decode('UTF-8')) | ||
2668 | 282 | if scope is not None: | 296 | if scope is not None: |
2669 | 283 | return config_data | 297 | return config_data |
2670 | 284 | return Config(config_data) | 298 | return Config(config_data) |
2671 | @@ -297,10 +311,10 @@ | |||
2672 | 297 | if unit: | 311 | if unit: |
2673 | 298 | _args.append(unit) | 312 | _args.append(unit) |
2674 | 299 | try: | 313 | try: |
2676 | 300 | return json.loads(subprocess.check_output(_args)) | 314 | return json.loads(subprocess.check_output(_args).decode('UTF-8')) |
2677 | 301 | except ValueError: | 315 | except ValueError: |
2678 | 302 | return None | 316 | return None |
2680 | 303 | except CalledProcessError, e: | 317 | except CalledProcessError as e: |
2681 | 304 | if e.returncode == 2: | 318 | if e.returncode == 2: |
2682 | 305 | return None | 319 | return None |
2683 | 306 | raise | 320 | raise |
2684 | @@ -312,7 +326,7 @@ | |||
2685 | 312 | relation_cmd_line = ['relation-set'] | 326 | relation_cmd_line = ['relation-set'] |
2686 | 313 | if relation_id is not None: | 327 | if relation_id is not None: |
2687 | 314 | relation_cmd_line.extend(('-r', relation_id)) | 328 | relation_cmd_line.extend(('-r', relation_id)) |
2689 | 315 | for k, v in (relation_settings.items() + kwargs.items()): | 329 | for k, v in (list(relation_settings.items()) + list(kwargs.items())): |
2690 | 316 | if v is None: | 330 | if v is None: |
2691 | 317 | relation_cmd_line.append('{}='.format(k)) | 331 | relation_cmd_line.append('{}='.format(k)) |
2692 | 318 | else: | 332 | else: |
2693 | @@ -329,7 +343,8 @@ | |||
2694 | 329 | relid_cmd_line = ['relation-ids', '--format=json'] | 343 | relid_cmd_line = ['relation-ids', '--format=json'] |
2695 | 330 | if reltype is not None: | 344 | if reltype is not None: |
2696 | 331 | relid_cmd_line.append(reltype) | 345 | relid_cmd_line.append(reltype) |
2698 | 332 | return json.loads(subprocess.check_output(relid_cmd_line)) or [] | 346 | return json.loads( |
2699 | 347 | subprocess.check_output(relid_cmd_line).decode('UTF-8')) or [] | ||
2700 | 333 | return [] | 348 | return [] |
2701 | 334 | 349 | ||
2702 | 335 | 350 | ||
2703 | @@ -340,7 +355,8 @@ | |||
2704 | 340 | units_cmd_line = ['relation-list', '--format=json'] | 355 | units_cmd_line = ['relation-list', '--format=json'] |
2705 | 341 | if relid is not None: | 356 | if relid is not None: |
2706 | 342 | units_cmd_line.extend(('-r', relid)) | 357 | units_cmd_line.extend(('-r', relid)) |
2708 | 343 | return json.loads(subprocess.check_output(units_cmd_line)) or [] | 358 | return json.loads( |
2709 | 359 | subprocess.check_output(units_cmd_line).decode('UTF-8')) or [] | ||
2710 | 344 | 360 | ||
2711 | 345 | 361 | ||
2712 | 346 | @cached | 362 | @cached |
2713 | @@ -380,21 +396,31 @@ | |||
2714 | 380 | 396 | ||
2715 | 381 | 397 | ||
2716 | 382 | @cached | 398 | @cached |
2717 | 399 | def metadata(): | ||
2718 | 400 | """Get the current charm metadata.yaml contents as a python object""" | ||
2719 | 401 | with open(os.path.join(charm_dir(), 'metadata.yaml')) as md: | ||
2720 | 402 | return yaml.safe_load(md) | ||
2721 | 403 | |||
2722 | 404 | |||
2723 | 405 | @cached | ||
2724 | 383 | def relation_types(): | 406 | def relation_types(): |
2725 | 384 | """Get a list of relation types supported by this charm""" | 407 | """Get a list of relation types supported by this charm""" |
2726 | 385 | charmdir = os.environ.get('CHARM_DIR', '') | ||
2727 | 386 | mdf = open(os.path.join(charmdir, 'metadata.yaml')) | ||
2728 | 387 | md = yaml.safe_load(mdf) | ||
2729 | 388 | rel_types = [] | 408 | rel_types = [] |
2730 | 409 | md = metadata() | ||
2731 | 389 | for key in ('provides', 'requires', 'peers'): | 410 | for key in ('provides', 'requires', 'peers'): |
2732 | 390 | section = md.get(key) | 411 | section = md.get(key) |
2733 | 391 | if section: | 412 | if section: |
2734 | 392 | rel_types.extend(section.keys()) | 413 | rel_types.extend(section.keys()) |
2735 | 393 | mdf.close() | ||
2736 | 394 | return rel_types | 414 | return rel_types |
2737 | 395 | 415 | ||
2738 | 396 | 416 | ||
2739 | 397 | @cached | 417 | @cached |
2740 | 418 | def charm_name(): | ||
2741 | 419 | """Get the name of the current charm as is specified on metadata.yaml""" | ||
2742 | 420 | return metadata().get('name') | ||
2743 | 421 | |||
2744 | 422 | |||
2745 | 423 | @cached | ||
2746 | 398 | def relations(): | 424 | def relations(): |
2747 | 399 | """Get a nested dictionary of relation data for all related units""" | 425 | """Get a nested dictionary of relation data for all related units""" |
2748 | 400 | rels = {} | 426 | rels = {} |
2749 | @@ -449,7 +475,7 @@ | |||
2750 | 449 | """Get the unit ID for the remote unit""" | 475 | """Get the unit ID for the remote unit""" |
2751 | 450 | _args = ['unit-get', '--format=json', attribute] | 476 | _args = ['unit-get', '--format=json', attribute] |
2752 | 451 | try: | 477 | try: |
2754 | 452 | return json.loads(subprocess.check_output(_args)) | 478 | return json.loads(subprocess.check_output(_args).decode('UTF-8')) |
2755 | 453 | except ValueError: | 479 | except ValueError: |
2756 | 454 | return None | 480 | return None |
2757 | 455 | 481 | ||
2758 | 456 | 482 | ||
2759 | === modified file 'hooks/charmhelpers/core/host.py' | |||
2760 | --- hooks/charmhelpers/core/host.py 2014-10-02 09:18:00 +0000 | |||
2761 | +++ hooks/charmhelpers/core/host.py 2014-12-11 17:56:40 +0000 | |||
2762 | @@ -6,19 +6,20 @@ | |||
2763 | 6 | # Matthew Wedgwood <matthew.wedgwood@canonical.com> | 6 | # Matthew Wedgwood <matthew.wedgwood@canonical.com> |
2764 | 7 | 7 | ||
2765 | 8 | import os | 8 | import os |
2766 | 9 | import re | ||
2767 | 9 | import pwd | 10 | import pwd |
2768 | 10 | import grp | 11 | import grp |
2769 | 11 | import random | 12 | import random |
2770 | 12 | import string | 13 | import string |
2771 | 13 | import subprocess | 14 | import subprocess |
2772 | 14 | import hashlib | 15 | import hashlib |
2773 | 15 | import shutil | ||
2774 | 16 | from contextlib import contextmanager | 16 | from contextlib import contextmanager |
2775 | 17 | |||
2776 | 18 | from collections import OrderedDict | 17 | from collections import OrderedDict |
2777 | 19 | 18 | ||
2780 | 20 | from hookenv import log | 19 | import six |
2781 | 21 | from fstab import Fstab | 20 | |
2782 | 21 | from .hookenv import log | ||
2783 | 22 | from .fstab import Fstab | ||
2784 | 22 | 23 | ||
2785 | 23 | 24 | ||
2786 | 24 | def service_start(service_name): | 25 | def service_start(service_name): |
2787 | @@ -54,7 +55,9 @@ | |||
2788 | 54 | def service_running(service): | 55 | def service_running(service): |
2789 | 55 | """Determine whether a system service is running""" | 56 | """Determine whether a system service is running""" |
2790 | 56 | try: | 57 | try: |
2792 | 57 | output = subprocess.check_output(['service', service, 'status'], stderr=subprocess.STDOUT) | 58 | output = subprocess.check_output( |
2793 | 59 | ['service', service, 'status'], | ||
2794 | 60 | stderr=subprocess.STDOUT).decode('UTF-8') | ||
2795 | 58 | except subprocess.CalledProcessError: | 61 | except subprocess.CalledProcessError: |
2796 | 59 | return False | 62 | return False |
2797 | 60 | else: | 63 | else: |
2798 | @@ -67,7 +70,9 @@ | |||
2799 | 67 | def service_available(service_name): | 70 | def service_available(service_name): |
2800 | 68 | """Determine whether a system service is available""" | 71 | """Determine whether a system service is available""" |
2801 | 69 | try: | 72 | try: |
2803 | 70 | subprocess.check_output(['service', service_name, 'status'], stderr=subprocess.STDOUT) | 73 | subprocess.check_output( |
2804 | 74 | ['service', service_name, 'status'], | ||
2805 | 75 | stderr=subprocess.STDOUT).decode('UTF-8') | ||
2806 | 71 | except subprocess.CalledProcessError as e: | 76 | except subprocess.CalledProcessError as e: |
2807 | 72 | return 'unrecognized service' not in e.output | 77 | return 'unrecognized service' not in e.output |
2808 | 73 | else: | 78 | else: |
2809 | @@ -96,6 +101,26 @@ | |||
2810 | 96 | return user_info | 101 | return user_info |
2811 | 97 | 102 | ||
2812 | 98 | 103 | ||
2813 | 104 | def add_group(group_name, system_group=False): | ||
2814 | 105 | """Add a group to the system""" | ||
2815 | 106 | try: | ||
2816 | 107 | group_info = grp.getgrnam(group_name) | ||
2817 | 108 | log('group {0} already exists!'.format(group_name)) | ||
2818 | 109 | except KeyError: | ||
2819 | 110 | log('creating group {0}'.format(group_name)) | ||
2820 | 111 | cmd = ['addgroup'] | ||
2821 | 112 | if system_group: | ||
2822 | 113 | cmd.append('--system') | ||
2823 | 114 | else: | ||
2824 | 115 | cmd.extend([ | ||
2825 | 116 | '--group', | ||
2826 | 117 | ]) | ||
2827 | 118 | cmd.append(group_name) | ||
2828 | 119 | subprocess.check_call(cmd) | ||
2829 | 120 | group_info = grp.getgrnam(group_name) | ||
2830 | 121 | return group_info | ||
2831 | 122 | |||
2832 | 123 | |||
2833 | 99 | def add_user_to_group(username, group): | 124 | def add_user_to_group(username, group): |
2834 | 100 | """Add a user to a group""" | 125 | """Add a user to a group""" |
2835 | 101 | cmd = [ | 126 | cmd = [ |
2836 | @@ -115,7 +140,7 @@ | |||
2837 | 115 | cmd.append(from_path) | 140 | cmd.append(from_path) |
2838 | 116 | cmd.append(to_path) | 141 | cmd.append(to_path) |
2839 | 117 | log(" ".join(cmd)) | 142 | log(" ".join(cmd)) |
2841 | 118 | return subprocess.check_output(cmd).strip() | 143 | return subprocess.check_output(cmd).decode('UTF-8').strip() |
2842 | 119 | 144 | ||
2843 | 120 | 145 | ||
2844 | 121 | def symlink(source, destination): | 146 | def symlink(source, destination): |
2845 | @@ -130,7 +155,7 @@ | |||
2846 | 130 | subprocess.check_call(cmd) | 155 | subprocess.check_call(cmd) |
2847 | 131 | 156 | ||
2848 | 132 | 157 | ||
2850 | 133 | def mkdir(path, owner='root', group='root', perms=0555, force=False): | 158 | def mkdir(path, owner='root', group='root', perms=0o555, force=False): |
2851 | 134 | """Create a directory""" | 159 | """Create a directory""" |
2852 | 135 | log("Making dir {} {}:{} {:o}".format(path, owner, group, | 160 | log("Making dir {} {}:{} {:o}".format(path, owner, group, |
2853 | 136 | perms)) | 161 | perms)) |
2854 | @@ -146,7 +171,7 @@ | |||
2855 | 146 | os.chown(realpath, uid, gid) | 171 | os.chown(realpath, uid, gid) |
2856 | 147 | 172 | ||
2857 | 148 | 173 | ||
2859 | 149 | def write_file(path, content, owner='root', group='root', perms=0444): | 174 | def write_file(path, content, owner='root', group='root', perms=0o444): |
2860 | 150 | """Create or overwrite a file with the contents of a string""" | 175 | """Create or overwrite a file with the contents of a string""" |
2861 | 151 | log("Writing file {} {}:{} {:o}".format(path, owner, group, perms)) | 176 | log("Writing file {} {}:{} {:o}".format(path, owner, group, perms)) |
2862 | 152 | uid = pwd.getpwnam(owner).pw_uid | 177 | uid = pwd.getpwnam(owner).pw_uid |
2863 | @@ -177,7 +202,7 @@ | |||
2864 | 177 | cmd_args.extend([device, mountpoint]) | 202 | cmd_args.extend([device, mountpoint]) |
2865 | 178 | try: | 203 | try: |
2866 | 179 | subprocess.check_output(cmd_args) | 204 | subprocess.check_output(cmd_args) |
2868 | 180 | except subprocess.CalledProcessError, e: | 205 | except subprocess.CalledProcessError as e: |
2869 | 181 | log('Error mounting {} at {}\n{}'.format(device, mountpoint, e.output)) | 206 | log('Error mounting {} at {}\n{}'.format(device, mountpoint, e.output)) |
2870 | 182 | return False | 207 | return False |
2871 | 183 | 208 | ||
2872 | @@ -191,7 +216,7 @@ | |||
2873 | 191 | cmd_args = ['umount', mountpoint] | 216 | cmd_args = ['umount', mountpoint] |
2874 | 192 | try: | 217 | try: |
2875 | 193 | subprocess.check_output(cmd_args) | 218 | subprocess.check_output(cmd_args) |
2877 | 194 | except subprocess.CalledProcessError, e: | 219 | except subprocess.CalledProcessError as e: |
2878 | 195 | log('Error unmounting {}\n{}'.format(mountpoint, e.output)) | 220 | log('Error unmounting {}\n{}'.format(mountpoint, e.output)) |
2879 | 196 | return False | 221 | return False |
2880 | 197 | 222 | ||
2881 | @@ -218,8 +243,8 @@ | |||
2882 | 218 | """ | 243 | """ |
2883 | 219 | if os.path.exists(path): | 244 | if os.path.exists(path): |
2884 | 220 | h = getattr(hashlib, hash_type)() | 245 | h = getattr(hashlib, hash_type)() |
2887 | 221 | with open(path, 'r') as source: | 246 | with open(path, 'rb') as source: |
2888 | 222 | h.update(source.read()) # IGNORE:E1101 - it does have update | 247 | h.update(source.read()) |
2889 | 223 | return h.hexdigest() | 248 | return h.hexdigest() |
2890 | 224 | else: | 249 | else: |
2891 | 225 | return None | 250 | return None |
2892 | @@ -297,7 +322,7 @@ | |||
2893 | 297 | if length is None: | 322 | if length is None: |
2894 | 298 | length = random.choice(range(35, 45)) | 323 | length = random.choice(range(35, 45)) |
2895 | 299 | alphanumeric_chars = [ | 324 | alphanumeric_chars = [ |
2897 | 300 | l for l in (string.letters + string.digits) | 325 | l for l in (string.ascii_letters + string.digits) |
2898 | 301 | if l not in 'l0QD1vAEIOUaeiou'] | 326 | if l not in 'l0QD1vAEIOUaeiou'] |
2899 | 302 | random_chars = [ | 327 | random_chars = [ |
2900 | 303 | random.choice(alphanumeric_chars) for _ in range(length)] | 328 | random.choice(alphanumeric_chars) for _ in range(length)] |
2901 | @@ -306,18 +331,24 @@ | |||
2902 | 306 | 331 | ||
2903 | 307 | def list_nics(nic_type): | 332 | def list_nics(nic_type): |
2904 | 308 | '''Return a list of nics of given type(s)''' | 333 | '''Return a list of nics of given type(s)''' |
2906 | 309 | if isinstance(nic_type, basestring): | 334 | if isinstance(nic_type, six.string_types): |
2907 | 310 | int_types = [nic_type] | 335 | int_types = [nic_type] |
2908 | 311 | else: | 336 | else: |
2909 | 312 | int_types = nic_type | 337 | int_types = nic_type |
2910 | 313 | interfaces = [] | 338 | interfaces = [] |
2911 | 314 | for int_type in int_types: | 339 | for int_type in int_types: |
2912 | 315 | cmd = ['ip', 'addr', 'show', 'label', int_type + '*'] | 340 | cmd = ['ip', 'addr', 'show', 'label', int_type + '*'] |
2914 | 316 | ip_output = subprocess.check_output(cmd).split('\n') | 341 | ip_output = subprocess.check_output(cmd).decode('UTF-8').split('\n') |
2915 | 317 | ip_output = (line for line in ip_output if line) | 342 | ip_output = (line for line in ip_output if line) |
2916 | 318 | for line in ip_output: | 343 | for line in ip_output: |
2917 | 319 | if line.split()[1].startswith(int_type): | 344 | if line.split()[1].startswith(int_type): |
2919 | 320 | interfaces.append(line.split()[1].replace(":", "")) | 345 | matched = re.search('.*: (bond[0-9]+\.[0-9]+)@.*', line) |
2920 | 346 | if matched: | ||
2921 | 347 | interface = matched.groups()[0] | ||
2922 | 348 | else: | ||
2923 | 349 | interface = line.split()[1].replace(":", "") | ||
2924 | 350 | interfaces.append(interface) | ||
2925 | 351 | |||
2926 | 321 | return interfaces | 352 | return interfaces |
2927 | 322 | 353 | ||
2928 | 323 | 354 | ||
2929 | @@ -329,7 +360,7 @@ | |||
2930 | 329 | 360 | ||
2931 | 330 | def get_nic_mtu(nic): | 361 | def get_nic_mtu(nic): |
2932 | 331 | cmd = ['ip', 'addr', 'show', nic] | 362 | cmd = ['ip', 'addr', 'show', nic] |
2934 | 332 | ip_output = subprocess.check_output(cmd).split('\n') | 363 | ip_output = subprocess.check_output(cmd).decode('UTF-8').split('\n') |
2935 | 333 | mtu = "" | 364 | mtu = "" |
2936 | 334 | for line in ip_output: | 365 | for line in ip_output: |
2937 | 335 | words = line.split() | 366 | words = line.split() |
2938 | @@ -340,7 +371,7 @@ | |||
2939 | 340 | 371 | ||
2940 | 341 | def get_nic_hwaddr(nic): | 372 | def get_nic_hwaddr(nic): |
2941 | 342 | cmd = ['ip', '-o', '-0', 'addr', 'show', nic] | 373 | cmd = ['ip', '-o', '-0', 'addr', 'show', nic] |
2943 | 343 | ip_output = subprocess.check_output(cmd) | 374 | ip_output = subprocess.check_output(cmd).decode('UTF-8') |
2944 | 344 | hwaddr = "" | 375 | hwaddr = "" |
2945 | 345 | words = ip_output.split() | 376 | words = ip_output.split() |
2946 | 346 | if 'link/ether' in words: | 377 | if 'link/ether' in words: |
2947 | @@ -357,8 +388,8 @@ | |||
2948 | 357 | 388 | ||
2949 | 358 | ''' | 389 | ''' |
2950 | 359 | import apt_pkg | 390 | import apt_pkg |
2951 | 360 | from charmhelpers.fetch import apt_cache | ||
2952 | 361 | if not pkgcache: | 391 | if not pkgcache: |
2953 | 392 | from charmhelpers.fetch import apt_cache | ||
2954 | 362 | pkgcache = apt_cache() | 393 | pkgcache = apt_cache() |
2955 | 363 | pkg = pkgcache[package] | 394 | pkg = pkgcache[package] |
2956 | 364 | return apt_pkg.version_compare(pkg.current_ver.ver_str, revno) | 395 | return apt_pkg.version_compare(pkg.current_ver.ver_str, revno) |
2957 | 365 | 396 | ||
2958 | === modified file 'hooks/charmhelpers/core/services/__init__.py' | |||
2959 | --- hooks/charmhelpers/core/services/__init__.py 2014-09-19 16:52:38 +0000 | |||
2960 | +++ hooks/charmhelpers/core/services/__init__.py 2014-12-11 17:56:40 +0000 | |||
2961 | @@ -1,2 +1,2 @@ | |||
2964 | 1 | from .base import * | 1 | from .base import * # NOQA |
2965 | 2 | from .helpers import * | 2 | from .helpers import * # NOQA |
2966 | 3 | 3 | ||
2967 | === modified file 'hooks/charmhelpers/core/services/helpers.py' | |||
2968 | --- hooks/charmhelpers/core/services/helpers.py 2014-09-22 20:21:38 +0000 | |||
2969 | +++ hooks/charmhelpers/core/services/helpers.py 2014-12-11 17:56:40 +0000 | |||
2970 | @@ -196,7 +196,7 @@ | |||
2971 | 196 | if not os.path.isabs(file_name): | 196 | if not os.path.isabs(file_name): |
2972 | 197 | file_name = os.path.join(hookenv.charm_dir(), file_name) | 197 | file_name = os.path.join(hookenv.charm_dir(), file_name) |
2973 | 198 | with open(file_name, 'w') as file_stream: | 198 | with open(file_name, 'w') as file_stream: |
2975 | 199 | os.fchmod(file_stream.fileno(), 0600) | 199 | os.fchmod(file_stream.fileno(), 0o600) |
2976 | 200 | yaml.dump(config_data, file_stream) | 200 | yaml.dump(config_data, file_stream) |
2977 | 201 | 201 | ||
2978 | 202 | def read_context(self, file_name): | 202 | def read_context(self, file_name): |
2979 | @@ -211,15 +211,19 @@ | |||
2980 | 211 | 211 | ||
2981 | 212 | class TemplateCallback(ManagerCallback): | 212 | class TemplateCallback(ManagerCallback): |
2982 | 213 | """ | 213 | """ |
2986 | 214 | Callback class that will render a Jinja2 template, for use as a ready action. | 214 | Callback class that will render a Jinja2 template, for use as a ready |
2987 | 215 | 215 | action. | |
2988 | 216 | :param str source: The template source file, relative to `$CHARM_DIR/templates` | 216 | |
2989 | 217 | :param str source: The template source file, relative to | ||
2990 | 218 | `$CHARM_DIR/templates` | ||
2991 | 219 | |||
2992 | 217 | :param str target: The target to write the rendered template to | 220 | :param str target: The target to write the rendered template to |
2993 | 218 | :param str owner: The owner of the rendered file | 221 | :param str owner: The owner of the rendered file |
2994 | 219 | :param str group: The group of the rendered file | 222 | :param str group: The group of the rendered file |
2995 | 220 | :param int perms: The permissions of the rendered file | 223 | :param int perms: The permissions of the rendered file |
2996 | 221 | """ | 224 | """ |
2998 | 222 | def __init__(self, source, target, owner='root', group='root', perms=0444): | 225 | def __init__(self, source, target, |
2999 | 226 | owner='root', group='root', perms=0o444): | ||
3000 | 223 | self.source = source | 227 | self.source = source |
3001 | 224 | self.target = target | 228 | self.target = target |
3002 | 225 | self.owner = owner | 229 | self.owner = owner |
3003 | 226 | 230 | ||
3004 | === modified file 'hooks/charmhelpers/core/templating.py' | |||
3005 | --- hooks/charmhelpers/core/templating.py 2014-09-19 16:52:38 +0000 | |||
3006 | +++ hooks/charmhelpers/core/templating.py 2014-12-11 17:56:40 +0000 | |||
3007 | @@ -4,7 +4,8 @@ | |||
3008 | 4 | from charmhelpers.core import hookenv | 4 | from charmhelpers.core import hookenv |
3009 | 5 | 5 | ||
3010 | 6 | 6 | ||
3012 | 7 | def render(source, target, context, owner='root', group='root', perms=0444, templates_dir=None): | 7 | def render(source, target, context, owner='root', group='root', |
3013 | 8 | perms=0o444, templates_dir=None): | ||
3014 | 8 | """ | 9 | """ |
3015 | 9 | Render a template. | 10 | Render a template. |
3016 | 10 | 11 | ||
3017 | 11 | 12 | ||
3018 | === modified file 'hooks/charmhelpers/fetch/__init__.py' | |||
3019 | --- hooks/charmhelpers/fetch/__init__.py 2014-10-02 09:18:00 +0000 | |||
3020 | +++ hooks/charmhelpers/fetch/__init__.py 2014-12-11 17:56:40 +0000 | |||
3021 | @@ -5,10 +5,6 @@ | |||
3022 | 5 | from charmhelpers.core.host import ( | 5 | from charmhelpers.core.host import ( |
3023 | 6 | lsb_release | 6 | lsb_release |
3024 | 7 | ) | 7 | ) |
3025 | 8 | from urlparse import ( | ||
3026 | 9 | urlparse, | ||
3027 | 10 | urlunparse, | ||
3028 | 11 | ) | ||
3029 | 12 | import subprocess | 8 | import subprocess |
3030 | 13 | from charmhelpers.core.hookenv import ( | 9 | from charmhelpers.core.hookenv import ( |
3031 | 14 | config, | 10 | config, |
3032 | @@ -16,6 +12,12 @@ | |||
3033 | 16 | ) | 12 | ) |
3034 | 17 | import os | 13 | import os |
3035 | 18 | 14 | ||
3036 | 15 | import six | ||
3037 | 16 | if six.PY3: | ||
3038 | 17 | from urllib.parse import urlparse, urlunparse | ||
3039 | 18 | else: | ||
3040 | 19 | from urlparse import urlparse, urlunparse | ||
3041 | 20 | |||
3042 | 19 | 21 | ||
3043 | 20 | CLOUD_ARCHIVE = """# Ubuntu Cloud Archive | 22 | CLOUD_ARCHIVE = """# Ubuntu Cloud Archive |
3044 | 21 | deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main | 23 | deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main |
3045 | @@ -72,6 +74,7 @@ | |||
3046 | 72 | FETCH_HANDLERS = ( | 74 | FETCH_HANDLERS = ( |
3047 | 73 | 'charmhelpers.fetch.archiveurl.ArchiveUrlFetchHandler', | 75 | 'charmhelpers.fetch.archiveurl.ArchiveUrlFetchHandler', |
3048 | 74 | 'charmhelpers.fetch.bzrurl.BzrUrlFetchHandler', | 76 | 'charmhelpers.fetch.bzrurl.BzrUrlFetchHandler', |
3049 | 77 | 'charmhelpers.fetch.giturl.GitUrlFetchHandler', | ||
3050 | 75 | ) | 78 | ) |
3051 | 76 | 79 | ||
3052 | 77 | APT_NO_LOCK = 100 # The return code for "couldn't acquire lock" in APT. | 80 | APT_NO_LOCK = 100 # The return code for "couldn't acquire lock" in APT. |
3053 | @@ -148,7 +151,7 @@ | |||
3054 | 148 | cmd = ['apt-get', '--assume-yes'] | 151 | cmd = ['apt-get', '--assume-yes'] |
3055 | 149 | cmd.extend(options) | 152 | cmd.extend(options) |
3056 | 150 | cmd.append('install') | 153 | cmd.append('install') |
3058 | 151 | if isinstance(packages, basestring): | 154 | if isinstance(packages, six.string_types): |
3059 | 152 | cmd.append(packages) | 155 | cmd.append(packages) |
3060 | 153 | else: | 156 | else: |
3061 | 154 | cmd.extend(packages) | 157 | cmd.extend(packages) |
3062 | @@ -181,7 +184,7 @@ | |||
3063 | 181 | def apt_purge(packages, fatal=False): | 184 | def apt_purge(packages, fatal=False): |
3064 | 182 | """Purge one or more packages""" | 185 | """Purge one or more packages""" |
3065 | 183 | cmd = ['apt-get', '--assume-yes', 'purge'] | 186 | cmd = ['apt-get', '--assume-yes', 'purge'] |
3067 | 184 | if isinstance(packages, basestring): | 187 | if isinstance(packages, six.string_types): |
3068 | 185 | cmd.append(packages) | 188 | cmd.append(packages) |
3069 | 186 | else: | 189 | else: |
3070 | 187 | cmd.extend(packages) | 190 | cmd.extend(packages) |
3071 | @@ -192,7 +195,7 @@ | |||
3072 | 192 | def apt_hold(packages, fatal=False): | 195 | def apt_hold(packages, fatal=False): |
3073 | 193 | """Hold one or more packages""" | 196 | """Hold one or more packages""" |
3074 | 194 | cmd = ['apt-mark', 'hold'] | 197 | cmd = ['apt-mark', 'hold'] |
3076 | 195 | if isinstance(packages, basestring): | 198 | if isinstance(packages, six.string_types): |
3077 | 196 | cmd.append(packages) | 199 | cmd.append(packages) |
3078 | 197 | else: | 200 | else: |
3079 | 198 | cmd.extend(packages) | 201 | cmd.extend(packages) |
3080 | @@ -218,6 +221,7 @@ | |||
3081 | 218 | pocket for the release. | 221 | pocket for the release. |
3082 | 219 | 'cloud:' may be used to activate official cloud archive pockets, | 222 | 'cloud:' may be used to activate official cloud archive pockets, |
3083 | 220 | such as 'cloud:icehouse' | 223 | such as 'cloud:icehouse' |
3084 | 224 | 'distro' may be used as a noop | ||
3085 | 221 | 225 | ||
3086 | 222 | @param key: A key to be added to the system's APT keyring and used | 226 | @param key: A key to be added to the system's APT keyring and used |
3087 | 223 | to verify the signatures on packages. Ideally, this should be an | 227 | to verify the signatures on packages. Ideally, this should be an |
3088 | @@ -251,12 +255,14 @@ | |||
3089 | 251 | release = lsb_release()['DISTRIB_CODENAME'] | 255 | release = lsb_release()['DISTRIB_CODENAME'] |
3090 | 252 | with open('/etc/apt/sources.list.d/proposed.list', 'w') as apt: | 256 | with open('/etc/apt/sources.list.d/proposed.list', 'w') as apt: |
3091 | 253 | apt.write(PROPOSED_POCKET.format(release)) | 257 | apt.write(PROPOSED_POCKET.format(release)) |
3092 | 258 | elif source == 'distro': | ||
3093 | 259 | pass | ||
3094 | 254 | else: | 260 | else: |
3096 | 255 | raise SourceConfigError("Unknown source: {!r}".format(source)) | 261 | log("Unknown source: {!r}".format(source)) |
3097 | 256 | 262 | ||
3098 | 257 | if key: | 263 | if key: |
3099 | 258 | if '-----BEGIN PGP PUBLIC KEY BLOCK-----' in key: | 264 | if '-----BEGIN PGP PUBLIC KEY BLOCK-----' in key: |
3101 | 259 | with NamedTemporaryFile() as key_file: | 265 | with NamedTemporaryFile('w+') as key_file: |
3102 | 260 | key_file.write(key) | 266 | key_file.write(key) |
3103 | 261 | key_file.flush() | 267 | key_file.flush() |
3104 | 262 | key_file.seek(0) | 268 | key_file.seek(0) |
3105 | @@ -293,14 +299,14 @@ | |||
3106 | 293 | sources = safe_load((config(sources_var) or '').strip()) or [] | 299 | sources = safe_load((config(sources_var) or '').strip()) or [] |
3107 | 294 | keys = safe_load((config(keys_var) or '').strip()) or None | 300 | keys = safe_load((config(keys_var) or '').strip()) or None |
3108 | 295 | 301 | ||
3110 | 296 | if isinstance(sources, basestring): | 302 | if isinstance(sources, six.string_types): |
3111 | 297 | sources = [sources] | 303 | sources = [sources] |
3112 | 298 | 304 | ||
3113 | 299 | if keys is None: | 305 | if keys is None: |
3114 | 300 | for source in sources: | 306 | for source in sources: |
3115 | 301 | add_source(source, None) | 307 | add_source(source, None) |
3116 | 302 | else: | 308 | else: |
3118 | 303 | if isinstance(keys, basestring): | 309 | if isinstance(keys, six.string_types): |
3119 | 304 | keys = [keys] | 310 | keys = [keys] |
3120 | 305 | 311 | ||
3121 | 306 | if len(sources) != len(keys): | 312 | if len(sources) != len(keys): |
3122 | @@ -397,7 +403,7 @@ | |||
3123 | 397 | while result is None or result == APT_NO_LOCK: | 403 | while result is None or result == APT_NO_LOCK: |
3124 | 398 | try: | 404 | try: |
3125 | 399 | result = subprocess.check_call(cmd, env=env) | 405 | result = subprocess.check_call(cmd, env=env) |
3127 | 400 | except subprocess.CalledProcessError, e: | 406 | except subprocess.CalledProcessError as e: |
3128 | 401 | retry_count = retry_count + 1 | 407 | retry_count = retry_count + 1 |
3129 | 402 | if retry_count > APT_NO_LOCK_RETRY_COUNT: | 408 | if retry_count > APT_NO_LOCK_RETRY_COUNT: |
3130 | 403 | raise | 409 | raise |
3131 | 404 | 410 | ||
3132 | === modified file 'hooks/charmhelpers/fetch/archiveurl.py' | |||
3133 | --- hooks/charmhelpers/fetch/archiveurl.py 2014-10-02 09:18:00 +0000 | |||
3134 | +++ hooks/charmhelpers/fetch/archiveurl.py 2014-12-11 17:56:40 +0000 | |||
3135 | @@ -1,8 +1,23 @@ | |||
3136 | 1 | import os | 1 | import os |
3137 | 2 | import urllib2 | ||
3138 | 3 | from urllib import urlretrieve | ||
3139 | 4 | import urlparse | ||
3140 | 5 | import hashlib | 2 | import hashlib |
3141 | 3 | import re | ||
3142 | 4 | |||
3143 | 5 | import six | ||
3144 | 6 | if six.PY3: | ||
3145 | 7 | from urllib.request import ( | ||
3146 | 8 | build_opener, install_opener, urlopen, urlretrieve, | ||
3147 | 9 | HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler, | ||
3148 | 10 | ) | ||
3149 | 11 | from urllib.parse import urlparse, urlunparse, parse_qs | ||
3150 | 12 | from urllib.error import URLError | ||
3151 | 13 | else: | ||
3152 | 14 | from urllib import urlretrieve | ||
3153 | 15 | from urllib2 import ( | ||
3154 | 16 | build_opener, install_opener, urlopen, | ||
3155 | 17 | HTTPPasswordMgrWithDefaultRealm, HTTPBasicAuthHandler, | ||
3156 | 18 | URLError | ||
3157 | 19 | ) | ||
3158 | 20 | from urlparse import urlparse, urlunparse, parse_qs | ||
3159 | 6 | 21 | ||
3160 | 7 | from charmhelpers.fetch import ( | 22 | from charmhelpers.fetch import ( |
3161 | 8 | BaseFetchHandler, | 23 | BaseFetchHandler, |
3162 | @@ -15,6 +30,24 @@ | |||
3163 | 15 | from charmhelpers.core.host import mkdir, check_hash | 30 | from charmhelpers.core.host import mkdir, check_hash |
3164 | 16 | 31 | ||
3165 | 17 | 32 | ||
3166 | 33 | def splituser(host): | ||
3167 | 34 | '''urllib.splituser(), but six's support of this seems broken''' | ||
3168 | 35 | _userprog = re.compile('^(.*)@(.*)$') | ||
3169 | 36 | match = _userprog.match(host) | ||
3170 | 37 | if match: | ||
3171 | 38 | return match.group(1, 2) | ||
3172 | 39 | return None, host | ||
3173 | 40 | |||
3174 | 41 | |||
3175 | 42 | def splitpasswd(user): | ||
3176 | 43 | '''urllib.splitpasswd(), but six's support of this is missing''' | ||
3177 | 44 | _passwdprog = re.compile('^([^:]*):(.*)$', re.S) | ||
3178 | 45 | match = _passwdprog.match(user) | ||
3179 | 46 | if match: | ||
3180 | 47 | return match.group(1, 2) | ||
3181 | 48 | return user, None | ||
3182 | 49 | |||
3183 | 50 | |||
3184 | 18 | class ArchiveUrlFetchHandler(BaseFetchHandler): | 51 | class ArchiveUrlFetchHandler(BaseFetchHandler): |
3185 | 19 | """ | 52 | """ |
3186 | 20 | Handler to download archive files from arbitrary URLs. | 53 | Handler to download archive files from arbitrary URLs. |
3187 | @@ -42,20 +75,20 @@ | |||
3188 | 42 | """ | 75 | """ |
3189 | 43 | # propogate all exceptions | 76 | # propogate all exceptions |
3190 | 44 | # URLError, OSError, etc | 77 | # URLError, OSError, etc |
3192 | 45 | proto, netloc, path, params, query, fragment = urlparse.urlparse(source) | 78 | proto, netloc, path, params, query, fragment = urlparse(source) |
3193 | 46 | if proto in ('http', 'https'): | 79 | if proto in ('http', 'https'): |
3195 | 47 | auth, barehost = urllib2.splituser(netloc) | 80 | auth, barehost = splituser(netloc) |
3196 | 48 | if auth is not None: | 81 | if auth is not None: |
3200 | 49 | source = urlparse.urlunparse((proto, barehost, path, params, query, fragment)) | 82 | source = urlunparse((proto, barehost, path, params, query, fragment)) |
3201 | 50 | username, password = urllib2.splitpasswd(auth) | 83 | username, password = splitpasswd(auth) |
3202 | 51 | passman = urllib2.HTTPPasswordMgrWithDefaultRealm() | 84 | passman = HTTPPasswordMgrWithDefaultRealm() |
3203 | 52 | # Realm is set to None in add_password to force the username and password | 85 | # Realm is set to None in add_password to force the username and password |
3204 | 53 | # to be used whatever the realm | 86 | # to be used whatever the realm |
3205 | 54 | passman.add_password(None, source, username, password) | 87 | passman.add_password(None, source, username, password) |
3210 | 55 | authhandler = urllib2.HTTPBasicAuthHandler(passman) | 88 | authhandler = HTTPBasicAuthHandler(passman) |
3211 | 56 | opener = urllib2.build_opener(authhandler) | 89 | opener = build_opener(authhandler) |
3212 | 57 | urllib2.install_opener(opener) | 90 | install_opener(opener) |
3213 | 58 | response = urllib2.urlopen(source) | 91 | response = urlopen(source) |
3214 | 59 | try: | 92 | try: |
3215 | 60 | with open(dest, 'w') as dest_file: | 93 | with open(dest, 'w') as dest_file: |
3216 | 61 | dest_file.write(response.read()) | 94 | dest_file.write(response.read()) |
3217 | @@ -91,17 +124,21 @@ | |||
3218 | 91 | url_parts = self.parse_url(source) | 124 | url_parts = self.parse_url(source) |
3219 | 92 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), 'fetched') | 125 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), 'fetched') |
3220 | 93 | if not os.path.exists(dest_dir): | 126 | if not os.path.exists(dest_dir): |
3222 | 94 | mkdir(dest_dir, perms=0755) | 127 | mkdir(dest_dir, perms=0o755) |
3223 | 95 | dld_file = os.path.join(dest_dir, os.path.basename(url_parts.path)) | 128 | dld_file = os.path.join(dest_dir, os.path.basename(url_parts.path)) |
3224 | 96 | try: | 129 | try: |
3225 | 97 | self.download(source, dld_file) | 130 | self.download(source, dld_file) |
3227 | 98 | except urllib2.URLError as e: | 131 | except URLError as e: |
3228 | 99 | raise UnhandledSource(e.reason) | 132 | raise UnhandledSource(e.reason) |
3229 | 100 | except OSError as e: | 133 | except OSError as e: |
3230 | 101 | raise UnhandledSource(e.strerror) | 134 | raise UnhandledSource(e.strerror) |
3232 | 102 | options = urlparse.parse_qs(url_parts.fragment) | 135 | options = parse_qs(url_parts.fragment) |
3233 | 103 | for key, value in options.items(): | 136 | for key, value in options.items(): |
3235 | 104 | if key in hashlib.algorithms: | 137 | if not six.PY3: |
3236 | 138 | algorithms = hashlib.algorithms | ||
3237 | 139 | else: | ||
3238 | 140 | algorithms = hashlib.algorithms_available | ||
3239 | 141 | if key in algorithms: | ||
3240 | 105 | check_hash(dld_file, value, key) | 142 | check_hash(dld_file, value, key) |
3241 | 106 | if checksum: | 143 | if checksum: |
3242 | 107 | check_hash(dld_file, checksum, hash_type) | 144 | check_hash(dld_file, checksum, hash_type) |
3243 | 108 | 145 | ||
3244 | === modified file 'hooks/charmhelpers/fetch/bzrurl.py' | |||
3245 | --- hooks/charmhelpers/fetch/bzrurl.py 2014-06-24 11:05:17 +0000 | |||
3246 | +++ hooks/charmhelpers/fetch/bzrurl.py 2014-12-11 17:56:40 +0000 | |||
3247 | @@ -5,6 +5,10 @@ | |||
3248 | 5 | ) | 5 | ) |
3249 | 6 | from charmhelpers.core.host import mkdir | 6 | from charmhelpers.core.host import mkdir |
3250 | 7 | 7 | ||
3251 | 8 | import six | ||
3252 | 9 | if six.PY3: | ||
3253 | 10 | raise ImportError('bzrlib does not support Python3') | ||
3254 | 11 | |||
3255 | 8 | try: | 12 | try: |
3256 | 9 | from bzrlib.branch import Branch | 13 | from bzrlib.branch import Branch |
3257 | 10 | except ImportError: | 14 | except ImportError: |
3258 | @@ -42,7 +46,7 @@ | |||
3259 | 42 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", | 46 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", |
3260 | 43 | branch_name) | 47 | branch_name) |
3261 | 44 | if not os.path.exists(dest_dir): | 48 | if not os.path.exists(dest_dir): |
3263 | 45 | mkdir(dest_dir, perms=0755) | 49 | mkdir(dest_dir, perms=0o755) |
3264 | 46 | try: | 50 | try: |
3265 | 47 | self.branch(source, dest_dir) | 51 | self.branch(source, dest_dir) |
3266 | 48 | except OSError as e: | 52 | except OSError as e: |
3267 | 49 | 53 | ||
3268 | === added file 'hooks/charmhelpers/fetch/giturl.py' | |||
3269 | --- hooks/charmhelpers/fetch/giturl.py 1970-01-01 00:00:00 +0000 | |||
3270 | +++ hooks/charmhelpers/fetch/giturl.py 2014-12-11 17:56:40 +0000 | |||
3271 | @@ -0,0 +1,51 @@ | |||
3272 | 1 | import os | ||
3273 | 2 | from charmhelpers.fetch import ( | ||
3274 | 3 | BaseFetchHandler, | ||
3275 | 4 | UnhandledSource | ||
3276 | 5 | ) | ||
3277 | 6 | from charmhelpers.core.host import mkdir | ||
3278 | 7 | |||
3279 | 8 | import six | ||
3280 | 9 | if six.PY3: | ||
3281 | 10 | raise ImportError('GitPython does not support Python 3') | ||
3282 | 11 | |||
3283 | 12 | try: | ||
3284 | 13 | from git import Repo | ||
3285 | 14 | except ImportError: | ||
3286 | 15 | from charmhelpers.fetch import apt_install | ||
3287 | 16 | apt_install("python-git") | ||
3288 | 17 | from git import Repo | ||
3289 | 18 | |||
3290 | 19 | |||
3291 | 20 | class GitUrlFetchHandler(BaseFetchHandler): | ||
3292 | 21 | """Handler for git branches via generic and github URLs""" | ||
3293 | 22 | def can_handle(self, source): | ||
3294 | 23 | url_parts = self.parse_url(source) | ||
3295 | 24 | # TODO (mattyw) no support for ssh git@ yet | ||
3296 | 25 | if url_parts.scheme not in ('http', 'https', 'git'): | ||
3297 | 26 | return False | ||
3298 | 27 | else: | ||
3299 | 28 | return True | ||
3300 | 29 | |||
3301 | 30 | def clone(self, source, dest, branch): | ||
3302 | 31 | if not self.can_handle(source): | ||
3303 | 32 | raise UnhandledSource("Cannot handle {}".format(source)) | ||
3304 | 33 | |||
3305 | 34 | repo = Repo.clone_from(source, dest) | ||
3306 | 35 | repo.git.checkout(branch) | ||
3307 | 36 | |||
3308 | 37 | def install(self, source, branch="master", dest=None): | ||
3309 | 38 | url_parts = self.parse_url(source) | ||
3310 | 39 | branch_name = url_parts.path.strip("/").split("/")[-1] | ||
3311 | 40 | if dest: | ||
3312 | 41 | dest_dir = os.path.join(dest, branch_name) | ||
3313 | 42 | else: | ||
3314 | 43 | dest_dir = os.path.join(os.environ.get('CHARM_DIR'), "fetched", | ||
3315 | 44 | branch_name) | ||
3316 | 45 | if not os.path.exists(dest_dir): | ||
3317 | 46 | mkdir(dest_dir, perms=0o755) | ||
3318 | 47 | try: | ||
3319 | 48 | self.clone(source, dest_dir, branch) | ||
3320 | 49 | except OSError as e: | ||
3321 | 50 | raise UnhandledSource(e.strerror) | ||
3322 | 51 | return dest_dir |
charm_lint_check #165 neutron-api-next for corey.bryant mp244325
LINT OK: passed
Build: http:// 10.230. 18.80:8080/ job/charm_ lint_check/ 165/