def mark(self, phasename):
     contents = dict()
     contents['name'] = phasename
     contents['when'] = date.rcf8222date()
     yield phasename
     LOG.debug("Marking the completion of phase %r in file %r", phasename, self.fn)
     lines = [json.dumps(contents), '']
     sh.append_file(self.fn, utils.joinlinesep(*lines))
Beispiel #2
0
 def _configure_db_confs(self):
     LOG.info("Fixing up %s mysql configs.", colorizer.quote(self.distro.name))
     new_lines = []
     for line in sh.load_file(DBInstaller.MYSQL_CONF).splitlines():
         if line.startswith('skip-grant-tables'):
             new_lines.append('#' + line)
         elif line.startswith('bind-address'):
             new_lines.append('#' + line)
             new_lines.append('bind-address = 0.0.0.0')
         else:
             new_lines.append(line)
     sh.write_file_and_backup(DBInstaller.MYSQL_CONF, utils.joinlinesep(*new_lines))
 def _configure_db_confs(self):
     LOG.info("Fixing up %s mysql configs.", colorizer.quote(self.distro.name))
     fc = sh.load_file('/etc/my.cnf')
     lines = fc.splitlines()
     new_lines = list()
     for line in lines:
         if line.startswith('skip-grant-tables'):
             line = '#' + line
         new_lines.append(line)
     fc = utils.joinlinesep(*new_lines)
     with sh.Rooted(True):
         sh.write_file('/etc/my.cnf', fc)
Beispiel #4
0
 def _configure_db_confs(self):
     LOG.info("Fixing up %s mysql configs.", colorizer.quote(self.distro.name))
     new_lines = []
     for line in sh.load_file(DBInstaller.MYSQL_CONF).splitlines():
         if line.startswith('skip-grant-tables'):
             new_lines.append('#' + line)
         elif line.startswith('bind-address'):
             new_lines.append('#' + line)
             new_lines.append('bind-address = 0.0.0.0')
         else:
             new_lines.append(line)
     with sh.Rooted(True):
         sh.write_file_and_backup(DBInstaller.MYSQL_CONF, utils.joinlinesep(*new_lines))
Beispiel #5
0
 def _generate_root_wrap(self):
     if not self.cfg.getboolean("nova", "do_root_wrap"):
         return False
     else:
         lines = list()
         lines.append("%s ALL=(root) NOPASSWD: %s" % (sh.getuser(), self.root_wrap_bin))
         fc = utils.joinlinesep(*lines)
         root_wrap_fn = sh.joinpths(self.distro.get_command_config("sudoers_dir"), "nova-rootwrap")
         self.tracewriter.file_touched(root_wrap_fn)
         with sh.Rooted(True):
             sh.write_file(root_wrap_fn, fc)
             sh.chmod(root_wrap_fn, 0440)
             sh.chown(root_wrap_fn, sh.getuid(sh.ROOT_USER), sh.getgid(sh.ROOT_GROUP))
         return True
Beispiel #6
0
 def _config_fix_httpd(self):
     LOG.info("Fixing up: %s", colorizer.quote(HorizonInstaller.HTTPD_CONF))
     (user, group) = self._get_apache_user_group()
     new_lines = []
     for line in sh.load_file(HorizonInstaller.HTTPD_CONF).splitlines():
         # Directives in the configuration files are case-insensitive,
         # but arguments to directives are often case sensitive...
         # NOTE(harlowja): we aren't handling multi-line fixups...
         if re.match(r"^\s*User\s+(.*)$", line, re.I):
             line = "User %s" % (user)
         if re.match(r"^\s*Group\s+(.*)$", line, re.I):
             line = "Group %s" % (group)
         if re.match(r"^\s*Listen\s+(.*)$", line, re.I):
             line = "Listen 0.0.0.0:80"
         new_lines.append(line)
     sh.write_file_and_backup(HorizonInstaller.HTTPD_CONF, utils.joinlinesep(*new_lines))
Beispiel #7
0
 def _config_fix_httpd(self):
     LOG.info("Fixing up: %s", colorizer.quote(HorizonInstaller.HTTPD_CONF))
     (user, group) = self._get_apache_user_group()
     new_lines = []
     for line in sh.load_file(HorizonInstaller.HTTPD_CONF).splitlines():
         # Directives in the configuration files are case-insensitive,
         # but arguments to directives are often case sensitive...
         # NOTE(harlowja): we aren't handling multi-line fixups...
         if re.match("^\s*User\s+(.*)$", line, re.I):
             line = "User %s" % (user)
         if re.match("^\s*Group\s+(.*)$", line, re.I):
             line = "Group %s" % (group)
         if re.match("^\s*Listen\s+(.*)$", line, re.I):
             line = "Listen 0.0.0.0:80"
         new_lines.append(line)
     with sh.Rooted(True):
         sh.write_file_and_backup(HorizonInstaller.HTTPD_CONF, utils.joinlinesep(*new_lines))
 def _get_session(self):
     sessions = self._active_sessions()
     LOG.debug("Found sessions [%s]" % ", ".join(sessions))
     if not sessions:
         return None
     if len(sessions) > 1:
         msg = [
                 "You are running multiple screen sessions [%s], please reduce the set to zero or one." % (", ".join(sessions)),
               ]
         for s in sorted(sessions):
             mp = {'SCREEN_ID': s}
             cmd_msg = self._gen_cmd(SCREEN_KILLER, mp)
             env = self._get_env()
             for (k, v) in env.items():
                 cmd_msg.insert(0, "%s=%s" % (k, v))
             msg.append("Try running %r to quit that session." % (" ".join(cmd_msg)))
         raise excp.StartException(utils.joinlinesep(msg))
     return sessions[0]
 def _config_fix_httpd(self):
     LOG.info("Fixing up: %s", colorizer.quote('/etc/httpd/conf/httpd.conf'))
     (user, group) = self._get_apache_user_group()
     old_lines = sh.load_file('/etc/httpd/conf/httpd.conf').splitlines()
     new_lines = list()
     for line in old_lines:
         # Directives in the configuration files are case-insensitive,
         # but arguments to directives are often case sensitive...
         # NOTE(harlowja): we aren't handling multi-line fixups...
         if re.match("^\s*User\s+(.*)$", line, re.I):
             line = "User %s" % (user)
         if re.match("^\s*Group\s+(.*)$", line, re.I):
             line = "Group %s" % (group)
         if re.match("^\s*Listen\s+(.*)$", line, re.I):
             line = "Listen 0.0.0.0:80"
         new_lines.append(line)
     contents = utils.joinlinesep(*new_lines)
     with sh.Rooted(True):
         sh.write_file('/etc/httpd/conf/httpd.conf', contents)
Beispiel #10
0
 def _get_content(self, nova_conf):
     generated_content = nova_conf.generate()
     extra_flags = self._get_extra('extra_flags')
     if extra_flags:
         LOG.warn("EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS!")
         extra_flags = self._convert_extra_flags(extra_flags)
     extra_opts = self._get_extra('extra_opts')
     if extra_flags or extra_opts:
         new_contents = list()
         new_contents.append(generated_content)
         new_contents.append("")
         new_contents.append("# Extra flags")
         new_contents.append("")
         new_contents.extend(extra_flags)
         new_contents.append("")
         new_contents.append("# Extra options")
         new_contents.append("")
         new_contents.extend(extra_opts)
         new_contents.append("")
         generated_content = utils.joinlinesep(*new_contents)
     return generated_content
Beispiel #11
0
 def _get_content(self, nova_conf):
     generated_content = nova_conf.generate()
     extra_flags = self._get_extra('extra_flags')
     if extra_flags:
         LOG.warn("EXTRA_FLAGS is defined and may need to be converted to EXTRA_OPTS!")
         extra_flags = self._convert_extra_flags(extra_flags)
     extra_opts = self._get_extra('extra_opts')
     if extra_flags or extra_opts:
         new_contents = list()
         new_contents.append(generated_content)
         new_contents.append("")
         new_contents.append("# Extra flags")
         new_contents.append("")
         new_contents.extend(extra_flags)
         new_contents.append("")
         new_contents.append("# Extra options")
         new_contents.append("")
         new_contents.extend(extra_opts)
         new_contents.append("")
         generated_content = utils.joinlinesep(*new_contents)
     return generated_content
 def update(self, fn):
     current_vars = RcReader().extract(fn)
     possible_vars = dict()
     possible_vars.update(self._get_general_envs())
     possible_vars.update(self._get_ec2_envs())
     possible_vars.update(self._get_password_envs())
     possible_vars.update(self._get_os_envs())
     possible_vars.update(self._get_euca_envs())
     possible_vars.update(self._get_nova_envs())
     possible_vars.update(self._get_misc_envs())
     new_vars = dict()
     updated_vars = dict()
     for (key, value) in possible_vars.items():
         if value is not None:
             if key in current_vars and (current_vars.get(key) != value):
                 updated_vars[key] = value
             elif key not in current_vars:
                 new_vars[key] = value
     if new_vars or updated_vars:
         lines = list()
         lines.append("")
         lines.append('# Updated on %s' % (date.rcf8222date()))
         lines.append("")
         if new_vars:
             lines.append('# New stuff')
             lines.extend(self._make_dict_export(new_vars))
             lines.append("")
         if updated_vars:
             lines.append('# Updated stuff')
             lines.extend(self._make_dict_export(updated_vars))
             lines.append("")
         append_contents = utils.joinlinesep(*lines)
         sh.append_file(fn, append_contents)
         return len(new_vars) + len(updated_vars)
     else:
         return 0
 def write(self, fn):
     contents = utils.joinlinesep(*self._generate_lines())
     sh.write_file(fn, contents)
 def create(self, session_name, env_exports):
     lines = self._generate_lines(session_name, env_exports)
     contents = utils.joinlinesep(*lines)
     return contents