linux_container 1.7 → 1.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,15 @@
1
+ ---
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ ZWU5MGEzNTc4MWE5MWNiNTdiMGNiMWM4N2U2ZTBjZmNhZTVlZGM3MA==
5
+ data.tar.gz: !binary |-
6
+ NGYwYjgxYTU5NTNhZDkwOWUyNDk0YTlmNThhYWRiYTA0OTM1ZjU5OA==
7
+ !binary "U0hBNTEy":
8
+ metadata.gz: !binary |-
9
+ MGE2OWE2ZGM2NjdkZWY5ZmU0N2EyNmQ3ZjBhMTc3NDY1ZmEzOGJlMTNmYzQ0
10
+ YTQzNTcyYjk3N2Y1ZTlkNjJiYjRhOTc2YzRiODY0OTcyMjA4MGE4ZDYxNjFi
11
+ M2YzNTU5NjVjZmQ5MDcwOTVhYWYxM2Y4ODQ1YzE0NTJmZjZjMWM=
12
+ data.tar.gz: !binary |-
13
+ Nzc0NWE3YTE2MDU3ZDE1NDk1YjBhM2I3N2Y3MGIwZDViYjEwNjU0NjZjY2Jm
14
+ NWQ3MjA4MGYwZjc1NjFjYjUwYWIwNzc3NmUwOGIzZDM0MDRhMWIxMGRhNTRm
15
+ YjU5MDk0Yjk0MGZkZWNkMDkwMDUyOGFhYTZkNGM4NDAyYmY4NGY=
data/CHANGELOG CHANGED
@@ -1,3 +1,4 @@
1
+ v1.8. Yield execute/ssh output line by line
1
2
  v1.7. use Process.spawn instead of background shell for ephemeral
2
3
  v1.6. additional ephemeral container naming chars
3
4
  v1.5. match new ephemeral container naming scheme
data/README.md CHANGED
@@ -68,6 +68,10 @@ that uses little disk space. This container disappears when shut down.
68
68
 
69
69
  > c.destroy '-f'
70
70
 
71
+ ### SSH a long running command
72
+
73
+ > c.ssh('mason build') {|log| print "->#{log}" }
74
+
71
75
  ### other commands
72
76
 
73
77
  execute, kill, wait, cgroup, ps, info, freeze, unfreeze, netstat
@@ -71,8 +71,8 @@ class LinuxContainer
71
71
  self.class.new(name: newname, ssh_key_path: ssh_key_path, username: username)
72
72
  end
73
73
 
74
- def ssh(cmd)
75
- execute('ssh', *ssh_args, "#{username}@#{ip}", cmd)
74
+ def ssh(cmd, &bl)
75
+ execute('ssh', *ssh_args, "#{username}@#{ip}", cmd, &bl)
76
76
  end
77
77
 
78
78
  def scp_to(srcpath, dstpath, *args)
@@ -85,7 +85,7 @@ class LinuxContainer
85
85
 
86
86
  def ssh_args
87
87
  raise "cannot ssh without ip" unless ip
88
- args = ['-o','StrictHostKeyChecking=no','-o','UserKnownHostsFile=/dev/null']
88
+ args = ['-o','StrictHostKeyChecking=no','-o','UserKnownHostsFile=/dev/null','-q']
89
89
  args.push('-i', ssh_key_path) if ssh_key_path
90
90
  args
91
91
  end
@@ -127,7 +127,13 @@ class LinuxContainer
127
127
 
128
128
  def execute(*cmd)
129
129
  cmdstring = "#{self.class.sudo_if_needed} #{cmd.shift} #{Shellwords.join(cmd)}"
130
- result = `#{cmdstring} 2>&1`
130
+ result = ''
131
+ IO.popen("#{cmdstring} 2>&1", 'r') do |io|
132
+ io.each_line do |line|
133
+ yield line if block_given?
134
+ result << line
135
+ end
136
+ end
131
137
  raise "command failed: #{cmdstring.inspect}\n#{result}" unless $? == 0
132
138
  result
133
139
  end
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "linux_container"
5
- s.version = "1.7"
5
+ s.version = "1.8"
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-06-23"
9
+ s.date = "2013-08-20"
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"]
@@ -15,16 +15,7 @@ Gem::Specification.new do |s|
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 = "2.0.3"
19
19
  s.summary = "Ruby gem for ephemeral LXC linux containers"
20
20
  s.test_files = ["test/test_all.rb"]
21
-
22
- if s.respond_to? :specification_version then
23
- s.specification_version = 3
24
-
25
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
- else
27
- end
28
- else
29
- end
30
21
  end
data/test/test_all.rb CHANGED
@@ -49,7 +49,13 @@ class TestLinuxContainer < MiniTest::Unit::TestCase
49
49
  assert($ec.wait_for { running? }, 'wait_for running?')
50
50
  assert($ec.wait_for { ip }, 'wait_for ip')
51
51
  assert($ec.wait_for { sshable? }, 'wait_for sshable?')
52
- assert_equal "hi\n", $ec.execute('echo hi')
52
+
53
+ assert_equal "hi!\n", $ec.ssh('echo hi!')
54
+
55
+ yield_result = nil
56
+ $ec.execute('echo hi!') {|line| yield_result = line }
57
+ assert_equal "hi!\n", yield_result
58
+
53
59
  File.unlink('/tmp/lsb-release') rescue nil
54
60
  $ec.scp_from('/etc/lsb-release', '/tmp/lsb-release')
55
61
  assert File.exists?('/tmp/lsb-release')
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: linux_container
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.7'
5
- prerelease:
4
+ version: '1.8'
6
5
  platform: ruby
7
6
  authors:
8
7
  - Andrew Snow
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-23 00:00:00.000000000 Z
11
+ date: 2013-08-20 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description: Ruby gem for ephemeral LXC linux containers
15
14
  email: andrew@modulus.org
@@ -29,6 +28,7 @@ files:
29
28
  - linux_container.gemspec
30
29
  homepage: https://github.com/andys/linux_container
31
30
  licenses: []
31
+ metadata: {}
32
32
  post_install_message:
33
33
  rdoc_options:
34
34
  - --line-numbers
@@ -40,22 +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
47
  required_rubygems_version: !ruby/object:Gem::Requirement
49
- none: false
50
48
  requirements:
51
49
  - - ! '>='
52
50
  - !ruby/object:Gem::Version
53
51
  version: '1.2'
54
52
  requirements: []
55
53
  rubyforge_project: linux_container
56
- rubygems_version: 1.8.25
54
+ rubygems_version: 2.0.3
57
55
  signing_key:
58
- specification_version: 3
56
+ specification_version: 4
59
57
  summary: Ruby gem for ephemeral LXC linux containers
60
58
  test_files:
61
59
  - test/test_all.rb