Class: Kontena::Plugin::Cloud::Platform::UpgradeCommand

Inherits:
Command
  • Object
show all
Includes:
Cli::Common, Common
Defined in:
lib/kontena/plugin/cloud/platform/upgrade_command.rb

Constant Summary

Constants included from CloudCommand

CloudCommand::PLATFORM_NOT_SELECTED_ERROR

Instance Method Summary collapse

Methods included from Common

#cached_platforms, #current_organization, #current_platform, #fetch_platforms, #fetch_platforms_for_org, #find_platform_by_name, #login_to_platform, #parse_platform_name, #platform_config_exists?, #prompt_platform, #require_platform

Methods included from CloudCommand

#verify_current_grid, #verify_current_master, #verify_current_master_token

Instance Method Details

#executeObject



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
# File 'lib/kontena/plugin/cloud/platform/upgrade_command.rb', line 13

def execute
  require_platform(name)

  to_version = self.version
  platform = find_platform_by_name(current_platform, current_organization)
  unless to_version
    to_version = prompt_version(platform)
    if Gem::Version.new(to_version) < Gem::Version.new(platform.version)
      exit_with_error "Downgrade is not supported"
    end
  end
  data = {
    attributes: {
      name: platform.name,
      version: to_version
    }
  }
  spinner "Upgrading platform #{pastel.cyan(name)} to version #{to_version}" do
    cloud_client.put("/organizations/#{current_organization}/platforms/#{platform.name}", { data: data })
    while platform.version != to_version do
      sleep 5
      platform = find_platform_by_name(platform.id, current_organization, false)
    end
  end
end

#prompt_version(platform) ⇒ Object

Parameters:



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/kontena/plugin/cloud/platform/upgrade_command.rb', line 40

def prompt_version(platform)
  versions = cloud_client.get("/platform_versions")['data']

  platform_version = Gem::Version.new(platform.version)
  versions = versions.select { |v| Gem::Version.new(v['id']) > platform_version }

  exit_with_error "Platform is already on the latest version" if versions.size == 0

  prompt.select("Upgrade to version:") do |menu|
    versions.each do |v|
      menu.choice v['id']
    end
  end
end