项目作者: lxc

项目描述 :
ruby bindings for liblxc
高级语言: C
项目地址: git://github.com/lxc/ruby-lxc.git
创建时间: 2013-12-23T21:22:04Z
项目社区:https://github.com/lxc/ruby-lxc

开源协议:GNU Lesser General Public License v2.1

下载


Ruby-LXC

Build Status

Introduction

Ruby-LXC is a Ruby binding for liblxc. It allows the creation and management
of Linux Containers from Ruby scripts.

Build and installation

Assuming a current installation of LXC is available, to install Ruby-LXC
simply run the commands below

  1. sudo apt-get install ruby-dev lxc-dev
  2. bundle install
  3. bundle exec rake compile
  4. bundle exec rake gem
  5. gem install pkg/ruby-lxc-1.2.0.gem

or just add this to your Gemfile

  1. gem "ruby-lxc", github: "lxc/ruby-lxc", require: "lxc"

Usage

  • Container lifecycle management (create, start, stop and destroy containers)

    1. require 'lxc'
    2. c = LXC::Container.new('foo')
    3. c.create('ubuntu') # create a container named foo with ubuntu template
    4. c.start
    5. # attach to a running container
    6. c.attach do
    7. LXC.run_command('ifconfig eth0')
    8. end
    9. c.stop
    10. c.destroy
  • Container inspection

    1. c.name
    2. c.config_path
    3. c.config_item('lxc.cap.drop')
    4. c.cgroup_item('memory.limit_in_bytes')
    5. c.init_pid
    6. c.interfaces
    7. c.ip_addresses
    8. c.state
  • Additional state changing operations (freezing, unfreezing and cloning
    containers)

    1. c.freeze
    2. c.unfreeze
    3. c.reboot
    4. c.shutdown
  • Clone a container

    1. # clone foo into bar. Parent container has to be frozen or stopped.
    2. clone = c.clone('bar')
  • Wait for a state change

    1. # wait until container goes to STOPPED state, else timeout after 10 seconds
    2. c.wait(:stopped, 10)

Check the provided rdoc documentation for a full list of methods. You can
generate it running

  1. rake rdoc