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