virtop 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. data/README.rdoc +22 -0
  2. data/bin/virtop +61 -15
  3. data/lib/virtop/table.rb +24 -10
  4. data/lib/virtop.rb +1 -1
  5. metadata +8 -8
  6. data/README +0 -15
data/README.rdoc ADDED
@@ -0,0 +1,22 @@
1
+ == Installation ==
2
+
3
+ Add gems.github.com as a source for gems and install elliottcable-ncurses from
4
+ this mirror, because there is no version on rubygems.org which works with ruby
5
+ 1.9.
6
+
7
+ * gem sources -a http://gems.github.com
8
+ * gem install elliottcable-ncurses
9
+
10
+ Build the virtop gem and install it.
11
+
12
+ * gem build virtop.gemspec
13
+ * gem install virtop-*.gem
14
+
15
+ This should install ruby-libvirt as a dependency. Seems to me, that ruby-libvirt
16
+ from rubygems.org does not build with ruby 1.9. On Arch Linux you can install
17
+ ruby-libvirt from AUR:
18
+
19
+ http://aur.archlinux.org/packages.php?ID=31952
20
+
21
+ On other platforms you have to hallucinate another solution. At the link above
22
+ you find a patch to the ruby-libvirt sources, which makes it build in ruby 1.9.
data/bin/virtop CHANGED
@@ -25,6 +25,22 @@ EOF
25
25
  exit( 1 )
26
26
  end
27
27
 
28
+ # Show some lines of help.
29
+ if( ARGV.first == "-h" or ARGV.first == "--help" )
30
+ $stderr.puts <<EOF
31
+ #{$0} [libvirt-uri]
32
+
33
+ libvirt-uri is optional. Default is qemu:///system (for the local libvirt
34
+ daemon). See http://libvirt.org/uri.html for URI format.
35
+
36
+ Key bindings:
37
+ q Quit.
38
+ 1..6 Sort by column number.
39
+
40
+ EOF
41
+ exit( 1 )
42
+ end
43
+
28
44
  # Require and include virtop module. It will require libvirt.
29
45
  $:.unshift( File.join( File.dirname( __FILE__ ), '../lib' ) )
30
46
  require( 'virtop' )
@@ -37,6 +53,7 @@ if( ARGV.size < 1 )
37
53
  else
38
54
  uri = URI.parse( ARGV.first )
39
55
 
56
+ # Works around a deadlock if path is empty.
40
57
  if( uri.scheme == 'qemu+ssh' and uri.path == '' )
41
58
  raise( Exception.new( 'invalid url specified' ) )
42
59
  else
@@ -61,39 +78,68 @@ begin
61
78
  Ncurses.noecho
62
79
  Ncurses.halfdelay( 10 )
63
80
 
81
+ sortBy = 0
82
+
64
83
  while( true )
65
84
  Ncurses.clear
66
85
 
67
86
  n.intrflush( false )
68
87
  n.keypad( true )
69
88
 
89
+ info = c.node_get_info
90
+
91
+ n.addstr(
92
+ c.hostname.upcase +
93
+ "\n" +
94
+ ' cores ' + info.cores.to_s +
95
+ ' cpus ' + info.cpus.to_s +
96
+ ' mhz ' + info.mhz.to_s +
97
+ ' arch ' + info.model.to_s +
98
+ "\n" +
99
+ ' mem ' + info.memory.to_s +
100
+ ' nodes ' + info.nodes.to_s +
101
+ ' sockets ' + info.sockets.to_s +
102
+ ' threads ' + info.threads.to_s +
103
+ "\n" +
104
+ ' version ' + c.libversion.to_s +
105
+ "\n\n"
106
+ )
107
+
70
108
  t = Table.new(
71
- 'name',
72
- 'state',
73
- 'mem',
74
- 'mem_max',
75
- 'cpu_num',
76
- 'cpu_time'
109
+ 'NAME',
110
+ 'STATE',
111
+ 'MEM',
112
+ 'MEM_MAX',
113
+ 'CPU_NUM',
114
+ 'CPU_TIME'
77
115
  )
78
116
 
79
- c.domains.each do |domain|
117
+ c.domains.each do |d|
80
118
  t.add_row(
81
- domain.name,
82
- domain.state,
83
- domain.mem,
84
- domain.mem_max,
85
- domain.cpu_num,
86
- domain.cpu_time
119
+ d.name,
120
+ d.state,
121
+ d.mem,
122
+ d.mem_max,
123
+ d.cpu_num,
124
+ d.cpu_time
87
125
  )
88
126
  end
89
127
 
128
+ t.sort_by( sortBy )
129
+
90
130
  t.format.each do |line|
91
131
  n.addstr( line )
92
132
  end
93
133
 
94
- n.refresh
134
+ char = n.getch
135
+ case( char )
136
+ when 49..54
137
+ sortBy = char - 49
138
+ when 113
139
+ raise( LetsExit )
140
+ end
95
141
 
96
- raise( LetsExit ) if( n.getch == 113 )
142
+ n.refresh
97
143
  end
98
144
  rescue LetsExit
99
145
  ensure
data/lib/virtop/table.rb CHANGED
@@ -1,25 +1,38 @@
1
+ # Represents a table. Important for column width correction and sorting of rows.
1
2
  class Virtop::Table
3
+ # Contructor gets table header strings as arguments.
2
4
  def initialize( *args )
3
5
  @header = args
4
6
  @rows = []
5
7
  @widths = [0] * args.size
6
8
  end
7
9
 
8
- def header
9
- @header.to_s + "\n"
10
- end
11
-
10
+ # Adds a row to the table. Number of arguments must equal the number of
11
+ # columns given by header strings on contruction.
12
12
  def add_row( *args )
13
- raise( Exception ) if( args.size != @header.size )
13
+ if( args.size != @header.size )
14
+ raise( Exception.new( 'Wrong column number.' ) )
15
+ end
16
+
14
17
  @rows.push( args )
15
18
  end
16
19
 
17
- def each_row
18
- @rows.each do |row|
19
- yield( row.to_s )
20
+ # Sorts the table by a certain column given by it's header string or the
21
+ # index of the column starting at zero.
22
+ def sort_by( col )
23
+ if( col.class == String )
24
+ index = @header.index( col )
25
+ else
26
+ index = col.to_i
27
+ end
28
+
29
+ @rows = @rows.sort_by do |row|
30
+ row[index]
20
31
  end
21
32
  end
22
33
 
34
+ # Converts the whole table as array of strings, which are fancy formatted
35
+ # (mainly for good column widths).
23
36
  def format
24
37
  update_widths!
25
38
 
@@ -28,16 +41,17 @@ class Virtop::Table
28
41
  ( [ @header ] + @rows ).each do |row|
29
42
  line = ''
30
43
  @header.size.times do |i|
31
- line += row[i].ljust( @widths[i] + 2 )
44
+ line += row[i].to_s.ljust( @widths[i] + 2 )
32
45
  end
33
46
  a.push( line + "\n" )
34
47
  end
35
48
 
36
- a.insert( 1, "\n" )
49
+ a
37
50
  end
38
51
 
39
52
  private
40
53
 
54
+ # Saves maximum width per column into the +@header+ array.
41
55
  def update_widths!
42
56
  @header.size.times do |i|
43
57
  ( [ @header ] + @rows ).each do |row|
data/lib/virtop.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require( 'libvirt' )
2
2
 
3
3
  module Virtop
4
- VERSION = '0.0.7'
4
+ VERSION = '0.0.8'
5
5
  end
6
6
 
7
7
  $:.unshift( File.dirname( __FILE__ ) )
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: virtop
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 7
10
- version: 0.0.7
9
+ - 8
10
+ version: 0.0.8
11
11
  platform: ruby
12
12
  authors:
13
13
  - henning mueller
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-23 00:00:00 +02:00
18
+ date: 2010-07-16 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -44,12 +44,12 @@ extra_rdoc_files: []
44
44
 
45
45
  files:
46
46
  - bin/virtop
47
- - lib/virtop.rb
48
- - lib/virtop/letsexit.rb
49
- - lib/virtop/table.rb
50
47
  - lib/libvirt/connect.rb
51
48
  - lib/libvirt/domain.rb
52
- - README
49
+ - lib/virtop.rb
50
+ - lib/virtop/table.rb
51
+ - lib/virtop/letsexit.rb
52
+ - README.rdoc
53
53
  has_rdoc: true
54
54
  homepage:
55
55
  licenses: []
data/README DELETED
@@ -1,15 +0,0 @@
1
- == Installation ==
2
-
3
- Add gems.github.com as a source for gems and install elliottcable-ncurses from
4
- this mirror, because there is no version on rubygems.org which works with ruby
5
- 1.9.
6
-
7
- * gem sources -a http://gems.github.com
8
- * gem install elliottcable-ncurses
9
-
10
- Build the virtop gem and install it. Do not build ri and rdoc documentation for
11
- this would throw nasty errors.
12
-
13
- * gem build virtop.gemspec
14
- * gem install --no-ri --no-rdoc virtop-*.gem
15
-