Exemplo n.º 1
0
 def _unconfigure_links(self):
     sym_files = self.tracereader.symlinks_made()
     if sym_files:
         utils.log_iterable(sym_files, logger=LOG,
             header="Removing %s symlink files" % (len(sym_files)))
         for fn in sym_files:
             sh.unlink(fn, run_as_root=True)
Exemplo n.º 2
0
 def _unconfigure_files(self):
     cfg_files = self.tracereader.files_configured()
     if cfg_files:
         utils.log_iterable(cfg_files, logger=LOG,
             header="Removing %s configuration files" % (len(cfg_files)))
         for fn in cfg_files:
             sh.unlink(fn, run_as_root=True)
Exemplo n.º 3
0
 def pre_uninstall(self):
     dbtype = self.cfg.get("db", "type")
     dbactions = self.distro.get_command_config(dbtype, quiet=True)
     try:
         if dbactions:
             LOG.info(("Attempting to reset your db password to %r so"
                       " that we can set it the next time you install.") %
                      (RESET_BASE_PW))
             pwd_cmd = self.distro.get_command(dbtype, 'set_pwd')
             if pwd_cmd:
                 LOG.info(
                     "Ensuring your database is started before we operate on it."
                 )
                 self.runtime.restart()
                 params = {
                     'OLD_PASSWORD':
                     self.pw_gen.get_password('sql', PASSWORD_PROMPT),
                     'NEW_PASSWORD':
                     RESET_BASE_PW,
                     'USER':
                     self.cfg.getdefaulted("db", "sql_user", 'root'),
                 }
                 cmds = [{'cmd': pwd_cmd}]
                 utils.execute_template(*cmds, params=params)
     except IOError:
         LOG.warn((
             "Could not reset the database password. You might have to manually "
             "reset the password to %r before the next install") %
                  (RESET_BASE_PW))
         utils.log_iterable(SQL_RESET_PW_LINKS,
                            logger=LOG,
                            header="To aid in this check out:")
Exemplo n.º 4
0
 def _uninstall_touched_files(self):
     files_touched = self.tracereader.files_touched()
     if files_touched:
         utils.log_iterable(files_touched, logger=LOG,
             header="Removing %s touched files" % (len(files_touched)))
         for fn in files_touched:
             sh.unlink(fn, run_as_root=True)
Exemplo n.º 5
0
 def run(self, persona, root_dir):
     instances = self._construct_instances(persona, root_dir)
     self._handle_prereq(persona, instances, root_dir)
     component_order = self._order_components(persona.wanted_components)
     LOG.info("Processing components for action %r", (self.NAME or "???"))
     utils.log_iterable(component_order, header="Activating in the following order:", logger=LOG)
     self._verify_components(component_order, instances)
     self._warm_components(component_order, instances)
     self._run(persona, root_dir, component_order, instances)
Exemplo n.º 6
0
 def _uninstall_python(self):
     py_listing = self.tracereader.py_listing()
     if py_listing:
         py_listing_dirs = set()
         for (_, where) in py_listing:
             py_listing_dirs.add(where)
         utils.log_iterable(py_listing_dirs, logger=LOG,
             header="Uninstalling %s python setups" % (len(py_listing_dirs)))
         for where in py_listing_dirs:
             sh.execute(*PY_UNINSTALL, cwd=where, run_as_root=True)
Exemplo n.º 7
0
 def _install_pips(self):
     pips = self._get_pips()
     if pips:
         pip_names = set([p['name'] for p in pips])
         utils.log_iterable(pip_names, logger=LOG,
             header="Setting up %s python packages" % (len(pip_names)))
         with utils.progress_bar(INSTALL_TITLE, len(pips)) as p_bar:
             for (i, p) in enumerate(pips):
                 self.tracewriter.pip_installed(p)
                 pip.install(p, self.distro)
                 p_bar.update(i + 1)
Exemplo n.º 8
0
 def run(self, persona, root_dir):
     instances = self._construct_instances(persona, root_dir)
     self._handle_prereq(persona, instances, root_dir)
     component_order = self._order_components(persona.wanted_components)
     LOG.info("Processing components for action %r", (self.NAME or "???"))
     utils.log_iterable(component_order,
                        header="Activating in the following order:",
                        logger=LOG)
     self._verify_components(component_order, instances)
     self._warm_components(component_order, instances)
     self._run(persona, root_dir, component_order, instances)
Exemplo n.º 9
0
 def _uninstall_pips(self):
     if self.keep_old:
         LOG.info('Keep-old flag set, not removing any python packages.')
         return
     pips = self.tracereader.pips_installed()
     if pips:
         pip_names = set([p['name'] for p in pips])
         utils.log_iterable(pip_names, logger=LOG,
             header="Uninstalling %s python packages" % (len(pip_names)))
         with utils.progress_bar(UNINSTALL_TITLE, len(pips), reverse=True) as p_bar:
             for (i, p) in enumerate(pips):
                 pip.uninstall(p, self.distro)
                 p_bar.update(i + 1)
Exemplo n.º 10
0
 def _uninstall_dirs(self):
     dirs_made = self.tracereader.dirs_made()
     if dirs_made:
         dirs_made = [sh.abspth(d) for d in dirs_made]
         if self.keep_old:
             download_places = [path_location[0] for path_location in self.tracereader.download_locations()]
             if download_places:
                 utils.log_iterable(download_places, logger=LOG,
                     header="Keeping %s download directories (and there children directories)" % (len(download_places)))
                 for download_place in download_places:
                     dirs_made = sh.remove_parents(download_place, dirs_made)
         if dirs_made:
             utils.log_iterable(dirs_made, logger=LOG,
                 header="Removing %s created directories" % (len(dirs_made)))
             for dir_name in dirs_made:
                 sh.deldir(dir_name, run_as_root=True)
Exemplo n.º 11
0
 def install(self):
     LOG.debug('Preparing to install packages for %r', self.component_name)
     pkgs = self._get_packages()
     if pkgs:
         pkg_names = set([p['name'] for p in pkgs])
         utils.log_iterable(pkg_names, logger=LOG,
             header="Setting up %s distribution packages" % (len(pkg_names)))
         with utils.progress_bar(INSTALL_TITLE, len(pkgs)) as p_bar:
             for (i, p) in enumerate(pkgs):
                 self.tracewriter.package_installed(p)
                 packager = self.get_packager(p)
                 packager.install(p)
                 p_bar.update(i + 1)
     else:
         LOG.info('No packages to install for %r', self.component_name)
     return self.trace_dir
Exemplo n.º 12
0
 def _configure_files(self):
     config_fns = self._get_config_files()
     if config_fns:
         utils.log_iterable(config_fns, logger=LOG,
             header="Configuring %s files" % (len(config_fns)))
         for fn in config_fns:
             tgt_fn = self._get_target_config_name(fn)
             self.tracewriter.dirs_made(*sh.mkdirslist(sh.dirname(tgt_fn)))
             LOG.info("Configuring file %r", fn)
             (source_fn, contents) = self._get_source_config(fn)
             LOG.debug("Replacing parameters in file %r", source_fn)
             contents = self._config_param_replace(fn, contents, self._get_param_map(fn))
             LOG.debug("Applying final adjustments in file %r", source_fn)
             contents = self._config_adjust(contents, fn)
             LOG.info("Writing configuration file %r => %r", source_fn, tgt_fn)
             self.tracewriter.cfg_file_written(sh.write_file(tgt_fn, contents))
     return len(config_fns)
Exemplo n.º 13
0
 def _uninstall_pkgs(self):
     if self.keep_old:
         LOG.info('Keep-old flag set, not removing any packages.')
         return
     pkgs = self.tracereader.packages_installed()
     if pkgs:
         pkg_names = set([p['name'] for p in pkgs])
         utils.log_iterable(pkg_names, logger=LOG,
             header="Potentially removing %s packages" % (len(pkg_names)))
         which_removed = set()
         with utils.progress_bar(UNINSTALL_TITLE, len(pkgs), reverse=True) as p_bar:
             for (i, p) in enumerate(pkgs):
                 packager = self.get_packager(p)
                 if packager.remove(p):
                     which_removed.add(p['name'])
                 p_bar.update(i + 1)
         utils.log_iterable(which_removed, logger=LOG,
             header="Actually removed %s packages" % (len(which_removed)))
Exemplo n.º 14
0
    def install(self):
        LOG.info("Setting up any specified images in glance.")

        # Extract the urls from the config
        flat_locations = self.cfg.getdefaulted('img', 'image_urls', '')
        locations = [loc.strip() for loc in flat_locations.split(',') if len(loc.strip())]

        # Install them in glance
        am_installed = 0
        if locations:
            utils.log_iterable(locations, logger=LOG,
                                header="Attempting to download+extract+upload %s images." % len(locations))
            token = self._get_token()
            for uri in locations:
                try:
                    name = Image(uri, token).install()
                    if name:
                        LOG.info("Installed image named %r" % (name))
                        am_installed += 1
                except (IOError, tarfile.TarError) as e:
                    LOG.exception('Installing %r failed due to: %s', uri, e)
        return am_installed
Exemplo n.º 15
0
 def download(self):
     download_locs = self._get_real_download_locations()
     uris = [loc['uri'] for loc in download_locs]
     utils.log_iterable(uris, logger=LOG,
             header="Downloading from %s uris" % (len(uris)))
     for info in download_locs:
         # Extract da download!
         uri = info['uri']
         target_loc = info['target']
         branch = info['branch']
         # Activate da download!
         self.tracewriter.download_happened(target_loc, uri)
         dirs_made = self._do_download(uri, target_loc, branch)
         # Here we ensure this is always added so that
         # if a keep old happens then this of course
         # won't be recreated, but if u uninstall without keeping old
         # then this won't be deleted this time around
         # adding it in is harmless and will make sure its removed.
         if target_loc not in dirs_made:
             dirs_made.append(target_loc)
         self.tracewriter.dirs_made(*dirs_made)
     return len(download_locs)
Exemplo n.º 16
0
 def pre_uninstall(self):
     dbtype = self.cfg.get("db", "type")
     dbactions = self.distro.get_command_config(dbtype, quiet=True)
     try:
         if dbactions:
             LOG.info(("Attempting to reset your db password to %r so"
                       " that we can set it the next time you install.") % (RESET_BASE_PW))
             pwd_cmd = self.distro.get_command(dbtype, 'set_pwd')
             if pwd_cmd:
                 LOG.info("Ensuring your database is started before we operate on it.")
                 self.runtime.restart()
                 params = {
                     'OLD_PASSWORD': self.pw_gen.get_password('sql', PASSWORD_PROMPT),
                     'NEW_PASSWORD': RESET_BASE_PW,
                     'USER': self.cfg.getdefaulted("db", "sql_user", 'root'),
                     }
                 cmds = [{'cmd': pwd_cmd}]
                 utils.execute_template(*cmds, params=params)
     except IOError:
         LOG.warn(("Could not reset the database password. You might have to manually "
                   "reset the password to %r before the next install") % (RESET_BASE_PW))
         utils.log_iterable(SQL_RESET_PW_LINKS, logger=LOG,
                             header="To aid in this check out:")
Exemplo n.º 17
0
 def _install_python_setups(self):
     py_dirs = self._get_python_directories()
     if py_dirs:
         real_dirs = dict()
         for (name, wkdir) in py_dirs.items():
             real_dirs[name] = wkdir or self.app_dir
         utils.log_iterable(real_dirs.values(), logger=LOG,
             header="Setting up %s python directories" % (len(real_dirs)))
         for (name, working_dir) in real_dirs.items():
             self.tracewriter.dirs_made(*sh.mkdirslist(working_dir))
             self.tracewriter.py_installed(name, working_dir)
             (stdout, stderr) = sh.execute(*PY_INSTALL,
                                            cwd=working_dir,
                                            run_as_root=True)
             py_trace_name = "%s-%s" % (tr.PY_TRACE, name)
             py_writer = tr.TraceWriter(tr.trace_fn(self.trace_dir,
                                                    py_trace_name))
             # Format or json encoding isn't really needed here since this is
             # more just for information output/lookup if desired.
             py_writer.trace("CMD", " ".join(PY_INSTALL))
             py_writer.trace("STDOUT", stdout)
             py_writer.trace("STDERR", stderr)
             self.tracewriter.file_touched(py_writer.filename())