linux_container 0.3 → 0.4

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/CHANGELOG CHANGED
@@ -1,3 +1,4 @@
1
+ v0.4. sudo only if needed
1
2
  v0.3. Support shutdown
2
3
  v0.2. Support clone
3
4
  v0.1. first version
@@ -8,7 +8,7 @@ class LinuxContainer
8
8
  attr_writer :ip
9
9
 
10
10
  def self.all
11
- `sudo lxc-ls`.lines.map(&:strip).uniq.map {|cname| new(name: cname) }
11
+ `#{sudo_if_needed} lxc-ls`.lines.map(&:strip).uniq.map {|cname| new(name: cname) }
12
12
  end
13
13
 
14
14
  def initialize(params={})
@@ -93,7 +93,7 @@ class LinuxContainer
93
93
  end
94
94
 
95
95
  def execute(*cmd)
96
- cmdstring = "sudo #{cmd.shift} #{Shellwords.join(cmd)} "
96
+ cmdstring = "#{self.class.sudo_if_needed} #{cmd.shift} #{Shellwords.join(cmd)} "
97
97
  result = `#{cmdstring} 2>&1`
98
98
  raise "command failed: #{cmdstring.inspect}\n#{result}" unless $? == 0
99
99
  result
@@ -101,7 +101,7 @@ class LinuxContainer
101
101
 
102
102
  def bg_execute(*cmd)
103
103
  logfile = Tempfile.new(self.class.to_s)
104
- cmdstring = "sudo #{cmd.shift} #{Shellwords.join(cmd)} >>#{logfile.path} 2>>#{logfile.path} &"
104
+ cmdstring = "#{self.class.sudo_if_needed} #{cmd.shift} #{Shellwords.join(cmd)} >>#{logfile.path} 2>>#{logfile.path} &"
105
105
  system(cmdstring)
106
106
  raise "command failed: #{cmdstring.inspect}\n" unless $? == 0
107
107
  logfile
@@ -115,4 +115,9 @@ class LinuxContainer
115
115
  nil
116
116
  end
117
117
 
118
+ def self.sudo_if_needed
119
+ 'sudo' unless Process.uid == 0
120
+ end
121
+
118
122
  end
123
+
@@ -2,11 +2,11 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = "linux_container"
5
- s.version = "0.3"
5
+ s.version = "0.4"
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-13"
9
+ s.date = "2013-03-07"
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,7 +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.24"
18
+ s.rubygems_version = "1.8.25"
19
19
  s.summary = "Ruby gem for ephemeral LXC linux containers"
20
20
  s.test_files = ["test/test_all.rb"]
21
21
 
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.4'
4
5
  prerelease:
5
- version: '0.3'
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-13 00:00:00.000000000 Z
12
+ date: 2013-03-07 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: Ruby gem for ephemeral LXC linux containers
15
15
  email: andrew@modulus.org
@@ -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
43
44
  requirements:
44
45
  - - ! '>='
45
46
  - !ruby/object:Gem::Version
46
47
  version: '0'
47
- none: false
48
48
  required_rubygems_version: !ruby/object:Gem::Requirement
49
+ none: false
49
50
  requirements:
50
51
  - - ! '>='
51
52
  - !ruby/object:Gem::Version
52
53
  version: '1.2'
53
- none: false
54
54
  requirements: []
55
55
  rubyforge_project: linux_container
56
- rubygems_version: 1.8.24
56
+ rubygems_version: 1.8.25
57
57
  signing_key:
58
58
  specification_version: 3
59
59
  summary: Ruby gem for ephemeral LXC linux containers