lxc 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
+ [![Gem Version](https://badge.fury.io/rb/lxc.png)](http://badge.fury.io/rb/lxc)
2
+ [![Dependency Status](https://gemnasium.com/zpatten/lxc.png)](https://gemnasium.com/zpatten/lxc)
1
3
  [![Build Status](https://secure.travis-ci.org/zpatten/lxc.png)](http://travis-ci.org/zpatten/lxc)
2
4
  [![Code Climate](https://codeclimate.com/github/zpatten/lxc.png)](https://codeclimate.com/github/zpatten/lxc)
3
- [![Dependency Status](https://gemnasium.com/zpatten/lxc.png)](https://gemnasium.com/zpatten/lxc)
4
5
 
5
6
  # LXC
6
7
 
data/lib/lxc.rb CHANGED
@@ -85,7 +85,7 @@ class LXC
85
85
  # @param [Array] args Additional command-line arguments.
86
86
  # @return [Array<String>] A list of container names.
87
87
  def ls(*args)
88
- self.exec("ls", *args).split("\n").uniq
88
+ self.exec("lxc-ls", *args).split("\n").uniq
89
89
  end
90
90
 
91
91
  # Check if a container exists
@@ -106,7 +106,7 @@ class LXC
106
106
  # @param [Array] args Additional command-line arguments.
107
107
  # @return [Array<String>] Output text of the "lxc-ps" command.
108
108
  def ps(*args)
109
- self.exec("ps", *args).split("\n")
109
+ self.exec("lxc-ps", *args).split("\n")
110
110
  end
111
111
 
112
112
  # Linux container version
@@ -116,7 +116,7 @@ class LXC
116
116
  # @param [Array] args Additional command-line arguments.
117
117
  # @return [String] The installed version of LXC.
118
118
  def version(*args)
119
- result = self.exec("version", *args).scan(REGEX_VERSION)
119
+ result = self.exec("lxc-version", *args).scan(REGEX_VERSION)
120
120
  result.flatten!.compact!
121
121
 
122
122
  result.first.strip
@@ -129,7 +129,7 @@ class LXC
129
129
  # @param [Array] args Additional command-line arguments.
130
130
  # @return [Array<String>] Output text of the "lxc-checkconfig" command.
131
131
  def checkconfig(*args)
132
- self.exec("checkconfig", *args, " | #{SED_REMOVE_ANSI}").split("\n")
132
+ self.exec("lxc-checkconfig", *args, " | #{SED_REMOVE_ANSI}").split("\n")
133
133
  end
134
134
 
135
135
  # Linux container command execution wrapper
@@ -142,17 +142,15 @@ class LXC
142
142
  # If use_ssh is non-nil then all commands will be execute via the assigned
143
143
  # Net::SSH Session.
144
144
  #
145
- # No internal checking is performed against the object assigned to use_ssh as
146
- # to avoid an un-necessary direct dependency on the net-ssh gems.
147
- #
148
145
  # @param [Array] args Additional command-line arguments.
149
146
  # @return [Array<String>] Stripped output text of the executed command.
150
147
  def exec(*args)
151
148
  command = args.shift
152
149
 
153
150
  arguments = Array.new
154
- arguments << "sudo" if (@use_sudo == true)
155
- arguments << "lxc-#{command}"
151
+ arguments << %(sudo) if (@use_sudo == true)
152
+ arguments << %(DEBIAN_FRONTEND="noninteractive")
153
+ arguments << command
156
154
  arguments << args
157
155
  arguments = arguments.flatten.compact.join(' ')
158
156
 
@@ -165,7 +163,11 @@ class LXC
165
163
  end
166
164
  end
167
165
  else
168
- output << @use_ssh.exec!(arguments)
166
+ if @use_ssh.respond_to?(:exec!)
167
+ output << @use_ssh.exec!(arguments)
168
+ else
169
+ raise Error, "The object you assigned to use_ssh does not respond to #exec!"
170
+ end
169
171
  end
170
172
 
171
173
  output.join.strip
@@ -70,6 +70,26 @@ class LXC
70
70
  @name = name
71
71
  end
72
72
 
73
+ # Create the container
74
+ #
75
+ # Runs the "lxc-create" command.
76
+ #
77
+ # @param [Array] args Additional command-line arguments.
78
+ def create(*args)
79
+ self.exec("lxc-create", *args)
80
+ self.state
81
+ end
82
+
83
+ # Destroy the container
84
+ #
85
+ # Stops the container, then runs the "lxc-destroy" command.
86
+ #
87
+ # @param [Array] args Additional command-line arguments.
88
+ def destroy(*args)
89
+ self.stop
90
+ self.exec("lxc-destroy", *args)
91
+ end
92
+
73
93
  # Start the container
74
94
  #
75
95
  # Runs the "lxc-start" command with the "--daemon" flag.
@@ -77,7 +97,7 @@ class LXC
77
97
  # @param [Array] args Additional command-line arguments.
78
98
  # @return [Symbol] The state of the container.
79
99
  def start(*args)
80
- self.exec("start", "--daemon", *args)
100
+ self.exec("lxc-start", "--daemon", *args)
81
101
  self.state
82
102
  end
83
103
 
@@ -88,7 +108,7 @@ class LXC
88
108
  # @param [Array] args Additional command-line arguments.
89
109
  # @return [Symbol] The state of the container.
90
110
  def stop(*args)
91
- self.exec("stop", *args)
111
+ self.exec("lxc-stop", *args)
92
112
  self.state
93
113
  end
94
114
 
@@ -106,7 +126,7 @@ class LXC
106
126
  # @param [Array] args Additional command-line arguments.
107
127
  # @return [Symbol] The state of the container.
108
128
  def freeze(*args)
109
- self.exec("freeze", *args)
129
+ self.exec("lxc-freeze", *args)
110
130
  self.state
111
131
  end
112
132
 
@@ -117,7 +137,7 @@ class LXC
117
137
  # @param [Array] args Additional command-line arguments.
118
138
  # @return [Symbol] The state of the container.
119
139
  def unfreeze(*args)
120
- self.exec("unfreeze", *args)
140
+ self.exec("lxc-unfreeze", *args)
121
141
  self.state
122
142
  end
123
143
 
@@ -128,7 +148,7 @@ class LXC
128
148
  # @param [Array] args Additional command-line arguments.
129
149
  # @return [Array] Lines of output from the executed command.
130
150
  def info(*args)
131
- self.exec("info", *args).split("\n").uniq.flatten
151
+ self.exec("lxc-info", *args).split("\n").uniq.flatten
132
152
  end
133
153
 
134
154
  # State of the container
@@ -181,13 +201,13 @@ class LXC
181
201
 
182
202
  begin
183
203
  Timeout::timeout(timeout) do
184
- self.exec("wait", "-s", %('#{state_arg}'))
204
+ self.exec("lxc-wait", "-s", %('#{state_arg}'))
185
205
  end
186
206
  rescue Timeout::Error => e
187
207
  return false
188
208
  end
189
209
 
190
- return true
210
+ true
191
211
  end
192
212
 
193
213
  # Linux container command execution wrapper
@@ -203,7 +223,7 @@ class LXC
203
223
  def exec(*args)
204
224
  arguments = Array.new
205
225
  arguments << args.shift
206
- arguments << "--name=#{self.name}"
226
+ arguments << %(--name=#{self.name})
207
227
  arguments << args
208
228
  arguments.flatten!.compact!
209
229
 
@@ -2,7 +2,7 @@ class LXC
2
2
 
3
3
  unless const_defined?(:VERSION)
4
4
  # LXC Gem Version
5
- VERSION = "0.0.3"
5
+ VERSION = "0.0.4"
6
6
  end
7
7
 
8
8
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: lxc
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.3
5
+ version: 0.0.4
6
6
  platform: ruby
7
7
  authors:
8
8
  - Zachary Patten
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2013-04-13 00:00:00 Z
13
+ date: 2013-04-14 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ztk
@@ -148,7 +148,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
148
148
  requirements:
149
149
  - - ">="
150
150
  - !ruby/object:Gem::Version
151
- hash: 3183710469568139405
151
+ hash: 4075966732520277240
152
152
  segments:
153
153
  - 0
154
154
  version: "0"
@@ -157,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
157
157
  requirements:
158
158
  - - ">="
159
159
  - !ruby/object:Gem::Version
160
- hash: 3183710469568139405
160
+ hash: 4075966732520277240
161
161
  segments:
162
162
  - 0
163
163
  version: "0"