Exemplo n.º 1
0
 def _generate_help(self, session_name, env_exports):
     lines = list()
     lines.append("# Screen help stuff")
     cmd_pieces = list()
     for (k, v) in env_exports.items():
         cmd_pieces.append("%s=%s" % (k, sh.shellquote(v)))
     cmd_pieces.append("screen -r %s" % (session_name))
     cmd_pieces.insert(0, "sudo")
     lines.append("# To connect to this session run the following command: ")
     lines.append("# %s" % (" ".join(cmd_pieces)))
     lines.append("")
     return lines
Exemplo n.º 2
0
 def _write_exports(self, component_order, instances, path):
     entries = []
     contents = StringIO()
     contents.write("# Exports for action %s\n\n" % (self.name))
     for c in component_order:
         exports = instances[c].env_exports
         if exports:
             contents.write("# Exports for %s\n" % (c))
             for (k, v) in exports.items():
                 export_entry = "export %s=%s" % (k, sh.shellquote(str(v).strip()))
                 entries.append(export_entry)
                 contents.write("%s\n" % (export_entry))
             contents.write("\n")
     if entries:
         sh.write_file(path, contents.getvalue())
         utils.log_iterable(entries,
                            header="Wrote to %s %s exports" % (path, len(entries)),
                            logger=LOG)
Exemplo n.º 3
0
 def _write_exports(self, component_order, instances, path):
     entries = []
     contents = StringIO()
     contents.write("# Exports for action %s\n\n" % (self.name))
     for c in component_order:
         exports = instances[c].env_exports
         if exports:
             contents.write("# Exports for %s\n" % (c))
             for (k, v) in exports.items():
                 export_entry = "export %s=%s" % (k, sh.shellquote(str(v).strip()))
                 entries.append(export_entry)
                 contents.write("%s\n" % (export_entry))
             contents.write("\n")
     if entries:
         sh.write_file(path, contents.getvalue())
         utils.log_iterable(entries,
                            header="Wrote to %s %s exports" % (path, len(entries)),
                            logger=LOG)
Exemplo n.º 4
0
 def _generate_lines(self, session_name, env_exports):
     lines = list()
     lines.append("# RC file generated on %s" % (date.rcf8222date()))
     lines.append("")
     if env_exports:
         lines.append("# Environment settings (these will need to be exported)")
         for (k, v) in env_exports.items():
             lines.append("# export %s=%s" % (k, sh.shellquote(v)))
         lines.append("")
     lines.append("# Screen sockets & programs were created/ran as the root user")
     lines.append("# So you will need to run as user root (or sudo) to enter the following sessions")
     lines.append("")
     lines.append("# Session settings")
     lines.append("sessionname %s" % (session_name))
     lines.append(STATUS_BAR_CMD)
     lines.append("screen -t %s bash" % (SESSION_DEF_TITLE))
     lines.append("")
     lines.extend(self._generate_help(session_name, env_exports))
     return lines
Exemplo n.º 5
0
 def _get_upstart_conf_params(self, app_pth, program_name, *program_args):
     params = dict()
     if self.cfg.getboolean('upstart', 'respawn'):
         params['RESPAWN'] = "respawn"
     else:
         params['RESPAWN'] = ""
     params['SHORT_NAME'] = program_name
     params['MADE_DATE'] = date.rcf8222date()
     params['START_EVENT'] = self.cfg.getdefaulted('upstart', 'start_event', 'all_os_start')
     params['STOP_EVENT'] = self.cfg.getdefaulted('upstart', 'stop_event', 'all_os_stop')
     params['COMPONENT_START_EVENT'] = self.name + START_EVENT_SUFFIX
     params['COMPONENT_STOP_EVENT'] = self.name + STOP_EVENT_SUFFIX
     params['PROGRAM_NAME'] = app_pth
     params['AUTHOR'] = constants.PROG_NAME
     if program_args:
         escaped_args = list()
         for opt in program_args:
             LOG.debug("Current opt: %s" % (opt))
             escaped_args.append(sh.shellquote(opt))
         params['PROGRAM_OPTIONS'] = " ".join(escaped_args)
     else:
         params['PROGRAM_OPTIONS'] = ''
     return params
Exemplo n.º 6
0
    def _write_all_deps_package(self):
        spec_filename = sh.joinpths(
            self.rpmbuild_dir,
            "SPECS",
            "%s.spec" % self.OPENSTACK_DEPS_PACKAGE_NAME)

        # Clean out previous dirs.
        for dirname in (self.rpmbuild_dir, self.deps_repo_dir,
                        self.deps_src_repo_dir):
            sh.deldir(dirname)
            sh.mkdirslist(dirname, tracewriter=self.tracewriter)

        def get_version_release():
            right_now = datetime.now()
            components = [
                str(right_now.year),
                str(right_now.month),
                str(right_now.day),
            ]
            return (".".join(components), right_now.strftime("%s"))

        (version, release) = get_version_release()
        spec_content = """Name: %s
Version: %s
Release: %s
License: Apache 2.0
Summary: OpenStack dependencies
BuildArch: noarch

""" % (self.OPENSTACK_DEPS_PACKAGE_NAME, version, release)

        packages = {}
        for inst in self.instances:
            try:
                for pack in inst.packages:
                    packages[pack["name"]] = pack
            except AttributeError:
                pass

        scripts = {}
        script_map = {
            "pre-install": "%pre",
            "post-install": "%post",
            "pre-uninstall": "%preun",
            "post-uninstall": "%postun",
        }
        for pack_name in sorted(packages.iterkeys()):
            pack = packages[pack_name]
            cont = [spec_content, "Requires: ", pack["name"]]
            version = pack.get("version")
            if version:
                cont.append(" ")
                cont.append(version)
            cont.append("\n")
            spec_content = "".join(cont)
            for script_name in script_map.iterkeys():
                try:
                    script_list = pack[script_name]
                except (KeyError, ValueError):
                    continue
                script_body = scripts.get(script_name, "")
                script_body = "%s\n# %s\n" % (script_body, pack_name)
                for script in script_list:
                    try:
                        line = " ".join(
                            sh.shellquote(word)
                            for word in script["cmd"])
                    except (KeyError, ValueError):
                        continue
                    if script.get("ignore_failure"):
                        ignore = " 2>/dev/null || true"
                    else:
                        ignore = ""
                    script_body = "".join((
                        script_body,
                        line,
                        ignore,
                        "\n"))
                scripts[script_name] = script_body

        spec_content += "\n%description\n\n"
        for script_name in sorted(script_map.iterkeys()):
            try:
                script_body = scripts[script_name]
            except KeyError:
                pass
            else:
                spec_content = "%s\n%s\n%s\n" % (
                    spec_content,
                    script_map[script_name],
                    script_body)

        spec_content += "\n%files\n"
        sh.write_file(spec_filename, spec_content,
                      tracewriter=self.tracewriter)
        cmdline = [
            "rpmbuild", "-ba",
            "--define", "_topdir %s" % self.rpmbuild_dir,
            spec_filename,
        ]
        LOG.info("Building %s RPM" % self.OPENSTACK_DEPS_PACKAGE_NAME)
        sh.execute(cmdline)
Exemplo n.º 7
0
    def _write_all_deps_package(self):
        spec_filename = sh.joinpths(
            self.rpmbuild_dir, "SPECS",
            "%s.spec" % self.OPENSTACK_DEPS_PACKAGE_NAME)

        # Clean out previous dirs.
        for dirname in (self.rpmbuild_dir, self.deps_repo_dir,
                        self.deps_src_repo_dir):
            sh.deldir(dirname)
            sh.mkdirslist(dirname, tracewriter=self.tracewriter)

        def get_version_release():
            right_now = datetime.now()
            components = [
                str(right_now.year),
                str(right_now.month),
                str(right_now.day),
            ]
            return (".".join(components), right_now.strftime("%s"))

        (version, release) = get_version_release()
        spec_content = """Name: %s
Version: %s
Release: %s
License: Apache 2.0
Summary: OpenStack dependencies
BuildArch: noarch

""" % (self.OPENSTACK_DEPS_PACKAGE_NAME, version, release)

        packages = {}
        for inst in self.instances:
            try:
                for pack in inst.packages:
                    packages[pack["name"]] = pack
            except AttributeError:
                pass

        scripts = {}
        script_map = {
            "pre-install": "%pre",
            "post-install": "%post",
            "pre-uninstall": "%preun",
            "post-uninstall": "%postun",
        }
        for pack_name in sorted(packages.iterkeys()):
            pack = packages[pack_name]
            cont = [spec_content, "Requires: ", pack["name"]]
            version = pack.get("version")
            if version:
                cont.append(" ")
                cont.append(version)
            cont.append("\n")
            spec_content = "".join(cont)
            for script_name in script_map.iterkeys():
                try:
                    script_list = pack[script_name]
                except (KeyError, ValueError):
                    continue
                script_body = scripts.get(script_name, "")
                script_body = "%s\n# %s\n" % (script_body, pack_name)
                for script in script_list:
                    try:
                        line = " ".join(
                            sh.shellquote(word) for word in script["cmd"])
                    except (KeyError, ValueError):
                        continue
                    if script.get("ignore_failure"):
                        ignore = " 2>/dev/null || true"
                    else:
                        ignore = ""
                    script_body = "".join((script_body, line, ignore, "\n"))
                scripts[script_name] = script_body

        spec_content += "\n%description\n\n"
        for script_name in sorted(script_map.iterkeys()):
            try:
                script_body = scripts[script_name]
            except KeyError:
                pass
            else:
                spec_content = "%s\n%s\n%s\n" % (
                    spec_content, script_map[script_name], script_body)

        spec_content += "\n%files\n"
        sh.write_file(spec_filename,
                      spec_content,
                      tracewriter=self.tracewriter)
        cmdline = [
            "rpmbuild",
            "-ba",
            "--define",
            "_topdir %s" % self.rpmbuild_dir,
            spec_filename,
        ]
        LOG.info("Building %s RPM" % self.OPENSTACK_DEPS_PACKAGE_NAME)
        sh.execute(cmdline)
Exemplo n.º 8
0
 def _make_export(self, export_name, value):
     escaped_val = sh.shellquote(value)
     full_line = "export %s=%s" % (export_name, escaped_val)
     return full_line