lxc 0.0.9 → 0.1.0
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/README.md +50 -0
- data/lib/lxc/container.rb +9 -6
- data/lib/lxc/version.rb +1 -1
- data/lib/lxc.rb +7 -2
- data/spec/lxc/container_spec.rb +1 -1
- metadata +3 -3
data/README.md
CHANGED
@@ -8,6 +8,56 @@
|
|
8
8
|
|
9
9
|
An interface for controlling local or remote Linux Containers (LXC).
|
10
10
|
|
11
|
+
# EXAMPLES
|
12
|
+
|
13
|
+
|
14
|
+
Given the following code:
|
15
|
+
|
16
|
+
require 'lxc'
|
17
|
+
|
18
|
+
lxc = LXC.new(:use_sudo => true)
|
19
|
+
lxc.use_sudo = true
|
20
|
+
lxc.version
|
21
|
+
c = LXC::Container.new(:lxc => lxc, :name => 'test')
|
22
|
+
c.running?
|
23
|
+
c.exists?
|
24
|
+
|
25
|
+
Executed via the lxc-console development binary:
|
26
|
+
|
27
|
+
$ be ./bin/lxc-console
|
28
|
+
|
29
|
+
From: /home/zpatten/Dropbox/code/personal/testlab-repo/vendor/checkouts/lxc/bin/lxc-console @ line 12 Object#lxc_console:
|
30
|
+
|
31
|
+
3: def lxc_console
|
32
|
+
4: require 'pry'
|
33
|
+
5: require 'lxc'
|
34
|
+
6:
|
35
|
+
7: ##
|
36
|
+
8: #
|
37
|
+
9: # Welcome to the LXC RubyGem console!
|
38
|
+
10: #
|
39
|
+
11: ##
|
40
|
+
=> 12: binding.pry
|
41
|
+
13: end
|
42
|
+
|
43
|
+
[1] pry(main)> require 'lxc'
|
44
|
+
=> false
|
45
|
+
[2] pry(main)>
|
46
|
+
[3] pry(main)> lxc = LXC.new(:use_sudo => true)
|
47
|
+
=> #<LXC use_sudo=true use_ssh=false>
|
48
|
+
[4] pry(main)> lxc.use_sudo = true
|
49
|
+
=> true
|
50
|
+
[5] pry(main)> lxc.version
|
51
|
+
=> "0.8.0-rc2"
|
52
|
+
[6] pry(main)> c = LXC::Container.new(:lxc => lxc, :name => 'test')
|
53
|
+
=> #<LXC::Container name="test">
|
54
|
+
[7] pry(main)> c.running?
|
55
|
+
=> false
|
56
|
+
[8] pry(main)> c.exists?
|
57
|
+
=> false
|
58
|
+
[9] pry(main)>
|
59
|
+
|
60
|
+
|
11
61
|
# RESOURCES
|
12
62
|
|
13
63
|
Documentation:
|
data/lib/lxc/container.rb
CHANGED
@@ -64,12 +64,15 @@ class LXC
|
|
64
64
|
# @return [String] Container name
|
65
65
|
attr_reader :name
|
66
66
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
@lxc = lxc
|
72
|
-
@name = name
|
67
|
+
# @param [Hash] options Options hash.
|
68
|
+
# @option options [LXC] :lxc Our parent LXC class instance.
|
69
|
+
# @option options [String] :name The name of the container.
|
70
|
+
def initialize(options={})
|
71
|
+
@lxc = options[:lxc]
|
72
|
+
@name = options[:name]
|
73
|
+
|
74
|
+
raise ContainerError, "You must supply a LXC object!" if @lxc.nil?
|
75
|
+
raise ContainerError, "You must supply a container name!" if (@name.nil? || @name.empty?)
|
73
76
|
end
|
74
77
|
|
75
78
|
# LXC configuration class
|
data/lib/lxc/version.rb
CHANGED
data/lib/lxc.rb
CHANGED
@@ -51,6 +51,11 @@ class LXC
|
|
51
51
|
# @see http://www.commandlinefu.com/commands/view/3584/remove-color-codes-special-characters-with-sed CommandLineFu - Remove Color Codes (Special Characters) with SED
|
52
52
|
SED_REMOVE_ANSI = %q(sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")
|
53
53
|
|
54
|
+
# @param [Hash] options Options hash.
|
55
|
+
# @option options [Boolean] :use_sudo (false) Whether or not to prefix all
|
56
|
+
# commands with 'sudo'.
|
57
|
+
# @option options [Net::SSH,ZTK::SSH,nil] :use_ssh (nil) Whether or not to
|
58
|
+
# execute all commands remotely via an SSH connection.
|
54
59
|
def initialize(options={})
|
55
60
|
@ui = (options[:ui] || ZTK::UI.new)
|
56
61
|
@use_sudo = (options[:use_sudo] || false)
|
@@ -73,7 +78,7 @@ class LXC
|
|
73
78
|
# @param [String] name The container name to initalize.
|
74
79
|
# @return [LXC::Container] Returns the container object.
|
75
80
|
def container(name)
|
76
|
-
LXC::Container.new(self, name)
|
81
|
+
LXC::Container.new(:lxc => self, :name => name)
|
77
82
|
end
|
78
83
|
|
79
84
|
# Current containers
|
@@ -85,7 +90,7 @@ class LXC
|
|
85
90
|
def containers
|
86
91
|
container_names = self.ls
|
87
92
|
container_names.map do |container_name|
|
88
|
-
LXC::Container.new(self, container_name)
|
93
|
+
LXC::Container.new(:lxc => self, :name => container_name)
|
89
94
|
end
|
90
95
|
end
|
91
96
|
|
data/spec/lxc/container_spec.rb
CHANGED
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.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -182,7 +182,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
182
|
version: '0'
|
183
183
|
segments:
|
184
184
|
- 0
|
185
|
-
hash:
|
185
|
+
hash: 574706320060241310
|
186
186
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
187
187
|
none: false
|
188
188
|
requirements:
|
@@ -191,7 +191,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
version: '0'
|
192
192
|
segments:
|
193
193
|
- 0
|
194
|
-
hash:
|
194
|
+
hash: 574706320060241310
|
195
195
|
requirements: []
|
196
196
|
rubyforge_project:
|
197
197
|
rubygems_version: 1.8.25
|