Esempio n. 1
0
    def add_bootstrap_to_no_proxy(self):
        """Finds bootstrap node IP and adds it to the current setting of
        no-proxy in the juju env.
        """
        out = utils.get_command_output(
            "{0} juju status".format(
                self.config.juju_home()),
            timeout=None,
            user_sudo=True)
        if out['status'] != 0:
            log.debug("error from status: {}".format(out))
            raise Exception("Problem with juju status.")
        try:
            status = yaml.load(out['output'])
            bootstrap_dns_name = status['machines']['0']['dns-name']
        except:
            utils.pollinate(self.session_id, 'EJ')
            log.exception("Error parsing yaml from juju status")
            raise Exception("Problem getting bootstrap machine DNS name")

        # first attempt to get directly, then use juju run:
        try:
            bootstrap_ip = socket.gethostbyname(bootstrap_dns_name)

        except socket.gaierror as e:
            log.error("Failed to get ip directly: {}".format(e))

            out = utils.get_command_output(
                "{} juju run --machine 0 "
                "'ip -o -4 address show dev juju-br0'".format(
                    self.config.juju_home()))
            if out['status'] != 0:
                log.error("Failed to get ip: {}".format(out))
                raise Exception("Failed to get IP of bootstrap node")
            regex = re.compile("inet\s+(\d+\.\d+\.\d+\.\d+)\/")
            match = re.search(regex, out['output'].rstrip())
            if match:
                bootstrap_ip = match.group(1)
                bootstrap_ip = get_ip_set("{}/24".format(bootstrap_ip))
            else:
                log.error("Failed to get ip: {}".format(out))
                raise Exception("Failed to get IP of bootstrap node")

        out = utils.get_command_output(
            "{} juju get-env no-proxy".format(self.config.juju_home()),
            timeout=None, user_sudo=True)
        if out['status'] != 0:
            log.debug("error from get-env: {}".format(out))
            raise Exception("Problem getting existing no-proxy setting")

        no_proxy = "{},{}".format(
            out['output'].rstrip(), bootstrap_ip)

        out = utils.get_command_output(
            "{} juju set-env no-proxy={}".format(self.config.juju_home(),
                                                 no_proxy),
            timeout=None, user_sudo=True)
        if out['status'] != 0:
            log.debug("error from set-env: {}".format(out))
            raise Exception("Problem setting no-proxy environment")
Esempio n. 2
0
    def add_bootstrap_to_no_proxy(self):
        """Finds bootstrap node IP and adds it to the current setting of
        no-proxy in the juju env.
        """
        out = utils.get_command_output(
            "{0} juju status".format(
                self.config.juju_home()),
            timeout=None,
            user_sudo=True)
        if out['status'] != 0:
            log.debug("error from status: {}".format(out))
            raise Exception("Problem with juju status.")
        try:
            status = yaml.load(out['output'])
            bootstrap_dns_name = status['machines']['0']['dns-name']
        except:
            utils.pollinate(self.session_id, 'EJ')
            log.exception("Error parsing yaml from juju status")
            raise Exception("Problem getting bootstrap machine DNS name")

        # first attempt to get directly, then use juju run:
        try:
            bootstrap_ip = socket.gethostbyname(bootstrap_dns_name)

        except socket.gaierror as e:
            log.error("Failed to get ip directly: {}".format(e))

            out = utils.get_command_output(
                "{} juju run --machine 0 "
                "'ip -o -4 address show dev juju-br0'".format(
                    self.config.juju_home()))
            if out['status'] != 0:
                log.error("Failed to get ip: {}".format(out))
                raise Exception("Failed to get IP of bootstrap node")
            regex = re.compile("inet\s+(\d+\.\d+\.\d+\.\d+)\/")
            match = re.search(regex, out['output'].rstrip())
            if match:
                bootstrap_ip = match.group(1)
                bootstrap_ip = get_ip_set("{}/24".format(bootstrap_ip))
            else:
                log.error("Failed to get ip: {}".format(out))
                raise Exception("Failed to get IP of bootstrap node")

        out = utils.get_command_output(
            "{} juju get-env no-proxy".format(self.config.juju_home()),
            timeout=None, user_sudo=True)
        if out['status'] != 0:
            log.debug("error from get-env: {}".format(out))
            raise Exception("Problem getting existing no-proxy setting")

        no_proxy = "{},{}".format(
            out['output'].rstrip(), bootstrap_ip)

        out = utils.get_command_output(
            "{} juju set-env no-proxy={}".format(self.config.juju_home(),
                                                 no_proxy),
            timeout=None, user_sudo=True)
        if out['status'] != 0:
            log.debug("error from set-env: {}".format(out))
            raise Exception("Problem setting no-proxy environment")
    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)
Esempio n. 4
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)