chef-provisioning-lxc 0.6.1 → 0.7.0

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: fa53dc604984221d5f6f52a9cf23db3dd9ba5070
4
- data.tar.gz: edbcbb541604b5e31c3d38fd251a67bb7204accf
3
+ metadata.gz: e716f7488e9a91724608e3cbeb4ffa88e4bbf5f9
4
+ data.tar.gz: e8bc3b5f4b0773447e9d4ea9a60e7893b291762b
5
5
  SHA512:
6
- metadata.gz: 40e497dd182a9e1885801d64335701f94e444cb6cc1dd8c756726fbd426f8e9d67413ea3e95ebe3e311ea4ca5ca511c6dc6c6d16565a38b748daf56dcb58b0d0
7
- data.tar.gz: 8a0a1387a5d8a9f5b0b19a5692dd8301c76deb44034c407e663a0d0eda30a028a8256e9fa936fc7ecba21f3c718683acf041c01334993256d11137a52afcfdf8
6
+ metadata.gz: 72644cf2cb034eb64dcb0c4c3f4549f7bf8a2535bd993dc7fde92ec9d217f7b485c2e2edda9148eee0038740f26ac0cc90a34b5ddc888d8bb3d05da8628e856e
7
+ data.tar.gz: 322357ab6e178b1d86f50e355ff4f310fb1aff324e1d5311331cfa9dcf21f1961e1f9632ab74310b0fd663a4373ef0dda76c8183a21b924eef570e02fa1871d9
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source "https://rubygems.org"
2
+ gemfile
3
+ gemspec
4
+
5
+ gem 'chef-provisioning', github: 'chef/chef-provisioning'
6
+
7
+ group :development do
8
+ gem 'pry'
9
+ end
data/README.md CHANGED
@@ -1,18 +1,34 @@
1
+ # MAINTAINERS WANTED
2
+
3
+ We are actively seeking maintainers for the chef-provisioning-lxc driver. This project is not under active maintenance by CHEF, and does not currently pass tests with the latest version of [chef-provisioning](https://github.com/chef/chef-provisioning). If you are interested in maintaining it, please contact us in the [gitter](https://github.com/chef/chef-provisioning-lxc).
4
+
1
5
  # chef-provisioning-lxc
2
6
 
7
+ [![Build Status](https://travis-ci.org/chef/chef-provisioning-lxc.svg?branch=master)](https://travis-ci.org/chef/chef-provisioning-lxc) [![Gem Version](https://badge.fury.io/rb/chef-provisioning-lxc.svg)](https://badge.fury.io/rb/chef-provisioning-lxc)
8
+
3
9
  This is the LXC provisioner for chef-provisioning.
4
10
 
5
11
  ## Quick Start
6
12
 
7
- To run the tests, which creates an Ubuntu machine and installs this into it:
13
+ Assuming you have host with working LXC setup already, you can directly invoke an example recipe using chef localmode
8
14
 
9
- ```
10
- gem install chef-provisioning
11
- rake build
12
- cd test/
13
- set -x CHEF_DRIVER 'lxc'
14
- chef-client -z lxc.rb simple.rb
15
- ```
15
+ - Clone chef-provisioning-lxc repo
16
+
17
+ ```sh
18
+ git clone https://github.com/chef/chef-provisioning-lxc
19
+ ```
20
+
21
+ - Run bundle install
22
+
23
+ ```sh
24
+ bundle install
25
+ ```
26
+
27
+ - Execute the test recipe to create a linux container
28
+
29
+ ```sh
30
+ bundle exec chef-client -z -o recipe[lxctests::simple] -c test/client.rb
31
+ ```
16
32
 
17
33
  ## Basic Usage
18
34
 
@@ -35,6 +51,6 @@ with_machine_options :template => <template name>,
35
51
 
36
52
  These options correspond to the options in [lxc create](https://qa.linuxcontainers.org/master/current/doc/man/lxc-create.1.html):
37
53
 
38
- * **template**: the LXC template name to use.
39
- * **template_options**: An array of string arguments to pass to the template.
40
- * **backing_store**: The backing store to use for the file system.
54
+ - **template**: the LXC template name to use.
55
+ - **template_options**: An array of string arguments to pass to the template.
56
+ - **backing_store**: The backing store to use for the file system.
data/Rakefile CHANGED
@@ -1,6 +1,11 @@
1
1
  require 'bundler'
2
2
  require 'bundler/gem_tasks'
3
3
 
4
- task :spec do
5
- require File.expand_path('spec/run')
4
+ require "github_changelog_generator/task"
5
+
6
+ GitHubChangelogGenerator::RakeTask.new :changelog do |config|
7
+ config.future_release = Chef::Provisioning::LXCDriver::VERSION
8
+ config.enhancement_labels = "enhancement,Enhancement,New Feature".split(",")
9
+ config.bug_labels = "bug,Bug,Improvement,Upstream Bug".split(",")
10
+ config.exclude_labels = "duplicate,question,invalid,wontfix,no_changelog,Exclude From Changelog,Question".split(",")
6
11
  end
@@ -0,0 +1,28 @@
1
+ $:.unshift(File.dirname(__FILE__) + '/lib')
2
+ require 'chef/provisioning/lxc_driver/version'
3
+
4
+ Gem::Specification.new do |s|
5
+ s.name = 'chef-provisioning-lxc'
6
+ s.version = Chef::Provisioning::LXCDriver::VERSION
7
+ s.platform = Gem::Platform::RUBY
8
+ s.extra_rdoc_files = ['README.md', 'LICENSE' ]
9
+ s.summary = 'Provisioner for creating LXC containers in Chef Provisioning.'
10
+ s.description = s.summary
11
+ s.author = 'Ranjib Dey'
12
+ s.email = 'dey.ranjib@gmail.com'
13
+ s.homepage = 'https://github.com/chef/chef-provisioning-lxc'
14
+
15
+ s.add_dependency 'chef-provisioning', '>= 1.0', '< 3.0'
16
+ s.add_dependency 'lxc-extra', '~> 0.0', '>= 0.0.3'
17
+
18
+ s.add_development_dependency 'rspec'
19
+ s.add_development_dependency 'rake'
20
+ s.add_development_dependency 'github_changelog_generator'
21
+
22
+ s.bindir = "bin"
23
+ s.executables = %w( )
24
+
25
+ s.require_path = 'lib'
26
+ s.files = %w(Gemfile Rakefile LICENSE README.md) + Dir.glob("*.gemspec") +
27
+ Dir.glob("{distro,lib,tasks,spec}/**/*", File::FNM_DOTMATCH).reject {|f| File.directory?(f) }
28
+ end
@@ -76,8 +76,13 @@ module LXCDriver
76
76
 
77
77
  #
78
78
  # Create the machine
79
- #
80
- ct.create(machine_options[:template], machine_options[:backingstore], machine_options[:devspecs], 0, machine_options[:template_options])
79
+ ct.create(
80
+ machine_options[:template],
81
+ machine_options[:backingstore],
82
+ machine_options[:devspecs] || {},
83
+ machine_options[:flags] || 0,
84
+ machine_options[:template_options] || []
85
+ )
81
86
 
82
87
  machine_spec.location = {
83
88
  'driver_url' => driver_url,
@@ -101,21 +106,9 @@ module LXCDriver
101
106
  end
102
107
 
103
108
  # Get stopped containers running
104
- unless ct.running?
109
+ if ct.defined? and not ct.running?
105
110
  action_handler.perform_action "start lxc container #{machine_spec.location['name']} (state is #{ct.state})" do
106
- # Have to shell out to lxc-start for now, ct.start holds server sockets open!
107
- lxc_start = "lxc-start -d -n #{Shellwords.escape(machine_spec.location['name'])}"
108
- # TODO add ability to change options on start
109
- # if machine_options[:config_file]
110
- # lxc_start << " -f #{Shellwords.escape(machine_options[:config_file])}"
111
- # end
112
- # if machine_options[:extra_config]
113
- # machine_options[:extra_config].each_pair do |key,value|
114
- # lxc_start << " -s #{Shellwords.escape("#{key}=#{value}")}"
115
- # end
116
- # end
117
- shell_out!(lxc_start)
118
- # ct.start
111
+ ct.start
119
112
  end
120
113
  end
121
114
 
@@ -1,6 +1,6 @@
1
1
  require 'chef/provisioning/transport'
2
2
  require 'lxc/extra'
3
- require 'chef/mixin/shell_out'
3
+ require 'mixlib/shellout'
4
4
  require 'lxc/extra/proxy_client_side'
5
5
  require 'lxc/extra/proxy_server_side'
6
6
  require 'lxc/extra/channel'
@@ -8,149 +8,155 @@ require 'uri'
8
8
  require 'socket'
9
9
 
10
10
  class Chef
11
- module Provisioning
12
- module LXCDriver
13
- class LXCTransport < Chef::Provisioning::Transport
14
- @@active_transports = []
15
-
16
- class LXCExecuteResult < Struct.new(:command, :options, :stdout, :stderr, :exitstatus)
17
- def error!
18
- raise "Error: '#{command}' failed with exit code #{exitstatus}.\nSTDOUT:#{stdout}\nSTDERR:#{stderr}" if exitstatus != 0
19
- end
20
- end
21
-
22
- attr_reader :name, :options, :lxc_path
23
-
24
- include Chef::Mixin::ShellOut
25
-
26
- def initialize(name, lxc_path, options={})
27
- @options = options
28
- @name = name
29
- @lxc_path = lxc_path
30
- @port_forwards = {}
31
- @@active_transports << self
32
- end
11
+ module Provisioning
12
+ module LXCDriver
13
+ class LXCTransport < Chef::Provisioning::Transport
14
+ @@active_transports = []
15
+
16
+ class LXCExecuteResult < Struct.new(:command, :options, :stdout, :stderr, :exitstatus)
17
+ def error!
18
+ raise "Error: '#{command}' failed with exit code #{exitstatus}.\nSTDOUT:#{stdout}\nSTDERR:#{stderr}" if exitstatus != 0
19
+ end
20
+ end
33
21
 
34
- def container
35
- @container ||= LXC::Container.new(name, lxc_path)
36
- end
22
+ attr_reader :name, :options, :lxc_path
37
23
 
38
- def rootfs
39
- container.config_item('lxc.rootfs')
40
- end
24
+ include Chef::Mixin::ShellOut
41
25
 
42
- def container_path(path)
43
- File.join(rootfs, path)
44
- end
26
+ def initialize(name, lxc_path, options={})
27
+ @options = options
28
+ @name = name
29
+ @lxc_path = lxc_path
30
+ @port_forwards = {}
31
+ @@active_transports << self
32
+ end
45
33
 
46
- def execute(command, options = {})
47
- Chef::Log.info("Executing #{command} on #{name}")
48
- container.execute(:timeout => (execute_timeout(options) || 0)) do
49
- begin
50
- # TODO support streaming (shell out needs work)
51
- out = shell_out(command)
52
- LXCExecuteResult.new(command, options, out.stdout, out.stderr, out.exitstatus)
53
- rescue Exception => e
54
- LXCExecuteResult.new('', e.message, -1)
34
+ def container
35
+ @container ||= LXC::Container.new(name, lxc_path)
55
36
  end
56
- end
57
- end
58
37
 
59
- def make_url_available_to_remote(local_url)
60
- uri = URI(local_url)
61
- host = Socket.getaddrinfo(uri.host, uri.scheme, nil, :STREAM)[0][3]
62
- if host == '127.0.0.1' || host == '::1'
63
- unless @port_forwards[uri.port]
38
+ def rootfs
39
+ container.config_item('lxc.rootfs')
40
+ end
64
41
 
65
- Chef::Log.debug("Forwarding container port #{uri.port} to local port #{uri.port}")
66
- # Create the channel that will let the container and the host talk to each other
67
- channel = LXC::Extra::Channel.new
42
+ def container_path(path)
43
+ File.join(rootfs, path)
44
+ end
68
45
 
69
- # Start the container side of the proxy, listening for client connections
70
- pid = container.attach do
46
+ def execute(command, options = {})
47
+ timeout = options[:timeout] || 3600
48
+ Chef::Log.info("Executing #{command} on #{name}")
49
+ container.execute(timeout: timeout) do
50
+ cmd = Mixlib::ShellOut.new(command)
51
+ cmd.timeout = timeout
71
52
  begin
72
- server = TCPServer.new(host, uri.port)
73
- proxy = LXC::Extra::ProxyClientSide.new(channel, server)
74
- proxy.start
75
- rescue
76
- Chef::Log.error("ERROR in proxy (container side): #{$!}\n#{$!.backtrace.join("\n")}")
77
- raise
53
+ cmd.run_command
54
+ LXCExecuteResult.new(command, {}, cmd.stdout, cmd.stderr, cmd.exitstatus)
55
+ rescue Errno::ENOENT => e
56
+ LXCExecuteResult.new(command, {} , '', e.message, 2)
78
57
  end
79
58
  end
59
+ end
80
60
 
81
- # Start the host side of the proxy, which contacts the real server
82
- thread = Thread.new do
83
- proxy = LXC::Extra::ProxyServerSide.new(channel) do
84
- TCPSocket.new(host, uri.port)
61
+ def make_url_available_to_remote(local_url)
62
+ uri = URI(local_url)
63
+ uri_scheme = uri.scheme
64
+ uri_scheme = nil if uri.scheme == 'chefzero'
65
+ host = Socket.getaddrinfo(uri.host, uri_scheme, nil, :STREAM)[0][3]
66
+ if host == '127.0.0.1' || host == '::1'
67
+ unless @port_forwards[uri.port]
68
+
69
+ Chef::Log.debug("Forwarding container port #{uri.port} to local port #{uri.port}")
70
+ # Create the channel that will let the container and the host talk to each other
71
+ channel = LXC::Extra::Channel.new
72
+
73
+ # Start the container side of the proxy, listening for client connections
74
+ pid = container.attach do
75
+ begin
76
+ server = TCPServer.new(host, uri.port)
77
+ proxy = LXC::Extra::ProxyClientSide.new(channel, server)
78
+ proxy.start
79
+ rescue
80
+ Chef::Log.error("ERROR in proxy (container side): #{$!}\n#{$!.backtrace.join("\n")}")
81
+ raise
82
+ end
83
+ end
84
+
85
+ # Start the host side of the proxy, which contacts the real server
86
+ thread = Thread.new do
87
+ proxy = LXC::Extra::ProxyServerSide.new(channel) do
88
+ TCPSocket.new(host, uri.port)
89
+ end
90
+ proxy.start
91
+ end
92
+
93
+ Chef::Log.debug("Forwarded #{uri.port} on container #{name} to local port #{uri.port}. Container listener id PID #{pid}")
94
+
95
+ @port_forwards[uri.port] = [ pid, thread, channel ]
85
96
  end
86
- proxy.start
87
- end
88
-
89
- Chef::Log.debug("Forwarded #{uri.port} on container #{name} to local port #{uri.port}. Container listener id PID #{pid}")
90
97
 
91
- @port_forwards[uri.port] = [ pid, thread, channel ]
98
+ end
99
+ local_url
92
100
  end
93
101
 
94
- end
95
- local_url
96
- end
97
-
98
- def read_file(path)
99
- if File.exists?(container_path(path))
100
- File.read(container_path(path))
101
- end
102
- end
103
-
104
- def download_file(path, local_path)
105
- Chef::Log.debug("Copying file #{path} from #{name} to local #{local_path}")
106
- FileUtils.cp_r(container_path(path), local_path)
107
- end
102
+ def read_file(path)
103
+ container.execute(wait: true) do
104
+ if File.exists?(container_path(path))
105
+ File.read(container_path(path))
106
+ end
107
+ end
108
+ end
108
109
 
109
- def write_file(path, content)
110
- File.open(container_path(path), 'w') do |f|
111
- f.write(content)
112
- end
113
- end
110
+ def download_file(path, local_path)
111
+ Chef::Log.debug("Copying file #{path} from #{name} to local #{local_path}")
112
+ data = read_file(path)
113
+ File.open(local_path, 'w') do |f|
114
+ f.write(data)
115
+ end
116
+ end
114
117
 
115
- def upload_file(local_path, path)
116
- FileUtils.cp_r(local_path, container_path(path))
117
- end
118
+ def write_file(path, content)
119
+ container.execute(wait: true) do
120
+ File.open(path, 'w') do |f|
121
+ f.write(content)
122
+ end
123
+ end
124
+ end
118
125
 
119
- def disconnect
120
- @port_forwards.each_pair do |port, (pid, thread, channel)|
121
- Chef::Log.debug("stopping port forward #{port} for container #{name}")
122
- begin
123
- Chef::Log.debug("Killing PID #{pid}")
124
- Process.kill('KILL', pid)
125
- rescue
126
+ def upload_file(local_path, path)
127
+ write_file(path, File.read(local_path))
126
128
  end
127
- begin
128
- thread.kill
129
- rescue
129
+
130
+ def disconnect
131
+ @port_forwards.each_pair do |port, (pid, thread, channel)|
132
+ Chef::Log.debug("stopping port forward #{port} for container #{name}")
133
+ begin
134
+ Chef::Log.debug("Killing PID #{pid}")
135
+ Process.kill('KILL', pid)
136
+ rescue
137
+ end
138
+ begin
139
+ thread.kill
140
+ rescue
141
+ end
142
+ end
143
+ @port_forwards = {}
144
+ @@active_transports.delete(self)
130
145
  end
131
- end
132
- @port_forwards = {}
133
- @@active_transports.delete(self)
134
- end
135
146
 
136
- def available?
137
- begin
138
- execute('pwd')
139
- true
140
- rescue Exception =>e
141
- false
142
- end
143
- end
147
+ def available?
148
+ container.running?
149
+ end
144
150
 
145
- def self.disconnect_active_transports
146
- @@active_transports.to_a.dup.each do |transport|
147
- transport.disconnect
151
+ def self.disconnect_active_transports
152
+ @@active_transports.to_a.dup.each do |transport|
153
+ transport.disconnect
154
+ end
155
+ end
148
156
  end
149
157
  end
150
158
  end
151
159
  end
152
- end
153
- end
154
160
 
155
161
  at_exit do
156
162
  Chef::Provisioning::LXCDriver::LXCTransport.disconnect_active_transports
@@ -1,7 +1,7 @@
1
1
  class Chef
2
- module Provisioning
3
- module LXCDriver
4
- VERSION = '0.6.1'
5
- end
6
- end
2
+ module Provisioning
3
+ module LXCDriver
4
+ VERSION = '0.7.0'
5
+ end
6
+ end
7
7
  end
metadata CHANGED
@@ -1,57 +1,35 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-provisioning-lxc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.1
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ranjib Dey
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: chef
14
+ name: chef-provisioning
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: chef-provisioning
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
19
+ version: '1.0'
20
+ - - "<"
32
21
  - !ruby/object:Gem::Version
33
- version: '0.11'
22
+ version: '3.0'
34
23
  type: :runtime
35
24
  prerelease: false
36
25
  version_requirements: !ruby/object:Gem::Requirement
37
26
  requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.11'
41
- - !ruby/object:Gem::Dependency
42
- name: ruby-lxc
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
27
+ - - ">="
46
28
  - !ruby/object:Gem::Version
47
- version: '1.1'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
29
+ version: '1.0'
30
+ - - "<"
53
31
  - !ruby/object:Gem::Version
54
- version: '1.1'
32
+ version: '3.0'
55
33
  - !ruby/object:Gem::Dependency
56
34
  name: lxc-extra
57
35
  requirement: !ruby/object:Gem::Requirement
@@ -100,7 +78,21 @@ dependencies:
100
78
  - - ">="
101
79
  - !ruby/object:Gem::Version
102
80
  version: '0'
103
- description: Provisioner for creating LXC containers in Chef Metal.
81
+ - !ruby/object:Gem::Dependency
82
+ name: github_changelog_generator
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ version: '0'
95
+ description: Provisioner for creating LXC containers in Chef Provisioning.
104
96
  email: dey.ranjib@gmail.com
105
97
  executables: []
106
98
  extensions: []
@@ -108,15 +100,17 @@ extra_rdoc_files:
108
100
  - README.md
109
101
  - LICENSE
110
102
  files:
103
+ - Gemfile
111
104
  - LICENSE
112
105
  - README.md
113
106
  - Rakefile
107
+ - chef-provisioning-lxc.gemspec
114
108
  - lib/chef/provisioning/driver_init/lxc.rb
115
109
  - lib/chef/provisioning/lxc_driver.rb
116
110
  - lib/chef/provisioning/lxc_driver/driver.rb
117
111
  - lib/chef/provisioning/lxc_driver/lxc_transport.rb
118
112
  - lib/chef/provisioning/lxc_driver/version.rb
119
- homepage: https://github.com/opscode/chef-provisioning-lxc
113
+ homepage: https://github.com/chef/chef-provisioning-lxc
120
114
  licenses: []
121
115
  metadata: {}
122
116
  post_install_message:
@@ -135,9 +129,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
135
129
  version: '0'
136
130
  requirements: []
137
131
  rubyforge_project:
138
- rubygems_version: 2.2.2
132
+ rubygems_version: 2.5.1
139
133
  signing_key:
140
134
  specification_version: 4
141
- summary: Provisioner for creating LXC containers in Chef Metal.
135
+ summary: Provisioner for creating LXC containers in Chef Provisioning.
142
136
  test_files: []
143
- has_rdoc: