class TritonOps::Snapshot::Reporter
Constants
- Format
Public Class Methods
new(snapshot, **options)
click to toggle source
# File lib/triton-ops/snapshot/reporter.rb, line 22 def initialize(snapshot, **options) @snapshot = snapshot @options = options self end
Public Instance Methods
usage()
click to toggle source
# File lib/triton-ops/snapshot/reporter.rb, line 29 def usage users.each do |user| uuid = user.uuid ram = memory(uuid) || 0 disk = storage(uuid) || 0 next if [ram, disk].all?(&:zero?) login = user.login cn = user.cn puts "# #{login} (#{cn}) has (#{ram} MB of Memory) and (#{disk} MB of Storage) reserved" puts TTY::Table.new( header: ['VM Alias', 'Memory', 'Storage', 'Creation Date'], rows: owned_by(uuid) .sort_by { |vm| vm.create_timestamp } .map do |vm| [ vm.alias, vm.max_physical_memory, (vm.disks ? vm.disks.map { |disk| disk.size }.reduce(:+) : 0), vm.create_timestamp.iso8601 ] end).render(format) end end
Private Instance Methods
exclusions()
click to toggle source
# File lib/triton-ops/snapshot/reporter.rb, line 62 def exclusions @options.fetch(:exclude) { [] } end
format()
click to toggle source
# File lib/triton-ops/snapshot/reporter.rb, line 58 def format @options.fetch(:format) { :basic } end
memory(owner_uuid)
click to toggle source
# File lib/triton-ops/snapshot/reporter.rb, line 83 def memory(owner_uuid) owned_by(owner_uuid) .map { |vm| vm.max_physical_memory } .reduce(:+) end
owned_by(owner_uuid)
click to toggle source
# File lib/triton-ops/snapshot/reporter.rb, line 77 def owned_by(owner_uuid) @snapshot .vms .select { |vm| vm.owner_uuid == owner_uuid } end
storage(owner_uuid)
click to toggle source
# File lib/triton-ops/snapshot/reporter.rb, line 89 def storage(owner_uuid) owned_by(owner_uuid) .reject { |vm| vm.disks.empty? } .map { |vm| vm.disks .map { |disk| disk.size } .reduce(:+) } .reduce(:+) end
targets()
click to toggle source
# File lib/triton-ops/snapshot/reporter.rb, line 66 def targets @options.fetch(:targets) { @snapshots.users.map { |user| user.login } } end
users()
click to toggle source
# File lib/triton-ops/snapshot/reporter.rb, line 70 def users @snapshot.users .reject { |user| exclusions.include? user.login } .reject { |user| @snapshot.vms.none? { |vm| vm.owner_uuid == user.uuid } } .select { |user| targets.empty? or targets.include?(user.login) } end