summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Hicks <mhicks@redhat.com>2008-06-11 08:26:17 -0400
committerMatt Hicks <mhicks@redhat.com>2008-06-11 08:26:17 -0400
commit305254ee2500e899bf6410ef9b76f3a496dbfdaa (patch)
tree9d6ba925cc3866bade484cf3e4b8c8aa60a195cc
parentea3b96969bc7a80ac7238611b7b107c7960566e9 (diff)
downloadtools-305254ee2500e899bf6410ef9b76f3a496dbfdaa.tar.gz
tools-305254ee2500e899bf6410ef9b76f3a496dbfdaa.tar.xz
tools-305254ee2500e899bf6410ef9b76f3a496dbfdaa.zip
Adding support for returning a specific vm
-rw-r--r--everest-lib/lib/everest-lib.rb24
-rw-r--r--everest-lib/pkg/everest-lib-0.0.9.gembin28672 -> 28672 bytes
-rw-r--r--everest-lib/pkg/everest-lib-0.0.9.tgzbin25969 -> 26071 bytes
-rw-r--r--everest-lib/pkg/everest-lib-0.0.9/lib/everest-lib.rb24
4 files changed, 34 insertions, 14 deletions
diff --git a/everest-lib/lib/everest-lib.rb b/everest-lib/lib/everest-lib.rb
index 0883b7b..ce494e6 100644
--- a/everest-lib/lib/everest-lib.rb
+++ b/everest-lib/lib/everest-lib.rb
@@ -102,12 +102,12 @@ module EverestLib
end
def vm(name)
- vms {|vm| vm if vm[:name] == name}.flatten
+ parse_rows("virsh dominfo #{name}", [:id, :name, :uuid, :os_type, :state, :cpus, :cpu_time, :max_mem, :used_mem])
end
def vms(&block)
block ||= lambda {|val| val}
- _exec('virsh list | tail -n +3', [:id, :name, :state], &block)
+ parse_columns('virsh list | tail -n +3', [:id, :name, :state], &block)
end
# Collect the list of available volume groups
@@ -155,7 +155,20 @@ module EverestLib
lvs_name.split("-disk0")[0]
end
- def _exec(command, columns, method = 'collect')
+ def parse_columns(command, fields, method = 'collect')
+ exec_retry(command).split("\n").send(method, &lambda { |row|
+ # Combine the columns and the values into a hash
+ yield Hash[*fields.zip(row.split(" ")).flatten]
+ })
+ end
+
+ def parse_rows(command, fields, delimiter = ':')
+ row_values = exec_retry(command).split("\n").collect {|row| row.split(delimiter)[1].strip}
+ # Combine the columns and the values into a hash
+ Hash[*fields.zip(row_values).flatten]
+ end
+
+ def exec_retry(command)
output = `#{command}`
while not $?.success? do
@@ -163,9 +176,6 @@ module EverestLib
output = `#{command}`
end
- output.split("\n").send(method, &lambda { |row|
- # Combine the columns and the values into a hash
- yield Hash[*columns.zip(row.split(" ")).flatten]
- })
+ return output
end
end
diff --git a/everest-lib/pkg/everest-lib-0.0.9.gem b/everest-lib/pkg/everest-lib-0.0.9.gem
index 80d35be..5380b41 100644
--- a/everest-lib/pkg/everest-lib-0.0.9.gem
+++ b/everest-lib/pkg/everest-lib-0.0.9.gem
Binary files differ
diff --git a/everest-lib/pkg/everest-lib-0.0.9.tgz b/everest-lib/pkg/everest-lib-0.0.9.tgz
index 16125f6..7cd7bed 100644
--- a/everest-lib/pkg/everest-lib-0.0.9.tgz
+++ b/everest-lib/pkg/everest-lib-0.0.9.tgz
Binary files differ
diff --git a/everest-lib/pkg/everest-lib-0.0.9/lib/everest-lib.rb b/everest-lib/pkg/everest-lib-0.0.9/lib/everest-lib.rb
index 0883b7b..ce494e6 100644
--- a/everest-lib/pkg/everest-lib-0.0.9/lib/everest-lib.rb
+++ b/everest-lib/pkg/everest-lib-0.0.9/lib/everest-lib.rb
@@ -102,12 +102,12 @@ module EverestLib
end
def vm(name)
- vms {|vm| vm if vm[:name] == name}.flatten
+ parse_rows("virsh dominfo #{name}", [:id, :name, :uuid, :os_type, :state, :cpus, :cpu_time, :max_mem, :used_mem])
end
def vms(&block)
block ||= lambda {|val| val}
- _exec('virsh list | tail -n +3', [:id, :name, :state], &block)
+ parse_columns('virsh list | tail -n +3', [:id, :name, :state], &block)
end
# Collect the list of available volume groups
@@ -155,7 +155,20 @@ module EverestLib
lvs_name.split("-disk0")[0]
end
- def _exec(command, columns, method = 'collect')
+ def parse_columns(command, fields, method = 'collect')
+ exec_retry(command).split("\n").send(method, &lambda { |row|
+ # Combine the columns and the values into a hash
+ yield Hash[*fields.zip(row.split(" ")).flatten]
+ })
+ end
+
+ def parse_rows(command, fields, delimiter = ':')
+ row_values = exec_retry(command).split("\n").collect {|row| row.split(delimiter)[1].strip}
+ # Combine the columns and the values into a hash
+ Hash[*fields.zip(row_values).flatten]
+ end
+
+ def exec_retry(command)
output = `#{command}`
while not $?.success? do
@@ -163,9 +176,6 @@ module EverestLib
output = `#{command}`
end
- output.split("\n").send(method, &lambda { |row|
- # Combine the columns and the values into a hash
- yield Hash[*columns.zip(row.split(" ")).flatten]
- })
+ return output
end
end