Class: Chef::Knife::XenserverTemplateList

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

Instance Method Summary collapse

Methods included from XenserverBase

#bytes_to_megabytes, #connection, included, #locate_config_value

Instance Method Details

#runObject



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

def run
  $stdout.sync = true
  templates = connection.servers.custom_templates || []
  table = table do |t|
    t.headings = %w{NAME MEMORY GUEST_TOOLS NETWORKS}
    if templates.empty? and !config[:include_builtin]
      ui.warn "No custom templates found. Use --include-builtin to list them all."
    end
    if config[:include_builtin]
      templates += connection.servers.builtin_templates
    end
    templates.each do |vm|
      networks = []
      vm.vifs.each do |vif|
        name = vif.network.name
        if name.size > 20
          name = name[0..16] + '...'
        end
        networks << name
      end
      networks = networks.join("\n")
      mem = bytes_to_megabytes(vm.memory_static_max)
      t << ["#{vm.name}\n  #{ui.color('uuid: ', :yellow)}#{vm.uuid}", mem, vm.tools_installed?, networks]
    end
  end
  puts table if !templates.empty?
end