Class: Kontena::Plugin::Cloud::Platform::ListCommand

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

Constant Summary

Constants included from CloudCommand

CloudCommand::PLATFORM_NOT_SELECTED_ERROR

Instance Method Summary collapse

Methods included from Organization::Common

#fetch_organizations, #prompt_organization

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

#default_organizationObject



26
27
28
# File 'lib/kontena/plugin/cloud/platform/list_command.rb', line 26

def default_organization
  prompt_organization
end

#executeObject



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/kontena/plugin/cloud/platform/list_command.rb', line 14

def execute
  platforms = cloud_client.get("/organizations/#{organization}/platforms")['data']

  print_table(platforms) do |p|
    platform = Kontena::Cli::Models::Platform.new(p)
    p['name'] = "#{state_icon(platform.state)} #{organization}/#{platform.name}"
    p['organization'] = platform.organization
    p['hosted_type'] = platform.hosted_type
    p['region'] = platform.region
  end
end

#fieldsObject



30
31
32
33
34
35
36
# File 'lib/kontena/plugin/cloud/platform/list_command.rb', line 30

def fields
  {
    name: 'name',
    type: 'hosted_type',
    region: 'region'
  }
end

#state_icon(health) ⇒ Object



38
39
40
41
42
43
44
45
46
47
# File 'lib/kontena/plugin/cloud/platform/list_command.rb', line 38

def state_icon(health)
  case health
  when nil
    " ".freeze
  when 'running'.freeze
    pastel.green(''.freeze)
  else
    pastel.dark(''.freeze)
  end
end