Class: VolumeVisualizer::Cli

Inherits:
Thor
  • Object
show all
Defined in:
lib/volume_visualizer/cli.rb

Instance Method Summary collapse

Instance Method Details

#generateObject



89
90
91
92
93
94
95
96
97
98
99
# File 'lib/volume_visualizer/cli.rb', line 89

def generate
  json_filename = File.join( options[:output_path], options[:data_name] + ".json" )
  File.open(json_filename, "w") do |json|
    json.puts zfs.to_json
  end
  STDERR.puts "generated data file #{json_filename}"

  html_filename = File.join( options[:output_path], "index.html" )
  FileUtils.cp html_source, html_filename
  STDERR.puts "installed #{html_filename}"
end

#instawebObject



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
# File 'lib/volume_visualizer/cli.rb', line 114

def instaweb
  if false && (ENV["USER"] != "root") # && not in parse mode
    STDERR.puts <<-EOF
ERROR: Sorry. Instaweb mode requires root privileges, or requires
  input data to parse. Try one of these:

sudo vv instaweb

  or 

sudo `vv show-command` > /tmp/data
vv instaweb --parse-file /tmp/data
    EOF
    exit 1
  end

  port = nil
  begin
    port = rand(20000) + 20000
    server = WEBrick::HTTPServer.new(
      :AccessLog => [],
      :Port => port,
      :Logger => WEBrick::Log::new("/dev/null", 7)
    )
  rescue Errno::EADDRINUSE
    puts "ERROR: port #{port} already in use -- retrying"
    retry
  end


  server.mount_proc "/" do |req, res|
    res.body = File.open(html_source).read
  end

  zfs_data = zfs.to_json
  server.mount_proc "/volviz.json" do |req, res|
    res.body = zfs_data
  end

  trap 'INT' do 
    server.shutdown 
  end

  STDERR.puts "server running on http://#{Socket.gethostname}:#{port}"

  server.start
end

#show_commandObject



57
58
59
# File 'lib/volume_visualizer/cli.rb', line 57

def show_command
  puts ZFS::Pool.query_command options[:volume]
end