linux_container 0.1 → 0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1 +1,2 @@
1
+ v0.2. Support clone
1
2
  v0.1. first version
data/Manifest CHANGED
@@ -1,6 +1,6 @@
1
1
  CHANGELOG
2
+ Manifest
2
3
  README.md
3
4
  Rakefile
4
5
  lib/linux_container.rb
5
6
  test/test_all.rb
6
- Manifest
data/README.md CHANGED
@@ -42,6 +42,14 @@ very little disk space, which then disappears when shut down.
42
42
  ### Start an ephemeral container cloning an existing container
43
43
 
44
44
  > e = c.start_ephemeral
45
+ > e.wait_for { ip && sshable? }
46
+
47
+
48
+ ### Clone an existing container and start it in background, with 512M memlimit
49
+
50
+ > c2 = LinuxContainer.new(name: 'clonetest')
51
+ > c2.clone_from(c)
52
+ > c2.start('-d', '-s', 'lxc.cgroup.memory.limit_in_bytes=512M')
45
53
 
46
54
 
47
55
  ### Get existing containers
@@ -57,6 +65,4 @@ very little disk space, which then disappears when shut down.
57
65
 
58
66
  execute, kill, wait, cgroup, ps, info, freeze, unfreeze, netstat
59
67
 
60
-
61
-
62
68
 
@@ -33,6 +33,11 @@ class LinuxContainer
33
33
  define_method(cmd) {|*args| lxc_execute(cmd, *args) }
34
34
  end
35
35
 
36
+ def clone_from(from, *args)
37
+ fromname = self.class === from ? from.name : from
38
+ lxc_execute('clone', '-o',fromname, *args)
39
+ end
40
+
36
41
  def start_ephemeral
37
42
  args = ['lxc-start-ephemeral','-U','aufs','-u',username,'-o',name]
38
43
  logfile = bg_execute(*args)
@@ -2,20 +2,20 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "linux_container"
5
- s.version = "0.1"
5
+ s.version = "0.2"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Andrew Snow"]
9
- s.date = "2013-02-08"
9
+ s.date = "2013-02-10"
10
10
  s.description = "Ruby gem for ephemeral LXC linux containers"
11
11
  s.email = "andrew@modulus.org"
12
12
  s.extra_rdoc_files = ["CHANGELOG", "README.md", "lib/linux_container.rb"]
13
- s.files = ["CHANGELOG", "README.md", "Rakefile", "lib/linux_container.rb", "test/test_all.rb", "Manifest", "linux_container.gemspec"]
13
+ s.files = ["CHANGELOG", "Manifest", "README.md", "Rakefile", "lib/linux_container.rb", "test/test_all.rb", "linux_container.gemspec"]
14
14
  s.homepage = "https://github.com/andys/linux_container"
15
15
  s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Linux_container", "--main", "README.md"]
16
16
  s.require_paths = ["lib"]
17
17
  s.rubyforge_project = "linux_container"
18
- s.rubygems_version = "1.8.25"
18
+ s.rubygems_version = "1.8.24"
19
19
  s.summary = "Ruby gem for ephemeral LXC linux containers"
20
20
  s.test_files = ["test/test_all.rb"]
21
21
 
data/test/test_all.rb CHANGED
@@ -1,13 +1,21 @@
1
- require "#{File.dirname(__FILE__)}/../lib/linux_container"
1
+ at_exit do
2
+ puts "Destroying test containers"
3
+ File.unlink($sshkey) rescue nil
4
+ ($ec.destroy '-f' if $ec) rescue nil
5
+ ($c2.destroy '-f' if $c2) rescue nil
6
+ $c.destroy '-f'
7
+ end
2
8
 
3
9
  require 'minitest/autorun'
10
+ require "#{File.dirname(__FILE__)}/../lib/linux_container"
4
11
 
5
12
  class TestLinuxContainer < MiniTest::Unit::TestCase
6
13
  def self.startup
14
+ puts "Creating test containers"
7
15
  $sshkey = "/tmp/linuxcontainergemtestssh#{$$}"
8
16
  `ssh-keygen -q -t rsa -f #{$sshkey} -N ''` unless File.exists?($sshkey)
9
17
  $c = LinuxContainer.new(name: 'linuxcontainergemtest', ssh_key_path: $sshkey)
10
- $c.create
18
+ $c.create or raise "Create failed"
11
19
  end
12
20
 
13
21
  def test_state
@@ -26,6 +34,14 @@ class TestLinuxContainer < MiniTest::Unit::TestCase
26
34
  assert_includes LinuxContainer.all.map(&:name), 'linuxcontainergemtest'
27
35
  end
28
36
 
37
+ def test_clone
38
+ $c2 = LinuxContainer.new name: 'linuxcontainergemtest2'
39
+ $c2.clone_from $c.name
40
+ assert_includes LinuxContainer.all.map(&:name), 'linuxcontainergemtest2'
41
+ $c2.destroy('-f')
42
+ refute_includes LinuxContainer.all.map(&:name), 'linuxcontainergemtest2'
43
+ end
44
+
29
45
  def test_ephemeral
30
46
  assert($ec = $c.start_ephemeral)
31
47
  assert_match /^linuxcontainergemtest.+/, $ec.name
@@ -38,11 +54,4 @@ class TestLinuxContainer < MiniTest::Unit::TestCase
38
54
  end
39
55
  end
40
56
 
41
-
42
-
43
- MiniTest::Unit.after_tests do
44
- File.unlink($sshkey) rescue nil
45
- ($ec.destroy '-f' if $ec) rescue nil
46
- $c.destroy '-f'
47
- end
48
- TestLinuxContainer.startup
57
+ TestLinuxContainer.startup
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_container
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
5
4
  prerelease:
5
+ version: '0.2'
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andrew Snow
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-02-08 00:00:00.000000000 Z
12
+ date: 2013-02-10 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Ruby gem for ephemeral LXC linux containers
15
15
  email: andrew@modulus.org
@@ -21,11 +21,11 @@ extra_rdoc_files:
21
21
  - lib/linux_container.rb
22
22
  files:
23
23
  - CHANGELOG
24
+ - Manifest
24
25
  - README.md
25
26
  - Rakefile
26
27
  - lib/linux_container.rb
27
28
  - test/test_all.rb
28
- - Manifest
29
29
  - linux_container.gemspec
30
30
  homepage: https://github.com/andys/linux_container
31
31
  licenses: []
@@ -40,20 +40,20 @@ rdoc_options:
40
40
  require_paths:
41
41
  - lib
42
42
  required_ruby_version: !ruby/object:Gem::Requirement
43
- none: false
44
43
  requirements:
45
44
  - - ! '>='
46
45
  - !ruby/object:Gem::Version
47
46
  version: '0'
48
- required_rubygems_version: !ruby/object:Gem::Requirement
49
47
  none: false
48
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
49
  requirements:
51
50
  - - ! '>='
52
51
  - !ruby/object:Gem::Version
53
52
  version: '1.2'
53
+ none: false
54
54
  requirements: []
55
55
  rubyforge_project: linux_container
56
- rubygems_version: 1.8.25
56
+ rubygems_version: 1.8.24
57
57
  signing_key:
58
58
  specification_version: 3
59
59
  summary: Ruby gem for ephemeral LXC linux containers