Class: OpenVZ::Inventory

Inherits:
ConfigHash show all
Defined in:
lib/openvz/inventory.rb

Instance Method Summary collapse

Methods inherited from ConfigHash

#[], #[]=, #method_missing, #update!

Constructor Details

#initialize(data = {}) ⇒ Inventory

Returns a new instance of Inventory.



3
4
5
6
7
# File 'lib/openvz/inventory.rb', line 3

def initialize(data={})
  @data = {}
  update!(data)
  @vzlist = "/usr/sbin/vzlist"
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class OpenVZ::ConfigHash

Instance Method Details

#idsObject

Returns cotainers’ id as a array of strings



19
20
21
# File 'lib/openvz/inventory.rb', line 19

def ids
    Util.execute("#{@vzlist} -a1").split
end

#loadObject



9
10
11
12
13
14
15
16
# File 'lib/openvz/inventory.rb', line 9

def load
    Util.execute("#{@vzlist} -a").each_line { |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

#to_hashObject



23
24
25
# File 'lib/openvz/inventory.rb', line 23

def to_hash
    @data
end