diff options
| author | Matt Hicks <mhicks@redhat.com> | 2008-06-11 08:26:17 -0400 |
|---|---|---|
| committer | Matt Hicks <mhicks@redhat.com> | 2008-06-11 08:26:17 -0400 |
| commit | 305254ee2500e899bf6410ef9b76f3a496dbfdaa (patch) | |
| tree | 9d6ba925cc3866bade484cf3e4b8c8aa60a195cc | |
| parent | ea3b96969bc7a80ac7238611b7b107c7960566e9 (diff) | |
| download | tools-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.rb | 24 | ||||
| -rw-r--r-- | everest-lib/pkg/everest-lib-0.0.9.gem | bin | 28672 -> 28672 bytes | |||
| -rw-r--r-- | everest-lib/pkg/everest-lib-0.0.9.tgz | bin | 25969 -> 26071 bytes | |||
| -rw-r--r-- | everest-lib/pkg/everest-lib-0.0.9/lib/everest-lib.rb | 24 |
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 Binary files differindex 80d35be..5380b41 100644 --- a/everest-lib/pkg/everest-lib-0.0.9.gem +++ b/everest-lib/pkg/everest-lib-0.0.9.gem diff --git a/everest-lib/pkg/everest-lib-0.0.9.tgz b/everest-lib/pkg/everest-lib-0.0.9.tgz Binary files differindex 16125f6..7cd7bed 100644 --- a/everest-lib/pkg/everest-lib-0.0.9.tgz +++ b/everest-lib/pkg/everest-lib-0.0.9.tgz 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 |
