lib/openvz/inventory.rb in openvz-1.5 vs lib/openvz/inventory.rb in openvz-1.5.3
- old
+ new
@@ -1,24 +1,25 @@
module OpenVZ
class Inventory < ConfigHash
+ def initialize()
+ @vzlist = "/usr/sbin/vzlist"
+ end
+
def load
- s = Shell.new("/usr/sbin/vzlist -a", :cwd => "/tmp")
- s.runcommand
-
- ret_code = s.status
- if ret_code != 0
- raise StandardError, "Execution of shell command failed. Command: #{s.command} RC: #{ret_code} Error: #{s.stderr}\n\n"
- end
-
- s.stdout.each { |l|
+ Util.execute("#{@vzlist} -a").each { |l|
# inventarize a container object for each avaiable container.
if l =~ /^\s+(\d+)\s+(.*)\s+(running|stopped)\s+(.*)\s\s(.*)$/
self[$1] = Container.new($1)
end
}
end
+
+ # Returns cotainers' id as a array of strings
+ def ids
+ Util.execute("#{@vzlist} -a1").split
+ end
def to_hash
@data
end
end
-end
+end
\ No newline at end of file