Module: LXC

Extended by:
Shell
Defined in:
lib/lxc.rb,
lib/lxc/shell.rb,
lib/lxc/errors.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

Constant Summary collapse

VERSION =
'0.2.2'

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



15
16
17
18
# File 'lib/lxc.rb', line 15

def 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



28
29
30
31
32
33
34
# File 'lib/lxc.rb', line 28

def 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 container information record

Parameters:

  • container (name)

    name

Returns:



39
40
41
# File 'lib/lxc.rb', line 39

def 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



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

def 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| Container.new(name) }
end

.installed?Boolean

Check if all binaries are present in the system

Returns:

  • (Boolean)

    true if binary files are found



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

def installed?
  !BIN_FILES.map { |f| binary_installed?(f) }.uniq.include?(false)
end

.versionString

Get current LXC version

Returns:

  • (String)

    current LXC version



54
55
56
# File 'lib/lxc.rb', line 54

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