Class: Chef::Knife::DigitalOceanImageList

Inherits:
Chef::Knife
  • Object
show all
Includes:
DigitalOceanBase
Defined in:
lib/chef/knife/digital_ocean_image_list.rb

Instance Method Summary collapse

Methods included from DigitalOceanBase

#client, #h, included, load_deps, #locate_config_value, #validate!

Instance Method Details

#runObject



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
# File 'lib/chef/knife/digital_ocean_image_list.rb', line 27

def run
  $stdout.sync = true

  validate!

  image_list = [
      h.color('ID',           :bold),
      h.color('Distribution', :bold),
      h.color('Name',         :bold),
      h.color('Global',       :bold)
  ]

  if config[:global_images]
    filter = 'global'
  else
    filter = 'my_images'
  end

  images = client.images.list(:filter => filter).images

  images.sort! do |a, b|
    [ a.distribution, a.name ] <=> [ b.distribution, b.name ]
  end

  images.each do |image|
    image_list << image.id.to_s
    image_list << image.distribution.to_s
    image_list << image.name.to_s
    image_list << truefalse(config[:global_images])
  end

  puts h.list(image_list, :uneven_columns_across, 4)
end

#truefalse(boolean) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/chef/knife/digital_ocean_image_list.rb', line 61

def truefalse(boolean)
  if boolean
    '+'
  else
    '-'
  end
end