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

#initializeInventory

Returns a new instance of Inventory.



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

def initialize()
  @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



17
18
19
# File 'lib/openvz/inventory.rb', line 17

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

#loadObject



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

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



21
22
23
# File 'lib/openvz/inventory.rb', line 21

def to_hash
    @data
end