jamie-lxc 0.0.1.alpha1

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.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in jamie-lxc.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Sean Porter
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Jamie LXC
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jamie-lxc'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install jamie-lxc
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |test|
5
+ test.pattern = "test/*_tests.rb"
6
+ end
7
+
8
+ task :default => "test"
data/jamie-lxc.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.name = "jamie-lxc"
3
+ gem.version = "0.0.1.alpha1"
4
+ gem.authors = ["Sean Porter"]
5
+ gem.email = ["portertech@gmail.com"]
6
+ gem.description = "LXC driver for Jamie"
7
+ gem.summary = "LXC driver for Jamie"
8
+ gem.homepage = "https://github.com/portertech/jamie-lxc"
9
+ gem.license = "MIT"
10
+ gem.has_rdoc = false
11
+
12
+ gem.add_dependency("jamie")
13
+
14
+ gem.add_development_dependency("rake")
15
+
16
+ gem.files = `git ls-files`.split($/)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,66 @@
1
+ require "securerandom"
2
+ require "benchmark"
3
+ require "jamie"
4
+
5
+ module Jamie
6
+
7
+ module Driver
8
+
9
+ class Lxc < Jamie::Driver::SSHBase
10
+
11
+ default_config "use_sudo", true
12
+ default_config "dhcp_lease_file", "/var/lib/misc/dnsmasq.leases"
13
+ default_config "port", "22"
14
+
15
+ def perform_create(instance, state)
16
+ state["container_id"] = instance.name + "-" + ::SecureRandom.hex(3)
17
+ elapsed_time = ::Benchmark.measure do
18
+ clone_container(state)
19
+ start_container(state)
20
+ state["hostname"] = container_ip(state)
21
+ wait_for_sshd(state["hostname"])
22
+ end
23
+ puts " Created #{state["container_id"]} in #{elapsed_time.real} seconds."
24
+ end
25
+
26
+ def perform_destroy(instance, state)
27
+ destroy_container(state)
28
+ end
29
+
30
+ protected
31
+
32
+ def clone_container(state)
33
+ run_command("lxc-clone -o #{config["base_container"]} -n #{state["container_id"]}")
34
+ end
35
+
36
+ def start_container(state)
37
+ run_command("lxc-start -n #{state["container_id"]} -d")
38
+ run_command("lxc-wait -n #{state["container_id"]} -s RUNNING")
39
+ end
40
+
41
+ def destroy_container(state)
42
+ run_command("lxc-destroy -n #{state["container_id"]} -f")
43
+ end
44
+
45
+ def container_ip(state)
46
+ if ::File.exists?(config["dhcp_lease_file"])
47
+ 10.times do
48
+ leases = ::File.readlines(config["dhcp_lease_file"]).map{ |line| line.split(" ") }
49
+ leases.each do |lease|
50
+ if lease.include?(state["container_id"])
51
+ return lease[2]
52
+ end
53
+ end
54
+ sleep 3
55
+ end
56
+ else
57
+ raise ActionFailed, "LXC DHCP lease file does not exist '#{config["dhcp_lease_file"]}'"
58
+ end
59
+ raise ActionFailed, "Could not determine IP address for LXC container '#{state["container_id"]}'"
60
+ end
61
+
62
+ end
63
+
64
+ end
65
+
66
+ end
@@ -0,0 +1,24 @@
1
+ require "minitest/spec"
2
+ require "minitest/autorun"
3
+
4
+ require File.join(File.dirname(__FILE__), "..", "lib", "jamie", "driver", "lxc")
5
+
6
+ describe Jamie::Driver::Lxc do
7
+
8
+ before do
9
+ suite = Jamie::Suite.new("name" => "test", "run_list" => Array.new)
10
+ config = {
11
+ "jamie_root" => File.dirname(__FILE__),
12
+ "base_container" => "iac-testing"
13
+ }
14
+ driver = Jamie::Driver::LXC.new(config)
15
+ platform = Jamie::Platform.new("name" => "ubuntu-12.04", "driver" => driver)
16
+ @instance = Jamie::Instance.new(suite, platform)
17
+ end
18
+
19
+ it "can clone a base lxc container" do
20
+ @instance.create
21
+ @instance.destroy
22
+ end
23
+
24
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jamie-lxc
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: 6
5
+ version: 0.0.1.alpha1
6
+ platform: ruby
7
+ authors:
8
+ - Sean Porter
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ type: :runtime
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ! '>='
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ name: jamie
30
+ - !ruby/object:Gem::Dependency
31
+ type: :development
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ name: rake
46
+ description: LXC driver for Jamie
47
+ email:
48
+ - portertech@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE.txt
56
+ - README.md
57
+ - Rakefile
58
+ - jamie-lxc.gemspec
59
+ - lib/jamie/driver/lxc.rb
60
+ - test/lxc_driver_tests.rb
61
+ homepage: https://github.com/portertech/jamie-lxc
62
+ licenses:
63
+ - MIT
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>'
78
+ - !ruby/object:Gem::Version
79
+ version: 1.3.1
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.24
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: LXC driver for Jamie
86
+ test_files:
87
+ - test/lxc_driver_tests.rb