lxc 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/lib/lxc/container.rb +34 -3
  2. data/lib/lxc/version.rb +6 -1
  3. data/lib/lxc.rb +8 -3
  4. metadata +86 -121
data/lib/lxc/container.rb CHANGED
@@ -1,11 +1,16 @@
1
1
  class LXC
2
+
3
+ # Container Error Class
2
4
  class ContainerError < Error; end
3
5
 
6
+ # Main Container Class
7
+ #
8
+ # @author Zachary Patten <zachary@jovelabs.net>
4
9
  class Container
5
10
 
6
11
  # An array containing the valid container states extracted from the LXC
7
12
  # c-source code.
8
- STATES = %w(stopped starting running stopping aborting freezing frozen thawed)
13
+ STATES = %w(stopped starting running stopping aborting freezing frozen thawed).map(&:to_sym)
9
14
 
10
15
  # @!method stopped?
11
16
  # Returns true if the container is stopped, false otherwise.
@@ -39,8 +44,8 @@ class LXC
39
44
  # Returns true if the container is thawed, false otherwise.
40
45
  # @return [Boolean]
41
46
  STATES.each do |state|
42
- define_method "#{state.downcase}?" do
43
- (self.state == state.downcase.to_sym)
47
+ define_method "#{state}?" do
48
+ (self.state == state)
44
49
  end
45
50
  end
46
51
 
@@ -159,6 +164,32 @@ class LXC
159
164
  @lxc.exists?(self.name)
160
165
  end
161
166
 
167
+ # Wait for a specific container state
168
+ #
169
+ # Runs the "lxc-wait" command.
170
+ #
171
+ # @param [Array] states An array of container states for which we will wait
172
+ # for the container to change state to.
173
+ # @param [Integer] timeout How long in seconds we will wait before the
174
+ # operation times out.
175
+ # @return [Boolean] Returns true of the state change happened, false
176
+ # otherwise.
177
+ def wait(states, timeout=60)
178
+ state_arg = states.map do |state|
179
+ state.to_s.upcase.strip
180
+ end.join('|')
181
+
182
+ begin
183
+ Timeout::timeout(timeout) do
184
+ self.exec("wait", "-s", %('#{state_arg}'))
185
+ end
186
+ rescue Timeout::Error => e
187
+ return false
188
+ end
189
+
190
+ return true
191
+ end
192
+
162
193
  # Linux container command execution wrapper
163
194
  #
164
195
  # Executes the supplied command by injecting the container name into the
data/lib/lxc/version.rb CHANGED
@@ -1,3 +1,8 @@
1
1
  class LXC
2
- VERSION = "0.0.2" unless const_defined?(:VERSION)
2
+
3
+ unless const_defined?(:VERSION)
4
+ # LXC Gem Version
5
+ VERSION = "0.0.3"
6
+ end
7
+
3
8
  end
data/lib/lxc.rb CHANGED
@@ -2,7 +2,7 @@ require 'ztk'
2
2
 
3
3
  require 'lxc/version'
4
4
 
5
- # Main LXC (Linux Container) Class
5
+ # Top-Level LXC Class
6
6
  #
7
7
  # @author Zachary Patten <zachary@jovelabs.net>
8
8
  class LXC
@@ -45,6 +45,11 @@ class LXC
45
45
  # output.
46
46
  REGEX_VERSION = /^lxc version:\s+([\w\W]+)$/
47
47
 
48
+ # SED command for removing ANSI colors
49
+ #
50
+ # @see http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed CommandLineFu - Remove Color Codes (Special Characters) with SED
51
+ SED_REMOVE_ANSI = %q(sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")
52
+
48
53
  def initialize
49
54
  @use_sudo = false
50
55
  @use_ssh = nil
@@ -122,9 +127,9 @@ class LXC
122
127
  # Runs the "lxc-checkconfig" command.
123
128
  #
124
129
  # @param [Array] args Additional command-line arguments.
125
- # @return [Array<String>] Output text of the "lxc-ps" command.
130
+ # @return [Array<String>] Output text of the "lxc-checkconfig" command.
126
131
  def checkconfig(*args)
127
- self.exec("checkconfig", *args).split("\n")
132
+ self.exec("checkconfig", *args, " | #{SED_REMOVE_ANSI}").split("\n")
128
133
  end
129
134
 
130
135
  # Linux container command execution wrapper
metadata CHANGED
@@ -1,152 +1,115 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: lxc
3
- version: !ruby/object:Gem::Version
4
- version: 0.0.2
3
+ version: !ruby/object:Gem::Version
5
4
  prerelease:
5
+ version: 0.0.3
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Zachary Patten
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-12 00:00:00.000000000 Z
13
- dependencies:
14
- - !ruby/object:Gem::Dependency
12
+
13
+ date: 2013-04-13 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
15
16
  name: ztk
16
- requirement: !ruby/object:Gem::Requirement
17
+ requirement: &id001 !ruby/object:Gem::Requirement
17
18
  none: false
18
- requirements:
19
- - - ! '>='
20
- - !ruby/object:Gem::Version
21
- version: '0'
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
22
23
  type: :runtime
23
24
  prerelease: false
24
- version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ! '>='
28
- - !ruby/object:Gem::Version
29
- version: '0'
30
- - !ruby/object:Gem::Dependency
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
31
27
  name: bundler
32
- requirement: !ruby/object:Gem::Requirement
28
+ requirement: &id002 !ruby/object:Gem::Requirement
33
29
  none: false
34
- requirements:
30
+ requirements:
35
31
  - - ~>
36
- - !ruby/object:Gem::Version
37
- version: '1.3'
32
+ - !ruby/object:Gem::Version
33
+ version: "1.3"
38
34
  type: :development
39
35
  prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ~>
44
- - !ruby/object:Gem::Version
45
- version: '1.3'
46
- - !ruby/object:Gem::Dependency
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
47
38
  name: pry
48
- requirement: !ruby/object:Gem::Requirement
39
+ requirement: &id003 !ruby/object:Gem::Requirement
49
40
  none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
54
45
  type: :development
55
46
  prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
47
+ version_requirements: *id003
48
+ - !ruby/object:Gem::Dependency
63
49
  name: rake
64
- requirement: !ruby/object:Gem::Requirement
50
+ requirement: &id004 !ruby/object:Gem::Requirement
65
51
  none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
70
56
  type: :development
71
57
  prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
- - !ruby/object:Gem::Dependency
58
+ version_requirements: *id004
59
+ - !ruby/object:Gem::Dependency
79
60
  name: redcarpet
80
- requirement: !ruby/object:Gem::Requirement
61
+ requirement: &id005 !ruby/object:Gem::Requirement
81
62
  none: false
82
- requirements:
83
- - - ! '>='
84
- - !ruby/object:Gem::Version
85
- version: '0'
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
86
67
  type: :development
87
68
  prerelease: false
88
- version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
- requirements:
91
- - - ! '>='
92
- - !ruby/object:Gem::Version
93
- version: '0'
94
- - !ruby/object:Gem::Dependency
69
+ version_requirements: *id005
70
+ - !ruby/object:Gem::Dependency
95
71
  name: rspec
96
- requirement: !ruby/object:Gem::Requirement
72
+ requirement: &id006 !ruby/object:Gem::Requirement
97
73
  none: false
98
- requirements:
99
- - - ! '>='
100
- - !ruby/object:Gem::Version
101
- version: '0'
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
102
78
  type: :development
103
79
  prerelease: false
104
- version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
- requirements:
107
- - - ! '>='
108
- - !ruby/object:Gem::Version
109
- version: '0'
110
- - !ruby/object:Gem::Dependency
80
+ version_requirements: *id006
81
+ - !ruby/object:Gem::Dependency
111
82
  name: simplecov
112
- requirement: !ruby/object:Gem::Requirement
83
+ requirement: &id007 !ruby/object:Gem::Requirement
113
84
  none: false
114
- requirements:
115
- - - ! '>='
116
- - !ruby/object:Gem::Version
117
- version: '0'
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: "0"
118
89
  type: :development
119
90
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
- requirements:
123
- - - ! '>='
124
- - !ruby/object:Gem::Version
125
- version: '0'
126
- - !ruby/object:Gem::Dependency
91
+ version_requirements: *id007
92
+ - !ruby/object:Gem::Dependency
127
93
  name: yard
128
- requirement: !ruby/object:Gem::Requirement
94
+ requirement: &id008 !ruby/object:Gem::Requirement
129
95
  none: false
130
- requirements:
131
- - - ! '>='
132
- - !ruby/object:Gem::Version
133
- version: '0'
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: "0"
134
100
  type: :development
135
101
  prerelease: false
136
- version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
- requirements:
139
- - - ! '>='
140
- - !ruby/object:Gem::Version
141
- version: '0'
102
+ version_requirements: *id008
142
103
  description: An interface for controlling local or remote Linux Containers (LXC)
143
- email:
104
+ email:
144
105
  - zachary@jovelabs.com
145
- executables:
106
+ executables:
146
107
  - lxc-console
147
108
  extensions: []
109
+
148
110
  extra_rdoc_files: []
149
- files:
111
+
112
+ files:
150
113
  - .gitignore
151
114
  - .rspec
152
115
  - .rvmrc.template
@@ -173,37 +136,39 @@ files:
173
136
  - spec/lxc_spec.rb
174
137
  - spec/spec_helper.rb
175
138
  homepage: https://github.com/zpatten/lxc
176
- licenses:
139
+ licenses:
177
140
  - Apache 2.0
178
141
  post_install_message:
179
142
  rdoc_options: []
180
- require_paths:
143
+
144
+ require_paths:
181
145
  - lib
182
- required_ruby_version: !ruby/object:Gem::Requirement
146
+ required_ruby_version: !ruby/object:Gem::Requirement
183
147
  none: false
184
- requirements:
185
- - - ! '>='
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- segments:
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ hash: 3183710469568139405
152
+ segments:
189
153
  - 0
190
- hash: 4541588393573481545
191
- required_rubygems_version: !ruby/object:Gem::Requirement
154
+ version: "0"
155
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
156
  none: false
193
- requirements:
194
- - - ! '>='
195
- - !ruby/object:Gem::Version
196
- version: '0'
197
- segments:
157
+ requirements:
158
+ - - ">="
159
+ - !ruby/object:Gem::Version
160
+ hash: 3183710469568139405
161
+ segments:
198
162
  - 0
199
- hash: 4541588393573481545
163
+ version: "0"
200
164
  requirements: []
165
+
201
166
  rubyforge_project:
202
167
  rubygems_version: 1.8.25
203
168
  signing_key:
204
169
  specification_version: 3
205
170
  summary: An interface for controlling local or remote Linux Containers (LXC)
206
- test_files:
171
+ test_files:
207
172
  - spec/fixtures/0.7.5/lxc-checkconfig.out
208
173
  - spec/fixtures/0.7.5/lxc-ls-w-containers.out
209
174
  - spec/fixtures/0.7.5/lxc-ls-wo-containers.out