virtop 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,15 @@
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
+
data/bin/virtop CHANGED
@@ -1,13 +1,17 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # Require libvirt and uri modules and print out exception message if they could
4
+ # not be loaded.
3
5
  begin
4
- require 'libvirt'
5
- require 'uri'
6
+ require( 'libvirt' )
7
+ require( 'uri' )
6
8
  rescue LoadError => e
7
9
  $stderr.puts( e.message )
8
10
  exit( 1 )
9
11
  end
10
12
 
13
+ # Require ncurses module and print out instructions howto install it if it could
14
+ # not be loaded.
11
15
  begin
12
16
  require 'ncurses'
13
17
  rescue LoadError
@@ -23,6 +27,16 @@ EOF
23
27
  exit( 1 )
24
28
  end
25
29
 
30
+ # Require virtop module. If not installed as gem, try it in the source's
31
+ # directory.
32
+ begin
33
+ require( 'virtop' )
34
+ rescue LoadError
35
+ require( File.dirname( __FILE__ ) + '/../lib/virtop' )
36
+ end
37
+
38
+ # Connection URL will be qemu:///system if nothing else is given as the first
39
+ # parameter.
26
40
  if( ARGV.size < 1 )
27
41
  url = 'qemu:///system'
28
42
  else
@@ -35,58 +49,7 @@ else
35
49
  end
36
50
  end
37
51
 
38
- class LetsExit < Exception
39
- end
40
-
41
- module Libvirt
42
- class Connect
43
- def domains
44
- ret = Array.new
45
-
46
- self.list_domains.each do |id|
47
- ret.push(
48
- self.lookup_domain_by_id( id )
49
- )
50
- end
51
-
52
- ret
53
- end
54
- end
55
-
56
- class Domain
57
- def to_s
58
- self.name
59
- end
60
-
61
- def state
62
- case( self.info.state )
63
- when 1
64
- ">"
65
- when 3
66
- "||"
67
- else
68
- "?"
69
- end
70
- end
71
-
72
- def mem
73
- ( self.info.memory / 1024 ).to_s + "M"
74
- end
75
-
76
- def mem_max
77
- ( self.info.max_mem / 1024 ).to_s + "M"
78
- end
79
-
80
- def cpu_num
81
- self.info.nr_virt_cpu.to_s
82
- end
83
-
84
- def cpu_time
85
- self.info.cpu_time.to_s
86
- end
87
- end
88
- end
89
-
52
+ # Open the connection to the libvirt ressource or print out error message.
90
53
  begin
91
54
  c = Libvirt::open( url )
92
55
  rescue Libvirt::ConnectionError
@@ -94,6 +57,8 @@ rescue Libvirt::ConnectionError
94
57
  exit( 1 )
95
58
  end
96
59
 
60
+ # Initialize ncurses context. Clear and print details for each domain in a 10s
61
+ # interval. Quit on keypress of 'q'.
97
62
  begin
98
63
  n = Ncurses.initscr
99
64
 
@@ -0,0 +1,3 @@
1
+ # This exception should be thrown, if an exit is triggered.
2
+ class LetsExit < Exception
3
+ end
@@ -0,0 +1,17 @@
1
+ # Extend Libvirt::Connect with a method which returns all available domains as
2
+ # an array.
3
+ module Libvirt
4
+ class Connect
5
+ def domains
6
+ ret = Array.new
7
+
8
+ self.list_domains.each do |id|
9
+ ret.push(
10
+ self.lookup_domain_by_id( id )
11
+ )
12
+ end
13
+
14
+ ret
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ # Extend Libvirt::Domain with different methods for human readable display of
2
+ # the domain state.
3
+ module Libvirt
4
+ class Domain
5
+ def to_s
6
+ self.name
7
+ end
8
+
9
+ def state
10
+ case( self.info.state )
11
+ when 1
12
+ ">"
13
+ when 3
14
+ "||"
15
+ else
16
+ "?"
17
+ end
18
+ end
19
+
20
+ def mem
21
+ ( self.info.memory / 1024 ).to_s + "M"
22
+ end
23
+
24
+ def mem_max
25
+ ( self.info.max_mem / 1024 ).to_s + "M"
26
+ end
27
+
28
+ def cpu_num
29
+ self.info.nr_virt_cpu.to_s
30
+ end
31
+
32
+ def cpu_time
33
+ self.info.cpu_time.to_s
34
+ end
35
+ end
36
+ end
data/lib/virtop.rb ADDED
@@ -0,0 +1,5 @@
1
+ $:.unshift( File.dirname( __FILE__ ) )
2
+
3
+ Dir.glob( $:.first + '/**/*.rb' ).each do |file|
4
+ require( file )
5
+ end
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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
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-05-28 00:00:00 +02:00
18
+ date: 2010-05-30 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -44,6 +44,11 @@ extra_rdoc_files: []
44
44
 
45
45
  files:
46
46
  - bin/virtop
47
+ - lib/virtop/letsexit.rb
48
+ - lib/virtop/libvirt/domain.rb
49
+ - lib/virtop/libvirt/connect.rb
50
+ - lib/virtop.rb
51
+ - README
47
52
  has_rdoc: true
48
53
  homepage:
49
54
  licenses: []