chef-lxc 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +34 -13
- data/lib/chef/application/lxc.rb +2 -2
- data/lib/chef/lxc/version.rb +1 -1
- data/lib/chef/lxc_helper.rb +3 -7
- data/lib/chef/provider/lxc.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0262d6fd87cc8eea3ba11ea0260baa9d3e00e739
|
4
|
+
data.tar.gz: ca65b6a466bb8d2a3c8de5563fdc9ae0e509515b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6eeb3c9e8224fed349bc4bf0cff860c9c6df21c0962c2a94bfacba6ec9cc1f9e22c6ff494a18ef018b03399a449a751cbdd249f63f228a716391613bd8a13581
|
7
|
+
data.tar.gz: b354cd3d2458f33aa795c460efbdb9cbe340a66c9661a523029dd960082953c398fd7d6888c70a83c34ade6b5574f406a1a8540ba5aa628186ffe3cb39a1a7f9
|
data/README.md
CHANGED
@@ -3,23 +3,21 @@
|
|
3
3
|
[Chef](http://www.getchef.com/) integration for [LXC](http://linuxcontainers.org/).
|
4
4
|
|
5
5
|
## Installation
|
6
|
-
|
7
|
-
released around April, 2014(alongside LXC 1.0, Ubuntu 14.04 release). Till then,
|
8
|
-
use bundler to experiement with chef-lxc.
|
6
|
+
This library depends on [ruby-lxc](https://github.com/lxc/ruby-lxc), a native liblxc binding.
|
9
7
|
|
10
|
-
|
8
|
+
Use standard rubygem way to install chef-lxc
|
11
9
|
|
12
|
-
gem
|
13
|
-
|
14
|
-
And then execute:
|
10
|
+
$ gem install chef-lxc
|
15
11
|
|
16
|
-
|
12
|
+
## Usage
|
17
13
|
|
18
|
-
|
14
|
+
There are three ways you can use chef-lxc.
|
15
|
+
* Use the command line tool
|
16
|
+
* Use the lxc resource/provider from any chef recipe
|
17
|
+
* Use the Chef::LXCHelper module from any arbitrary ruby script.
|
19
18
|
|
20
|
-
|
19
|
+
### CLI examples
|
21
20
|
|
22
|
-
## Usage
|
23
21
|
- Execute a chef recipe against a running container (like chef-apply)
|
24
22
|
```sh
|
25
23
|
lxc-create -n test -t ubuntu
|
@@ -34,14 +32,17 @@ or supply a file
|
|
34
32
|
```sh
|
35
33
|
chef-lxc test /path/to/recipe.rb
|
36
34
|
```
|
35
|
+
### Chef resource/provider examples
|
37
36
|
|
38
|
-
- Create & manage containers (inside chef recipes)
|
39
|
-
Following will create a default (ubuntu) container named `web`
|
37
|
+
- Create & manage containers (inside chef recipes), named `web`
|
40
38
|
```ruby
|
39
|
+
require 'chef/lxc'
|
41
40
|
lxc "web"
|
42
41
|
```
|
43
42
|
A more elaborate example,
|
44
43
|
```ruby
|
44
|
+
require 'chef/lxc'
|
45
|
+
|
45
46
|
lxc "web" do
|
46
47
|
template "ubuntu"
|
47
48
|
|
@@ -56,6 +57,26 @@ A more elaborate example,
|
|
56
57
|
end
|
57
58
|
```
|
58
59
|
|
60
|
+
### Use Chef-Lxc from arbitrary ruby code
|
61
|
+
- Install openssh-server package on a vanilla un-privileged ubuntu container and change the default ubuntu user's password
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
require 'lxc'
|
65
|
+
require 'chef'
|
66
|
+
require 'chef/lxc'
|
67
|
+
|
68
|
+
include Chef::LXCHelper
|
69
|
+
|
70
|
+
ct = LXC::Container.new('foo')
|
71
|
+
ct.create('download', nil, {}, 0, %w{-a amd64 -r trusty -d ubuntu}) # reference: http://www.rubydoc.info/gems/ruby-lxc/LXC/Container#create-instance_method
|
72
|
+
ct.start
|
73
|
+
sleep 5 # wait till network is up and DHCP allocates the IP
|
74
|
+
recipe_in_container(ct) do
|
75
|
+
package 'openssh-server'
|
76
|
+
execute 'echo "ubuntu:ubuntu" | chpasswd'
|
77
|
+
end
|
78
|
+
```
|
79
|
+
|
59
80
|
## Contributing
|
60
81
|
|
61
82
|
1. Fork it
|
data/lib/chef/application/lxc.rb
CHANGED
@@ -79,11 +79,11 @@ class Chef::Application::LXC < Chef::Application
|
|
79
79
|
elsif config[:stdin]
|
80
80
|
recipe_text = STDIN.read
|
81
81
|
else
|
82
|
-
recipe_text = ::File.read(ARGV
|
82
|
+
recipe_text = ::File.read(ARGV.first)
|
83
83
|
end
|
84
84
|
Chef::Config[:solo] = true
|
85
85
|
ct = ::LXC::Container.new(ARGV.first)
|
86
|
-
recipe_in_container(ct,
|
86
|
+
recipe_in_container(ct, recipe_text)
|
87
87
|
end
|
88
88
|
|
89
89
|
def run_application
|
data/lib/chef/lxc/version.rb
CHANGED
data/lib/chef/lxc_helper.rb
CHANGED
@@ -3,7 +3,7 @@ require 'lxc/extra'
|
|
3
3
|
|
4
4
|
class Chef
|
5
5
|
module LXCHelper
|
6
|
-
def recipe_in_container(ct,
|
6
|
+
def recipe_in_container(ct, recipe_text = nil, &recipe_block)
|
7
7
|
client = Class.new(Chef::Client) do
|
8
8
|
def run_ohai
|
9
9
|
ohai.run_plugins
|
@@ -17,12 +17,8 @@ class Chef
|
|
17
17
|
client.build_node
|
18
18
|
run_context = Chef::RunContext.new(client.node, {}, client.events)
|
19
19
|
recipe = Chef::Recipe.new("chef-loxc-cookbook", "chef-lxc-recipe", run_context)
|
20
|
-
if
|
21
|
-
|
22
|
-
elsif options[:text]
|
23
|
-
recipe.instance_eval(options[:text], __FILE__, __LINE__)
|
24
|
-
else
|
25
|
-
end
|
20
|
+
recipe.instance_eval(&recipe_block) if recipe_block
|
21
|
+
recipe.instance_eval(recipe_text, __FILE__, __LINE__) if recipe_text
|
26
22
|
runner = Chef::Runner.new(run_context)
|
27
23
|
runner.converge
|
28
24
|
end
|
data/lib/chef/provider/lxc.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-lxc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ranjib Dey
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: chef
|