Sha256: 248c6e2f4354e5ce57b338d0fd9b526e86ab0267d3dcfde07878d8ef86289149

Contents?: true

Size: 1.89 KB

Versions: 1

Compression:

Stored size: 1.89 KB

Contents

require 'posix/spawn'
require 'lxc/version'

module LXC
  class Error              < StandardError ; end
  class ContainerError     < Error ; end
  class ConfigurationError < Error ; end

  autoload :Shell,                'lxc/shell'
  autoload :Configuration,        'lxc/configuration'
  autoload :ConfigurationOptions, 'lxc/configuration_options'
  autoload :Container,            'lxc/container'
  autoload :Status,               'lxc/status'

  class << self
    include LXC::Shell
  end

  # Check if binary file is installed
  # @param [String] binary filename
  # @return [Boolean] true if installed
  def self.binary_installed?(name)
    path = File.join(LXC::Shell::BIN_PREFIX, name)
    File.exists?(path)
  end

  # Check if all binaries are present in the system
  # @return [Boolean] true if binary files are found
  def self.installed?
    LXC::Shell::BIN_FILES.all?{ |f| binary_installed?(f) }
  end

  # Get LXC configuration info
  # @return [Hash] hash containing config groups
  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

  # Get a single container instance
  # @param [String] name of the container
  # @return [LXC::Container] container instance
  def self.container(name)
    LXC::Container.new(name)
  end

  # Get a list of all available containers
  # @param [String] select containers that match string
  # @return [Array] array of LXC::Containers
  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

  # Get currently installeded LXC version
  # @return [String] current LXC version
  def self.version
    LXC.run('version').strip.split(' ').last
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lxc-ruby-0.3.1 lib/lxc.rb