rubiojr-domctl 0.2.20090414130028 → 0.2.20090415143011

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -9,3 +9,11 @@
9
9
 
10
10
  * lots of new commands implemented
11
11
  * bug fixes
12
+
13
+ === 0.3 / 2009-04-15
14
+
15
+ * all the commands are now threaded and faster
16
+ * bug fixes
17
+ * help docs/command improved
18
+ * code cleanup and refactoring
19
+ * better error handling
data/README.txt CHANGED
@@ -17,7 +17,7 @@ It also serves as an example of Pangea xen-api ruby implementation (http://pange
17
17
 
18
18
  == SYNOPSIS:
19
19
 
20
- FIX (code sample of usage)
20
+ * See the getting started guide: http://www.xen-fu.org/blog/?p=86
21
21
 
22
22
  == REQUIREMENTS:
23
23
 
data/bin/domctl CHANGED
@@ -5,6 +5,15 @@ require 'term/ansicolor'
5
5
  gem 'pangea', '~> 0.1'
6
6
  require 'pangea'
7
7
 
8
+ debug_enabled = false
9
+
10
+ debug = ! ARGV.index('--debug').nil?
11
+ if debug
12
+ puts 'Debugging enabled.'
13
+ debug_enabled = true
14
+ ARGV.delete('--debug')
15
+ end
16
+
8
17
  begin
9
18
  require "#{File.join(File.dirname(__FILE__), '../lib/domctl.rb')}"
10
19
  rescue
@@ -16,47 +25,47 @@ include Domctl
16
25
 
17
26
  DOMCTL_COMMANDS = {
18
27
  :cpu_utilisation => {
19
- :help => "domctl cpu_utilisation",
28
+ :help => "domctl cpu_utilisation\n",
20
29
  :proc => CpuUtilisationCommand
21
30
  },
22
31
  :farm_info => {
23
- :help => "domctl farm_info",
32
+ :help => FarmInfoHelp,
24
33
  :proc => FarmInfoCommand
25
34
  },
26
35
  :mem_info => {
27
- :help => "domctl mem_info [host]",
36
+ :help => MemInfoHelp,
28
37
  :proc => MemInfoCommand
29
38
  },
30
39
  :locate_domu => {
31
- :help => "domctl locate_domu <domU name>",
40
+ :help => LocateDomuHelp,
32
41
  :proc => LocateDomuCommand
33
42
  },
34
43
  :list_running => {
35
- :help => "domctl list_running <dom0|all>",
44
+ :help => ListRunningHelp,
36
45
  :proc => ListRunningCommand
37
46
  },
38
47
  :cluster_nodes => {
39
- :help => "domctl cluster_nodes",
48
+ :help => ClusterNodesHelp,
40
49
  :proc => ClusterNodesCommand
41
50
  },
42
51
  :show_vifs => {
43
- :help => "domctl show_vifs <domU>",
52
+ :help => ShowVifsHelp,
44
53
  :proc => ShowVifsCommand
45
54
  },
46
55
  :domu_info => {
47
- :help => "domctl domu_info <domU>",
56
+ :help => DomuInfoHelp,
48
57
  :proc => DomuInfoCommand
49
58
  },
50
59
  :dom0_info => {
51
- :help => "domctl dom0_info <dom0>",
60
+ :help => Dom0InfoHelp,
52
61
  :proc => Dom0InfoCommand
53
62
  },
54
63
  :recent_domus => {
55
- :help => "domctl recent_domus",
64
+ :help => RecentDomusHelp,
56
65
  :proc => RecentDomusCommand
57
66
  },
58
67
  :oldest_domus => {
59
- :help => "domctl oldest_domus",
68
+ :help => OldestDomusHelp,
60
69
  :proc => OldestDomusCommand
61
70
  },
62
71
  :version => {
@@ -68,19 +77,27 @@ DOMCTL_COMMANDS = {
68
77
  }
69
78
  }
70
79
 
80
+ trap("INT") { $stderr.puts "\nAborting."; exit }
81
+
71
82
  Domctl::Config.validate
72
83
  command = ARGV.shift
73
84
  if command.nil? or DOMCTL_COMMANDS[command.to_sym].nil?
74
- HelpCommand.call
75
- exit 1
85
+ DOMCTL_COMMANDS[:help][:args] = []
86
+ HelpCommand.call
87
+ exit 1
76
88
  end
77
89
  begin
78
90
  args = ARGV
79
91
  DOMCTL_COMMANDS[command.to_sym][:args] = args
80
92
  DOMCTL_COMMANDS[command.to_sym][:proc].call
93
+ rescue SystemExit => e
94
+ $stderr.puts "Aborting."
81
95
  rescue Exception => e
82
- if not e.is_a? SystemExit
96
+ if debug_enabled
83
97
  puts e.message
84
98
  puts e.backtrace
99
+ else
100
+ puts "CRITICAL: #{e.message}"
85
101
  end
86
102
  end
103
+
data/domctl.gemspec CHANGED
@@ -1,10 +1,10 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = %q{domctl}
3
- s.version = "0.2.20090414130028"
3
+ s.version = "0.2.20090415143011"
4
4
 
5
5
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
6
6
  s.authors = ["Sergio RubioSergio Rubio"]
7
- s.date = %q{2009-04-14}
7
+ s.date = %q{2009-04-15}
8
8
  s.default_executable = %q{domctl}
9
9
  s.description = %q{Xen Cluster Management Tool}
10
10
  s.email = %q{sergio@rubio.namesergio@rubio.name}
data/lib/domctl.rb CHANGED
@@ -2,5 +2,5 @@ require "#{File.join(File.dirname(__FILE__), 'domctl/config.rb')}"
2
2
  require "#{File.join(File.dirname(__FILE__), 'domctl/commands.rb')}"
3
3
 
4
4
  module Domctl
5
- VERSION = "0.2.20090414130247"
5
+ VERSION = "0.3.20090415155328"
6
6
  end
@@ -2,6 +2,14 @@ module Domctl
2
2
  ################
3
3
  # cluster_nodes
4
4
  # ##############
5
+ ClusterNodesHelp = <<-EOF
6
+
7
+ Usage: domctl cluster_nodes
8
+
9
+ Show the Xen hosts (dom0) defined in #{Domctl::Config.config_file}
10
+
11
+ EOF
12
+
5
13
  ClusterNodesCommand = Proc.new do
6
14
  Domctl::Config.cluster_nodes.keys.sort.each do |n|
7
15
  puts n
@@ -2,6 +2,20 @@ module Domctl
2
2
  ################
3
3
  # dom0_info
4
4
  ################
5
+
6
+ Dom0InfoHelp = <<-HERE
7
+
8
+ domctl dom0_info <dom0_name>
9
+
10
+ Print some info from the given dom0
11
+
12
+ EXAMPLES
13
+
14
+ 1. domctl dom0_info xen0
15
+
16
+ "Print info from the xen0 host"
17
+
18
+ HERE
5
19
  Dom0InfoCommand = Proc.new do
6
20
  def print_dom0_info(h)
7
21
  puts "Label: #{h.label}"
@@ -12,7 +26,7 @@ module Domctl
12
26
  puts "Xen Version: #{h.software_version['Xen']}"
13
27
  puts "Arch: #{h.software_version['machine']}"
14
28
  puts "Kernel Version: #{h.software_version['release']}"
15
- print "CPUs: "
29
+ print "CPUs: "
16
30
  h.cpus.each do |c|
17
31
  print "%.2f " % (c.utilisation * 100)
18
32
  end
@@ -23,13 +37,14 @@ module Domctl
23
37
  $stderr.puts DOMCTL_COMMANDS[:dom0_info][:help]
24
38
  exit 1
25
39
  end
40
+ Domctl::Config.exit_if_not_defined(dom0)
26
41
  dom0.strip.chomp!
27
42
  settings = Domctl::Config.cluster_nodes[dom0]
28
43
  begin
29
44
  h = Pangea::Host.connect(settings['url'], settings['username'], settings['password'])
30
45
  print_dom0_info(h)
31
46
  rescue Exception
32
- puts "Error connecting to host #{node}. Skipping."
47
+ puts "Error connecting to host #{dom0}. Skipping."
33
48
  end
34
49
  end
35
50
  end
@@ -2,17 +2,45 @@ module Domctl
2
2
  ################
3
3
  # domu_info
4
4
  ################
5
+
6
+ DomuInfoHelp = <<-HERE
7
+
8
+ domctl domu_info <domu_name>
9
+
10
+ Print some info from the given domU. domu_name can be the full name
11
+ or the partial name from a running domU.
12
+
13
+ EXAMPLES
14
+
15
+ 1. domctl domu_info vm-test
16
+
17
+ "Print info from vm-test"
18
+
19
+ 2. domctl domu_info xen0:vm-test
20
+
21
+ "Print info from vm-test, but match only domUs resident in xen0 host"
22
+
23
+ HERE
24
+
5
25
  DomuInfoCommand = Proc.new do
6
- def print_vm_status(vm)
7
- puts "Dom ID: #{vm.domid}"
8
- puts "Max Mem: #{Pangea::Util::humanize_bytes(vm.dyn_max_mem)}"
9
- puts "Min Mem: #{Pangea::Util::humanize_bytes(vm.dyn_min_mem)}"
10
- puts "Power State: #{vm.power_state}"
11
- puts "Resident On: #{vm.resident_on.label}"
12
- puts "Actions:"
13
- puts " after crash: #{vm.actions_after_crash}"
14
- puts " after reboot: #{vm.actions_after_reboot}"
15
- puts " after shutdown: #{vm.actions_after_shutdown}"
26
+ def print_vm_status(h, vm_label)
27
+ h.resident_vms.each do |vm|
28
+ if vm.label =~ /^.*#{vm_label}.*$/
29
+ puts
30
+ header = "[#{vm.label}]"
31
+ puts header
32
+ puts "-" * header.size
33
+ puts "Dom ID: #{vm.domid}"
34
+ puts "Max Mem: #{Pangea::Util::humanize_bytes(vm.dyn_max_mem)}"
35
+ puts "Min Mem: #{Pangea::Util::humanize_bytes(vm.dyn_min_mem)}"
36
+ puts "Power State: #{vm.power_state}"
37
+ puts "Resident On: #{vm.resident_on.label}"
38
+ puts "Actions:"
39
+ puts " after crash: #{vm.actions_after_crash}"
40
+ puts " after reboot: #{vm.actions_after_reboot}"
41
+ puts " after shutdown: #{vm.actions_after_shutdown}"
42
+ end
43
+ end
16
44
  end
17
45
  args = DOMCTL_COMMANDS[:domu_info][:args][0]
18
46
  if args.nil?
@@ -20,36 +48,18 @@ module Domctl
20
48
  exit 1
21
49
  end
22
50
  args.strip.chomp!
23
- found = false
24
51
  # dom0:domU notation
25
52
  if args =~ /^.*:.*$/
26
53
  host, domu = args.split(':')
27
54
  settings = Domctl::Config.cluster_nodes[host]
28
55
  h = Pangea::Host.connect(settings['url'], settings['username'], settings['password'])
29
- h.resident_vms.each do |vm|
30
- if vm.label == domu
31
- found = true
32
- print_vm_status(vm)
33
- end
34
- end
35
- puts "DomU #{domu} not found in #{host}" if not found
56
+ print_vm_status(h, domu)
36
57
  else
37
58
  domu = args
38
59
  puts "Searching..."
39
- Domctl::Config.cluster_nodes.each do |node, settings|
40
- begin
41
- h = Pangea::Host.connect(settings['url'], settings['username'], settings['password'])
42
- rescue Exception
43
- puts "Error connecting to host #{node}. Skipping."
44
- end
45
- h.resident_vms.each do |vm|
46
- if vm.label == domu
47
- found = true
48
- print_vm_status(vm)
49
- end
50
- end
60
+ Domctl::Config.each_host do |h|
61
+ print_vm_status(h, domu)
51
62
  end
52
- puts "DomU #{domu} not found" if not found
53
63
  end
54
64
  end
55
65
  end
@@ -2,23 +2,66 @@ module Domctl
2
2
  ################
3
3
  # farm_info
4
4
  # ##############
5
+
6
+ FarmInfoHelp = <<-HELP
7
+
8
+ domctl farm_info
9
+
10
+ Print info from all the hosts defined in the config file:
11
+ - Memory Free
12
+ - Total Memory
13
+ - Number of CPUs
14
+ - Resident Virtual Machines (domUs)
15
+ - Number of CPUs/Cores
16
+ - CPUs/Cores utilisation
17
+
18
+ HELP
19
+
5
20
  FarmInfoCommand = Proc.new do
6
- puts "Gathering Info..."
21
+ buffer = ""
22
+ print "Gathering Info"
23
+ farm_total_mem = 0
24
+ farm_free_mem = 0
25
+ farm_resident_vms = 0
26
+ farm_cpus = 0
27
+ farm_hosts = 0
28
+ threads = []
7
29
  Domctl::Config.each_host do |h|
8
- puts h.label
9
- puts "-------"
10
- metrics = h.metrics
11
- mfree = Pangea::Util.humanize_bytes(metrics.memory_free)
12
- mtotal = Pangea::Util.humanize_bytes(metrics.memory_total)
13
- puts "Resident VMs: #{h.resident_vms.size}"
14
- puts "Mem Free: #{mfree} Mem Total: #{mtotal}"
15
- cpus = h.cpus.sort { |a,b| a.number <=> b.number }
16
- print "CPUs: "
17
- cpus.each do |c|
18
- print "%.2f " % (c.utilisation * 100)
30
+ print '.'
31
+ threads << Thread.new(buffer) do |bf|
32
+ farm_hosts += 1
33
+ buff = ''
34
+ buff << "\n\n[#{h.label}]\n"
35
+ buff << "-------\n"
36
+ metrics = h.metrics
37
+ mfree = Pangea::Util.humanize_bytes(metrics.memory_free)
38
+ farm_free_mem += metrics.memory_free.to_i
39
+ mtotal = Pangea::Util.humanize_bytes(metrics.memory_total)
40
+ farm_total_mem += metrics.memory_total.to_i
41
+ vms = h.resident_vms.size - 1
42
+ farm_resident_vms += vms
43
+ buff += "Resident VMs: #{vms}\n"
44
+ buff += "Mem Free: #{mfree} Mem Total: #{mtotal}\n"
45
+ cpus = h.cpus.sort { |a,b| a.number <=> b.number }
46
+ buff += "CPUs (#{cpus.size}): "
47
+ cpus.each do |c|
48
+ farm_cpus += 1
49
+ buff += "%.2f " % (c.utilisation * 100)
50
+ end
51
+ bf << buff
19
52
  end
20
- puts
21
- puts
22
53
  end
54
+ threads.each { |t| t.join }
55
+ buffer += "\n\n"
56
+ puts buffer
57
+ puts
58
+ puts 'Global Info:'
59
+ puts '-----------------------------------------------'
60
+ puts "Farm Hosts: #{farm_hosts}"
61
+ puts "Farm Total Memory: #{Pangea::Util.humanize_bytes(farm_total_mem)}"
62
+ puts "Farm Free Memory: #{Pangea::Util.humanize_bytes(farm_free_mem)}"
63
+ puts "Farm Resident VMs: #{farm_resident_vms}"
64
+ puts "Farm CPUs: #{farm_cpus}"
65
+ puts '-----------------------------------------------'
23
66
  end
24
67
  end
@@ -3,28 +3,34 @@ module Domctl
3
3
  # help
4
4
  # ##############
5
5
  HelpCommand = Proc.new do
6
- puts """
7
- domctl #{Domctl::VERSION}
6
+ cmd = DOMCTL_COMMANDS[:help][:args][0]
7
+ if not cmd.nil? and not DOMCTL_COMMANDS[cmd.to_sym].nil?
8
+ puts DOMCTL_COMMANDS[cmd.to_sym][:help]
9
+ else
10
+ puts """
11
+ domctl #{Domctl::VERSION}
8
12
 
9
- Usage: #{File.basename(__FILE__)} command [arguments...]
13
+ Usage: #{File.basename(__FILE__)} command [arguments...]
10
14
 
11
- Available commands:
15
+ Available commands:
12
16
 
13
- help print this help or the help associated
14
- to a command
15
- list_running list all running domUs in the specified dom0
16
- locate_domu find the dom0 hosting the specified domU
17
- show_vifs list the VIFs from a given domU
18
- domu_info print DomU info
19
- dom0_info print Dom0 info
20
- recent_domus print the last 10 domus created
21
- oldest_domus print the first 10 domus created
22
- mem_info print the memory available in a host
23
- farm_info print statistics from all the Hosts
24
- cpu_utilisation CPU utilisation from all the Hosts
17
+ help print this help or the help associated
18
+ to a command
19
+ list_running list all running domUs in the specified dom0
20
+ locate_domu find the dom0 hosting the specified domU
21
+ show_vifs list the VIFs from a given domU
22
+ domu_info print DomU info
23
+ dom0_info print Dom0 info
24
+ recent_domus print the last 10 domus created
25
+ oldest_domus print the first 10 domus created
26
+ mem_info print the memory available in a host
27
+ farm_info print statistics from all the Hosts
28
+ cpu_utilisation CPU utilisation from all the Hosts
29
+ cluster_nodes print the cluster nodes defined in #{Domctl::Config.config_file}
25
30
 
26
- Type domctl help <command> to get specific command help.
31
+ Type domctl help <command> to get specific command help.
27
32
 
28
- """
33
+ """
34
+ end
29
35
  end
30
36
  end
@@ -2,57 +2,73 @@ module Domctl
2
2
  ################
3
3
  # list_running
4
4
  # ##############
5
+ ListRunningHelp = <<-HERE
6
+
7
+ Usage: domctl list_running <dom0_name|all>
8
+
9
+ Lists the running domUs in a given host (in every defined host if 'all' parameter is used instead of the dom0 name)
10
+
11
+ EXAMPLES
12
+
13
+ 1. domctl list_running xen0
14
+
15
+ "List all the domUs running in xen0"
16
+
17
+ 2. domctl list_running all
18
+
19
+ "List all the domUs in every host defined in #{Domctl::Config.config_file}"
20
+
21
+ HERE
22
+
5
23
  ListRunningCommand = Proc.new do
24
+ def print_running(h)
25
+ buffer = "\n"
26
+ header = 'label'.ljust(30) + 'memory'.ljust(15) + 'power state'.ljust(15) + 'cpus'
27
+ buffer << "[#{h.label}]".rjust(header.size) + "\n"
28
+ buffer << header + "\n"
29
+ buffer << ("-" * header.size) + "\n"
30
+ h.resident_vms.each do |vm|
31
+ label = vm.label
32
+ next if vm.is_control_domain?
33
+ buffer << "#{label}".ljust(30)
34
+ metrics = vm.metrics
35
+ m = Pangea::Util.humanize_bytes(metrics.memory_actual)
36
+ buffer << m.ljust(15)
37
+ buffer << vm.power_state.to_s.ljust(15)
38
+ buffer << metrics.vcpus_number + "\n"
39
+ end
40
+ buffer
41
+ end
6
42
  node = DOMCTL_COMMANDS[:list_running][:args][0]
7
43
  if node.nil?
8
44
  $stderr.puts DOMCTL_COMMANDS[:list_running][:help]
9
45
  exit 1
10
46
  end
47
+ threads = []
48
+ buffer = ''
11
49
  if node == 'all'
50
+ print "Working"
12
51
  Domctl::Config.each_host do |h|
13
- puts
14
- header = 'label'.ljust(30) + 'memory'.ljust(15) + 'power state'.ljust(15) + 'cpus'
15
- puts "[#{h.label}]".rjust(header.size)
16
- puts header
17
- puts "-" * header.size
18
- h.resident_vms.each do |vm|
19
- label = vm.label
20
- next if vm.is_control_domain?
21
- print "#{label}".ljust(30)
22
- metrics = vm.metrics
23
- m = Pangea::Util.humanize_bytes(metrics.memory_actual)
24
- print m.ljust(15)
25
- print vm.power_state.to_s.ljust(15)
26
- print metrics.vcpus_number
27
- puts
52
+ print '.'
53
+ threads << Thread.new do
54
+ buffer << print_running(h)
28
55
  end
29
56
  end
30
57
  else
31
- if not Domctl::Config.node_defined?(node)
32
- $stderr.puts "ERROR: Xen host not defined in #{Domctl::Config.config_file}"
33
- exit 1
34
- end
58
+ Domctl::Config.exit_if_not_defined(node)
35
59
  settings = Domctl::Config.cluster_nodes[node]
36
60
  begin
61
+ puts 'Working...'
37
62
  h = Pangea::Host.connect(settings['url'], settings['username'], settings['password'])
38
- header = 'label'.ljust(30) + 'memory'.ljust(15) + 'power state'.ljust(15) + 'cpus'
39
- puts header
40
- puts "-" * header.size
41
- h.resident_vms.each do |vm|
42
- label = vm.label
43
- next if vm.is_control_domain?
44
- print "#{label}".ljust(30)
45
- metrics = vm.metrics
46
- m = Pangea::Util.humanize_bytes(metrics.memory_actual)
47
- print m.ljust(15)
48
- print vm.power_state.to_s.ljust(15)
49
- print metrics.vcpus_number
50
- puts
63
+ threads << Thread.new do
64
+ buffer << print_running(h)
51
65
  end
52
66
  rescue Exception => e
53
67
  puts e.message
54
68
  puts "Error connecting to host #{node}. Skipping."
55
69
  end
56
70
  end
71
+ threads.each { |t| t.join }
72
+ puts buffer
57
73
  end
58
74
  end
@@ -2,29 +2,42 @@ module Domctl
2
2
  ################
3
3
  # locate_domu
4
4
  # ##############
5
+ LocateDomuHelp = <<-HERE
6
+
7
+ domctl locate_domu <domU name>
8
+
9
+ Find the domUs matching <domU name>
10
+
11
+ EXAMPLES
12
+
13
+ domctl locate_domu test-vm
14
+
15
+ "Locates a DomU named test-vm."
16
+
17
+ HERE
18
+
5
19
  LocateDomuCommand = Proc.new do
6
20
  domus = []
7
- args = DOMCTL_COMMANDS[:locate_domu][:args]
8
- if args.nil?
21
+ threads = []
22
+ arg = DOMCTL_COMMANDS[:locate_domu][:args][0]
23
+ if arg.nil?
9
24
  $stderr.puts DOMCTL_COMMANDS[:locate_domu][:help]
10
25
  exit 1
11
26
  end
12
27
  print "Searching"
13
- Domctl::Config.cluster_nodes.sort.each do |node, settings|
14
- begin
15
- h = Pangea::Host.connect(settings['url'], settings['username'], settings['password'])
16
- rescue Exception
17
- puts "Error connecting to host #{node}. Skipping."
18
- end
19
- h.resident_vms.each do |vm|
20
- if vm.label =~ /^.*#{args}.*$/
21
- domus << "#{node}: #{vm.label}"
28
+ Domctl::Config.each_host do |h|
29
+ print '.'
30
+ threads << Thread.new do
31
+ h.resident_vms.each do |vm|
32
+ if vm.label =~ /^.*#{arg}.*$/
33
+ domus << "#{h.label}: #{vm.label}"
34
+ end
22
35
  end
23
36
  end
24
- print '.'
25
37
  end
38
+ threads.each { |t| t.join }
26
39
  puts
27
- puts " Not found." if domus.empty?
40
+ puts "DomU matching '#{arg}' not found." if domus.empty?
28
41
  domus.each { |d| puts d }
29
42
  end
30
43
  end
@@ -2,17 +2,43 @@ module Domctl
2
2
  ################
3
3
  # mem_info
4
4
  # ##############
5
+
6
+ MemInfoHelp = <<-HERE
7
+
8
+ Usage: domctl mem_info [dom0_name]
9
+
10
+ dom0_name is optional. If dom0_name is supplied, it only prints the memory info from the given host.
11
+
12
+ EXAMPLES
13
+
14
+ 1. domctl mem_info xen0
15
+
16
+ "Print the memory info from xen0"
17
+
18
+ 2. domctl mem_info
19
+
20
+ "Print the memory info from all the hosts defined in domctl config file"
21
+ HERE
22
+
5
23
  MemInfoCommand = Proc.new do
6
24
  node = DOMCTL_COMMANDS[:mem_info][:args][0]
25
+ threads = []
26
+ buffer = ""
7
27
  if node.nil?
28
+ print 'Working'
8
29
  Domctl::Config.each_host do |h|
9
- mfree = Pangea::Util.humanize_bytes(h.metrics.memory_free)
10
- mtotal = Pangea::Util.humanize_bytes(h.metrics.memory_total)
11
- print "#{h.label}".ljust(30)
12
- print "#{mfree} free".ljust(15)
13
- puts "#{mtotal} available"
30
+ print '.'
31
+ threads << Thread.new do
32
+ mfree = Pangea::Util.humanize_bytes(h.metrics.memory_free)
33
+ mtotal = Pangea::Util.humanize_bytes(h.metrics.memory_total)
34
+ buffer << "#{h.label.ljust(30)} #{(mfree + ' free').ljust(15)} #{mtotal} available\n"
35
+ end
14
36
  end
37
+ threads.each { |t| t.join }
38
+ puts
39
+ puts buffer
15
40
  else
41
+ Domctl::Config.exit_if_not_defined(node)
16
42
  settings = Domctl::Config.cluster_nodes[node]
17
43
  begin
18
44
  h = Pangea::Host.connect(settings['url'], settings['username'], settings['password'])
@@ -1,13 +1,25 @@
1
1
  module Domctl
2
+ OldestDomusHelp = <<-HELP
3
+
4
+ Usage: domctl oldest_domus
5
+
6
+ Print the oldest domUs (the first 10 created).
7
+
8
+ HELP
9
+
2
10
  OldestDomusCommand = Proc.new do
3
11
  oldest = []
12
+ threads = []
4
13
  print 'Working '
5
14
  Domctl::Config.each_host do |h|
6
15
  print '.'
7
- h.resident_vms.each do |vm|
8
- oldest << [vm.label, vm.metrics.start_time] if vm.label != 'Domain-0'
16
+ threads << Thread.new do
17
+ h.resident_vms.each do |vm|
18
+ oldest << [vm.label, vm.metrics.start_time] if vm.label != 'Domain-0'
19
+ end
9
20
  end
10
21
  end
22
+ threads.each { |t| t.join }
11
23
  puts ' done.'
12
24
  oldest.sort { |a,b| a[1] <=> b[1] }[0..9].each do |label, date|
13
25
  puts "#{label}".ljust(30) + date.to_s
@@ -1,15 +1,28 @@
1
1
  module Domctl
2
+
3
+ RecentDomusHelp = <<-HELP
4
+
5
+ domctl recent_domus
6
+
7
+ Print the most recent domUs created (the last 10 created).
8
+
9
+ HELP
10
+
2
11
  RecentDomusCommand = Proc.new do
3
12
  recent = []
13
+ t = []
4
14
  print 'Working '
5
15
  Domctl::Config.each_host do |h|
6
- print '.'
7
- h.resident_vms.each do |vm|
8
- recent << [vm.label, vm.metrics.start_time] if vm.label != 'Domain-0'
16
+ t << Thread.new do
17
+ print '.'
18
+ h.resident_vms.each do |vm|
19
+ recent << [vm.label, vm.metrics.start_time] if vm.label != 'Domain-0'
20
+ end
9
21
  end
10
22
  end
23
+ t.each { |thread| thread.join }
11
24
  puts ' done.'
12
- recent.sort { |a,b| a[1] <=> b[1] }[-10..-1].each do |label, date|
25
+ recent.sort { |a,b| a[1] <=> b[1] }[-10..-1].reverse.each do |label, date|
13
26
  puts "#{label}".ljust(30) + date.to_s
14
27
  end
15
28
  end
@@ -2,56 +2,67 @@ module Domctl
2
2
  ################
3
3
  # show_vifs
4
4
  # ##############
5
+
6
+ ShowVifsHelp = <<-HERE
7
+
8
+ domctl show_vifs <[dom0_name:]domU_name>
9
+
10
+ Print the virtual interfaces from the given domU
11
+
12
+ EXAMPLES
13
+
14
+ 1. domctl show_vifs vm-test
15
+
16
+ "Print the VIFs found in vm-test (if vm-test exists)"
17
+
18
+ 1. domctl show_vifs xen0:vm-test
19
+
20
+ "Print the VIFs found in vm-test, but look for vm-test in xen0 host only."
21
+ HERE
22
+
5
23
  ShowVifsCommand = Proc.new do
6
- def print_vif(vif)
7
- puts "Device: #{vif.device}"
8
- puts "MAC Address: #{vif.mac}"
9
- metrics = vif.metrics
10
- puts "KBits/s IN: #{metrics.io_read_kbs}"
11
- puts "KBits/s OUT: #{metrics.io_write_kbs}"
24
+ def print_vifs(h, vm_label)
25
+ buffer = ''
26
+ h.resident_vms.each do |vm|
27
+ if vm.label =~ /^.*#{vm_label}.*$/
28
+ header = "\n[#{vm.label}]\n"
29
+ buffer << header
30
+ buffer << ("-" * header.size)
31
+ vm.vifs.each do |vif|
32
+ buffer << "\nDevice: #{vif.device} **\n"
33
+ buffer << "MAC Address: #{vif.mac}\n"
34
+ metrics = vif.metrics
35
+ buffer << "KBits/s IN: %.3f\n" % metrics.io_read_kbs
36
+ buffer << "KBits/s OUT: %.3f\n" % metrics.io_write_kbs
37
+ end
38
+ end
39
+ end
40
+ buffer
12
41
  end
13
- found = false
14
- args = DOMCTL_COMMANDS[:show_vifs][:args][0]
15
- if args.nil?
42
+ domu_name = DOMCTL_COMMANDS[:show_vifs][:args][0]
43
+ if domu_name.nil?
16
44
  $stderr.puts DOMCTL_COMMANDS[:show_vifs][:help]
17
45
  exit 1
18
46
  end
19
- if args =~ /^.*:.*$/
20
- host, domu = args.split(':')
47
+ if domu_name =~ /^.*:.*$/
48
+ host, domu = domu_name.split(':')
21
49
  Domctl::Config.exit_if_not_defined(host)
22
50
  settings = Domctl::Config.cluster_nodes[host]
23
51
  h = Pangea::Host.connect(settings['url'], settings['username'], settings['password'])
24
- h.resident_vms.each do |vm|
25
- if vm.label == domu
26
- found = true
27
- puts "#{vm.label}"
28
- puts "------------------"
29
- vm.vifs.each do |vif|
30
- print_vif(vif)
31
- end
32
- end
33
- end
34
- puts "DomU #{domu} not found in #{host}" if not found
52
+ puts print_vifs(h, domu)
35
53
  else
36
- puts "Searching..."
37
- Domctl::Config.cluster_nodes.each do |node, settings|
38
- begin
39
- h = Pangea::Host.connect(settings['url'], settings['username'], settings['password'])
40
- rescue Exception
41
- puts "Error connecting to host #{node}. Skipping."
42
- end
43
- h.resident_vms.each do |vm|
44
- if vm.label == args
45
- found = true
46
- puts "#{vm.label}"
47
- puts "------------------"
48
- vm.vifs.each do |vif|
49
- print_vif(vif)
50
- end
51
- end
54
+ threads = []
55
+ print "Searching"
56
+ buffer = ''
57
+ Domctl::Config.each_host do |h|
58
+ print '.'
59
+ threads << Thread.new do
60
+ buffer << print_vifs(h, domu_name)
52
61
  end
53
62
  end
63
+ threads.each { |t| t.join }
64
+ puts ' done.'
65
+ puts buffer if not buffer.empty?
54
66
  end
55
- puts "#{args} not found." if not found
56
67
  end
57
68
  end
data/lib/domctl/config.rb CHANGED
@@ -49,7 +49,7 @@ module Domctl
49
49
  begin
50
50
  h = Pangea::Host.connect(settings['url'], settings['username'], settings['password'])
51
51
  yield h
52
- rescue Exception
52
+ rescue Pangea::LinkConnectError => e
53
53
  puts "Error connecting to host #{node}. Skipping."
54
54
  end
55
55
  end
@@ -58,7 +58,7 @@ module Domctl
58
58
  def self.exit_if_not_defined(node)
59
59
  settings = Domctl::Config.cluster_nodes[node]
60
60
  if settings.nil?
61
- $stderr.puts "ERROR: Xen host not defined in #{Domctl::Config.config_file}"
61
+ $stderr.puts "ERROR: Xen host #{node} not defined in #{Domctl::Config.config_file}"
62
62
  exit 1
63
63
  end
64
64
  end
data/scripts/newrelease CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/bin/sh
2
- VERSION=0.2.`ruby -e 'puts Time.now.strftime("%Y%m%d%H%M%S")'`
2
+ VERSION=0.3.`ruby -e 'puts Time.now.strftime("%Y%m%d%H%M%S")'`
3
3
  echo $VERSION
4
4
  sed -i bak "s/VERSION .*$/VERSION = \"$VERSION\"/" lib/domctl.rb
5
5
  rm lib/domctl.rbbak
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubiojr-domctl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.20090414130028
4
+ version: 0.2.20090415143011
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sergio RubioSergio Rubio
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-04-14 00:00:00 -07:00
12
+ date: 2009-04-15 00:00:00 -07:00
13
13
  default_executable: domctl
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency