Example #1
0
    def prep_userdata(self):
        """ preps userdata file for container install
        """
        render_parts = {"extra_sshkeys": [utils.ssh_readkey()]}

        if self.config.getopt("upstream_ppa"):
            render_parts["upstream_ppa"] = self.config.getopt("upstream_ppa")

        render_parts["seed_command"] = self._proxy_pollinate()

        for opt in [
            "apt_proxy",
            "apt_https_proxy",
            "http_proxy",
            "https_proxy",
            "no_proxy",
            "image_metadata_url",
            "tools_metadata_url",
            "apt_mirror",
        ]:
            val = self.config.getopt(opt)
            if val:
                render_parts[opt] = val

        dst_file = os.path.join(self.config.cfg_path, "userdata.yaml")
        original_data = utils.load_template("userdata.yaml")
        log.info("Prepared userdata: {}".format(render_parts))
        modified_data = original_data.render(render_parts)
        utils.spew(dst_file, modified_data)
    def write_lxc_net_config(self):
        """Finds and configures a new subnet for the host container,
        to avoid overlapping with IPs used for Neutron.
        """
        lxc_net_template = utils.load_template('lxc-net')
        lxc_net_container_filename = os.path.join(self.container_abspath,
                                                  'rootfs/etc/default/lxc-net')

        network = netutils.get_unique_lxc_network()
        self.config.setopt('lxc_network', network)

        nw = IPv4Network(network)
        addr = nw[1]
        netmask = nw.with_netmask.split('/')[-1]
        net_low, net_high = netutils.ip_range_max(nw, [addr])
        dhcp_range = "{},{}".format(net_low, net_high)
        render_parts = dict(addr=addr,
                            netmask=netmask,
                            network=network,
                            dhcp_range=dhcp_range)
        lxc_net = lxc_net_template.render(render_parts)
        name = self.container_name
        log.info("Writing lxc-net config for {}".format(name))
        utils.spew(lxc_net_container_filename, lxc_net)

        return network
Example #3
0
    def write_lxc_net_config(self):
        """Finds and configures a new subnet for the host container,
        to avoid overlapping with IPs used for Neutron.
        """
        lxc_net_template = utils.load_template('lxc-net')
        lxc_net_container_filename = os.path.join(
            self.container_abspath, 'rootfs/etc/default/lxc-net')

        network = netutils.get_unique_lxc_network()
        self.config.setopt('lxc_network', network)

        nw = IPv4Network(network)
        addr = nw[1]
        netmask = nw.with_netmask.split('/')[-1]
        net_low, net_high = netutils.ip_range_max(nw, [addr])
        dhcp_range = "{},{}".format(net_low, net_high)
        render_parts = dict(addr=addr,
                            netmask=netmask,
                            network=network,
                            dhcp_range=dhcp_range)
        lxc_net = lxc_net_template.render(render_parts)
        name = self.container_name
        log.info("Writing lxc-net config for {}".format(name))
        utils.spew(lxc_net_container_filename, lxc_net)

        return network
 def prep_userdata(self):
     """ preps userdata file for container install """
     dst_file = os.path.join(self.config.cfg_path,
                             'userdata.yaml')
     original_data = utils.load_template('userdata.yaml')
     modified_data = original_data.render(
         extra_sshkeys=[utils.ssh_readkey()],
         extra_pkgs=['juju-local'])
     utils.spew(dst_file, modified_data)
 def prep_juju(self):
     """ preps juju environments for bootstrap
     """
     # configure juju environment for bootstrap
     single_env = utils.load_template('juju-env/single.yaml')
     single_env_modified = single_env.render(
         openstack_password=self.config.openstack_password)
     utils.spew(os.path.join(self.config.juju_path,
                             'environments.yaml'),
                single_env_modified,
                owner=utils.install_user())
 def prep_userdata(self):
     """ preps userdata file for container install
     """
     render_parts = {'extra_sshkeys': [utils.ssh_readkey()],
                     'extra_pkgs': ['juju-local']}
     if self.opts.extra_ppa:
         render_parts['extra_ppa'] = self.opts.extra_ppa
     dst_file = os.path.join(self.config.cfg_path,
                             'userdata.yaml')
     original_data = utils.load_template('userdata.yaml')
     log.debug("Userdata options: {}".format(render_parts))
     modified_data = original_data.render(render_parts)
     utils.spew(dst_file, modified_data)
    def render_setup_script(self):
        setup_template = utils.load_template("nova-controller-setup.sh")
        if self.config.is_single():
            lxc_network = self.config.getopt("lxc_network")
            N = lxc_network.split(".")[2]
        else:
            # N is used to define networks for single, so we simply
            # set a dummy value for multi
            N = 0

        setup_script_path = os.path.join(self.config.cfg_path, "nova-controller-setup.sh")
        osrel = self.config.getopt("openstack_release")
        template_args = dict(N=N, openstack_release=osrel)
        utils.spew(setup_script_path, setup_template.render(template_args))
        return setup_script_path
Example #8
0
    def render_setup_script(self):
        setup_template = utils.load_template("nova-controller-setup.sh")
        if self.config.is_single():
            lxc_network = self.config.getopt('lxc_network')
            N = lxc_network.split('.')[2]
        else:
            # N is used to define networks for single, so we simply
            # set a dummy value for multi
            N = 0

        setup_script_path = os.path.join(self.config.cfg_path,
                                         "nova-controller-setup.sh")

        utils.spew(setup_script_path, setup_template.render(dict(N=N)))
        return setup_script_path
    def render_setup_script(self):
        setup_template = utils.load_template("nova-controller-setup.sh")
        if self.config.is_single():
            lxc_network = self.config.getopt('lxc_network')
            N = lxc_network.split('.')[2]
        else:
            # N is used to define networks for single, so we simply
            # set a dummy value for multi
            N = 0

        setup_script_path = os.path.join(self.config.cfg_path,
                                         "nova-controller-setup.sh")

        utils.spew(setup_script_path,
                   setup_template.render(dict(N=N)))
        return setup_script_path
    def do_install(self):
        self.display_controller.info_message("Building environment")
        if os.path.exists(self.container_abspath):
            # Container exists, handle return code in installer
            raise Exception("Container exists, please uninstall or kill "
                            "existing cloud before proceeding.")

        utils.ssh_genkey()

        # Prepare cloud-init file for creation
        self.prep_userdata()

        # Start container
        self.create_container_and_wait()

        # configure juju environment for bootstrap
        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')

        # Set permissions
        self.copy_installdata_and_set_perms()

        # start the party
        cloud_status_bin = ['openstack-status']
        if self.opts.enable_swift:
            cloud_status_bin.append('--enable-swift')
        self.display_controller.info_message("Bootstrapping Juju ..")
        self.start_task("Starting Juju server")
        utils.container_run(self.container_name, "juju bootstrap")
        utils.container_run(self.container_name, "juju status")

        if self.opts.install_only:
            log.info("Done installing, stopping here per --install-only.")
            sys.exit(0)

        self.display_controller.info_message("Starting cloud deployment ..")
        utils.container_run_status(
            self.container_name, " ".join(cloud_status_bin))
    def prep_juju(self):
        """ preps juju environments for bootstrap
        """
        render_parts = {'openstack_password':
                        self.config.getopt('openstack_password')}

        if self.config.getopt('http_proxy'):
            render_parts['http_proxy'] = self.config.getopt('http_proxy')

        if self.config.getopt('https_proxy'):
            render_parts['https_proxy'] = self.config.getopt('https_proxy')

        # configure juju environment for bootstrap
        single_env = utils.load_template('juju-env/single.yaml')
        single_env_modified = single_env.render(render_parts)
        utils.spew(os.path.join(self.config.juju_path(),
                                'environments.yaml'),
                   single_env_modified,
                   owner=utils.install_user())
    def run_deployer(self):
        # Prep deployer template for landscape
        lscape_password = utils.random_password()
        lscape_env = utils.load_template('landscape-deployments.yaml')
        lscape_env_modified = lscape_env.render(
            landscape_password=lscape_password.strip())
        utils.spew(self.lscape_yaml_path,
                   lscape_env_modified)

        out = utils.get_command_output(
            "JUJU_HOME={0} juju-deployer -WdvL -w 180 -c {1} "
            "landscape-dense-maas".format(
                self.config.cfg_path,
                self.lscape_yaml_path),
            timeout=None,
            user_sudo=True)
        if out['status']:
            log.error("Problem deploying Landscape: {}".format(out))
            raise Exception("Error deploying Landscape.")
Example #13
0
    def prep_juju(self):
        """ preps juju environments for bootstrap
        """
        render_parts = {
            'openstack_password': self.config.getopt('openstack_password')
        }

        if self.config.getopt('http_proxy'):
            render_parts['http_proxy'] = self.config.getopt('http_proxy')

        if self.config.getopt('https_proxy'):
            render_parts['https_proxy'] = self.config.getopt('https_proxy')

        # configure juju environment for bootstrap
        single_env = utils.load_template('juju-env/single.yaml')
        single_env_modified = single_env.render(render_parts)
        utils.spew(os.path.join(self.config.juju_path(), 'environments.yaml'),
                   single_env_modified,
                   owner=utils.install_user())
Example #14
0
    def render_setup_script(self):
        setup_template = utils.load_template("nova-controller-setup.sh")
        if self.config.is_single():
            lxc_network = self.config.getopt('lxc_network')
            if lxc_network is None:
                log.error("lxc_network config not found")
                raise Exception("can't find lxc_network")
            N = lxc_network.split('.')[2]
        else:
            # N is used to define networks for single, so we simply
            # set a dummy value for multi
            N = 0

        setup_script_path = os.path.join(self.config.cfg_path,
                                         "nova-controller-setup.sh")
        osrel = self.config.getopt('openstack_release')
        template_args = dict(N=N, openstack_release=osrel)
        utils.spew(setup_script_path, setup_template.render(template_args))
        return setup_script_path
Example #15
0
    def prep_juju(self):
        """ preps juju environments for bootstrap
        """
        render_parts = {
            "openstack_password": self.config.getopt("openstack_password"),
            "ubuntu_series": self.config.getopt("ubuntu_series"),
        }

        for opt in ["apt_proxy", "apt_https_proxy", "http_proxy", "https_proxy"]:
            val = self.config.getopt(opt)
            if val:
                render_parts[opt] = val

        # configure juju environment for bootstrap
        single_env = utils.load_template("juju-env/single.yaml")
        single_env_modified = single_env.render(render_parts)
        utils.spew(
            os.path.join(self.config.juju_path(), "environments.yaml"), single_env_modified, owner=utils.install_user()
        )
    def prep_juju(self):
        """ preps juju environments for bootstrap
        """
        render_parts = {'openstack_password':
                        self.config.getopt('openstack_password'),
                        'ubuntu_series':
                        self.config.getopt('ubuntu_series')}

        for opt in ['apt_proxy', 'apt_https_proxy', 'http_proxy',
                    'https_proxy']:
            val = self.config.getopt(opt)
            if val:
                render_parts[opt] = val

        # configure juju environment for bootstrap
        single_env = utils.load_template('juju-env/single.yaml')
        single_env_modified = single_env.render(render_parts)
        utils.spew(os.path.join(self.config.juju_path(),
                                'environments.yaml'),
                   single_env_modified,
                   owner=utils.install_user())
    def render_setup_script(self):
        setup_template = utils.load_template("nova-controller-setup.sh")
        if self.config.is_single():
            lxc_network = self.config.getopt('lxc_network')
            if lxc_network is None:
                log.error("lxc_network config not found")
                raise Exception("can't find lxc_network")
            N = lxc_network.split('.')[2]
        else:
            # N is used to define networks for single, so we simply
            # set a dummy value for multi
            N = 0

        setup_script_path = os.path.join(self.config.cfg_path,
                                         "nova-controller-setup.sh")
        osrel = self.config.getopt('openstack_release')
        template_args = dict(N=N,
                             openstack_release=osrel)
        utils.spew(setup_script_path,
                   setup_template.render(template_args))
        return setup_script_path
Example #18
0
    def prep_juju(self):
        """ preps juju environments for bootstrap
        """
        render_parts = {
            'openstack_password': self.config.getopt('openstack_password'),
            'ubuntu_series': self.config.getopt('ubuntu_series')
        }

        for opt in [
                'apt_proxy', 'apt_https_proxy', 'http_proxy', 'https_proxy'
        ]:
            val = self.config.getopt(opt)
            if val:
                render_parts[opt] = val

        # configure juju environment for bootstrap
        single_env = utils.load_template('juju-env/single.yaml')
        single_env_modified = single_env.render(render_parts)
        utils.spew(os.path.join(self.config.juju_path(), 'environments.yaml'),
                   single_env_modified,
                   owner=utils.install_user())
    def copy_installdata_and_set_perms(self):
        """ copies install data and sets permissions on files/dirs
        """
        try:
            utils.chown(self.config.cfg_path,
                        utils.install_user(),
                        utils.install_user(),
                        recursive=True)
        except:
            raise SingleInstallException(
                "Unable to set ownership for {}".format(self.config.cfg_path))

        # copy over the rest of our installation data from host
        # and setup permissions

        # setup charm configurations
        charm_conf = utils.load_template('charmconf.yaml')
        charm_conf_modified = charm_conf.render(
            openstack_password=self.config.openstack_password)
        utils.spew(os.path.join(self.config.cfg_path,
                                'charmconf.yaml'),
                   charm_conf_modified)

        utils.container_run(
            self.container_name, 'mkdir -p .cloud-install')
        utils.container_run(
            self.container_name, 'sudo mkdir -p /etc/openstack')

        utils.container_cp(self.container_name,
                           os.path.join(
                               utils.install_home(), '.cloud-install/*'),
                           '.cloud-install/.')

        # our ssh keys too
        utils.container_cp(self.container_name,
                           os.path.join(utils.install_home(),
                                        '.ssh/id_rsa*'),
                           '.ssh/.')
        utils.container_run(self.container_name, "chmod 600 .ssh/id_rsa*")
Example #20
0
    def prep_userdata(self):
        """ preps userdata file for container install
        """
        render_parts = {'extra_sshkeys': [utils.ssh_readkey()]}

        if self.config.getopt('extra_ppa'):
            render_parts['extra_ppa'] = self.config.getopt('extra_ppa')

        render_parts['seed_command'] = self._proxy_pollinate()

        for opt in [
                'http_proxy', 'https_proxy', 'no_proxy', 'image_metadata_url',
                'tools_metadata_url', 'apt_mirror'
        ]:
            val = self.config.getopt(opt)
            if val:
                render_parts[opt] = val

        dst_file = os.path.join(self.config.cfg_path, 'userdata.yaml')
        original_data = utils.load_template('userdata.yaml')
        log.info("Prepared userdata: {}".format(render_parts))
        modified_data = original_data.render(render_parts)
        utils.spew(dst_file, modified_data)
    def prep_userdata(self):
        """ preps userdata file for container install
        """
        render_parts = {'extra_sshkeys': [utils.ssh_readkey()]}

        if self.config.getopt('extra_ppa'):
            render_parts['extra_ppa'] = self.config.getopt('extra_ppa')

        render_parts['seed_command'] = self._proxy_pollinate()

        for opt in ['http_proxy', 'https_proxy', 'no_proxy',
                    'image_metadata_url', 'tools_metadata_url',
                    'apt_mirror']:
            val = self.config.getopt(opt)
            if val:
                render_parts[opt] = val

        dst_file = os.path.join(self.config.cfg_path,
                                'userdata.yaml')
        original_data = utils.load_template('userdata.yaml')
        log.info("Prepared userdata: {}".format(render_parts))
        modified_data = original_data.render(render_parts)
        utils.spew(dst_file, modified_data)
Example #22
0
    def do_install(self):
        # Install package deps
        utils.apt_install('openstack-multi')
        self.tasker.start_task("Bootstrapping Juju")
        self.config.setopt('current_state', InstallState.RUNNING.value)

        maas_creds = self.config.getopt('maascreds')
        maas_env = utils.load_template('juju-env/maas.yaml')

        render_parts = {'openstack_password':
                        self.config.getopt('openstack_password'),
                        'maas_server': maas_creds['api_host'],
                        'maas_apikey': maas_creds['api_key'],
                        'ubuntu_series':
                        self.config.getopt('ubuntu_series')}

        for opt in ['http_proxy', 'https_proxy', 'no_proxy',
                    'image_metadata_url', 'tools_metadata_url']:
            val = self.config.getopt(opt)
            if val:
                render_parts[opt] = val

        maas_env_modified = maas_env.render(render_parts)

        check_output(['mkdir', '-p', self.config.juju_path()])
        utils.spew(self.config.juju_environments_path,
                   maas_env_modified)

        utils.render_charm_config(self.config)

        utils.ssh_genkey()

        # Set remaining permissions
        self.set_perms()

        # Starts the party
        self.display_controller.status_info_message("Bootstrapping Juju")

        dbgflags = ""
        if os.getenv("DEBUG_JUJU_BOOTSTRAP"):
            dbgflags = "--debug"

        bsflags = ""

        bstarget = os.getenv("JUJU_BOOTSTRAP_TO")
        if bstarget:
            bsflags += " --to {}".format(bstarget)

        cons = self.config.getopt('constraints')
        if cons:
            bsflags += " --constraints \"{}\"".format(cons)

        cmd = ("{0} juju {1} bootstrap {2}".format(
            self.config.juju_home(), dbgflags, bsflags))

        log.debug("Bootstrapping Juju: {}".format(cmd))

        out = utils.get_command_output(cmd,
                                       timeout=None,
                                       user_sudo=True)
        if out['status'] != 0:
            log.debug("Problem during bootstrap: '{}'".format(out))
            raise Exception("Problem with juju bootstrap.")

        # workaround to avoid connection failure at beginning of
        # openstack-status
        out = utils.get_command_output(
            "{0} juju status".format(
                self.config.juju_home()),
            timeout=None,
            user_sudo=True)
        if out['status'] != 0:
            log.debug("failure to get initial juju status: '{}'".format(out))
            raise Exception("Problem with juju status poke.")

        self.add_bootstrap_to_no_proxy()

        self.tasker.stop_current_task()

        if self.config.getopt('install_only'):
            log.info("Done installing, stopping here per --install-only.")
            self.config.setopt('install_only', True)
            self.loop.exit(0)

        # Return control back to landscape_install if need be
        if not self.config.is_landscape():
            args = ['openstack-status']
            if self.config.getopt('edit_placement'):
                args.append('--edit-placement')

            self.drop_privileges()
            os.execvp('openstack-status', args)
        else:
            log.debug("Finished MAAS step, now deploying Landscape.")
            return LandscapeInstallFinal(self,
                                         self.display_controller,
                                         self.config,
                                         self.loop).run()
    def do_install(self):
        self.start_task("Starting Juju server")

        maas_creds = self.config.maas_creds
        maas_env = utils.load_template('juju-env/maas.yaml')
        maas_env_modified = maas_env.render(
            maas_server=maas_creds['api_host'],
            maas_apikey=maas_creds['api_key'],
            openstack_password=self.config.openstack_password)
        check_output(['mkdir', '-p', self.config.juju_path])
        utils.spew(self.config.juju_environments_path,
                   maas_env_modified)

        # setup charm configurations
        charm_conf = utils.load_template('charmconf.yaml')
        charm_conf_modified = charm_conf.render(
            openstack_password=self.config.openstack_password)
        utils.spew(os.path.join(self.config.cfg_path,
                                'charmconf.yaml'),
                   charm_conf_modified)

        utils.ssh_genkey()

        # Set remaining permissions
        self.set_perms()

        # Starts the party
        self.display_controller.info_message("Bootstrapping juju ..")

        dbgflags = ""
        if os.getenv("DEBUG_JUJU_BOOTSTRAP"):
            dbgflags = "--debug"

        bsflags = ""
        # FIXME: this tag is never defined, removing to allow
        # installers to work again
        # if not self.installing_new_maas:
        #    bsflags = " --constraints tags=physical"

        out = utils.get_command_output("juju {} bootstrap {}".format(dbgflags,
                                                                     bsflags),
                                       timeout=None,
                                       user_sudo=True)
        if out['status'] != 0:
            log.debug("Problem during bootstrap: '{}'".format(out))
            raise Exception("Problem with juju bootstrap.")

        # workaround to avoid connection failure at beginning of
        # openstack-status
        out = utils.get_command_output("juju status",
                                       timeout=None,
                                       user_sudo=True)
        if out['status'] != 0:
            log.debug("failure to get initial juju status: '{}'".format(out))
            raise Exception("Problem with juju status poke.")

        self.stop_current_task()

        if self.opts.install_only:
            return

        # Return control back to landscape_install if need be
        if not self.config.is_landscape:
            args = ['openstack-status']
            if self.opts.enable_swift:
                args.append('--enable-swift')
            if self.opts.edit_placement:
                args.append('--placement')

            self.drop_privileges()
            os.execvp('openstack-status', args)
        else:
            log.debug("Finished MAAS step, now deploying Landscape.")
            return LandscapeInstallFinal(self.opts,
                                         self,
                                         self.display_controller).run()
    def deploy_landscape(self):
        self.multi_installer.start_task("Preparing Landscape")
        self.display_controller.info_message(
            "Running ..")
        # FIXME: not sure if deployer is failing to access the juju
        # environment but I get random connection refused when
        # running juju-deployer (adam.stokes)
        time.sleep(10)

        # Set remaining permissions
        self.set_perms()

        # Prep deployer template for landscape
        lscape_password = utils.random_password()
        lscape_env = utils.load_template('landscape-deployments.yaml')
        lscape_env_modified = lscape_env.render(
            landscape_password=lscape_password.strip())
        utils.spew(self.lscape_yaml_path,
                   lscape_env_modified)

        # Juju deployer
        self.multi_installer.start_task("Deploying Landscape")

        out = utils.get_command_output("juju-deployer -WdvL -w 180 -c {0} "
                                       "landscape-dense-maas".format(
                                           self.lscape_yaml_path),
                                       timeout=None,
                                       user_sudo=True)
        if out['status']:
            log.error("Problem deploying Landscape: {}".format(out))
            raise Exception("Error deploying Landscape.")

        # Configure landscape
        # Running landscape configure:
        # /usr/share/openstack/bin/configure-landscape --admin-email adam
        # --admin-name [email protected] --system-email [email protected] --maas-host
        # 172.16.0.1
        self.multi_installer.start_task("Registering against Landscape")
        cmd = ("{bin} --admin-email {admin_email} "
               "--admin-name {name} "
               "--system-email {sys_email} "
               "--maas-host {maas_host}".format(
                   bin=self.lscape_configure_bin,
                   admin_email=self.config.landscape_creds['admin_email'],
                   name=self.config.landscape_creds['admin_name'],
                   sys_email=self.config.landscape_creds['system_email'],
                   maas_host=self.config.maas_creds['api_host']))

        log.debug("Running landscape configure: {}".format(cmd))

        out = utils.get_command_output(cmd, timeout=None, user_sudo=True)

        if out['status']:
            log.error("Problem with configuring Landscape: {}.".format(out))
            raise Exception("Error configuring Landscape.")

        self.multi_installer.stop_current_task()
        self.display_controller.info_message("Complete")

        msg = []
        msg.append("You can now continue with the installation of Openstack")
        msg.append(" by visiting:\n\n")
        msg.append("http://{0}/account/standalone/openstack ".format(
            out['output'].strip()))
        msg.append("\n\nCredentials:\n")
        msg.append(" Email: {}\n".format(
            self.config.landscape_creds['admin_email']))
        msg.append(" Password: {}".format(self.config.openstack_password))

        self.display_controller.step_info(msg)
Example #25
0
    def do_install(self):
        # Install package deps
        utils.apt_install('openstack-multi')
        self.tasker.start_task("Bootstrapping Juju")
        self.config.setopt('current_state', InstallState.RUNNING.value)

        maas_creds = self.config.getopt('maascreds')
        maas_env = utils.load_template('juju-env/maas.yaml')

        render_parts = {
            'openstack_password': self.config.getopt('openstack_password'),
            'maas_server': maas_creds['api_host'],
            'maas_apikey': maas_creds['api_key'],
            'ubuntu_series': self.config.getopt('ubuntu_series')
        }

        for opt in [
                'http_proxy', 'https_proxy', 'no_proxy', 'apt_proxy',
                'image_metadata_url', 'tools_metadata_url'
        ]:
            val = self.config.getopt(opt)
            if val:
                render_parts[opt] = val

        maas_env_modified = maas_env.render(render_parts)

        check_output(['mkdir', '-p', self.config.juju_path()])
        utils.spew(self.config.juju_environments_path, maas_env_modified)

        utils.render_charm_config(self.config)

        utils.ssh_genkey()

        # Set remaining permissions
        self.set_perms()

        # Starts the party
        self.display_controller.status_info_message("Bootstrapping Juju")

        dbgflags = ""
        if os.getenv("DEBUG_JUJU_BOOTSTRAP"):
            dbgflags = "--debug"

        bsflags = ""

        bstarget = os.getenv("JUJU_BOOTSTRAP_TO")
        if bstarget:
            bsflags += " --to {}".format(bstarget)

        cons = self.config.getopt('constraints')
        if cons:
            bsflags += " --constraints \"{}\"".format(cons)

        cmd = ("{0} juju {1} bootstrap {2}".format(self.config.juju_home(),
                                                   dbgflags, bsflags))

        log.debug("Bootstrapping Juju: {}".format(cmd))

        out = utils.get_command_output(cmd, timeout=None, user_sudo=True)
        if out['status'] != 0:
            log.debug("Problem during bootstrap: '{}'".format(out))
            raise Exception("Problem with juju bootstrap.")

        # workaround to avoid connection failure at beginning of
        # openstack-status
        out = utils.get_command_output("{0} juju status".format(
            self.config.juju_home()),
                                       timeout=None,
                                       user_sudo=True)
        if out['status'] != 0:
            log.debug("failure to get initial juju status: '{}'".format(out))
            raise Exception("Problem with juju status poke.")

        self.add_bootstrap_to_no_proxy()

        self.tasker.stop_current_task()

        if self.config.getopt('install_only'):
            log.info("Done installing, stopping here per --install-only.")
            self.config.setopt('install_only', True)
            self.loop.exit(0)

        # Return control back to landscape_install if need be
        if not self.config.is_landscape():
            args = ['openstack-status']
            if self.config.getopt('edit_placement'):
                args.append('--edit-placement')

            self.drop_privileges()
            os.execvp('openstack-status', args)
        else:
            log.debug("Finished MAAS step, now deploying Landscape.")
            return LandscapeInstallFinal(self, self.display_controller,
                                         self.config, self.loop).run()
    def do_install(self):
        self.start_task("Bootstrapping Juju")
        self.display_controller.current_state = InstallState.RUNNING

        maas_creds = self.config.maas_creds
        maas_env = utils.load_template('juju-env/maas.yaml')
        maas_env_modified = maas_env.render(
            maas_server=maas_creds['api_host'],
            maas_apikey=maas_creds['api_key'],
            openstack_password=self.config.openstack_password)
        check_output(['mkdir', '-p', self.config.juju_path])
        utils.spew(self.config.juju_environments_path,
                   maas_env_modified)

        utils.render_charm_config(self.config, self.opts)

        utils.ssh_genkey()

        # Set remaining permissions
        self.set_perms()

        # Starts the party
        self.display_controller.info_message("Bootstrapping Juju")

        dbgflags = ""
        if os.getenv("DEBUG_JUJU_BOOTSTRAP"):
            dbgflags = "--debug"

        bsflags = ""
        #    bsflags = " --constraints tags=physical"
        bstarget = os.getenv("JUJU_BOOTSTRAP_TO")
        if bstarget:
            bsflags += " --to {}".format(bstarget)

        cmd = ("JUJU_HOME={0} juju {1} bootstrap {2}".format(
            self.config.cfg_path, dbgflags, bsflags))

        log.debug("Bootstrapping Juju: {}".format(cmd))

        out = utils.get_command_output(cmd,
                                       timeout=None,
                                       user_sudo=True)
        if out['status'] != 0:
            log.debug("Problem during bootstrap: '{}'".format(out))
            raise Exception("Problem with juju bootstrap.")

        # workaround to avoid connection failure at beginning of
        # openstack-status
        out = utils.get_command_output(
            "JUJU_HOME={} juju status".format(
                self.config.cfg_path),
            timeout=None,
            user_sudo=True)
        if out['status'] != 0:
            log.debug("failure to get initial juju status: '{}'".format(out))
            raise Exception("Problem with juju status poke.")

        self.stop_current_task()

        if self.opts.install_only:
            return

        # Return control back to landscape_install if need be
        if not self.config.is_landscape:
            args = ['openstack-status']
            if self.opts.edit_placement:
                args.append('--placement')

            self.drop_privileges()
            os.execvp('openstack-status', args)
        else:
            log.debug("Finished MAAS step, now deploying Landscape.")
            return LandscapeInstallFinal(self,
                                         self.display_controller).run()