lxc 0.2.12 → 0.2.13

Sign up to get free protection for your applications and to get access to all the features.
data/bin/lxc-console CHANGED
@@ -1,3 +1,4 @@
1
+ #!/usr/bin/env ruby
1
2
  ################################################################################
2
3
  #
3
4
  # Author: Zachary Patten <zachary AT jovelabs DOT com>
@@ -17,7 +18,8 @@
17
18
  # limitations under the License.
18
19
  #
19
20
  ################################################################################
20
- #!/usr/bin/env ruby
21
+ require 'rubygems'
22
+ require 'bundler/setup'
21
23
 
22
24
  def lxc_console
23
25
  require 'pry'
data/lib/lxc/config.rb CHANGED
@@ -140,8 +140,8 @@ class LXC
140
140
 
141
141
  content.split("\n").map(&:strip).each do |line|
142
142
  key, value = line.split('=').map(&:strip)
143
- if key =~ /network/
144
- if key =~ /network.type/
143
+ if key =~ /lxc\.network/
144
+ if key =~ /lxc\.network\.type/
145
145
  # this is a new network object
146
146
  @networks << network
147
147
  network = Hash.new
data/lib/lxc/runner.rb ADDED
@@ -0,0 +1,17 @@
1
+ require 'timeout'
2
+
3
+ class LXC
4
+
5
+ # Runner Error Class
6
+ class RunnerError < LXCError; end
7
+
8
+ # Main Runner Class
9
+ #
10
+ # @author Zachary Patten <zachary AT jovelabs DOT com>
11
+ class Runner
12
+
13
+ autoload :Shell, 'lxc/runners/shell'
14
+ autoload :SSH, 'lxc/runners/ssh'
15
+
16
+ end
17
+ end
@@ -0,0 +1,81 @@
1
+ class LXC
2
+ class Runner
3
+
4
+ class ShellError < RunnerError; end
5
+
6
+ class Shell
7
+ require 'socket'
8
+
9
+ # Controls if sudo is prefixed on all executed commands.
10
+ #
11
+ # @overload use_sudo=(value)
12
+ # Sets if all executed commands should be prefixed with sudo.
13
+ # @param [Boolean] value
14
+ #
15
+ # @overload use_sudo
16
+ # Gets if we are prefixing all executed commands with sudo.
17
+ #
18
+ # @return [Boolean] Returns true if we are prefixing commands with "sudo";
19
+ # otherwise false.
20
+ attr_accessor :use_sudo
21
+
22
+ # @param [Hash] options Options hash.
23
+ # @option options [Boolean] :use_sudo (false) Whether or not to prefix all
24
+ # commands with 'sudo'.
25
+ def initialize(options={})
26
+ @hostname = Socket.gethostname.split('.').first.strip
27
+
28
+ @ui = (options[:ui] || ZTK::UI.new)
29
+ @use_sudo = (options[:use_sudo] || false)
30
+ end
31
+
32
+ # Linux container command execution wrapper
33
+ #
34
+ # Runs the supplied LXC command. The first element in the "args" splat is the
35
+ # command to be execute, the rest of the elements are treated as command line
36
+ # arguments.
37
+ #
38
+ # If use_sudo is true then all commands will be prefix with "sudo".
39
+ # If use_ssh is non-nil then all commands will be execute via the assigned
40
+ # Net::SSH Session.
41
+ #
42
+ # @param [Array] args Additional command-line arguments.
43
+ # @return [Array<String>] Stripped output text of the executed command.
44
+ def exec(*args)
45
+ command = args.shift
46
+
47
+ arguments = Array.new
48
+ arguments << %(sudo) if (@use_sudo == true)
49
+ arguments << command
50
+ arguments << args
51
+ arguments = arguments.flatten.compact.join(' ')
52
+
53
+ output = Array.new
54
+
55
+ begin
56
+ ::ZTK::PTY.spawn(arguments) do |reader, writer, pid|
57
+ while (buffer = reader.readpartial(1024))
58
+ output << buffer
59
+ end
60
+ end
61
+ rescue EOFError
62
+ # NOOP
63
+ end
64
+
65
+ output.join
66
+ end
67
+
68
+ # Provides a concise string representation of the class
69
+ # @return [String]
70
+ def inspect
71
+ tags = Array.new
72
+ tags << "host=#{@hostname.inspect}"
73
+ tags << "use_sudo=#{@use_sudo.inspect}"
74
+ tags = tags.join(' ')
75
+
76
+ "#<#{self.class} #{tags}>"
77
+ end
78
+
79
+ end
80
+ end
81
+ end
data/lib/lxc/version.rb CHANGED
@@ -2,7 +2,7 @@ class LXC
2
2
 
3
3
  unless const_defined?(:VERSION)
4
4
  # LXC Gem Version
5
- VERSION = "0.2.12"
5
+ VERSION = "0.2.13"
6
6
  end
7
7
 
8
8
  end
data/lib/lxc.rb CHANGED
@@ -10,8 +10,9 @@ class LXC
10
10
  # Top-Level Error Class
11
11
  class LXCError < StandardError; end
12
12
 
13
- autoload :Config, 'lxc/config'
13
+ autoload :Config, 'lxc/config'
14
14
  autoload :Container, 'lxc/container'
15
+ autoload :Runner, 'lxc/runner'
15
16
 
16
17
  # Controls if sudo is prefixed on all executed commands.
17
18
  #
data/spec/lxc_spec.rb CHANGED
@@ -199,7 +199,8 @@ describe LXC do
199
199
  @ssh_connection = ::ZTK::SSH.new(
200
200
  :host_name => "127.0.0.1",
201
201
  :user => ENV['USER'],
202
- :keys => "#{ENV['HOME']}/.ssh/id_rsa"
202
+ :keys => File.join(ENV['HOME'], '.ssh', 'id_rsa'),
203
+ :keys_only => true
203
204
  ).ssh
204
205
  end
205
206
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lxc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.12
4
+ version: 0.2.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-17 00:00:00.000000000 Z
12
+ date: 2013-06-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: ztk
@@ -161,6 +161,8 @@ files:
161
161
  - lib/lxc.rb
162
162
  - lib/lxc/config.rb
163
163
  - lib/lxc/container.rb
164
+ - lib/lxc/runner.rb
165
+ - lib/lxc/runners/shell.rb
164
166
  - lib/lxc/version.rb
165
167
  - lxc.gemspec
166
168
  - spec/lxc/config_spec.rb
@@ -214,12 +216,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
214
216
  - - ! '>='
215
217
  - !ruby/object:Gem::Version
216
218
  version: '0'
219
+ segments:
220
+ - 0
221
+ hash: 2981418491518284885
217
222
  required_rubygems_version: !ruby/object:Gem::Requirement
218
223
  none: false
219
224
  requirements:
220
225
  - - ! '>='
221
226
  - !ruby/object:Gem::Version
222
227
  version: '0'
228
+ segments:
229
+ - 0
230
+ hash: 2981418491518284885
223
231
  requirements: []
224
232
  rubyforge_project:
225
233
  rubygems_version: 1.8.25