class Registry
Constants
- LIST_COLUMNS
Attributes
user_columns[R]
Public Class Methods
new(path, cache_key:)
click to toggle source
# File lib/smartos-manager/core.rb, line 93 def initialize(path, cache_key:) @registry = {} @hosts = {} @config_path = path @cache_path = "#{path}.cache" @cache = load_cache() @cache_key = cache_key @config = TOML.load_file(path) @global_data = @config.delete('global') @user_columns = @config.delete('user_columns') || {} @config.each do |name, opts| host = SSHHost.from_hash(name, opts, @global_data) @hosts[host.address] = host end end
Public Instance Methods
diag()
click to toggle source
# File lib/smartos-manager/core.rb, line 175 def diag ret = {} run_on_all("prtdiag").each do |addr, data| host = find_host(addr) system_id = "(none)" free_memory_banks = 0 if matches = data.match(/^System Configuration: (.+)$/) system_id = matches[1] data.scan(/(empty).*DIMM\s+([0-9])/).each do |reg| free_memory_banks+= 1 end end ret[host] = { system_id: system_id, free_memory_banks: free_memory_banks } end ret end
find_host(addr)
click to toggle source
# File lib/smartos-manager/core.rb, line 112 def find_host(addr) @hosts[addr] end
list_images()
click to toggle source
# File lib/smartos-manager/core.rb, line 156 def list_images ret = {} columns = %w(uuid name version os) images = run_on_all("imgadm list -j") images.each do |addr, data| host = find_host(addr) json = JSON.parse(data) ret[host] = json.map do |img_data| Image.new( img_data['manifest'] ) end end ret end
list_vms()
click to toggle source
# File lib/smartos-manager/core.rb, line 116 def list_vms columns = LIST_COLUMNS + @user_columns.values ret = {} rss = {} @hosts.values.each do |host| ret[host] = [] end # Memory used for each VM run_on_all("zonememstat").each do |_, data| data.split("\n").each do |line| # ignore headers / global unless line.start_with?(' ') uuid, used_mem, cap, _, _ = line.gsub(/\s+/, ' ').split(" ") rss[uuid] = used_mem.to_i.megabytes end end end vms = run_on_all("vmadm list -o #{columns.join(',')} -p") vms.each do |addr, data| if data host = find_host(addr) ret[host] = data.split("\n").map! do |line| dd = {} line.split(':', 20).each.with_index do |val, n| dd[columns[n]] = val end VirtualMachine.new(dd, rss) end end end ret end
sysinfo()
click to toggle source
# File lib/smartos-manager/core.rb, line 199 def sysinfo ret = {} # Memory size: 8157 Megabytes run_on_all("prtconf | head -3 | grep Mem").each do |addr, data| host = find_host(addr) _, _, mem, _ = data.split(" ") ret[host] = {memory: mem.to_i.megabytes} end # main MAC address run_on_all("ifconfig `dladm show-phys -p -o link | head -n 1` | grep ether | cut -d ' ' -f 2").each do |addr, data| host = find_host(addr) ret[host][:mac0] = data.strip() end # disk infos run_on_all("diskinfo -Hp").each do |addr, data| host = find_host(addr) ret[host][:disks] = {} data.split("\n").each do |line| type, name, _, _, size_bytes, _, ssd = line.split("\t") ret[host][:disks][name] = {size: size_bytes.to_i} end end # disk size run_on_all("zfs list -Ho name,quota,volsize").each do |addr, data| host = find_host(addr) ret[host][:zfs_volumes] = {} data.split("\n").each do |line| name, quota, size = line.split("\t") ret[host][:zfs_volumes][name] = {size: size[0...-1].split(',').first, quota: quota[0...-1].split(',').first} end end # ARC Max Size # zfs:0:arcstats:c:2850704524 # zfs:0:arcstats:size:1261112216 run_on_all("kstat -C zfs:0:arcstats:c zfs:0:arcstats:size").each do |addr, data| host = find_host(addr) zfs_arc_current = nil zfs_arc_reserved = nil data.split("\n").each do |line| value = line.split(':').last.to_i if line.start_with?('zfs:0:arcstats:size:') zfs_arc_current = value else zfs_arc_reserved = value end end ret[host].merge!( zfs_arc_current: zfs_arc_current, zfs_arc_reserved: zfs_arc_reserved ) end # joyent_20140207T053435Z run_on_all("uname -a | cut -d ' ' -f 4").each do |addr, data| host = find_host(addr) _, rev = data.strip().split('_') ret[host][:smartos_version] = rev end ret end
Private Instance Methods
cache_result(cmd, result)
click to toggle source
# File lib/smartos-manager/core.rb, line 271 def cache_result(cmd, result) @cache[@cache_key] ||= {} @cache[@cache_key][cmd] = result data = Oj.dump(@cache, indent: 2) IO.write(@cache_path, data) end
load_cache()
click to toggle source
# File lib/smartos-manager/core.rb, line 279 def load_cache Oj.load_file(@cache_path) rescue Oj::ParseError, IOError => err {} end