File: outdated.rb

package info (click to toggle)
vagrant 2.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,072 kB
  • sloc: ruby: 80,731; sh: 369; makefile: 9; lisp: 1
file content (96 lines) | stat: -rw-r--r-- 2,978 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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
require 'optparse'

require_relative 'download_mixins'

module VagrantPlugins
  module CommandBox
    module Command
      class Outdated < Vagrant.plugin("2", :command)
        include DownloadMixins

        def execute
          options = {}
          download_options = {}

          opts = OptionParser.new do |o|
            o.banner = "Usage: vagrant box outdated [options]"
            o.separator ""
            o.separator "Checks if there is a new version available for the box"
            o.separator "that are you are using. If you pass in the --global flag,"
            o.separator "all boxes will be checked for updates."
            o.separator ""
            o.separator "Options:"
            o.separator ""

            o.on("--global", "Check all boxes installed") do |g|
              options[:global] = g
            end

            build_download_options(o, download_options)
          end

          argv = parse_options(opts)
          return if !argv

          # If we're checking the boxes globally, then do that.
          if options[:global]
            outdated_global(download_options)
            return 0
          end

          with_target_vms(argv) do |machine|
            @env.action_runner.run(Vagrant::Action.action_box_outdated, {
              box_outdated_force: true,
              box_outdated_refresh: true,
              box_outdated_success_ui: true,
              machine: machine,
            }.merge(download_options))
          end
        end

        def outdated_global(download_options)
          boxes = {}
          @env.boxes.all.reverse.each do |name, version, provider|
            box = @env.boxes.find(name, provider, version)
            if !box.metadata_url
              @env.ui.output(I18n.t(
                "vagrant.box_outdated_no_metadata",
                name: box.name,
                provider: box.provider))
              next
            end

            md = nil
            begin
              md = box.load_metadata(download_options)
            rescue Vagrant::Errors::BoxMetadataDownloadError => e
              @env.ui.error(I18n.t(
                "vagrant.box_outdated_metadata_error",
                name: box.name,
                provider: box.provider,
                message: e.extra_data[:message]))
              next
            end

            current = Gem::Version.new(box.version)
            latest  = Gem::Version.new(md.versions.last)
            if latest <= current
              @env.ui.success(I18n.t(
                "vagrant.box_up_to_date",
                name: box.name,
                provider: box.provider,
                version: box.version))
            else
              @env.ui.warn(I18n.t(
                "vagrant.box_outdated",
                name: box.name,
                provider: box.provider,
                current: box.version,
                latest: latest.to_s,))
            end
          end
        end
      end
    end
  end
end