OLD | NEW |
1 # This file is part of the Juju GUI, which lets users view and manage Juju | 1 # This file is part of the Juju GUI, which lets users view and manage Juju |
2 # environments within a graphical interface (https://launchpad.net/juju-gui). | 2 # environments within a graphical interface (https://launchpad.net/juju-gui). |
3 # Copyright (C) 2012-2013 Canonical Ltd. | 3 # Copyright (C) 2012-2013 Canonical Ltd. |
4 # | 4 # |
5 # This program is free software: you can redistribute it and/or modify it under | 5 # This program is free software: you can redistribute it and/or modify it under |
6 # the terms of the GNU Affero General Public License version 3, as published by | 6 # the terms of the GNU Affero General Public License version 3, as published by |
7 # the Free Software Foundation. | 7 # the Free Software Foundation. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, but WITHOUT | 9 # This program is distributed in the hope that it will be useful, but WITHOUT |
10 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, | 10 # ANY WARRANTY; without even the implied warranties of MERCHANTABILITY, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 import json | 67 import json |
68 import os | 68 import os |
69 import logging | 69 import logging |
70 import re | 70 import re |
71 import shutil | 71 import shutil |
72 from subprocess import CalledProcessError | 72 from subprocess import CalledProcessError |
73 import tempfile | 73 import tempfile |
74 import urlparse | 74 import urlparse |
75 | 75 |
76 import apt | 76 import apt |
| 77 from launchpadlib.launchpad import Launchpad |
77 import tempita | 78 import tempita |
| 79 import yaml |
78 | 80 |
79 from launchpadlib.launchpad import Launchpad | 81 from charmhelpers import ( |
| 82 get_config, |
| 83 log, |
| 84 RESTART, |
| 85 service_control, |
| 86 START, |
| 87 STOP, |
| 88 unit_get, |
| 89 ) |
80 from shelltoolbox import ( | 90 from shelltoolbox import ( |
81 Serializer, | |
82 apt_get_install, | 91 apt_get_install, |
83 command, | 92 command, |
84 environ, | 93 environ, |
85 install_extra_repositories, | 94 install_extra_repositories, |
86 run, | 95 run, |
87 script_name, | 96 script_name, |
88 search_file, | 97 search_file, |
| 98 Serializer, |
89 su, | 99 su, |
90 ) | 100 ) |
91 from charmhelpers import ( | |
92 RESTART, | |
93 START, | |
94 STOP, | |
95 get_config, | |
96 log, | |
97 service_control, | |
98 unit_get, | |
99 ) | |
100 | 101 |
101 | 102 |
102 AGENT = 'juju-api-agent' | 103 AGENT = 'juju-api-agent' |
103 APACHE = 'apache2' | 104 APACHE = 'apache2' |
104 BUILTIN_SERVER = 'guiserver' | 105 BUILTIN_SERVER = 'guiserver' |
105 HAPROXY = 'haproxy' | 106 HAPROXY = 'haproxy' |
106 IMPROV = 'juju-api-improv' | 107 IMPROV = 'juju-api-improv' |
107 | 108 |
108 API_PORT = 8080 | 109 API_PORT = 8080 |
109 WEB_PORT = 8000 | 110 WEB_PORT = 8000 |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 167 |
167 If not present in the hook context as an environment variable, try to | 168 If not present in the hook context as an environment variable, try to |
168 retrieve the address parsing the machiner agent.conf file. | 169 retrieve the address parsing the machiner agent.conf file. |
169 """ | 170 """ |
170 api_addresses = os.getenv('JUJU_API_ADDRESSES') | 171 api_addresses = os.getenv('JUJU_API_ADDRESSES') |
171 if api_addresses is not None: | 172 if api_addresses is not None: |
172 return api_addresses.split()[0] | 173 return api_addresses.split()[0] |
173 # The JUJU_API_ADDRESSES environment variable is not included in the hooks | 174 # The JUJU_API_ADDRESSES environment variable is not included in the hooks |
174 # context in older releases of juju-core. Retrieve it from the machiner | 175 # context in older releases of juju-core. Retrieve it from the machiner |
175 # agent file instead. | 176 # agent file instead. |
176 import yaml # python-yaml is only installed if juju-core is used. | |
177 if unit_dir is None: | 177 if unit_dir is None: |
178 base_dir = os.path.join(CURRENT_DIR, '..', '..') | 178 base_dir = os.path.join(CURRENT_DIR, '..', '..') |
179 else: | 179 else: |
180 base_dir = os.path.join(unit_dir, '..') | 180 base_dir = os.path.join(unit_dir, '..') |
181 base_dir = os.path.abspath(base_dir) | 181 base_dir = os.path.abspath(base_dir) |
182 for dirname in os.listdir(base_dir): | 182 for dirname in os.listdir(base_dir): |
183 if dirname.startswith('machine-'): | 183 if dirname.startswith('machine-'): |
184 agent_conf = os.path.join(base_dir, dirname, 'agent.conf') | 184 agent_conf = os.path.join(base_dir, dirname, 'agent.conf') |
185 break | 185 break |
186 else: | 186 else: |
(...skipping 625 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
812 """ | 812 """ |
813 missing = find_missing_packages(*packages) | 813 missing = find_missing_packages(*packages) |
814 if missing: | 814 if missing: |
815 if repository is not None: | 815 if repository is not None: |
816 log('Adding the apt repository {}.'.format(repository)) | 816 log('Adding the apt repository {}.'.format(repository)) |
817 install_extra_repositories(repository) | 817 install_extra_repositories(repository) |
818 log('Installing deb packages: {}.'.format(', '.join(missing))) | 818 log('Installing deb packages: {}.'.format(', '.join(missing))) |
819 cmd_log(apt_get_install(*missing)) | 819 cmd_log(apt_get_install(*missing)) |
820 else: | 820 else: |
821 log('No missing deb packages.') | 821 log('No missing deb packages.') |
OLD | NEW |