Module: LXC

Extended by:
Shell
Defined in:
lib/lxc.rb,
lib/lxc/shell.rb,
lib/lxc/status.rb,
lib/lxc/version.rb,
lib/lxc/container.rb,
lib/lxc/configuration.rb,
lib/lxc/configuration_options.rb

Defined Under Namespace

Modules: ConfigurationOptions, Shell Classes: Configuration, ConfigurationError, Container, ContainerError, Error, Status

Constant Summary collapse

VERSION =
"0.3.1"

Constants included from Shell

Shell::BIN_FILES, Shell::BIN_PREFIX, Shell::CONTAINER_STATES, Shell::REMOVE_COLORS

Class Method Summary collapse

Methods included from Shell

run, use_sudo, use_sudo=, valid_state?

Class Method Details

.binary_installed?(name) ⇒ Boolean

Check if binary file is installed

Parameters:

  • binary (String)

    filename

Returns:

  • (Boolean)

    true if installed



22
23
24
25
# File 'lib/lxc.rb', line 22

def self.binary_installed?(name)
  path = File.join(LXC::Shell::BIN_PREFIX, name)
  File.exists?(path)
end

.configHash

Get LXC configuration info

Returns:

  • (Hash)

    hash containing config groups



35
36
37
38
39
40
41
42
43
# File 'lib/lxc.rb', line 35

def self.config
  str = LXC.run('checkconfig') { LXC::Shell::REMOVE_COLORS }

  data = str.scan(/^([\w\s]+): (enabled|disabled)$/).map { |r|
    [r.first.downcase.gsub(' ', '_'), r.last == 'enabled']
  }

  Hash[data]
end

.container(name) ⇒ LXC::Container

Get a single container instance

Parameters:

  • name (String)

    of the container

Returns:



48
49
50
# File 'lib/lxc.rb', line 48

def self.container(name)
  LXC::Container.new(name)
end

.containers(filter = nil) ⇒ Array

Get a list of all available containers

Parameters:

  • select (String)

    containers that match string

Returns:

  • (Array)

    array of LXC::Containers



55
56
57
58
59
60
# File 'lib/lxc.rb', line 55

def self.containers(filter=nil)
  names = LXC.run('ls').split("\n").uniq

  names.delete_if { |v| !v.include?(filter) } if filter.kind_of?(String)
  names.map { |name| LXC::Container.new(name) }
end

.installed?Boolean

Check if all binaries are present in the system

Returns:

  • (Boolean)

    true if binary files are found



29
30
31
# File 'lib/lxc.rb', line 29

def self.installed?
  LXC::Shell::BIN_FILES.all?{ |f| binary_installed?(f) }
end

.versionString

Get currently installeded LXC version

Returns:

  • (String)

    current LXC version



64
65
66
# File 'lib/lxc.rb', line 64

def self.version
  LXC.run('version').strip.split(' ').last
end