216
215
dump_euca_console(host_id, directory)
219
def get_local_root(juju_home, env):
220
return os.path.join(juju_home, env.environment)
223
218
def copy_local_logs(directory, env):
224
219
local = get_local_root(get_juju_home(), env)
225
220
log_names = [os.path.join(local, 'cloud-init-output.log')]
299
294
return (machine_id for machine_id, name in description)
302
def check_free_disk_space(path, required, purpose):
303
df_result = subprocess.check_output(["df", "-k", path])
304
df_result = df_result.split('\n')[1]
305
df_result = re.split(' +', df_result)
306
available = int(df_result[3])
307
if available < required:
309
"Warning: Probably not enough disk space available for\n"
310
"%(purpose)s in directory %(path)s,\n"
311
"mount point %(mount)s\n"
312
"required: %(required)skB, available: %(available)skB."
315
'path': path, 'mount': df_result[5], 'required': required,
316
'available': available, 'purpose': purpose
320
def bootstrap_from_env(juju_home, env):
321
# Always bootstrap a matching environment.
322
env.config['agent-version'] = env.get_matching_agent_version()
323
if env.config['type'] == 'local':
324
env.config.setdefault('root-dir', get_local_root(juju_home, env))
325
new_config = {'environments': {env.environment: env.config}}
326
jenv_path = get_jenv_path(juju_home, env.environment)
327
with temp_dir(juju_home) as temp_juju_home:
328
if os.path.lexists(jenv_path):
329
raise Exception('%s already exists!' % jenv_path)
330
new_jenv_path = get_jenv_path(temp_juju_home, env.environment)
332
# MongoDB requires a lot of free disk space, and the only
333
# visible error message is from "juju bootstrap":
334
# "cannot initiate replication set" if disk space is low.
335
# What "low" exactly means, is unclear, but 8GB should be
337
check_free_disk_space(temp_juju_home, 8000000, "MongoDB files")
339
check_free_disk_space(
340
"/var/lib/uvtool/libvirt/images", 2000000,
343
check_free_disk_space(
344
"/var/lib/lxc", 2000000, "LXC containers")
345
# Create a symlink to allow access while bootstrapping, and to reduce
346
# races. Can't use a hard link because jenv doesn't exist until
347
# partway through bootstrap.
349
os.mkdir(os.path.join(juju_home, 'environments'))
351
if e.errno != errno.EEXIST:
353
os.symlink(new_jenv_path, jenv_path)
355
temp_environments = get_environments_path(temp_juju_home)
356
with open(temp_environments, 'w') as config_file:
357
yaml.safe_dump(new_config, config_file)
358
with scoped_environ():
359
os.environ['JUJU_HOME'] = temp_juju_home
361
# replace symlink with file before deleting temp home.
362
os.rename(new_jenv_path, jenv_path)
367
297
def deploy_job():
368
298
from argparse import ArgumentParser
369
299
parser = ArgumentParser('deploy_job')