コード例 #1
0
 def set_perms(self):
     """ sets permissions
     """
     try:
         log.info("Setting permissions for user {}".format(utils.install_user()))
         utils.chown(self.config.cfg_path, utils.install_user(), utils.install_user(), recursive=True)
         utils.get_command_output("sudo chmod 777 {}".format(self.config.cfg_path))
         utils.get_command_output("sudo chmod 777 -R {}/*".format(self.config.cfg_path))
     except:
         msg = "Error setting ownership for " "{}".format(self.config.cfg_path)
         log.exception(msg)
         raise Exception(msg)
コード例 #2
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))
コード例 #3
0
ファイル: multi.py プロジェクト: ddompe/openstack-installer
 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))
コード例 #4
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))
コード例 #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:
             utils.pollinate(self.session_id, 'EO')
             raise MaasInstallError(
                 "Unable to set ownership for {}".format(d))
コード例 #6
0
 def set_perms(self):
     """ sets permissions
     """
     try:
         utils.chown(self.config.cfg_path,
                     utils.install_user(),
                     utils.install_user(),
                     recursive=True)
         utils.get_command_output("sudo chmod 700 {}".format(
             self.config.cfg_path))
         utils.get_command_output("sudo chmod 600 -R {}/*".format(
             self.config.cfg_path))
     except:
         raise SingleInstallException(
             "Unable to set ownership for {}".format(self.config.cfg_path))
コード例 #7
0
    def start_task(self, newtaskname):
        self.tasks_started_debug.append(newtaskname)

        if len(self.tasks) <= self.current_task_index:
            log.error("ran off end of task list, "
                      "can't start {}".format(newtaskname))
            return

        (n, s, e) = self.tasks[self.current_task_index]
        if s is not None and e is None:
            self.stop_current_task()
            if len(self.tasks) <= self.current_task_index:
                log.error("ran off end of task list")
                return

        (expectedname, _, _) = self.tasks[self.current_task_index]
        if expectedname != newtaskname:
            log.warning("task name: expected {}, got {}".format(expectedname,
                                                                newtaskname))
            log.info("tasks        : {}\n"
                     "tasks_started: {}".format(self.tasks,
                                                self.tasks_started_debug))

        self.tasks[self.current_task_index] = (expectedname, time.time(), None)
        self.stopped = False
        if self.alarm is None:
            self.update_progress()
        utils.spew(os.path.join(self.config.cfg_path, 'timings.yaml'),
                   yaml.dump(self.tasks),
                   utils.install_user())
コード例 #8
0
 def set_perms(self):
     """ sets permissions
     """
     try:
         log.info("Setting permissions for user {}".format(
             utils.install_user()))
         utils.chown(self.config.cfg_path,
                     utils.install_user(),
                     utils.install_user(),
                     recursive=True)
         utils.get_command_output("sudo chmod 777 {}".format(
             self.config.cfg_path))
         utils.get_command_output("sudo chmod 777 -R {}/*".format(
             self.config.cfg_path))
     except:
         msg = ("Error setting ownership for "
                "{}".format(self.config.cfg_path))
         log.exception(msg)
         raise Exception(msg)
コード例 #9
0
ファイル: task.py プロジェクト: sincereuk/openstack-installer
    def write_timings(self):
        readable_tasks = []
        for n, s, e in self.tasks:
            if e is not None and s is not None:
                timing = e - s
            else:
                timing = None
            readable_tasks.append((n, s, e, timing))

        utils.spew(os.path.join(self.config.cfg_path, 'timings.yaml'),
                   yaml.dump(readable_tasks), utils.install_user())
コード例 #10
0
 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())
コード例 #11
0
ファイル: task.py プロジェクト: nikobeth/openstack-installer
    def write_timings(self):
        readable_tasks = []
        for n, s, e in self.tasks:
            if e is not None and s is not None:
                timing = e - s
            else:
                timing = None
            readable_tasks.append((n, s, e, timing))

        utils.spew(os.path.join(self.config.cfg_path, 'timings.yaml'),
                   yaml.dump(readable_tasks),
                   utils.install_user())
コード例 #12
0
    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*")
コード例 #13
0
    def __init__(self, loop, display_controller, config):
        self.display_controller = display_controller
        self.config = config
        self.loop = loop
        self.tasker = self.display_controller.tasker(loop, config)
        self.progress_output = ""
        username = utils.install_user()
        self.container_name = "openstack-single-{}".format(username)
        self.container_path = "/var/lib/lxc"
        self.container_abspath = os.path.join(self.container_path, self.container_name)
        self.userdata = os.path.join(self.config.cfg_path, "userdata.yaml")

        # Sets install type
        self.config.setopt("install_type", "Single")
コード例 #14
0
    def __init__(self, loop, display_controller, config):
        self.display_controller = display_controller
        self.config = config
        self.loop = loop
        self.tasker = self.display_controller.tasker(loop, config)
        username = utils.install_user()
        self.container_name = 'openstack-single-{}'.format(username)
        self.container_path = '/var/lib/lxc'
        self.container_abspath = os.path.join(self.container_path,
                                              self.container_name)
        self.userdata = os.path.join(self.config.cfg_path, 'userdata.yaml')

        # Sets install type
        self.config.setopt('install_type', 'Single')
コード例 #15
0
    def __init__(self, loop, display_controller, config):
        self.display_controller = display_controller
        self.config = config
        self.loop = loop
        self.tasker = self.display_controller.tasker(loop, config)
        username = utils.install_user()
        self.container_name = 'openstack-single-{}'.format(username)
        self.container_path = '/var/lib/lxc'
        self.container_abspath = os.path.join(self.container_path,
                                              self.container_name)
        self.userdata = os.path.join(
            self.config.cfg_path, 'userdata.yaml')

        # Sets install type
        self.config.setopt('install_type', 'Single')
コード例 #16
0
 def run_status(cls, name, cmd, config):
     """ Runs cloud-status in container
     """
     ip = cls.ip(name)
     cmd = ("sudo -H -u {2} TERM=xterm256-color ssh -t -q "
            "-l ubuntu -o \"StrictHostKeyChecking=no\" "
            "-o \"UserKnownHostsFile=/dev/null\" "
            "-o \"ControlMaster=auto\" "
            "-o \"ControlPersist=600\" "
            "-i {1} "
            "{0} {3}".format(ip, utils.ssh_privkey(), utils.install_user(),
                             cmd))
     log.debug("Running command without waiting "
               "for response.: {}".format(cmd))
     args = deque(shlex.split(cmd))
     os.execlp(args.popleft(), *args)
コード例 #17
0
 def run_status(cls, name, cmd, config):
     """ Runs cloud-status in container
     """
     ip = cls.ip(name)
     cmd = ("sudo -H -u {2} TERM=xterm256-color ssh -t -q "
            "-l ubuntu -o \"StrictHostKeyChecking=no\" "
            "-o \"UserKnownHostsFile=/dev/null\" "
            "-o \"ControlMaster=auto\" "
            "-o \"ControlPersist=600\" "
            "-i {1} "
            "{0} {3}".format(ip, utils.ssh_privkey(),
                             utils.install_user(), cmd))
     log.debug("Running command without waiting "
               "for response.: {}".format(cmd))
     args = deque(shlex.split(cmd))
     os.execlp(args.popleft(), *args)
コード例 #18
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())
コード例 #19
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())
コード例 #20
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())
コード例 #21
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())
コード例 #22
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
コード例 #23
0
    def run(cls, name, cmd, use_ssh=False, use_sudo=False, output_cb=None):
        """ run command in container

        :param str name: name of container
        :param str cmd: command to run
        """

        if use_ssh:
            ip = cls.ip(name)
            quoted_cmd = shlex.quote(cmd)
            wrapped_cmd = ("sudo -H -u {3} TERM=xterm256-color ssh -t -q "
                           "-l ubuntu -o \"StrictHostKeyChecking=no\" "
                           "-o \"UserKnownHostsFile=/dev/null\" "
                           "-o \"ControlMaster=auto\" "
                           "-o \"ControlPersist=600\" "
                           "-i {2} "
                           "{0} {1}".format(ip, quoted_cmd,
                                            utils.ssh_privkey(),
                                            utils.install_user()))
        else:
            ip = "-"
            quoted_cmd = cmd
            wrapped_cmd = []
            if use_sudo:
                wrapped_cmd.append("sudo")
            wrapped_cmd.append("lxc-attach -n {container_name} -- "
                               "{cmd}".format(container_name=name, cmd=cmd))
            wrapped_cmd = " ".join(wrapped_cmd)

        stdoutmaster, stdoutslave = pty.openpty()
        subproc = subprocess.Popen(wrapped_cmd,
                                   shell=True,
                                   stdout=stdoutslave,
                                   stderr=subprocess.PIPE)
        os.close(stdoutslave)
        decoder = codecs.getincrementaldecoder('utf-8')()

        def last_ten_lines(s):
            chunk = s[-1500:]
            lines = chunk.splitlines(True)
            return ''.join(lines[-10:]).replace('\r', '')

        decoded_output = ""
        try:
            while subproc.poll() is None:
                try:
                    b = os.read(stdoutmaster, 512)
                except OSError as e:
                    if e.errno != errno.EIO:
                        raise
                    break
                else:
                    final = False
                    if not b:
                        final = True
                    decoded_chars = decoder.decode(b, final)
                    if decoded_chars is None:
                        continue

                    decoded_output += decoded_chars
                    if output_cb:
                        ls = last_ten_lines(decoded_output)

                        output_cb(ls)
                    if final:
                        break
        finally:
            os.close(stdoutmaster)
            if subproc.poll() is None:
                subproc.kill()
            subproc.wait()

        errors = [l.decode('utf-8') for l in subproc.stderr.readlines()]
        if output_cb:
            output_cb(last_ten_lines(decoded_output))

        errors = ''.join(errors)

        if subproc.returncode == 0:
            return decoded_output.strip()
        else:
            raise ContainerRunException(
                "Problem running {0} in container "
                "{1}:{2}".format(quoted_cmd, name, ip), subproc.returncode)
コード例 #24
0
    def run(cls, name, cmd, use_ssh=False, use_sudo=False, output_cb=None):
        """ run command in container

        :param str name: name of container
        :param str cmd: command to run
        """

        if use_ssh:
            ip = cls.ip(name)
            quoted_cmd = shlex.quote(cmd)
            wrapped_cmd = ("sudo -H -u {3} TERM=xterm256-color ssh -t -q "
                           "-l ubuntu -o \"StrictHostKeyChecking=no\" "
                           "-o \"UserKnownHostsFile=/dev/null\" "
                           "-o \"ControlMaster=auto\" "
                           "-o \"ControlPersist=600\" "
                           "-i {2} "
                           "{0} {1}".format(ip, quoted_cmd,
                                            utils.ssh_privkey(),
                                            utils.install_user()))
        else:
            ip = "-"
            quoted_cmd = cmd
            wrapped_cmd = []
            if use_sudo:
                wrapped_cmd.append("sudo")
            wrapped_cmd.append("lxc-attach -n {container_name} -- "
                               "{cmd}".format(container_name=name,
                                              cmd=cmd))
            wrapped_cmd = " ".join(wrapped_cmd)

        stdoutmaster, stdoutslave = pty.openpty()
        subproc = subprocess.Popen(wrapped_cmd, shell=True,
                                   stdout=stdoutslave,
                                   stderr=subprocess.PIPE)
        os.close(stdoutslave)
        decoder = codecs.getincrementaldecoder('utf-8')()

        def last_ten_lines(s):
            chunk = s[-1500:]
            lines = chunk.splitlines(True)
            return ''.join(lines[-10:]).replace('\r', '')

        decoded_output = ""
        try:
            while subproc.poll() is None:
                try:
                    b = os.read(stdoutmaster, 512)
                except OSError as e:
                    if e.errno != errno.EIO:
                        raise
                    break
                else:
                    final = False
                    if not b:
                        final = True
                    decoded_chars = decoder.decode(b, final)
                    if decoded_chars is None:
                        continue

                    decoded_output += decoded_chars
                    if output_cb:
                        ls = last_ten_lines(decoded_output)

                        output_cb(ls)
                    if final:
                        break
        finally:
            os.close(stdoutmaster)
            if subproc.poll() is None:
                subproc.kill()
            subproc.wait()

        errors = [l.decode('utf-8') for l in subproc.stderr.readlines()]
        if output_cb:
            output_cb(last_ten_lines(decoded_output))

        errors = ''.join(errors)

        if subproc.returncode == 0:
            return decoded_output.strip()
        else:
            raise ContainerRunException("Problem running {0} in container "
                                        "{1}:{2}".format(quoted_cmd, name, ip),
                                        subproc.returncode)
コード例 #25
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
コード例 #26
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()
        )