Ejemplo n.º 1
0
    def juju_env(self):
        """ parses current juju environment """
        if self._juju_env:
            return self._juju_env

        env_file = None
        if self.is_single:
            env_file = 'local.jenv'

        if self.is_multi:
            env_file = 'maas.jenv'

        if env_file:
            env_path = os.path.join(utils.install_home(),
                                    '.juju/environments',
                                    env_file)
        else:
            raise ConfigException('Unable to determine installer type.')

        if os.path.exists(env_path):
            with open(env_path) as f:
                self._juju_env = yaml.load(f.read().strip())
            return self._juju_env

        raise ConfigException('Unable to load environments file. Is '
                              'juju bootstrapped?')
Ejemplo n.º 2
0
    def create_container_and_wait(self):
        """ Creates container and waits for cloud-init to finish
        """
        self.start_task("Creating container")
        utils.container_create(self.container_name, self.userdata)

        # Set autostart bit
        with open(os.path.join(self.container_abspath, 'config'), 'a+') as f:
            f.write("lxc.start.auto = 1\nlxc.start.delay = 5\n")

        # Mount points
        with open(os.path.join(self.container_abspath, 'fstab'), 'a+') as f:
            f.write(
                "{0} {1} none bind,create=dir\n".format(
                    self.config.cfg_path,
                    'home/ubuntu/.cloud-install'))
            f.write(
                "{0} {1} none bind,create=dir\n".format(
                    self.config.juju_path,
                    'home/ubuntu/.juju'))
            f.write(
                "{0} {1} none bind,create=dir\n".format(
                    os.path.join(utils.install_home(), '.ssh'),
                    'home/ubuntu/.ssh'))

        utils.container_start(self.container_name)
        utils.container_wait(self.container_name)

        tries = 1
        while not self.cloud_init_finished():
            time.sleep(1)
            tries = tries + 1
Ejemplo n.º 3
0
    def login_to_maas(self, apikey):
        cmd = ("maas login maas {} {}".format(self.LOCAL_MAAS_URL, apikey))

        out = utils.get_command_output(cmd)
        if out['status'] != 0:
            log.debug("failed to login to maas: {}".format(out))

            # Remove maascli.db that gets created regardless of
            # status of login
            utils.get_command_output('rm -f {}'.format(
                os.path.join(utils.install_home(), '.maascli.db')))
            raise MaasInstallError("Couldn't log in")
Ejemplo n.º 4
0
    def login_to_maas(self, apikey):
        cmd = ("maas login maas {} {}".format(self.LOCAL_MAAS_URL,
                                              apikey))

        out = utils.get_command_output(cmd)
        if out['status'] != 0:
            log.debug("failed to login to maas: {}".format(out))

            # Remove maascli.db that gets created regardless of
            # status of login
            utils.get_command_output('rm -f {}'.format(
                os.path.join(utils.install_home(), '.maascli.db')))
            raise MaasInstallError("Couldn't log in")
Ejemplo n.º 5
0
 def set_perms(self):
     # Set permissions
     dirs = [self.config.cfg_path,
             os.path.join(utils.install_home(), '.juju')]
     for d in dirs:
         try:
             utils.chown(d,
                         utils.install_user(),
                         utils.install_user(),
                         recursive=True)
         except:
             raise MaasInstallError(
                 "Unable to set ownership for {}".format(d))
    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*")
Ejemplo n.º 7
0
 def set_perms(self):
     # Set permissions
     dirs = [
         self.config.cfg_path,
         os.path.join(utils.install_home(), '.juju')
     ]
     for d in dirs:
         try:
             utils.chown(d,
                         utils.install_user(),
                         utils.install_user(),
                         recursive=True)
         except:
             raise Exception("Unable to set ownership for {}".format(d))
Ejemplo n.º 8
0
 def set_perms(self):
     # Set permissions
     dirs = [self.config.cfg_path,
             os.path.join(utils.install_home(), '.juju')]
     for d in dirs:
         try:
             utils.chown(d,
                         utils.install_user(),
                         utils.install_user(),
                         recursive=True)
         except:
             utils.pollinate(self.session_id, 'EO')
             raise MaasInstallError(
                 "Unable to set ownership for {}".format(d))
Ejemplo n.º 9
0
 def set_perms(self):
     # Set permissions
     dirs = [self.config.cfg_path,
             os.path.join(utils.install_home(), '.juju')]
     for d in dirs:
         try:
             utils.chown(d,
                         utils.install_user(),
                         utils.install_user(),
                         recursive=True)
         except:
             utils.pollinate(self.session_id, 'EO')
             raise Exception(
                 "Unable to set ownership for {}".format(d))
Ejemplo n.º 10
0
 def update_environments_yaml(self, key, val, provider='local'):
     """ updates environments.yaml base file """
     _env_yaml = os.path.join(utils.install_home(),
                              ".juju/environments.yaml")
     if os.path.exists(_env_yaml):
         with open(_env_yaml) as f:
             _env_yaml_raw = f.read()
             env_yaml = yaml.load(_env_yaml_raw)
     else:
         raise ConfigException("~/.juju/environments.yaml unavailable, "
                               "is juju bootstrapped?")
     if key in env_yaml['environments'][provider]:
         env_yaml['environments'][provider][key] = val
     with open(_env_yaml, 'w') as f:
         _env_yaml_raw = yaml.safe_dump_all(env_yaml)
         f.write(_env_yaml_raw)
Ejemplo n.º 11
0
 def cfg_path(self):
     """ top level configuration path """
     return os.path.join(utils.install_home(), '.cloud-install')
Ejemplo n.º 12
0
 def cfg_path(self):
     """ top level configuration path """
     if self._cfg_file is None:
         return os.path.join(utils.install_home(), '.cloud-install')
     else:
         return os.path.dirname(self._cfg_file)
Ejemplo n.º 13
0
 def juju_path(self):
     return os.path.join(utils.install_home(), '.juju')
Ejemplo n.º 14
0
    def do_install(self):
        self.display_controller.status_info_message("Building environment")
        if os.path.exists(self.container_abspath):
            raise Exception("Container exists, please uninstall or kill "
                            "existing cloud before proceeding.")

        # check for deb early, will actually install it later
        upstream_deb = self.config.getopt('upstream_deb')
        if upstream_deb and not os.path.isfile(upstream_deb):
            raise Exception("Upstream deb '{}' "
                            "not found.".format(upstream_deb))

        utils.ssh_genkey()

        self.setup_apt_proxy()

        self.prep_userdata()

        utils.render_charm_config(self.config)

        self.prep_juju()

        self.set_perms()

        self.create_container_and_wait()

        # Copy over host ssh keys
        Container.cp(self.container_name,
                     os.path.join(utils.install_home(), '.ssh/id_rsa*'),
                     '.ssh/.')

        # Install local copy of openstack installer if provided
        if upstream_deb:
            shutil.copy(upstream_deb, self.config.cfg_path)
            self._install_upstream_deb()

        # Stop before we attempt to access container
        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)

        # Update jujus no-proxy setting if applicable
        if self.config.getopt('http_proxy') or \
           self.config.getopt('https_proxy'):
            log.info("Updating juju environments for proxy support")
            lxc_net = self.config.getopt('lxc_network')
            self.config.update_environments_yaml(
                key='no-proxy',
                val='{},localhost,{}'.format(
                    Container.ip(self.container_name),
                    netutils.get_ip_set(lxc_net)))

        # start the party
        cloud_status_bin = ['openstack-status']
        self.tasker.start_task("Bootstrapping Juju",
                               self.read_progress_output)
        Container.run(self.container_name,
                      "{0} juju --debug bootstrap".format(
                          self.config.juju_home(use_expansion=True)),
                      use_ssh=True, output_cb=self.set_progress_output)
        Container.run(
            self.container_name,
            "{0} juju status".format(
                self.config.juju_home(use_expansion=True)),
            use_ssh=True)
        self.tasker.stop_current_task()

        self.display_controller.status_info_message(
            "Starting cloud deployment")
        Container.run_status(
            self.container_name, " ".join(cloud_status_bin), self.config)
Ejemplo n.º 15
0
    def continue_with_interface(self):
        self.display_controller.ui.hide_widget_on_top()
        self.start_task("Installing MAAS")

        check_output('mkdir -p /etc/openstack', shell=True)
        check_output(['cp', '/etc/network/interfaces',
                      '/etc/openstack/interfaces.cloud.bak'])
        check_output(['cp', '-r', '/etc/network/interfaces.d',
                      '/etc/openstack/interfaces.cloud.d.bak'])

        utils.spew('/etc/openstack/interface', self.target_iface)

        utils.apt_install('openstack-multi')

        self.start_task("Configuring MAAS")
        self.create_superuser()
        self.apikey = self.get_apikey()

        self.login_to_maas(self.apikey)

        try:
            utils.chown(os.path.join(utils.install_home(), '.maascli.db'),
                        utils.install_user(),
                        utils.install_user())
        except:
            raise MaasInstallError("Unable to set permissions on {}".format(
                os.path.join(utils.install_home(), '.maascli.db')))

        self.start_task("Waiting for MAAS cluster registration")
        cluster_uuid = self.wait_for_registration()
        self.create_maas_bridge(self.target_iface)

        self.prompt_for_bridge()

        self.start_task("Configuring MAAS networks")
        self.configure_maas_networking(cluster_uuid,
                                       'br0',
                                       self.gateway,
                                       self.dhcp_range,
                                       self.static_range)

        self.configure_dns()

        self.config.save_maas_creds(self.gateway,
                                    self.apikey)

        if "MAAS_HTTP_PROXY" in os.environ:
            pv = os.environ['MAAS_HTTP_PROXY']
            out = utils.get_command_output('maas maas maas set-config '
                                           'name=http_proxy '
                                           'value={}'.format(pv))
            if out['status'] != 0:
                log.debug("Error setting maas proxy config: {}".format(out))
                raise MaasInstallError("Error setting proxy config")

        self.display_controller.info_message("Importing MAAS boot images")
        self.start_task("Importing MAAS boot images")
        out = utils.get_command_output('maas maas boot-resources import')
        if out['status'] != 0:
            log.debug("Error starting boot images import: {}".format(out))
            raise MaasInstallError("Error setting proxy config")

        def pred(out):
            return out['output'] != '[]'

        ok = utils.poll_until_true('maas maas boot-images read '
                                   ' {}'.format(cluster_uuid),
                                   pred, 15, timeout=7200)
        if not ok:
            log.debug("poll timed out for getting boot images")
            raise MaasInstallError("Downloading boot images timed out")

        self.display_controller.info_message("Done importing boot images")

        self.stop_current_task()
        msg = "Waiting for sufficient resources in MAAS"
        self.display_controller.info_message(msg)
        self.display_controller.current_installer = self
        self.display_controller.current_state = InstallState.NODE_WAIT
Ejemplo n.º 16
0
    def do_install(self):
        self.display_controller.status_info_message("Building environment")
        if os.path.exists(self.container_abspath):
            raise Exception("Container exists, please uninstall or kill "
                            "existing cloud before proceeding.")

        # check for deb early, will actually install it later
        upstream_deb = self.config.getopt('upstream_deb')
        if upstream_deb and not os.path.isfile(upstream_deb):
            raise Exception("Upstream deb '{}' "
                            "not found.".format(upstream_deb))

        utils.ssh_genkey()

        self.setup_apt_proxy()

        self.prep_userdata()

        utils.render_charm_config(self.config)

        self.prep_juju()

        self.set_perms()

        self.create_container_and_wait()

        # Copy over host ssh keys
        Container.cp(self.container_name,
                     os.path.join(utils.install_home(), '.ssh/id_rsa*'),
                     '.ssh/.')

        # Install local copy of openstack installer if provided
        if upstream_deb:
            shutil.copy(upstream_deb, self.config.cfg_path)
            self._install_upstream_deb()

        # Stop before we attempt to access container
        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)

        # Update jujus no-proxy setting if applicable
        if self.config.getopt('http_proxy') or \
           self.config.getopt('https_proxy'):
            log.info("Updating juju environments for proxy support")
            lxc_net = self.config.getopt('lxc_network')
            self.config.update_environments_yaml(
                key='no-proxy',
                val='{},localhost,{}'.format(Container.ip(self.container_name),
                                             netutils.get_ip_set(lxc_net)))

        # start the party
        cloud_status_bin = ['openstack-status']
        self.tasker.start_task("Bootstrapping Juju", self.read_progress_output)
        Container.run(self.container_name,
                      "{0} juju --debug bootstrap".format(
                          self.config.juju_home(use_expansion=True)),
                      use_ssh=True,
                      output_cb=self.set_progress_output)
        Container.run(self.container_name,
                      "{0} juju status".format(
                          self.config.juju_home(use_expansion=True)),
                      use_ssh=True)
        self.tasker.stop_current_task()

        self.display_controller.status_info_message(
            "Starting cloud deployment")
        Container.run_status(self.container_name, " ".join(cloud_status_bin),
                             self.config)
Ejemplo n.º 17
0
 def cfg_path(self):
     """ top level configuration path """
     return os.path.join(utils.install_home(), '.cloud-install')
Ejemplo n.º 18
0
 def cfg_path(self):
     """ top level configuration path """
     if self._cfg_file is None:
         return os.path.join(utils.install_home(), '.cloud-install')
     else:
         return os.path.dirname(self._cfg_file)
Ejemplo n.º 19
0
    def continue_with_interface(self):
        self.display_controller.hide_widget_on_top()
        self.tasker.start_task("Installing MAAS")

        check_output('mkdir -p /etc/openstack', shell=True)
        check_output([
            'cp', '/etc/network/interfaces',
            '/etc/openstack/interfaces.cloud.bak'
        ])
        check_output([
            'cp', '-r', '/etc/network/interfaces.d',
            '/etc/openstack/interfaces.cloud.d.bak'
        ])

        utils.spew('/etc/openstack/interface', self.target_iface)

        utils.apt_install('openstack-multi')

        self.tasker.start_task("Configuring MAAS")
        self.create_superuser()
        self.apikey = self.get_apikey()

        self.login_to_maas(self.apikey)

        try:
            utils.chown(os.path.join(utils.install_home(), '.maascli.db'),
                        utils.install_user(), utils.install_user())
        except:
            raise MaasInstallError("Unable to set permissions on {}".format(
                os.path.join(utils.install_home(), '.maascli.db')))

        self.tasker.start_task("Waiting for MAAS cluster registration")
        cluster_uuid = self.wait_for_registration()
        self.create_maas_bridge(self.target_iface)

        self.prompt_for_bridge()

        self.tasker.start_task("Configuring MAAS networks")
        self.configure_maas_networking(cluster_uuid, 'br0', self.gateway,
                                       self.dhcp_range, self.static_range)

        self.configure_dns()

        self.config.setopt('maascreds',
                           dict(api_host=self.gateway, api_key=self.apikey))

        if "MAAS_HTTP_PROXY" in os.environ:
            pv = os.environ['MAAS_HTTP_PROXY']
            out = utils.get_command_output('maas maas maas set-config '
                                           'name=http_proxy '
                                           'value={}'.format(pv))
            if out['status'] != 0:
                log.debug("Error setting maas proxy config: {}".format(out))
                raise MaasInstallError("Error setting proxy config")

        self.display_controller.status_info_message(
            "Importing MAAS boot images")
        self.tasker.start_task("Importing MAAS boot images")
        out = utils.get_command_output('maas maas boot-resources import')
        if out['status'] != 0:
            log.debug("Error starting boot images import: {}".format(out))
            raise MaasInstallError("Error setting proxy config")

        def pred(out):
            return out['output'] != '[]'

        ok = utils.poll_until_true('maas maas boot-images read '
                                   ' {}'.format(cluster_uuid),
                                   pred,
                                   15,
                                   timeout=7200)
        if not ok:
            log.debug("poll timed out for getting boot images")
            raise MaasInstallError("Downloading boot images timed out")

        self.display_controller.status_info_message(
            "Done importing boot images")

        self.tasker.stop_current_task()
        msg = "Waiting for sufficient resources in MAAS"
        self.display_controller.status_info_message(msg)
        self.display_controller.current_installer = self
        self.display_controller.current_state = InstallState.NODE_WAIT