2 ##############################################################################
3 # Copyright (c) 2017 Huawei Technologies Co.,Ltd and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
9 ##############################################################################
13 from utils.logger import Logger
14 from utils.parser import Parser as config
15 import utils.infra_setup.heat.manager as utils
17 LOG = Logger(__name__).getLogger()
20 def _prepare_env_daemon():
22 installer_ip = os.environ.get('INSTALLER_IP', 'undefined')
23 installer_type = os.environ.get('INSTALLER_TYPE', 'undefined')
25 rc_file = config.bottlenecks_config["rc_dir"]
27 _get_remote_rc_file(rc_file, installer_ip, installer_type)
31 _append_external_network(rc_file)
33 # update the external_network
37 def _get_remote_rc_file(rc_file, installer_ip, installer_type):
39 RELENG_DIR = config.bottlenecks_config["releng_dir"]
40 OS_FETCH_SCRIPT = config.bottlenecks_config["fetch_os"]
41 os_fetch_script = os.path.join(RELENG_DIR, OS_FETCH_SCRIPT)
44 cmd = [os_fetch_script, '-d', rc_file, '-i', installer_type,
46 p = subprocess.Popen(cmd, stdout=subprocess.PIPE)
50 LOG.debug('Failed to fetch credentials from installer')
52 if e.errno != errno.EEXIST:
56 def _source_file(rc_file):
57 p = subprocess.Popen(". %s; env" % rc_file, stdout=subprocess.PIPE,
59 output = p.communicate()[0]
60 env = dict((line.split('=', 1) for line in output.splitlines()))
61 os.environ.update(env)
65 def _append_external_network(rc_file):
66 neutron_client = utils._get_neutron_client()
67 networks = neutron_client.list_networks()['networks']
69 ext_network = next(n['name'] for n in networks if n['router:external'])
71 LOG.warning("Can't find external network")
73 cmd = 'export EXTERNAL_NETWORK=%s' % ext_network
75 with open(rc_file, 'a') as f:
78 if e.errno != errno.EEXIST: