File: //lib/python3.6/site-packages/cloudinit/config/cc_pip_source.py
import os
from functools import partial
from cloudinit import templater
from cloudinit import util
def _gen_pip_conf(pip_path, pip_conf, cloud, log):
template_fn = cloud.get_template_filename(pip_conf)
if not template_fn:
log.warn("No template found, not rendering.")
return []
template_functor = partial(templater.render_from_file, template_fn)
fn_contents = []
pip_info = {}
for (_, v) in enumerate(cloud.datasource.get_source_address()):
pip_info["pip_url"] = v.strip("http://")
fn_contents.append((pip_path, template_functor(pip_info)))
return fn_contents
def gen_pip_repo(name, cfg, cloud, log, _args):
pip_conf_file = "pip.conf"
pydistutils = "pydistutils.cfg"
pip_conf_path = os.path.join("/root", ".pip", pip_conf_file)
pip_pydistutils_path = "/%s/.%s" % ("root", pydistutils)
fn_contents = _gen_pip_conf(pip_conf_path, pip_conf_file, cloud, log)
write_helper(fn_contents, log)
fn_contents = _gen_pip_conf(pip_pydistutils_path, pydistutils, cloud, log)
write_helper(fn_contents, log)
return
def write_helper(fn_contents, log):
for fn, content in fn_contents:
try:
util.write_file(fn, content)
except:
log.warn("Faild to write %s", fn)
def handle(name, cfg, cloud, log, _args):
if not cloud.datasource.get_source_address() or \
not isinstance(cloud.datasource.get_source_address(), list):
log.debug("there is not source_address")
return
functor = gen_pip_repo
try:
functor(name, cfg, cloud, log, _args)
except:
log.warn("Failed to config pip source")