Class: Crowbar::Client::Command::Upgrade::Repocheck

Inherits:
Base
  • Object
show all
Includes:
Mixin::Filter, Mixin::Format, Mixin::UpgradeError
Defined in:
lib/crowbar/client/command/upgrade/repocheck.rb

Overview

Implementation for the upgrade repocheck command

Instance Attribute Summary

Attributes inherited from Base

#args, #options, #stderr, #stdin, #stdout

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Crowbar::Client::Command::Base

Instance Method Details

#executeObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/crowbar/client/command/upgrade/repocheck.rb', line 35

def execute
  request.process do |request|
    case request.code
    when 200
      hint = ""
      if provide_format == :table
        response = request.parsed_response
        repos = {}
        response.each do |type, type_data|
          type_data["repos"].each do |repo|
            next if repo.nil?
            repos[repo] = { repo: repo, status: [], type: type } unless repos.key? repo
          end
          type_data["errors"].each do |error, error_data|
            error_data.each do |arch, bad_repos|
              bad_repos.each do |bad_repo|
                hint = "Some repopositories are not available. " \
                  "Fix the problem and call the step again."
                repos[bad_repo] = { repo: bad_repo, status: [], type: type } \
                  unless repos.key? bad_repo
                repos[bad_repo][:status] << "#{error} (#{arch})"
              end
            end
          end
        end

        repos.values.each do |repo|
          repo[:status] = repo[:status].uniq.join(", ")
          repo[:status] = "available" if repo[:status].empty?
        end

        formatter = Formatter::Hash.new(
          format: provide_format,
          headings: ["Repository", "Status", "Type"],
          values: Filter::Hash.new(
            filter: provide_filter,
            values: repos.values
          ).result
        )
      else
        formatter = Formatter::Nested.new(
          format: provide_format,
          values: Filter::Subset.new(
            filter: provide_filter,
            values: request.parsed_response
          ).result
        )
      end

      if formatter.empty?
        err "No repochecks"
      else
        say formatter.result
        next unless provide_format == :table
        say hint unless hint.empty?
        say "Next step: 'crowbarctl upgrade admin'" if args.component == "crowbar"
        say "Next step: 'crowbarctl upgrade services'" if args.component == "nodes"
      end
    else
      case args.component
      when "crowbar"
        err format_error(
          request.parsed_response["error"], "repocheck_crowbar"
        )
      when "nodes"
        err format_error(
          request.parsed_response["error"], "repocheck_nodes"
        )
      else
        err "No such component '#{args.component}'. " \
          "Only 'crowbar' and 'nodes' are valid components."
      end
    end
  end
end

#requestObject



29
30
31
32
33
# File 'lib/crowbar/client/command/upgrade/repocheck.rb', line 29

def request
  @request ||= Request::Upgrade::Repocheck.new(
    args
  )
end