Class: AppCLI

Inherits:
Thor
  • Object
show all
Defined in:
lib/smartos-manager/cli.rb

Instance Method Summary collapse

Instance Method Details

#listObject



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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/smartos-manager/cli.rb', line 57

def list
  registry = get_registry(cache_key: 'list')
  ret = registry.list_vms()
  
  rev_colors = ColorPicker.new
  
  sysinfos = registry.sysinfo()
  diags = registry.diag()
  
  failures = registry.failed_connections()
  unless failures.empty?
    puts "Error while connecting to:".red()
    failures.each do |s|
      puts "  - #{s.name} : #{s.address}".red()
    end
    
    puts ""
  end

  
  user_columns = registry.user_columns.keys.map{|s| humanize(s) }
  
  p_vm_list("Memory", "Name (gray = online)", "Type", "UUID", "State", "Admin IP", "DD(GB)", *user_columns)
  
  ret.each do |host, vms|
    mem = sysinfos[host][:memory]
    zfs_arc_reserved = sysinfos[host][:zfs_arc_reserved]
    zfs_arc_current = sysinfos[host][:zfs_arc_current]
    vm_memory = 0
    
    vms.each{|vm| vm_memory += vm.memory }
    # avail = (mem - vm_memory) - (20 * mem/100.0)
    avail = [1, (mem - vm_memory) - zfs_arc_current].max
    
    dd = sysinfos[host][:disks].map{|_, d| "#{format_size(d[:size])} GB" }.join(" - ")
    
    rev = sysinfos[host][:smartos_version]
    puts "\nHardware: #{diags[host][:system_id]} (MAC: #{sysinfos[host][:mac0].upcase.white()}, IP: #{host.address.white()} )"
    puts "HDD: #{sysinfos[host][:disks].keys.size} drives - #{dd}"
    puts "#{host.name} [SmartOS: #{rev.send(rev_colors.get(rev))}] (Free RAM: #{avail.human_size(1).green}/#{mem.human_size(1)} [Free Slots: #{diags[host][:free_memory_banks]}], ZFS: #{format_size(zfs_arc_current)}G/#{format_size(zfs_arc_reserved)}G)"
    vms.each do |vm|
      user_columns = registry.user_columns.values.map{|key| vm[key] }
      
      if vm.type == "KVM"
        vm_disk = sysinfos[host][:zfs_volumes]["zones/#{vm.uuid}-disk0"]
        vm_disk_label = "#{vm_disk[:size]}"
      else
        vm_disk = sysinfos[host][:zfs_volumes]["zones/#{vm.uuid}"]
        vm_disk_label = "#{vm_disk[:quota]}"
      end
      
      if vm.rss
        tmp = vm.rss.human_size(1)
      else
        tmp = "-"
      end
      formatted_mem = "#{tmp.ljust(5)} / #{vm.memory.human_size(1).ljust(5)}"
      
      p_vm_list(formatted_mem, vm.name, vm.type, vm.uuid, vm.state, vm.admin_ip, vm_disk_label, *user_columns)
    end
    
    if vms.empty?
      puts "  [ no VMS                     ]"
    end
    
    # avail = (mem - vm_memory) - (20 * mem/100)
    # puts "  Available Memory: #{avail.human_size(1)}".magenta()
  end
  
end

#list_imagesObject



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/smartos-manager/cli.rb', line 40

def list_images
  registry = get_registry(cache_key: 'list_images')
  ret = registry.list_images()
  
  rev_colors = ColorPicker.new
  p_img_list("UUID", "Name", "Version", "OS")
  
  ret.each do |host, images|
    puts "\n#{host.name} - #{host.address}"
    images.each do |img|
      # color = rev_colors.get(img.uuid)
      p_img_list( img.uuid, img.name, img.version, img.os)
    end
  end
end