1
1
# Copyright 2014-2015 Canonical Limited.
3
# This file is part of charm-helpers.
5
# charm-helpers is free software: you can redistribute it and/or modify
6
# it under the terms of the GNU Lesser General Public License version 3 as
7
# published by the Free Software Foundation.
9
# charm-helpers is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU Lesser General Public License for more details.
14
# You should have received a copy of the GNU Lesser General Public License
15
# along with charm-helpers. If not, see <http://www.gnu.org/licenses/>.
3
# Licensed under the Apache License, Version 2.0 (the "License");
4
# you may not use this file except in compliance with the License.
5
# You may obtain a copy of the License at
7
# http://www.apache.org/licenses/LICENSE-2.0
9
# Unless required by applicable law or agreed to in writing, software
10
# distributed under the License is distributed on an "AS IS" BASIS,
11
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
# See the License for the specific language governing permissions and
13
# limitations under the License.
17
15
# Common python helper functions used for OpenStack charms.
18
16
from collections import OrderedDict
725
722
requirements_dir = None
728
def git_default_repos(projects):
725
def git_default_repos(projects_yaml):
730
727
Returns default repos if a default openstack-origin-git value is specified.
732
729
service = service_name()
730
core_project = service
734
732
for default, branch in GIT_DEFAULT_BRANCHES.iteritems():
735
if projects == default:
733
if projects_yaml == default:
737
735
# add the requirements repo first
745
# neutron and nova charms require some additional repos
746
if service == 'neutron':
747
for svc in ['neutron-fwaas', 'neutron-lbaas', 'neutron-vpnaas']:
743
# NOTE(coreycb): This is a temp work-around until the requirements
744
# repo moves from stable/kilo branch to kilo-eol tag. The core
745
# repos have already done this.
746
if default == 'kilo':
749
# neutron-* and nova-* charms require some additional repos
750
if service in ['neutron-api', 'neutron-gateway',
751
'neutron-openvswitch']:
752
core_project = 'neutron'
753
for project in ['neutron-fwaas', 'neutron-lbaas',
754
'neutron-vpnaas', 'nova']:
750
'repository': GIT_DEFAULT_REPOS[svc],
757
'repository': GIT_DEFAULT_REPOS[project],
751
758
'branch': branch,
753
760
repos.append(repo)
754
elif service == 'nova':
762
elif service in ['nova-cloud-controller', 'nova-compute']:
763
core_project = 'nova'
756
765
'name': 'neutron',
757
766
'repository': GIT_DEFAULT_REPOS['neutron'],
758
767
'branch': branch,
760
769
repos.append(repo)
770
elif service == 'openstack-dashboard':
771
core_project = 'horizon'
762
# finally add the current service's repo
773
# finally add the current service's core project repo
765
'repository': GIT_DEFAULT_REPOS[service],
775
'name': core_project,
776
'repository': GIT_DEFAULT_REPOS[core_project],
766
777
'branch': branch,
768
779
repos.append(repo)
770
781
return yaml.dump(dict(repositories=repos))
775
786
def _git_yaml_load(projects_yaml):
829
840
pip_install(p, upgrade=True, proxy=http_proxy,
830
841
venv=os.path.join(parent_dir, 'venv'))
832
844
for p in projects['repositories']:
833
845
repo = p['repository']
834
846
branch = p['branch']
840
852
parent_dir, http_proxy,
841
853
update_requirements=False)
842
854
requirements_dir = repo_dir
855
constraints = os.path.join(repo_dir, "upper-constraints.txt")
856
# upper-constraints didn't exist until after icehouse
857
if not os.path.isfile(constraints):
844
860
repo_dir = _git_clone_and_install_single(repo, branch, depth,
845
861
parent_dir, http_proxy,
846
update_requirements=True)
862
update_requirements=True,
863
constraints=constraints)
848
865
os.environ = old_environ
877
894
def _git_clone_and_install_single(repo, branch, depth, parent_dir, http_proxy,
878
update_requirements):
895
update_requirements, constraints=None):
880
897
Clone and install a single git repository.
899
916
juju_log('Installing git repo from dir: {}'.format(repo_dir))
901
pip_install(repo_dir, proxy=http_proxy, venv=venv)
918
pip_install(repo_dir, proxy=http_proxy, venv=venv,
919
constraints=constraints)
903
pip_install(repo_dir, venv=venv)
921
pip_install(repo_dir, venv=venv, constraints=constraints)
980
998
script generation, which is used by the OpenStack packages.
982
1000
for f in os.listdir(templates_dir):
1001
# Create the init script and systemd unit file from the template
983
1002
if f.endswith(".init.in"):
984
1003
init_in_file = f
985
1004
init_file = f[:-8]
1005
1024
os.remove(init_dest)
1006
1025
if os.path.exists(service_dest):
1007
1026
os.remove(service_dest)
1008
shutil.move(init_source, init_dest)
1009
shutil.move(service_source, service_dest)
1027
shutil.copyfile(init_source, init_dest)
1028
shutil.copyfile(service_source, service_dest)
1010
1029
os.chmod(init_dest, 0o755)
1031
for f in os.listdir(templates_dir):
1032
# If there's a service.in file, use it instead of the generated one
1033
if f.endswith(".service.in"):
1035
service_file = f[:-3]
1037
service_in_source = os.path.join(templates_dir, service_in_file)
1038
service_source = os.path.join(templates_dir, service_file)
1039
service_dest = os.path.join('/lib/systemd/system', service_file)
1041
shutil.copyfile(service_in_source, service_source)
1043
if os.path.exists(service_dest):
1044
os.remove(service_dest)
1045
shutil.copyfile(service_source, service_dest)
1047
for f in os.listdir(templates_dir):
1048
# Generate the systemd unit if there's no existing .service.in
1049
if f.endswith(".init.in"):
1052
service_in_file = "{}.service.in".format(init_file)
1053
service_file = "{}.service".format(init_file)
1055
init_in_source = os.path.join(templates_dir, init_in_file)
1056
service_in_source = os.path.join(templates_dir, service_in_file)
1057
service_source = os.path.join(templates_dir, service_file)
1058
service_dest = os.path.join('/lib/systemd/system', service_file)
1060
if not os.path.exists(service_in_source):
1061
cmd = ['pkgos-gen-systemd-unit', init_in_source]
1062
subprocess.check_call(cmd)
1064
if os.path.exists(service_dest):
1065
os.remove(service_dest)
1066
shutil.copyfile(service_source, service_dest)
1013
1069
def os_workload_status(configs, required_interfaces, charm_func=None):