コード例 #1
0
  def install_package(self, name, context):
    """
    Install package

    :type name str
    :type context ambari_commons.shell.RepoCallContext

    :raise ValueError if name is empty
    """
    if not name:
      raise ValueError("Installation command was executed with no package name")
    elif context.is_upgrade or context.use_repos or not self._check_existence(name):
      cmd = self.properties.install_cmd[context.log_output]

      if context.use_repos:
        active_base_repos = self.get_active_base_repos()
        if 'base' in context.use_repos:
          # Remove 'base' from use_repos list
          use_repos = filter(lambda x: x != 'base', context.use_repos)
          use_repos.extend(active_base_repos)
        use_repos_options = []
        for repo in sorted(context.use_repos):
          use_repos_options = use_repos_options + ['--repo', repo]
        cmd = cmd + use_repos_options

      cmd = cmd + [name]
      Logger.info("Installing package {0} ('{1}')".format(name, shell.string_cmd_from_args_list(cmd)))

      shell.repository_manager_executor(cmd, self.properties, context)
    else:
      Logger.info("Skipping installation of existing package {0}".format(name))
コード例 #2
0
ファイル: yum_manager.py プロジェクト: z1446722374/ambari
    def install_package(self, name, context):
        """
    Install package

    :type name str
    :type context ambari_commons.shell.RepoCallContext

    :raise ValueError if name is empty
    """

        if not name:
            raise ValueError(
                "Installation command was executed with no package name")
        elif not self._check_existence(name) or context.action_force:
            cmd = self.properties.install_cmd[context.log_output]
            if context.use_repos:
                enable_repo_option = '--enablerepo=' + ",".join(
                    sorted(context.use_repos.keys()))
                disable_repo_option = '--disablerepo=' + "*" if not context.skip_repos or len(
                    context.skip_repos) == 0 else ','.join(context.skip_repos)
                cmd = cmd + [disable_repo_option, enable_repo_option]
            cmd = cmd + [name]
            Logger.info("Installing package {0} ('{1}')".format(
                name, shell.string_cmd_from_args_list(cmd)))
            shell.repository_manager_executor(cmd, self.properties, context)
        else:
            Logger.info(
                "Skipping installation of existing package {0}".format(name))
コード例 #3
0
  def remove_package(self, name, context, ignore_dependencies=False):
    """
    Remove package

    :type name str
    :type context ambari_commons.shell.RepoCallContext
    :type ignore_dependencies bool
    """
    if self._check_existence(name):
      cmd = self.properties.remove_cmd[context.log_output] + [name]
      Logger.info("Removing package {0} ('{1}')".format(name, shell.string_cmd_from_args_list(cmd)))
      shell.repository_manager_executor(cmd, self.properties, context)
    else:
      Logger.info("Skipping removal of non-existing package {0}".format(name))
コード例 #4
0
ファイル: yum_manager.py プロジェクト: z1446722374/ambari
    def remove_package(self, name, context, ignore_dependencies=False):
        """
    Remove package

    :type name str
    :type context ambari_commons.shell.RepoCallContext
    :type ignore_dependencies bool

    :raise ValueError if name is empty
    """
        if not name:
            raise ValueError(
                "Remove command were executed with no package name passed")
        if self._check_existence(name):
            if ignore_dependencies:
                cmd = self.properties.remove_without_dependencies_cmd + [name]
            else:
                cmd = self.properties.remove_cmd[context.log_output] + [name]
            Logger.info("Removing package {0} ('{1}')".format(
                name, shell.string_cmd_from_args_list(cmd)))
            shell.repository_manager_executor(cmd, self.properties, context)
        else:
            Logger.info(
                "Skipping removal of non-existing package {0}".format(name))
コード例 #5
0
    def install_package(self, name, context):
        """
    Install package

    :type name str
    :type context ambari_commons.shell.RepoCallContext
    """
        from resource_management.core import sudo

        apt_sources_list_tmp_dir = None

        if context.is_upgrade or context.use_repos or not self._check_existence(
                name):
            cmd = self.properties.install_cmd[context.log_output]
            copied_sources_files = []
            is_tmp_dir_created = False
            if context.use_repos:
                if 'base' in context.use_repos:
                    use_repos = set([
                        v for k, v in context.use_repos.items() if k != 'base'
                    ])
                else:
                    cmd = cmd + [
                        '-o', 'Dir::Etc::SourceList={0}'.format(
                            self.properties.empty_file)
                    ]
                    use_repos = set(context.use_repos.values())

                if use_repos:
                    is_tmp_dir_created = True
                    apt_sources_list_tmp_dir = tempfile.mkdtemp(
                        suffix="-ambari-apt-sources-d")
                    Logger.info("Temporary sources directory was created: %s" %
                                apt_sources_list_tmp_dir)

                    for repo in use_repos:
                        new_sources_file = os.path.join(
                            apt_sources_list_tmp_dir, repo + '.list')
                        Logger.info(
                            "Temporary sources file will be copied: {0}".
                            format(new_sources_file))
                        sudo.copy(
                            os.path.join(
                                self.properties.repo_definition_location,
                                repo + '.list'), new_sources_file)
                        copied_sources_files.append(new_sources_file)
                    cmd = cmd + [
                        '-o', 'Dir::Etc::SourceParts='.format(
                            apt_sources_list_tmp_dir)
                    ]

            cmd = cmd + [name]
            Logger.info("Installing package {0} ('{1}')".format(
                name, shell.string_cmd_from_args_list(cmd)))
            shell.repository_manager_executor(
                cmd,
                self.properties,
                context,
                env=self.properties.install_cmd_env)

            if is_tmp_dir_created:
                for temporary_sources_file in copied_sources_files:
                    Logger.info("Removing temporary sources file: {0}".format(
                        temporary_sources_file))
                    os.remove(temporary_sources_file)
                if apt_sources_list_tmp_dir:
                    Logger.info(
                        "Removing temporary sources directory: {0}".format(
                            apt_sources_list_tmp_dir))
                    os.rmdir(apt_sources_list_tmp_dir)
        else:
            Logger.info(
                "Skipping installation of existing package {0}".format(name))