Skip to content

Instantly share code, notes, and snippets.

@adam-stokes
Created October 9, 2014 18:30
Show Gist options
  • Save adam-stokes/ed3f8e650405f68cd60d to your computer and use it in GitHub Desktop.
Save adam-stokes/ed3f8e650405f68cd60d to your computer and use it in GitHub Desktop.
class SingleInstall:
def __init__(self, opts, ui):
self.opts = opts
self.ui = ui
self.config = Config()
self.container_name = 'uoi-bootstrap'
self.container_path = '/var/lib/lxc'
self.container_abspath = os.path.join(self.container_path,
self.container_name)
self.userdata = os.path.join(
utils.install_home(), '.cloud-install/userdata.yaml')
def prep_userdata(self):
""" preps userdata file for container install """
dst_file = os.path.join(utils.install_home(),
'.cloud-install/userdata.yaml')
original_data = utils.load_template('userdata.yaml')
modified_data = original_data.render(
extra_sshkeys=[utils.ssh_readkey()])
utils.spew(dst_file, modified_data)
def cloud_init_finished(self):
""" checks the log to see if cloud-init finished
"""
log_file = os.path.join(self.container_abspath,
'rootfs/var/log/cloud-init-output.log')
out = utils.get_command_output('sudo tail -n1 {0}'.format(log_file))
if 'finished at' in out['stdout']:
return True
return False
def run(self):
if os.path.exists(self.container_abspath):
# Container exists, handle return code in installer
raise SystemExit("Container exists, please uninstall or kill "
"existing cloud before proceeding.")
self.ui.info_message(
"* Please wait while we generate your isolated environment ...")
utils.ssh_genkey()
self.prep_userdata()
utils.container_create(self.container_name, self.userdata)
utils.container_start(self.container_name)
utils.container_wait(self.container_name)
tries = 1
while not self.cloud_init_finished():
self.ui.info_message("[{0}] * Waiting for container to finalize, "
"please wait ... ".format(tries))
time.sleep(1)
tries = tries + 1
# Finishes the installation steps once an openstack password
# has been entered.
# TODO: Maybe cleanup more?
def save_password_and_finish(password=None, confirm_pass=None):
if password and password == confirm_pass:
self.config.save_password(password)
else:
self.ui.error_message('Passwords did not match, try again ..')
show_password_input(
'Openstack Password', save_password_and_finish)
single_env = utils.load_template('juju-env/single.yaml')
single_env_modified = single_env.render(
openstack_password=self.config.openstack_password)
utils.spew('/tmp/single.yaml', single_env_modified)
utils.container_run(self.container_name,
'mkdir -p .juju')
utils.container_cp(self.container_name,
'/tmp/single.yaml',
'.juju/environments.yaml')
utils.container_run(self.container_name, "juju bootstrap")
utils.container_run(self.container_name, "cloud-status")
def show_password_input():
self.ui.show_password_input(
'Openstack Password', save_password_and_finish)
show_password_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment