chef-lxc 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 74d567115ba049ac8952d5d82075fecf2ab633c5
4
- data.tar.gz: 709b4aab0423d46cec4e2af27fe4c9e2be49e814
3
+ metadata.gz: 0262d6fd87cc8eea3ba11ea0260baa9d3e00e739
4
+ data.tar.gz: ca65b6a466bb8d2a3c8de5563fdc9ae0e509515b
5
5
  SHA512:
6
- metadata.gz: a23cbddca704a52d4999cccf55d6fc9df02137fc8aeecdd6935f59d618180d260de1c8da1170af9916806e638c56d054b1d95bbf4107263cdb170e4cd0c6ed66
7
- data.tar.gz: b6ac7276e06f35163ca876fbe9e4b56c15b0a628f175fd4b67cf5763856eee2f751c5527a65b6d827243380df88f85d3370567d6e255380ea94f7bbdffd1f843
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
- Note: This library depends on [ruby-lxc](https://github.com/lxc/ruby-lxc), a native liblxc binding, ruby-lxc will be
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
- Add this line to your application's Gemfile:
8
+ Use standard rubygem way to install chef-lxc
11
9
 
12
- gem 'chef-lxc', github: 'ranjib/chef-lxc'
13
-
14
- And then execute:
10
+ $ gem install chef-lxc
15
11
 
16
- $ bundle
12
+ ## Usage
17
13
 
18
- Or install it yourself as:
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
- $ gem install chef-lxc
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
@@ -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[1])
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, text: recipe_text)
86
+ recipe_in_container(ct, recipe_text)
87
87
  end
88
88
 
89
89
  def run_application
@@ -1,5 +1,5 @@
1
1
  class Chef
2
2
  module LXC
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@ require 'lxc/extra'
3
3
 
4
4
  class Chef
5
5
  module LXCHelper
6
- def recipe_in_container(ct, options={})
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 options[:block]
21
- recipe.instance_eval(&new_resource.recipe_block)
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
@@ -80,7 +80,7 @@ class Chef
80
80
  end
81
81
  end
82
82
  unless new_resource.recipe_block.nil?
83
- recipe_in_container(ct, block: new_resource.recipe_block)
83
+ recipe_in_container(ct, &new_resource.recipe_block)
84
84
  end
85
85
  end
86
86
 
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.2
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-09 00:00:00.000000000 Z
11
+ date: 2014-12-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chef